Default DND rules show at top and can't be deleted
Test: make ROBOTEST_FILTER=ZenModeAutomaticRulesPreferenceControllerTest RunSettingsRoboTests -j40 Bug: 63077372 Change-Id: I43e7e2a70df5defe931a7ecedc6f946853dab476
This commit is contained in:
@@ -35,6 +35,7 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -45,6 +46,7 @@ abstract public class AbstractZenModeAutomaticRulePreferenceController extends
|
||||
protected Fragment mParent;
|
||||
protected Set<Map.Entry<String, AutomaticZenRule>> mRules;
|
||||
protected PackageManager mPm;
|
||||
private static List<String> mDefaultRuleIds;
|
||||
|
||||
public AbstractZenModeAutomaticRulePreferenceController(Context context, String key, Fragment
|
||||
parent, Lifecycle lifecycle) {
|
||||
@@ -60,6 +62,13 @@ abstract public class AbstractZenModeAutomaticRulePreferenceController extends
|
||||
mRules = getZenModeRules();
|
||||
}
|
||||
|
||||
private static List<String> getDefaultRuleIds() {
|
||||
if (mDefaultRuleIds == null) {
|
||||
mDefaultRuleIds = ZenModeConfig.DEFAULT_RULE_IDS;
|
||||
}
|
||||
return mDefaultRuleIds;
|
||||
}
|
||||
|
||||
private Set<Map.Entry<String, AutomaticZenRule>> getZenModeRules() {
|
||||
Map<String, AutomaticZenRule> ruleMap =
|
||||
NotificationManager.from(mContext).getAutomaticZenRules();
|
||||
@@ -99,6 +108,13 @@ abstract public class AbstractZenModeAutomaticRulePreferenceController extends
|
||||
@Override
|
||||
public int compare(Map.Entry<String, AutomaticZenRule> lhs,
|
||||
Map.Entry<String, AutomaticZenRule> rhs) {
|
||||
// if it's a default rule, should be at the top of automatic rules
|
||||
boolean lhsIsDefaultRule = getDefaultRuleIds().contains(lhs.getKey());
|
||||
boolean rhsIsDefaultRule = getDefaultRuleIds().contains(rhs.getKey());
|
||||
if (lhsIsDefaultRule != rhsIsDefaultRule) {
|
||||
return lhsIsDefaultRule ? -1 : 1;
|
||||
}
|
||||
|
||||
int byDate = Long.compare(lhs.getValue().getCreationTime(),
|
||||
rhs.getValue().getCreationTime());
|
||||
if (byDate != 0) {
|
||||
|
@@ -73,6 +73,10 @@ public class ZenRulePreference extends TwoTargetPreference {
|
||||
|
||||
@Override
|
||||
protected int getSecondTargetResId() {
|
||||
if (mId != null && ZenModeConfig.DEFAULT_RULE_IDS.contains(mId)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return R.layout.zen_rule_widget;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user