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

Commit 18213459 authored by Chris Wren's avatar Chris Wren
Browse files

don't double set the dropdown value

idion: set the default value, and then add a callback
actual: spinner posts the change to a handler: so it posts after the callback is set.

This makes it hard to count actual user interactions without counting the initialization.

Bug: 21530764
Change-Id: I3ff8319edb374d8d7c10982512054f303c69a5ec
parent fa47bc02
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ public class DropDownPreference extends Preference {
    private final ArrayList<Object> mValues = new ArrayList<Object>();

    private Callback mCallback;
    private int mSelectedPosition = -1;

    public DropDownPreference(Context context) {
        this(context, null);
@@ -54,7 +55,7 @@ public class DropDownPreference extends Preference {
        mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
                setSelectedItem(position);
                setSelectedItem(position, true);
            }

            @Override
@@ -91,11 +92,19 @@ public class DropDownPreference extends Preference {
    }

    public void setSelectedItem(int position) {
        setSelectedItem(position, false);
    }

    public void setSelectedItem(int position, boolean fromSpinner) {
        if (fromSpinner && position == mSelectedPosition) {
            return;
        }
        final Object value = mValues.get(position);
        if (mCallback != null && !mCallback.onItemSelected(position, value)) {
            return;
        }
        mSpinner.setSelection(position);
        mSelectedPosition = mSpinner.getSelectedItemPosition();
        setSummary(mAdapter.getItem(position));
        final boolean disableDependents = value == null;
        notifyDependencyChange(disableDependents);