Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 804dfd42 authored by Bruno Martins's avatar Bruno Martins
Browse files

ConstraintsHelper: Allow replacing multiple keys at once

Change-Id: Ic676aaf12abd4d4b7a6a60b66308774a944ffdd8
parent d1f78690
Loading
Loading
Loading
Loading
+14 −3
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2016 The CyanogenMod Project
 * Copyright (C) 2016 The CyanogenMod Project
 *               2017,2019-2020 The LineageOS Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with 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.PreferenceManager;
import androidx.preference.PreferenceViewHolder;
import androidx.preference.PreferenceViewHolder;


import java.util.Arrays;
import java.util.List;
import java.util.List;
import java.util.Objects;
import java.util.Objects;
import java.util.Set;
import java.util.Set;
@@ -67,7 +69,7 @@ public class ConstraintsHelper {


    private int mSummaryMinLines = -1;
    private int mSummaryMinLines = -1;


    private String mReplacesKey = null;
    private String[] mReplacesKey = null;


    public ConstraintsHelper(Context context, AttributeSet attrs, Preference pref) {
    public ConstraintsHelper(Context context, AttributeSet attrs, Preference pref) {
        mContext = context;
        mContext = context;
@@ -77,7 +79,10 @@ public class ConstraintsHelper {
        TypedArray a = context.getResources().obtainAttributes(attrs,
        TypedArray a = context.getResources().obtainAttributes(attrs,
                R.styleable.lineage_SelfRemovingPreference);
                R.styleable.lineage_SelfRemovingPreference);
        mSummaryMinLines = a.getInteger(R.styleable.lineage_SelfRemovingPreference_minSummaryLines, -1);
        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());
        setAvailable(checkConstraints());


        Log.d(TAG, "construct key=" + mPref.getKey() + " available=" + mAvailable);
        Log.d(TAG, "construct key=" + mPref.getKey() + " available=" + mAvailable);
@@ -305,7 +310,7 @@ public class ConstraintsHelper {
        checkIntent();
        checkIntent();


        if (isAvailable() && mReplacesKey != null) {
        if (isAvailable() && mReplacesKey != null) {
            Graveyard.get(mContext).addTombstone(mReplacesKey);
            Graveyard.get(mContext).addTombstones(mReplacesKey);
        }
        }


        Graveyard.get(mContext).summonReaper(mPref.getPreferenceManager());
        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) {
        private PreferenceGroup getParent(Preference p1, Preference p2) {
            return getParent(p1.getPreferenceManager().getPreferenceScreen(), p2);
            return getParent(p1.getPreferenceManager().getPreferenceScreen(), p2);
        }
        }