Skip to content

Commit 63ec3ca

Browse files
authored
Init (wix#920)
1 parent 8fb981a commit 63ec3ca

File tree

5 files changed

+17
-98
lines changed

5 files changed

+17
-98
lines changed

lib/android/app/src/main/AndroidManifest.xml

-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
package="com.wix.reactnativenotifications">
55

66
<application>
7-
8-
<!--
9-
A proxy-service that gives the library an opportunity to do some work before launching/resuming the actual application task.
10-
-->
11-
<service android:name=".core.ProxyService"/>
12-
137
<service
148
android:name=".fcm.FcmInstanceIdListenerService"
159
android:exported="true">

lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java

+9-17
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.wix.reactnativenotifications.core.NotificationIntentAdapter;
1818
import com.wix.reactnativenotifications.core.notification.IPushNotification;
1919
import com.wix.reactnativenotifications.core.notification.PushNotification;
20+
import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
2021
import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer;
2122
import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer;
2223

@@ -61,14 +62,18 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
6162
final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(mApplication.getApplicationContext());
6263
notificationsDrawer.onNewActivity(activity);
6364

64-
callOnOpenedIfNeed(activity);
65+
Intent intent = activity.getIntent();
66+
if (NotificationIntentAdapter.canHandleIntent(intent)) {
67+
Bundle notificationData = intent.getExtras();
68+
final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData);
69+
if (pushNotification != null) {
70+
pushNotification.onOpened();
71+
}
72+
}
6573
}
6674

6775
@Override
6876
public void onActivityStarted(Activity activity) {
69-
if (InitialNotificationHolder.getInstance().get() == null) {
70-
callOnOpenedIfNeed(activity);
71-
}
7277
}
7378

7479
@Override
@@ -90,17 +95,4 @@ public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
9095
@Override
9196
public void onActivityDestroyed(Activity activity) {
9297
}
93-
94-
private void callOnOpenedIfNeed(Activity activity) {
95-
Intent intent = activity.getIntent();
96-
if (NotificationIntentAdapter.canHandleIntent(intent)) {
97-
Context appContext = mApplication.getApplicationContext();
98-
Bundle notificationData = NotificationIntentAdapter.canHandleTrampolineActivity(appContext) ?
99-
intent.getExtras() : NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent);
100-
final IPushNotification pushNotification = PushNotification.get(appContext, notificationData);
101-
if (pushNotification != null) {
102-
pushNotification.onOpened();
103-
}
104-
}
105-
}
10698
}

lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java

+6-20
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,26 @@
11
package com.wix.reactnativenotifications.core;
22

3-
import android.annotation.SuppressLint;
43
import android.app.PendingIntent;
5-
import android.app.TaskStackBuilder;
64
import android.content.Context;
75
import android.content.Intent;
6+
import android.os.Build;
87
import android.os.Bundle;
98

109
import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
1110

1211
public class NotificationIntentAdapter {
1312
private static final String PUSH_NOTIFICATION_EXTRA_NAME = "pushNotification";
1413

15-
@SuppressLint("UnspecifiedImmutableFlag")
1614
public static PendingIntent createPendingNotificationIntent(Context appContext, PushNotificationProps notification) {
17-
if (canHandleTrampolineActivity(appContext)) {
18-
Intent intent = new Intent(appContext, ProxyService.class);
19-
intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
20-
return PendingIntent.getService(appContext, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_ONE_SHOT);
15+
Intent intent = new AppLaunchHelper().getLaunchIntent(appContext);
16+
intent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
17+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
18+
return PendingIntent.getActivity(appContext, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
2119
} else {
22-
Intent mainActivityIntent = appContext.getPackageManager().getLaunchIntentForPackage(appContext.getPackageName());
23-
mainActivityIntent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, notification.asBundle());
24-
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(appContext);
25-
taskStackBuilder.addNextIntentWithParentStack(mainActivityIntent);
26-
return taskStackBuilder.getPendingIntent((int) System.currentTimeMillis(), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
20+
return PendingIntent.getActivity(appContext, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_ONE_SHOT);
2721
}
2822
}
2923

30-
public static boolean canHandleTrampolineActivity(Context appContext) {
31-
return android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.R || appContext.getApplicationInfo().targetSdkVersion < 31;
32-
}
33-
34-
public static Bundle extractPendingNotificationDataFromIntent(Intent intent) {
35-
return intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME);
36-
}
37-
3824
public static boolean canHandleIntent(Intent intent) {
3925
if (intent != null) {
4026
Bundle notificationData = intent.getExtras();

lib/android/app/src/main/java/com/wix/reactnativenotifications/core/ProxyService.java

-29
This file was deleted.

lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java

+2-26
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,16 @@ protected int postNotification(Integer notificationId) {
9797
protected void digestNotification() {
9898
if (!mAppLifecycleFacade.isReactInitialized()) {
9999
setAsInitialNotification();
100-
launchOrResumeApp();
101100
return;
102101
}
103102

104103
final ReactContext reactContext = mAppLifecycleFacade.getRunningReactContext();
105104
if (reactContext.getCurrentActivity() == null) {
106105
setAsInitialNotification();
106+
return;
107107
}
108108

109-
if (mAppLifecycleFacade.isAppVisible()) {
110-
dispatchImmediately();
111-
} else if (mAppLifecycleFacade.isAppDestroyed()) {
112-
launchOrResumeApp();
113-
} else {
114-
dispatchUponVisibility();
115-
}
109+
dispatchImmediately();
116110
}
117111

118112
protected PushNotificationProps createProps(Bundle bundle) {
@@ -127,17 +121,6 @@ protected void dispatchImmediately() {
127121
notifyOpenedToJS();
128122
}
129123

130-
protected void dispatchUponVisibility() {
131-
mAppLifecycleFacade.addVisibilityListener(getIntermediateAppVisibilityListener());
132-
133-
// Make the app visible so that we'll dispatch the notification opening when visibility changes to 'true' (see
134-
// above listener registration).
135-
launchOrResumeApp();
136-
}
137-
138-
protected AppVisibilityListener getIntermediateAppVisibilityListener() {
139-
return mAppVisibilityListener;
140-
}
141124

142125
protected Notification buildNotification(PendingIntent intent) {
143126
return getNotificationBuilder(intent).build();
@@ -212,13 +195,6 @@ private void notifyOpenedToJS() {
212195
mJsIOHelper.sendEventToJS(NOTIFICATION_OPENED_EVENT_NAME, response, mAppLifecycleFacade.getRunningReactContext());
213196
}
214197

215-
protected void launchOrResumeApp() {
216-
if (NotificationIntentAdapter.canHandleTrampolineActivity(mContext)) {
217-
final Intent intent = mAppLaunchHelper.getLaunchIntent(mContext);
218-
mContext.startActivity(intent);
219-
}
220-
}
221-
222198
private int getAppResourceId(String resName, String resType) {
223199
return mContext.getResources().getIdentifier(resName, resType, mContext.getPackageName());
224200
}

0 commit comments

Comments
 (0)