Skip to content

Commit 85e7ae5

Browse files
committed
Cosmetics and bug fix
1 parent 3a6ff18 commit 85e7ae5

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableNotificationHelper.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private void registerChannelIfEmpty(Context context, String channelId, String ch
270270
}
271271

272272
/**
273-
* Removes unused old channel if the configuration for notification badge is changed.
273+
* Safely removes unused and old channel if the configuration for notification badge is changed.
274274
*/
275275
private void removeUnusedChannel(Context context) {
276276
NotificationManager mNotificationManager = (NotificationManager)
@@ -310,23 +310,29 @@ private static boolean isNotificationBadgingEnabled(Context context) {
310310
return info.metaData.getBoolean(IterableConstants.NOTIFICAION_BADGING, true);
311311
}
312312
} catch (PackageManager.NameNotFoundException e) {
313-
IterableLogger.e(IterableNotificationBuilder.TAG, e.getLocalizedMessage() + " Defaulting the badging to true");
313+
IterableLogger.e(IterableNotificationBuilder.TAG, e.getLocalizedMessage() + " Failed to read notification badge settings. Setting to defaults - true");
314314
}
315315
return true;
316316
}
317317

318318
private String getChannelId(Context context) {
319-
getChannelIdName(context, !isNotificationBadgingEnabled(context))
319+
return getChannelIdName(context, true);
320320
}
321-
321+
322322
private String getOldChannelId(Context context) {
323-
getChannelIdName(context, isNotificationBadgingEnabled(context))
323+
return getChannelIdName(context, false);
324324
}
325-
326-
private String getChannelIdName(Context context, boolean badgingEnabled) {
325+
326+
private String getChannelIdName(Context context, boolean isActive) {
327327
String channelId = context.getPackageName();
328-
if (!isNotificationBadgingEnabled(context)) {
329-
channelId = channelId + NO_BADGE;
328+
if (isActive) {
329+
if (!isNotificationBadgingEnabled(context)) {
330+
channelId = channelId + NO_BADGE;
331+
}
332+
} else {
333+
if (isNotificationBadgingEnabled(context)) {
334+
channelId = channelId + NO_BADGE;
335+
}
330336
}
331337
return channelId;
332338
}

0 commit comments

Comments
 (0)