Эх сурвалжийг харах

Further work on #237

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 жил өмнө
parent
commit
257d3104b2

+ 15 - 9
app/src/main/java/com/nextcloud/talk/receivers/PackageReplacedReceiver.java

@@ -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);
+                            notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_CALLS);
+                            notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES);
 
-                        appPreferences.setNotificationChannelIsUpgradedToV2(true);
+                            appPreferences.setNotificationChannelIsUpgradedToV2(true);
+                        }
+
+                        if (!appPreferences.getIsMessagesNotificationChannelUpgradedToV3() && packageInfo.versionCode > 51) {
+                            notificationManager.deleteNotificationChannel(NotificationUtils.NOTIFICATION_CHANNEL_MESSAGES_V2);
+                            appPreferences.setNotificationChannelIsUpgradedToV2(true);
+                        }
                     }
 
                 }

+ 10 - 0
app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java

@@ -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();
 }