1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2024-12-02 21:20:10 +01:00

Add groups for notification channel

close #64
This commit is contained in:
NekoInverter 2020-04-17 12:29:08 +08:00
parent 6bba619de0
commit 4ab054520c
No known key found for this signature in database
GPG Key ID: 280D6CCCF95715F9

View File

@ -15,6 +15,7 @@ import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
@ -270,6 +271,18 @@ public class NotificationsController extends BaseController {
} catch (Throwable e) {
FileLog.e(e);
}
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);
}
}
});
}
@ -2449,6 +2462,11 @@ public class NotificationsController extends BaseController {
} else {
notificationChannel.setSound(null, builder.build());
}
TLRPC.User user = getUserConfig().getCurrentUser();
String keyGroup = currentAccount + "group";
NotificationChannelGroup notificationChannelGroup = new NotificationChannelGroup(keyGroup, UserObject.getUserName(user));
notificationChannel.setGroup(keyGroup);
systemNotificationManager.createNotificationChannelGroup(notificationChannelGroup);
systemNotificationManager.createNotificationChannel(notificationChannel);
preferences.edit().putString(key, channelId).putString(key + "_s", newSettingsHash).commit();
}