From 1ef9491336da6648fe9285e15e144e946e02cc81 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 26 Apr 2022 16:09:14 +0200 Subject: [PATCH] Make notification for Quota 99+ unremovable. Automatically cancel all notif if quota is becoming lower than 80% --- .../e/drive/work/AccountUserInfoWorker.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java b/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java index 26be1483..7690fd58 100644 --- a/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java +++ b/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java @@ -117,12 +117,15 @@ public class AccountUserInfoWorker extends Worker { private void addNotifAboutQuota(final double relativeQuota) { final Context context = getApplicationContext(); + final NotificationManager manager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); if (relativeQuota >= 99.0) { - addNotification(context.getString(R.string.notif_quota_99Plus_title), context.getString(R.string.notif_quota_99Plus_text)); + addNotification(manager, context.getString(R.string.notif_quota_99Plus_title), context.getString(R.string.notif_quota_99Plus_text), true); } else if (relativeQuota >= 90.0) { - addNotification(context.getString(R.string.notif_quota_80plus_title), context.getString(R.string.notif_quota_90Plus_text)); + addNotification(manager, context.getString(R.string.notif_quota_80plus_title), context.getString(R.string.notif_quota_90Plus_text), false); } else if (relativeQuota >= 80.0) { - addNotification(context.getString(R.string.notif_quota_80plus_title), context.getString(R.string.notif_quota_80Plus_text)); + addNotification(manager, context.getString(R.string.notif_quota_80plus_title), context.getString(R.string.notif_quota_80Plus_text), false); + } else { + manager.cancelAll(); } } @@ -133,15 +136,15 @@ public class AccountUserInfoWorker extends Worker { * - make message & title to be a parameter of the method, so we could reuse the function somewhere * - else with different notification. File conflict for example. **/ - private void addNotification(String title, String text) { + private void addNotification(NotificationManager manager, String title, String text, boolean isOnGoing) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), AppConstants.notificationChannelID) .setSmallIcon(android.R.drawable.stat_sys_warning) .setContentTitle(title) .setContentText(text) + .setOngoing(isOnGoing) .setStyle(new NotificationCompat.BigTextStyle().bigText(text)); // Add as notification - final NotificationManager manager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(0, builder.build()); } -- GitLab