improve performance when clearing notifications (#1283)

This commit is contained in:
Konrad Pozniak 2019-05-26 08:45:25 +02:00 committed by GitHub
parent 7733e387ee
commit da1089184c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 6 deletions

View File

@ -65,6 +65,9 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import io.reactivex.Single;
import io.reactivex.schedulers.Schedulers;
public class NotificationHelper { public class NotificationHelper {
private static int notificationId = 0; private static int notificationId = 0;
@ -465,13 +468,18 @@ public class NotificationHelper {
public static void clearNotificationsForActiveAccount(@NonNull Context context, @NonNull AccountManager accountManager) { public static void clearNotificationsForActiveAccount(@NonNull Context context, @NonNull AccountManager accountManager) {
AccountEntity account = accountManager.getActiveAccount(); AccountEntity account = accountManager.getActiveAccount();
if (account != null) { if (account != null && !account.getActiveNotifications().equals("[]")) {
Single.fromCallable(() -> {
account.setActiveNotifications("[]"); account.setActiveNotifications("[]");
accountManager.saveAccount(account); accountManager.saveAccount(account);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//noinspection ConstantConditions //noinspection ConstantConditions
notificationManager.cancel((int) account.getId()); notificationManager.cancel((int) account.getId());
return true;
})
.subscribeOn(Schedulers.io())
.subscribe();
} }
} }