Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 083feb04 authored by Aayush Gupta's avatar Aayush Gupta
Browse files

Merge branch '176-o-make-unremovable-notification' into 'v1-oreo'

Make notification for Quota >= 99% unremovable.

See merge request !118
parents af22ba71 1ef94913
Loading
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -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());
    }