Fix Flicker for ZenCustomRuleSettingsBase am: bab799899d
am: 9734698f71
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/17374483 Change-Id: I45fa8dca8c1f449741876191f62727de3040925b Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -19,9 +19,6 @@ package com.android.settings.notification.zen;
|
|||||||
import android.app.AutomaticZenRule;
|
import android.app.AutomaticZenRule;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Slog;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
@@ -37,23 +34,19 @@ abstract class AbstractZenCustomRulePreferenceController extends
|
|||||||
super(context, key, lifecycle);
|
super(context, key, lifecycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateState(Preference preference) {
|
|
||||||
if (mId != null) {
|
|
||||||
mRule = mBackend.getAutomaticZenRule(mId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return mRule != null;
|
return mRule != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResume(AutomaticZenRule rule, String id) {
|
public void setIdAndRule(String id, AutomaticZenRule rule) {
|
||||||
mId = id;
|
mId = id;
|
||||||
mRule = rule;
|
mRule = rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onResume() {
|
||||||
|
}
|
||||||
|
|
||||||
Bundle createBundle() {
|
Bundle createBundle() {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(ZenCustomRuleSettings.RULE_ID, mId);
|
bundle.putString(ZenCustomRuleSettings.RULE_ID, mId);
|
||||||
|
@@ -37,6 +37,7 @@ abstract class ZenCustomRuleSettingsBase extends ZenModeSettingsBase {
|
|||||||
String mId;
|
String mId;
|
||||||
AutomaticZenRule mRule;
|
AutomaticZenRule mRule;
|
||||||
List<AbstractPreferenceController> mControllers = new ArrayList<>();
|
List<AbstractPreferenceController> mControllers = new ArrayList<>();
|
||||||
|
private boolean mIsFirstLaunch = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null if no preference category exists
|
* @return null if no preference category exists
|
||||||
@@ -49,7 +50,7 @@ abstract class ZenCustomRuleSettingsBase extends ZenModeSettingsBase {
|
|||||||
Bundle bundle = getArguments();
|
Bundle bundle = getArguments();
|
||||||
if (bundle != null && bundle.containsKey(RULE_ID)) {
|
if (bundle != null && bundle.containsKey(RULE_ID)) {
|
||||||
mId = bundle.getString(RULE_ID);
|
mId = bundle.getString(RULE_ID);
|
||||||
mRule = mBackend.getAutomaticZenRule(mId);
|
updateRule();
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Rule id required to set custom dnd rule config settings");
|
Log.d(TAG, "Rule id required to set custom dnd rule config settings");
|
||||||
this.finish();
|
this.finish();
|
||||||
@@ -57,13 +58,32 @@ abstract class ZenCustomRuleSettingsBase extends ZenModeSettingsBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onZenModeConfigChanged() {
|
public void onResume() {
|
||||||
super.onZenModeConfigChanged();
|
super.onResume();
|
||||||
updatePreferences();
|
updatePreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePreferences() {
|
@Override
|
||||||
|
public void onZenModeConfigChanged() {
|
||||||
|
super.onZenModeConfigChanged();
|
||||||
|
updatePreferences();
|
||||||
|
updatePreferenceStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateRule() {
|
||||||
mRule = mBackend.getAutomaticZenRule(mId);
|
mRule = mBackend.getAutomaticZenRule(mId);
|
||||||
|
for (AbstractPreferenceController controller : mControllers) {
|
||||||
|
AbstractZenCustomRulePreferenceController zenRuleController =
|
||||||
|
(AbstractZenCustomRulePreferenceController) controller;
|
||||||
|
zenRuleController.setIdAndRule(mId, mRule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePreferences() {
|
||||||
|
if (!mIsFirstLaunch) {
|
||||||
|
updateRule();
|
||||||
|
}
|
||||||
|
|
||||||
final PreferenceScreen screen = getPreferenceScreen();
|
final PreferenceScreen screen = getPreferenceScreen();
|
||||||
String categoryKey = getPreferenceCategoryKey();
|
String categoryKey = getPreferenceCategoryKey();
|
||||||
if (categoryKey != null) {
|
if (categoryKey != null) {
|
||||||
@@ -78,23 +98,22 @@ abstract class ZenCustomRuleSettingsBase extends ZenModeSettingsBase {
|
|||||||
for (AbstractPreferenceController controller : mControllers) {
|
for (AbstractPreferenceController controller : mControllers) {
|
||||||
AbstractZenCustomRulePreferenceController zenRuleController =
|
AbstractZenCustomRulePreferenceController zenRuleController =
|
||||||
(AbstractZenCustomRulePreferenceController) controller;
|
(AbstractZenCustomRulePreferenceController) controller;
|
||||||
zenRuleController.onResume(mRule, mId);
|
zenRuleController.onResume();
|
||||||
|
if (!mIsFirstLaunch) {
|
||||||
|
// In first launch, displayPreference() is already called in DashboardFragment's
|
||||||
|
// onCreate().
|
||||||
zenRuleController.displayPreference(screen);
|
zenRuleController.displayPreference(screen);
|
||||||
updatePreference(zenRuleController);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mIsFirstLaunch = false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHelpResource() {
|
public int getHelpResource() {
|
||||||
return R.string.help_uri_interruptions;
|
return R.string.help_uri_interruptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
updatePreferences();
|
|
||||||
}
|
|
||||||
|
|
||||||
Bundle createZenRuleBundle() {
|
Bundle createZenRuleBundle() {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(RULE_ID, mId);
|
bundle.putString(RULE_ID, mId);
|
||||||
|
@@ -18,7 +18,6 @@ package com.android.settings.notification.zen;
|
|||||||
|
|
||||||
import static com.android.settings.notification.zen.ZenPrioritySendersHelper.UNKNOWN;
|
import static com.android.settings.notification.zen.ZenPrioritySendersHelper.UNKNOWN;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.service.notification.ZenPolicy;
|
import android.service.notification.ZenPolicy;
|
||||||
@@ -79,8 +78,8 @@ public class ZenRulePrioritySendersPreferenceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume(AutomaticZenRule rule, String id) {
|
public void onResume() {
|
||||||
super.onResume(rule, id);
|
super.onResume();
|
||||||
if (mIsMessages) {
|
if (mIsMessages) {
|
||||||
updateChannelCounts();
|
updateChannelCounts();
|
||||||
}
|
}
|
||||||
|
@@ -20,8 +20,6 @@ import android.app.AutomaticZenRule;
|
|||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.service.notification.ZenPolicy;
|
import android.service.notification.ZenPolicy;
|
||||||
|
|
||||||
import com.android.settings.notification.zen.AbstractZenCustomRulePreferenceController;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
@@ -37,6 +35,6 @@ abstract class ZenRuleCustomPrefContrTestBase {
|
|||||||
|
|
||||||
void updateControllerZenPolicy(ZenPolicy policy) {
|
void updateControllerZenPolicy(ZenPolicy policy) {
|
||||||
mRule.setZenPolicy(policy);
|
mRule.setZenPolicy(policy);
|
||||||
getController().onResume(mRule, RULE_ID);
|
getController().setIdAndRule(RULE_ID, mRule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -78,7 +78,7 @@ public class ZenRulePreferenceControllerTest {
|
|||||||
assertTrue(mController.mRule == null);
|
assertTrue(mController.mRule == null);
|
||||||
assertTrue(mController.mId == null);
|
assertTrue(mController.mId == null);
|
||||||
|
|
||||||
mController.onResume(rule, id);
|
mController.setIdAndRule(id, rule);
|
||||||
|
|
||||||
assertEquals(mController.mId, id);
|
assertEquals(mController.mId, id);
|
||||||
assertEquals(mController.mRule, rule);
|
assertEquals(mController.mRule, rule);
|
||||||
|
@@ -35,6 +35,6 @@ abstract class ZenRuleCustomPrefContrTestBase {
|
|||||||
|
|
||||||
void updateControllerZenPolicy(ZenPolicy policy) {
|
void updateControllerZenPolicy(ZenPolicy policy) {
|
||||||
mRule.setZenPolicy(policy);
|
mRule.setZenPolicy(policy);
|
||||||
getController().onResume(mRule, RULE_ID);
|
getController().setIdAndRule(RULE_ID, mRule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user