Fixing notification dots settings not updated properly

Also avoiding settings cache reset whenever someone registers
a new listener

Bug: 184200027
Test: Manual
Change-Id: I0c8b7084b6b4656102e9041b779b80a98624ddd8
This commit is contained in:
Sunny Goyal
2021-03-31 15:56:11 -07:00
parent 21dfadab76
commit 58530bd64b
7 changed files with 51 additions and 53 deletions

View File

@@ -17,6 +17,8 @@ package com.android.launcher3.settings;
import static com.android.launcher3.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY;
import static com.android.launcher3.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGS;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.SettingsCache.NOTIFICATION_BADGING_URI;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -24,6 +26,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.ContentObserver;
import android.os.Bundle;
import android.provider.Settings;
import android.util.AttributeSet;
@@ -49,6 +52,14 @@ public class NotificationDotsPreference extends Preference
/** Hidden field Settings.Secure.ENABLED_NOTIFICATION_LISTENERS */
private static final String NOTIFICATION_ENABLED_LISTENERS = "enabled_notification_listeners";
private final ContentObserver mListenerListObserver =
new ContentObserver(MAIN_EXECUTOR.getHandler()) {
@Override
public void onChange(boolean selfChange) {
updateUI();
}
};
public NotificationDotsPreference(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
@@ -66,6 +77,29 @@ public class NotificationDotsPreference extends Preference
super(context);
}
@Override
public void onAttached() {
super.onAttached();
SettingsCache.INSTANCE.get(getContext()).register(NOTIFICATION_BADGING_URI, this);
getContext().getContentResolver().registerContentObserver(
Settings.Secure.getUriFor(NOTIFICATION_ENABLED_LISTENERS),
false, mListenerListObserver);
updateUI();
}
private void updateUI() {
onSettingsChanged(SettingsCache.INSTANCE.get(getContext())
.getValue(NOTIFICATION_BADGING_URI));
}
@Override
public void onDetached() {
super.onDetached();
SettingsCache.INSTANCE.get(getContext()).unregister(NOTIFICATION_BADGING_URI, this);
getContext().getContentResolver().unregisterContentObserver(mListenerListObserver);
}
private void setWidgetFrameVisible(boolean isVisible) {
if (mWidgetFrameVisible != isVisible) {
mWidgetFrameVisible = isVisible;