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

Commit 50145bc8 authored by Bjorn Bringert's avatar Bjorn Bringert
Browse files

ACTV: getWindowVisibility() instead of private attach count

When debugging a problem with the search dialog drop-down
sometimes not showing up, I saw that the mAttachCount variable
in AutoCompleteTextView could get a negative value because
onDetachedFromWindow() was called multiple times. This lead to
the drop-down not being displayed on filtering.

Instead of the private attach count in ACTV, this change
uses View.getWindowVisibility().
parent a05487dd
Loading
Loading
Loading
Loading
+2 −7
Original line number Original line Diff line number Diff line
@@ -123,10 +123,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe


    private AutoCompleteTextView.ListSelectorHider mHideSelector;
    private AutoCompleteTextView.ListSelectorHider mHideSelector;


    // Indicates whether this AutoCompleteTextView is attached to a window or not
    // The widget is attached to a window when mAttachCount > 0
    private int mAttachCount;

    private AutoCompleteTextView.PassThroughClickListener mPassThroughClickListener;
    private AutoCompleteTextView.PassThroughClickListener mPassThroughClickListener;


    public AutoCompleteTextView(Context context) {
    public AutoCompleteTextView(Context context) {
@@ -960,7 +956,8 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe


    /** {@inheritDoc} */
    /** {@inheritDoc} */
    public void onFilterComplete(int count) {
    public void onFilterComplete(int count) {
        if (mAttachCount <= 0) return;
        // Not attached to window, don't update drop-down
        if (getWindowVisibility() == View.GONE) return;


        /*
        /*
         * This checks enoughToFilter() again because filtering requests
         * This checks enoughToFilter() again because filtering requests
@@ -999,13 +996,11 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
    @Override
    @Override
    protected void onAttachedToWindow() {
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        super.onAttachedToWindow();
        mAttachCount++;
    }
    }


    @Override
    @Override
    protected void onDetachedFromWindow() {
    protected void onDetachedFromWindow() {
        dismissDropDown();
        dismissDropDown();
        mAttachCount--;
        super.onDetachedFromWindow();
        super.onDetachedFromWindow();
    }
    }