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

Commit 1dff6b60 authored by Daisuke Miyakawa's avatar Daisuke Miyakawa
Browse files

[Phone] Conditionally show fast scroller on favorite

Bug: 5438604
Change-Id: If04d438a4b2d3d3218e422f06ec3008ccb6caf7f
parent 287a9b05
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -32,13 +32,13 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Directory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
@@ -158,6 +158,25 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen
        }
    }

    private class ScrollListener implements ListView.OnScrollListener {
        private boolean mShouldShowFastScroller;
        @Override
        public void onScroll(AbsListView view,
                int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // FastScroller should be visible only when the user is seeing "all" contacts section.
            final boolean shouldShow = mAdapter.shouldShowFirstScroller(firstVisibleItem);
            if (shouldShow != mShouldShowFastScroller) {
                mListView.setFastScrollEnabled(shouldShow);
                mListView.setFastScrollAlwaysVisible(shouldShow);
                mShouldShowFastScroller = shouldShow;
            }
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    }

    private Listener mListener;
    private PhoneFavoriteMergedAdapter mAdapter;
    private ContactTileAdapter mContactTileAdapter;
@@ -192,6 +211,7 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen
    private final OnClickListener mFilterHeaderClickListener = new FilterHeaderClickListener();
    private final ContactsPreferenceChangeListener mContactsPreferenceChangeListener =
            new ContactsPreferenceChangeListener();
    private final ScrollListener mScrollListener = new ScrollListener();

    @Override
    public void onCreate(Bundle savedState) {
@@ -223,9 +243,6 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen
        mListView = (ListView) listLayout.findViewById(R.id.contact_tile_list);
        mListView.setItemsCanFocus(true);
        mListView.setOnItemClickListener(this);
        mListView.setFastScrollEnabled(true);
        // We want to hide the scroll bar after a while.
        mListView.setFastScrollAlwaysVisible(false);
        mListView.setVerticalScrollBarEnabled(true);
        mListView.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT);
        mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
@@ -234,6 +251,10 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen

        mListView.setAdapter(mAdapter);

        mListView.setOnScrollListener(mScrollListener);
        mListView.setFastScrollEnabled(false);
        mListView.setFastScrollAlwaysVisible(false);

        mEmptyView = (TextView) listLayout.findViewById(R.id.contact_tile_list_empty);
        mEmptyView.setText(getString(R.string.listTotalAllContactsZero));
        mListView.setEmptyView(mEmptyView);
+10 −29
Original line number Diff line number Diff line
@@ -34,11 +34,6 @@ import android.widget.SectionIndexer;
 */
public class PhoneFavoriteMergedAdapter extends BaseAdapter implements SectionIndexer {

    // Should show nothing as SectionIndex.
    // " " will suppress the section indexer itself: nothing will be shown during user's scroll.
    private static final String SECTION_STRING_STARRED = " ";
    private static final String SECTION_STRING_FREQUENT = " ";

    private class CustomDataSetObserver extends DataSetObserver {
        @Override
        public void onChanged() {
@@ -200,42 +195,28 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter implements SectionIn
    @Override
    public int getPositionForSection(int sectionIndex) {
        final int contactTileAdapterCount = mContactTileAdapter.getCount();
        if (sectionIndex == 0) {  // "starred" section
            return 0;
        } else if (sectionIndex == 1) {  // "frequent" section
            return mContactTileAdapter.getFrequentHeaderPosition();
        } else {
            final int localSection = sectionIndex - 2;
            final int localPosition = mContactEntryListAdapter.getPositionForSection(localSection);
        final int localPosition = mContactEntryListAdapter.getPositionForSection(sectionIndex);
        return contactTileAdapterCount + 1 + localPosition;
    }
    }

    @Override
    public int getSectionForPosition(int position) {
        final int contactTileAdapterCount = mContactTileAdapter.getCount();
        if (position < contactTileAdapterCount) {
        if (position <= contactTileAdapterCount) {
            return 0;
        } else if (position == contactTileAdapterCount) {
            return 1;
        } else {
            final int localPosition = position - contactTileAdapterCount - 1;
            final int localSection = mContactEntryListAdapter.getSectionForPosition(localPosition);
            return localSection + 2;
            return mContactEntryListAdapter.getSectionForPosition(localPosition);
        }
    }

    @Override
    public Object[] getSections() {
        // Copy sections from "all" contacts, and add two additional sections for "starred", and
        // "frequent". Those new sections should not show anything as an indexer, but should
        // let users select those sections with a vertical scroll.
        final Object[] contactEntrySections = mContactEntryListAdapter.getSections();
        final Object[] ret = new Object[contactEntrySections.length + 2];
        System.arraycopy(contactEntrySections, 0, ret, 2, contactEntrySections.length);

        ret[0] = SECTION_STRING_STARRED;
        ret[1] = SECTION_STRING_FREQUENT;
        return ret;
        return mContactEntryListAdapter.getSections();
    }

    public boolean shouldShowFirstScroller(int firstVisibleItem) {
        final int contactTileAdapterCount = mContactTileAdapter.getCount();
        return firstVisibleItem > contactTileAdapterCount;
    }
}
 No newline at end of file