diff --git a/app/src/main/java/foundation/e/blisslauncher/BlissLauncher.java b/app/src/main/java/foundation/e/blisslauncher/BlissLauncher.java index 8141d07c65bc92786f55a3d45dc8694b36aae347..c808f8158c3333792d0deed7c4576598ce082850 100755 --- a/app/src/main/java/foundation/e/blisslauncher/BlissLauncher.java +++ b/app/src/main/java/foundation/e/blisslauncher/BlissLauncher.java @@ -2,15 +2,24 @@ package foundation.e.blisslauncher; import android.app.Application; import android.appwidget.AppWidgetManager; +import android.content.ComponentName; import android.content.Context; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.Handler; +import android.provider.Settings; import foundation.e.blisslauncher.core.DeviceProfile; import foundation.e.blisslauncher.core.IconsHandler; import foundation.e.blisslauncher.core.blur.BlurWallpaperProvider; import foundation.e.blisslauncher.core.customviews.WidgetHost; import foundation.e.blisslauncher.features.launcher.AppProvider; +import foundation.e.blisslauncher.features.notification.NotificationService; public class BlissLauncher extends Application { + public static final Uri NOTIFICATION_BADGING_URI = + Settings.Secure.getUriFor("notification_badging"); + private IconsHandler iconsPackHandler; private DeviceProfile deviceProfile; @@ -29,6 +38,24 @@ public class BlissLauncher extends Application { connectAppProvider(); BlurWallpaperProvider.Companion.getInstance(this); + + ContentObserver notificationSettingsObserver = new ContentObserver(new Handler()) { + @Override + public void onChange(boolean selfChange) { + onNotificationSettingsChanged(); + } + }; + getContentResolver().registerContentObserver( + NOTIFICATION_BADGING_URI, false, notificationSettingsObserver); + } + + private void onNotificationSettingsChanged() { + boolean areNotificationDotsEnabled = Settings.Secure.getInt( + getContentResolver(), NOTIFICATION_BADGING_URI.getLastPathSegment(), 1) == 1; + if (areNotificationDotsEnabled) { + NotificationService.requestRebind(new ComponentName( + this, NotificationService.class)); + } } public static BlissLauncher getApplication(Context context) { diff --git a/app/src/main/java/foundation/e/blisslauncher/features/notification/NotificationService.java b/app/src/main/java/foundation/e/blisslauncher/features/notification/NotificationService.java index 046fdc21720e3df92d6b5d82d8726519e147b198..6bd0657c6727cac4ec40fb654f1766b707b61a8f 100755 --- a/app/src/main/java/foundation/e/blisslauncher/features/notification/NotificationService.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/notification/NotificationService.java @@ -1,9 +1,16 @@ package foundation.e.blisslauncher.features.notification; +import static foundation.e.blisslauncher.BlissLauncher.NOTIFICATION_BADGING_URI; + import android.content.Intent; +import android.database.ContentObserver; +import android.os.Handler; +import android.provider.Settings; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; +import java.util.Collections; + import foundation.e.blisslauncher.core.utils.ListUtil; /** @@ -12,31 +19,70 @@ import foundation.e.blisslauncher.core.utils.ListUtil; public class NotificationService extends NotificationListenerService { + private static boolean sIsConnected = false; + NotificationRepository mNotificationRepository; + private boolean mAreDotsDisabled; + private final ContentObserver mNotificationSettingsObserver = new ContentObserver(new Handler()) { + @Override + public void onChange(boolean selfChange) { + onNotificationSettingsChanged(); + } + }; + @Override public void onCreate() { super.onCreate(); mNotificationRepository = NotificationRepository.getNotificationRepository(); + + getContentResolver().registerContentObserver( + NOTIFICATION_BADGING_URI, false, mNotificationSettingsObserver); + onNotificationSettingsChanged(); } @Override public void onDestroy() { super.onDestroy(); + getContentResolver().unregisterContentObserver(mNotificationSettingsObserver); + mNotificationRepository.updateNotification(Collections.emptyList()); + } + + private void onNotificationSettingsChanged() { + mAreDotsDisabled = Settings.Secure.getInt( + getContentResolver(), NOTIFICATION_BADGING_URI.getLastPathSegment(), 1) != 1; + if (mAreDotsDisabled && sIsConnected) { + requestUnbind(); + updateNotifications(); + } } @Override public void onListenerConnected() { - mNotificationRepository.updateNotification(ListUtil.asSafeList(getActiveNotifications())); + sIsConnected = true; + updateNotifications(); + } + + @Override + public void onListenerDisconnected() { + sIsConnected = false; } @Override public void onNotificationPosted(StatusBarNotification sbn) { - mNotificationRepository.updateNotification(ListUtil.asSafeList(getActiveNotifications())); + updateNotifications(); } @Override public void onNotificationRemoved(StatusBarNotification sbn) { + updateNotifications(); + } + + private void updateNotifications() { + if (mAreDotsDisabled) { + mNotificationRepository.updateNotification(Collections.emptyList()); + return; + } mNotificationRepository.updateNotification(ListUtil.asSafeList(getActiveNotifications())); }