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

Commit 47757164 authored by Ta-wei Yen's avatar Ta-wei Yen
Browse files

Fixed contacts tab reset to top after lock/unlock

+ save and restore list view position in ContactEntryListFragment
  when the fragment is not recreated.

Bug:19982820
Change-Id: I65f8f42f0088f8507e81990d73c301e5697055ae
parent aa85838f
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -113,6 +113,12 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
    private View mView;
    private ListView mListView;

    /**
     * Used to save the scrolling state of the list when the fragment is not recreated.
     */
    private int mListViewTopIndex;
    private int mListViewTopOffset;

    /**
     * Used for keeping track of the scroll state of the list.
     */
@@ -873,6 +879,11 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter

    @Override
    public void onPause() {
        // Save the scrolling state of the list view
        mListViewTopIndex = mListView.getFirstVisiblePosition();
        View v = mListView.getChildAt(0);
        mListViewTopOffset = (v == null) ? 0 : (v.getTop() - mListView.getPaddingTop());

        super.onPause();
        removePendingDirectorySearchRequests();
    }
@@ -884,6 +895,11 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
        if (mListState != null) {
            mListView.onRestoreInstanceState(mListState);
            mListState = null;
        } else {
            // Restore the scrolling state of the list view.
            // This has to be done manually be cause if the list view have its' emptyView set,
            // the scrolling state will be reset when clearPartitions() is called on the adapter.
            mListView.setSelectionFromTop(mListViewTopIndex, mListViewTopOffset);
        }
    }