Skip to content

Commit 28dac77

Browse files
committed
Code review comment updates
1 parent 9ad8e09 commit 28dac77

File tree

8 files changed

+36
-36
lines changed

8 files changed

+36
-36
lines changed

Examples/OneSignalDemo/app/src/huawei/java/com/onesignal/sdktest/notification/HmsMessageServiceAppLevel.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.huawei.hms.push.HmsMessageService;
77
import com.huawei.hms.push.RemoteMessage;
88
import com.onesignal.notifications.bridges.OneSignalHmsEventBridge;
9+
import com.onesignal.sdktest.constant.Tag;
910

1011
public class HmsMessageServiceAppLevel extends HmsMessageService {
1112

@@ -19,7 +20,7 @@ public class HmsMessageServiceAppLevel extends HmsMessageService {
1920
*/
2021
@Override
2122
public void onNewToken(String token, Bundle bundle) {
22-
Log.d("MainApplication", "HmsMessageServiceAppLevel onNewToken refresh token:" + token + " bundle: " + bundle);
23+
Log.d(Tag.LOG_TAG, "HmsMessageServiceAppLevel onNewToken refresh token:" + token + " bundle: " + bundle);
2324

2425
// Forward event on to OneSignal SDK
2526
OneSignalHmsEventBridge.INSTANCE.onNewToken(this, token, bundle);
@@ -28,7 +29,7 @@ public void onNewToken(String token, Bundle bundle) {
2829
@Deprecated
2930
@Override
3031
public void onNewToken(String token) {
31-
Log.d("MainApplication", "HmsMessageServiceAppLevel onNewToken refresh token:" + token);
32+
Log.d(Tag.LOG_TAG, "HmsMessageServiceAppLevel onNewToken refresh token:" + token);
3233

3334
// Forward event on to OneSignal SDK
3435
OneSignalHmsEventBridge.INSTANCE.onNewToken(this, token);
@@ -44,16 +45,16 @@ public void onNewToken(String token) {
4445
*/
4546
@Override
4647
public void onMessageReceived(RemoteMessage message) {
47-
Log.d("MainApplication", "HMS onMessageReceived: " + message);
48-
Log.d("MainApplication", "HMS onMessageReceived.ttl:" + message.getTtl());
49-
Log.d("MainApplication", "HMS onMessageReceived.data:" + message.getData());
50-
Log.d("MainApplication", "HMS onMessageReceived.title: " + message.getNotification().getTitle());
51-
Log.d("MainApplication", "HMS onMessageReceived.body: " + message.getNotification().getBody());
52-
Log.d("MainApplication", "HMS onMessageReceived.icon: " + message.getNotification().getIcon());
53-
Log.d("MainApplication", "HMS onMessageReceived.color: " + message.getNotification().getColor());
54-
Log.d("MainApplication", "HMS onMessageReceived.channelId: " + message.getNotification().getChannelId());
55-
Log.d("MainApplication", "HMS onMessageReceived.imageURL: " + message.getNotification().getImageUrl());
56-
Log.d("MainApplication", "HMS onMessageReceived.tag: " + message.getNotification().getTag());
48+
Log.d(Tag.LOG_TAG, "HMS onMessageReceived: " + message);
49+
Log.d(Tag.LOG_TAG, "HMS onMessageReceived.ttl:" + message.getTtl());
50+
Log.d(Tag.LOG_TAG, "HMS onMessageReceived.data:" + message.getData());
51+
Log.d(Tag.LOG_TAG, "HMS onMessageReceived.title: " + message.getNotification().getTitle());
52+
Log.d(Tag.LOG_TAG, "HMS onMessageReceived.body: " + message.getNotification().getBody());
53+
Log.d(Tag.LOG_TAG, "HMS onMessageReceived.icon: " + message.getNotification().getIcon());
54+
Log.d(Tag.LOG_TAG, "HMS onMessageReceived.color: " + message.getNotification().getColor());
55+
Log.d(Tag.LOG_TAG, "HMS onMessageReceived.channelId: " + message.getNotification().getChannelId());
56+
Log.d(Tag.LOG_TAG, "HMS onMessageReceived.imageURL: " + message.getNotification().getImageUrl());
57+
Log.d(Tag.LOG_TAG, "HMS onMessageReceived.tag: " + message.getNotification().getTag());
5758

5859
// Forward event on to OneSignal SDK
5960
OneSignalHmsEventBridge.INSTANCE.onMessageReceived(this, message);

Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/application/MainApplication.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.json.JSONObject;
2727

2828
public class MainApplication extends MultiDexApplication {
29+
private static final int SLEEP_TIME_TO_MIMIC_ASYNC_OPERATION = 2000;
2930

3031
public MainApplication() {
3132
// run strict mode default in debug mode to surface any potential issues easier
@@ -52,42 +53,42 @@ public void onCreate() {
5253
OneSignal.getInAppMessages().setInAppMessageLifecycleHandler(new IInAppMessageLifecycleHandler() {
5354
@Override
5455
public void onWillDisplayInAppMessage(@NonNull IInAppMessage message) {
55-
Log.v("MainApplication", "onWillDisplayInAppMessage");
56+
Log.v(Tag.LOG_TAG, "onWillDisplayInAppMessage");
5657
}
5758

5859
@Override
5960
public void onDidDisplayInAppMessage(@NonNull IInAppMessage message) {
60-
Log.v("MainApplication", "onDidDisplayInAppMessage");
61+
Log.v(Tag.LOG_TAG, "onDidDisplayInAppMessage");
6162
}
6263

6364
@Override
6465
public void onWillDismissInAppMessage(@NonNull IInAppMessage message) {
65-
Log.v("MainApplication", "onWillDismissInAppMessage");
66+
Log.v(Tag.LOG_TAG, "onWillDismissInAppMessage");
6667
}
6768

6869
@Override
6970
public void onDidDismissInAppMessage(@NonNull IInAppMessage message) {
70-
Log.v("MainApplication", "onDidDismissInAppMessage");
71+
Log.v(Tag.LOG_TAG, "onDidDismissInAppMessage");
7172
}
7273
});
7374

7475
OneSignal.getInAppMessages().setInAppMessageClickHandler(new IInAppMessageClickHandler() {
7576
@Override
7677
public void inAppMessageClicked(@Nullable IInAppMessageClickResult result) {
77-
Log.v("MainApplication", "inAppMessageClicked");
78+
Log.v(Tag.LOG_TAG, "INotificationClickListener.inAppMessageClicked");
7879
}
7980
});
8081

8182
OneSignal.getNotifications().addClickListener(event ->
8283
{
83-
Log.v("MainApplication", "INotificationClickListener.onClick fired!" +
84+
Log.v(Tag.LOG_TAG, "INotificationClickListener.onClick fired" +
8485
" with event: " + event);
8586
});
8687

8788
OneSignal.getNotifications().addForegroundLifecycleListener(new INotificationLifecycleListener() {
8889
@Override
8990
public void onWillDisplay(@NonNull INotificationWillDisplayEvent event) {
90-
Log.v("MainApplication", "INotificationLifecycleListener.onWillDisplay fired!" +
91+
Log.v(Tag.LOG_TAG, "INotificationLifecycleListener.onWillDisplay fired" +
9192
" with event: " + event);
9293

9394
IDisplayableNotification notification = event.getNotification();
@@ -99,9 +100,8 @@ public void onWillDisplay(@NonNull INotificationWillDisplayEvent event) {
99100
event.preventDefault();
100101
Runnable r = () -> {
101102
try {
102-
Thread.sleep(2000);
103-
} catch (InterruptedException e) {
104-
e.printStackTrace();
103+
Thread.sleep(SLEEP_TIME_TO_MIMIC_ASYNC_OPERATION);
104+
} catch (InterruptedException ignored) {
105105
}
106106

107107
notification.display();
@@ -115,7 +115,7 @@ public void onWillDisplay(@NonNull INotificationWillDisplayEvent event) {
115115
OneSignal.getInAppMessages().setPaused(true);
116116
OneSignal.getLocation().setShared(false);
117117

118-
Log.d(Tag.DEBUG, Text.ONESIGNAL_SDK_INIT);
118+
Log.d(Tag.LOG_TAG, Text.ONESIGNAL_SDK_INIT);
119119
}
120120

121121
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.onesignal.sdktest.constant;
22

33
public class Tag {
4-
5-
public static final String DEBUG = "DEBUG";
6-
public static final String ERROR = "ERROR";
7-
4+
public static final String LOG_TAG = "sdktest";
85
}

Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/SplashActivityViewModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private void setupOneSignalSDK() {
7171
boolean isInAppMessagingPaused = SharedPreferenceUtil.getCachedInAppMessagingPausedStatus(context);
7272
OneSignal.getInAppMessages().setPaused(isInAppMessagingPaused);
7373

74-
Log.d(Tag.DEBUG, Text.PRIVACY_CONSENT_REQUIRED_SET + ": " + privacyConsent);
74+
Log.d(Tag.LOG_TAG, Text.PRIVACY_CONSENT_REQUIRED_SET + ": " + privacyConsent);
7575

7676
// boolean isEmailCached = attemptSignIn(new EmailUpdateCallback() {
7777
// @Override

Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/notification/NotificationServiceExtension.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
import com.onesignal.notifications.INotificationReceivedEvent;
88
import com.onesignal.notifications.INotificationServiceExtension;
99
import com.onesignal.sdktest.R;
10+
import com.onesignal.sdktest.constant.Tag;
1011

1112
public class NotificationServiceExtension implements INotificationServiceExtension {
1213

1314
@Override
1415
public void onNotificationReceived(INotificationReceivedEvent event) {
15-
Log.v("MainApplication", "IRemoteNotificationReceivedHandler fired!" + " with INotificationReceivedEvent: " + event.toString());
16+
Log.v(Tag.LOG_TAG, "IRemoteNotificationReceivedHandler fired" + " with INotificationReceivedEvent: " + event.toString());
1617

1718
IDisplayableMutableNotification notification = event.getNotification();
1819

1920
if (notification.getActionButtons() != null) {
2021
for (IActionButton button : notification.getActionButtons()) {
21-
Log.v("MainApplication", "ActionButton: " + button.toString());
22+
Log.v(Tag.LOG_TAG, "ActionButton: " + button.toString());
2223
}
2324
}
2425

Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/notification/OneSignalNotificationSender.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static void sendDeviceNotification(final Notification notification) {
7777
if (scanner.useDelimiter("\\A").hasNext())
7878
responseStr = scanner.next();
7979
scanner.close();
80-
Log.d(Tag.DEBUG, "Success sending notification: " + responseStr);
80+
Log.d(Tag.LOG_TAG, "Success sending notification: " + responseStr);
8181
}
8282
else {
8383
InputStream inputStream = con.getErrorStream();
@@ -86,7 +86,7 @@ public static void sendDeviceNotification(final Notification notification) {
8686
if (scanner.useDelimiter("\\A").hasNext())
8787
responseStr = scanner.next();
8888
scanner.close();
89-
Log.d(Tag.ERROR, "Failure sending notification: " + responseStr);
89+
Log.d(Tag.LOG_TAG, "Failure sending notification: " + responseStr);
9090
}
9191
}
9292
} catch (Exception e) {

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/notifications/INotificationLifecycleListener.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ interface INotificationLifecycleListener {
1414
* gives the implementor the ability to prevent the notification from displaying to the
1515
* user.
1616
*
17-
* *Note:* this runs after the Notification Service Extension [INotificationServiceExtension]
18-
* has been called (if one exists), which has the following differences:
17+
* *Note:* If a Notification Service Extension [INotificationServiceExtension] exists,
18+
* [onWillDisplay] will run after the extension is called, which has the following differences:
1919
*
2020
* 1. The [INotificationServiceExtension] is configured within your `AndroidManifest.xml`.
2121
* 2. The [INotificationServiceExtension] will be called regardless of the state of your

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/notifications/INotificationReceivedEvent.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import android.content.Context
2121
* thread {
2222
* // do something async
2323
*
24-
* // optionally, change the display
24+
* // optionally, change the display using a native Android Extender
2525
* event.notification.setExtender(androidx.core.app.NotificationCompat.Extender {
26-
* // alter the notification
26+
* // alter the notification, for example to change the title
27+
* it.setContentTitle("CUSTOM TITLE")
2728
* })
2829
*
2930
* // optionally, display the notification manually

0 commit comments

Comments
 (0)