Further work on #237

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-07-26 22:50:17 +02:00
parent 58cfcdeb00
commit 257d3104b2
2 changed files with 25 additions and 9 deletions

View File

@ -53,7 +53,7 @@ public class PackageReplacedReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
if (!appPreferences.getIsNotificationChannelUpgradedToV2() && intent != null && intent.getAction() != null &&
if (intent != null && intent.getAction() != null &&
intent.getAction().equals("android.intent.action.MY_PACKAGE_REPLACED")) {
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
@ -62,17 +62,23 @@ public class PackageReplacedReceiver extends BroadcastReceiver {
(NotificationManager) context.getSystemService(Context
.NOTIFICATION_SERVICE);
if (notificationManager != null) {
for (NotificationChannelGroup notificationChannelGroup : notificationManager
.getNotificationChannelGroups()) {
notificationManager.deleteNotificationChannelGroup(notificationChannelGroup.getId());
if (!appPreferences.getIsNotificationChannelUpgradedToV2()) {
for (NotificationChannelGroup notificationChannelGroup : notificationManager
.getNotificationChannelGroups()) {
notificationManager.deleteNotificationChannelGroup(notificationChannelGroup.getId());
}
notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_CALLS);
notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES);
appPreferences.setNotificationChannelIsUpgradedToV2(true);
}
notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_CALLS);
notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES);
appPreferences.setNotificationChannelIsUpgradedToV2(true);
if (!appPreferences.getIsMessagesNotificationChannelUpgradedToV3() && packageInfo.versionCode > 51) {
notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES_V2);
appPreferences.setNotificationChannelIsUpgradedToV2(true);
}
}
}

View File

@ -168,6 +168,16 @@ public interface AppPreferences {
@RemoveMethod
void removeNotificationChannelUpgradeToV2();
@KeyByString("messages_notification_channel_upgrade_to_v3")
boolean getIsMessagesNotificationChannelUpgradedToV3();
@KeyByString("messages_notification_channel_upgrade_to_v3")
void setMessagesNotificationChannelIsUpgradedToV3(boolean value);
@KeyByString("messages_notification_channel_upgrade_to_v3")
@RemoveMethod
void removeMessagesNotificationChannelUpgradeToV3();
@ClearMethod
void clear();
}