1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2024-12-12 15:39:49 +01:00

add an option to clean notification channels

This commit is contained in:
luvletter2333 2021-10-18 01:30:38 +08:00
parent c85b411a3e
commit 9c31adf0db
No known key found for this signature in database
GPG Key ID: BFD68B892BECC1D8
2 changed files with 45 additions and 1 deletions

View File

@ -324,6 +324,47 @@ public class NotificationsController extends BaseController {
});
}
public void cleanupNotificationChannels() {
notificationsQueue.postRunnable(() -> {
if (Build.VERSION.SDK_INT >= 26) {
try {
String keyStart = currentAccount + "channel";
List<NotificationChannel> list = systemNotificationManager.getNotificationChannels();
int count = list.size();
for (int a = 0; a < count; a++) {
NotificationChannel channel = list.get(a);
String id = channel.getId();
if (id.startsWith(keyStart)) {
try {
systemNotificationManager.deleteNotificationChannel(id);
} catch (Exception e) {
FileLog.e(e);
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("delete channel cleanup " + id);
}
}
}
} catch (Throwable e) {
FileLog.e(e);
}
// Remove shits from 0552bcdc
try {
String keyGroup = currentAccount + "group";
List<NotificationChannelGroup> list = systemNotificationManager.getNotificationChannelGroups();
for (NotificationChannelGroup group : list) {
String id = group.getId();
if (id.equals(keyGroup)) {
systemNotificationManager.deleteNotificationChannelGroup(id);
}
}
} catch (Throwable e) {
FileLog.e(e);
}
}
});
}
public void setInChatSoundEnabled(boolean value) {
inChatSoundEnabled = value;
}

View File

@ -3061,6 +3061,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
"Scan accounts",
BuildVars.DEBUG_PRIVATE_VERSION ? "Clean app update" : null,
BuildVars.DEBUG_PRIVATE_VERSION ? "Reset suggestions" : null,
"Reset all notification channels",
};
builder.setItems(items, (dialog, which) -> {
if (which == 0) {
@ -3151,11 +3152,13 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
SharedConfig.pendingAppUpdate = null;
SharedConfig.saveConfig();
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.appUpdateAvailable);
} else if (which == 16) {
} else if (which == 17) {
Set<String> suggestions = getMessagesController().pendingSuggestions;
suggestions.add("VALIDATE_PHONE_NUMBER");
suggestions.add("VALIDATE_PASSWORD");
getNotificationCenter().postNotificationName(NotificationCenter.newSuggestionsAvailable);
} else if (which == 18) {
getNotificationsController().cleanupNotificationChannels();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);