ConstraintsHelper: Allow replacing multiple keys at once

Change-Id: Ic676aaf12abd4d4b7a6a60b66308774a944ffdd8
This commit is contained in:
Bruno Martins
2020-10-25 16:48:41 +00:00
parent 7bf74325e4
commit 88daa87a94

View File

@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 The CyanogenMod Project
* 2017,2019-2020 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,6 +37,7 @@ import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceViewHolder;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -67,7 +69,7 @@ public class ConstraintsHelper {
private int mSummaryMinLines = -1;
private String mReplacesKey = null;
private String[] mReplacesKey = null;
public ConstraintsHelper(Context context, AttributeSet attrs, Preference pref) {
mContext = context;
@@ -77,7 +79,10 @@ public class ConstraintsHelper {
TypedArray a = context.getResources().obtainAttributes(attrs,
R.styleable.lineage_SelfRemovingPreference);
mSummaryMinLines = a.getInteger(R.styleable.lineage_SelfRemovingPreference_minSummaryLines, -1);
mReplacesKey = a.getString(R.styleable.lineage_SelfRemovingPreference_replacesKey);
String replacesKey = a.getString(R.styleable.lineage_SelfRemovingPreference_replacesKey);
if (replacesKey != null) {
mReplacesKey = replacesKey.split("\\|");
}
setAvailable(checkConstraints());
Log.d(TAG, "construct key=" + mPref.getKey() + " available=" + mAvailable);
@@ -305,7 +310,7 @@ public class ConstraintsHelper {
checkIntent();
if (isAvailable() && mReplacesKey != null) {
Graveyard.get(mContext).addTombstone(mReplacesKey);
Graveyard.get(mContext).addTombstones(mReplacesKey);
}
Graveyard.get(mContext).summonReaper(mPref.getPreferenceManager());
@@ -355,6 +360,12 @@ public class ConstraintsHelper {
}
}
public void addTombstones(String[] prefs) {
synchronized (mDeathRow) {
mDeathRow.addAll(Arrays.asList(prefs));
}
}
private PreferenceGroup getParent(Preference p1, Preference p2) {
return getParent(p1.getPreferenceManager().getPreferenceScreen(), p2);
}