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