diff options
3 files changed, 43 insertions, 216 deletions
diff --git a/src/com/android/dialer/list/NewPhoneFavoriteFragment.java b/src/com/android/dialer/list/NewPhoneFavoriteFragment.java index db2999ccf..a181fb0fe 100644 --- a/src/com/android/dialer/list/NewPhoneFavoriteFragment.java +++ b/src/com/android/dialer/list/NewPhoneFavoriteFragment.java @@ -172,20 +172,9 @@ public class NewPhoneFavoriteFragment extends Fragment implements OnItemClickLis } 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.setVerticalScrollBarEnabled(shouldShow); - mListView.setFastScrollEnabled(shouldShow); - mListView.setFastScrollAlwaysVisible(shouldShow); - mShouldShowFastScroller = shouldShow; - } - - } @Override @@ -343,8 +332,7 @@ public class NewPhoneFavoriteFragment extends Fragment implements OnItemClickLis mLoadingView = inflater.inflate(R.layout.phone_loading_contacts, mListView, false); mAdapter = new NewPhoneFavoriteMergedAdapter(getActivity(), - mContactTileAdapter, mAccountFilterHeaderContainer, mAllContactsAdapter, - mCallLogAdapter, mLoadingView); + mContactTileAdapter, mAccountFilterHeaderContainer, mCallLogAdapter, mLoadingView); mListView.setAdapter(mAdapter); diff --git a/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java b/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java index 742892b61..d42189ef9 100644 --- a/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java +++ b/src/com/android/dialer/list/NewPhoneFavoriteMergedAdapter.java @@ -32,13 +32,10 @@ import com.android.dialer.R; import com.android.dialer.calllog.NewCallLogAdapter; /** - * An adapter that combines items from {@link com.android.contacts.common.list.ContactTileAdapter} and - * {@link com.android.contacts.common.list.ContactEntryListAdapter} into a single list. - * In between those two results, an account filter header will be inserted. - * - * Has one extra view at the top: The most recent call/voicemail/missed call. + * An adapter that combines items from {@link com.android.contacts.common.list.ContactTileAdapter} + * and {@link com.android.dialer.calllog.NewCallLogAdapter} into a single list. */ -public class NewPhoneFavoriteMergedAdapter extends BaseAdapter implements SectionIndexer { +public class NewPhoneFavoriteMergedAdapter extends BaseAdapter { private class CustomDataSetObserver extends DataSetObserver { @Override @@ -50,17 +47,9 @@ public class NewPhoneFavoriteMergedAdapter extends BaseAdapter implements Sectio private static final String TAG = NewPhoneFavoriteMergedAdapter.class.getSimpleName(); private final PhoneFavoritesTileAdapter mContactTileAdapter; - private final ContactEntryListAdapter mContactEntryListAdapter; private final NewCallLogAdapter mCallLogAdapter; - private final View mAccountFilterHeaderContainer; private final View mLoadingView; - // TODO krelease: Add a setting to toggle mShowAllContacts, and really handle it - // properly below. - private boolean mShowAllContacts = false; - - private final int mItemPaddingLeft; - private final int mItemPaddingRight; private final int mCallLogPadding; private final Context mContext; @@ -70,23 +59,16 @@ public class NewPhoneFavoriteMergedAdapter extends BaseAdapter implements Sectio public NewPhoneFavoriteMergedAdapter(Context context, PhoneFavoritesTileAdapter contactTileAdapter, View accountFilterHeaderContainer, - ContactEntryListAdapter contactEntryListAdapter, NewCallLogAdapter callLogAdapter, View loadingView) { final Resources resources = context.getResources(); mContext = context; - mItemPaddingLeft = resources.getDimensionPixelSize(R.dimen.detail_item_side_margin); - mItemPaddingRight = resources.getDimensionPixelSize(R.dimen.list_visible_scrollbar_padding); mCallLogPadding = resources.getDimensionPixelSize(R.dimen.recent_call_log_item_padding); mContactTileAdapter = contactTileAdapter; - mContactEntryListAdapter = contactEntryListAdapter; mCallLogAdapter = callLogAdapter; - mAccountFilterHeaderContainer = accountFilterHeaderContainer; - mObserver = new CustomDataSetObserver(); mContactTileAdapter.registerDataSetObserver(mObserver); - mContactEntryListAdapter.registerDataSetObserver(mObserver); mLoadingView = loadingView; } @@ -94,59 +76,29 @@ public class NewPhoneFavoriteMergedAdapter extends BaseAdapter implements Sectio public boolean isEmpty() { // Cannot use the super's method here because we add extra rows in getCount() to account // for headers - return mCallLogAdapter.getCount() + mContactTileAdapter.getCount() + - mContactEntryListAdapter.getCount() == 0; + return mCallLogAdapter.getCount() + mContactTileAdapter.getCount() == 0; } @Override public int getCount() { - final int contactTileAdapterCount = mContactTileAdapter.getCount(); - final int contactEntryListAdapterCount = mShowAllContacts ? - mContactEntryListAdapter.getCount() : 0; - - final int callLogAdapterCount = mCallLogAdapter.getCount(); - - if (mShowAllContacts && mContactEntryListAdapter.isLoading()) { - // Hide "all" contacts during its being loaded. Instead show "loading" view. - // - // "+2" for mAccountFilterHeaderContainer and mLoadingView - return contactTileAdapterCount + 1 + (mShowAllContacts ? 1 : 0) + - callLogAdapterCount; - } else { - // "+1" for mAccountFilterHeaderContainer - return contactTileAdapterCount + contactEntryListAdapterCount + - (mShowAllContacts ? 1 : 0) + callLogAdapterCount; - } + return mContactTileAdapter.getCount() + mCallLogAdapter.getCount(); } @Override public Object getItem(int position) { final int contactTileAdapterCount = mContactTileAdapter.getCount(); - final int contactEntryListAdapterCount = mShowAllContacts ? - mContactEntryListAdapter.getCount() : 0; final int callLogAdapterCount = mCallLogAdapter.getCount(); - // TODO krelease: Calculate the position properly. if (callLogAdapterCount > 0) { if (position < callLogAdapterCount) { return mCallLogAdapter.getItem(position); } - position -= callLogAdapterCount; + // Set position to the position of the actual favorite contact in the favorites adapter + position = getAdjustedFavoritePosition(position, callLogAdapterCount); } - if (position < contactTileAdapterCount) { // For "tile" and "frequent" sections - return mContactTileAdapter.getItem(position); - } else { // For "all" section - if (mShowAllContacts && mContactEntryListAdapter.isLoading()) { - // "All" section is being loaded. - return mLoadingView; - } else { - // "-1" for mAccountFilterHeaderContainer - final int localPosition = position - contactTileAdapterCount - 1; - return mContactTileAdapter.getItem(localPosition); - } - } + return mContactTileAdapter.getItem(position); } @Override @@ -156,78 +108,20 @@ public class NewPhoneFavoriteMergedAdapter extends BaseAdapter implements Sectio @Override public int getViewTypeCount() { - // "+1" for mLoadingView - return (mContactTileAdapter.getViewTypeCount() - + mContactEntryListAdapter.getViewTypeCount() - + 1 - + mCallLogAdapter.getViewTypeCount()); + return (mContactTileAdapter.getViewTypeCount() + mCallLogAdapter.getViewTypeCount()); } @Override public int getItemViewType(int position) { - final int contactTileAdapterCount = mContactTileAdapter.getCount(); - - final int contactEntryListAdapterCount = mShowAllContacts ? - mContactEntryListAdapter.getCount() : 0; - final int callLogAdapterCount = mCallLogAdapter.getCount(); - if (callLogAdapterCount > 0) { - if (position == 0) { - return mContactTileAdapter.getViewTypeCount() + - mContactEntryListAdapter.getViewTypeCount() + 2; - } - // Ignore the first position when calculating view types of all other items - position -= callLogAdapterCount; - } - - // There should be four kinds of types that are usually used, and one more exceptional - // type (IGNORE_ITEM_VIEW_TYPE), which sometimes comes from mContactTileAdapter. - // - // The four ordinary view types have the index equal to or more than 0, and less than - // mContactTileAdapter.getViewTypeCount()+ mContactEntryListAdapter.getViewTypeCount() + 2. - // (See also this class's getViewTypeCount()) - // - // We have those values for: - // - The view types mContactTileAdapter originally has - // - The view types mContactEntryListAdapter originally has - // - mAccountFilterHeaderContainer ("all" section's account header), and - // - mLoadingView - // - // Those types should not be mixed, so we have a different range for each kinds of types: - // - Types for mContactTileAdapter ("tile" and "frequent" sections) - // They should have the index, >=0 and <mContactTileAdapter.getViewTypeCount() - // - // - Types for mContactEntryListAdapter ("all" sections) - // They should have the index, >=mContactTileAdapter.getViewTypeCount() and - // <(mContactTileAdapter.getViewTypeCount() + mContactEntryListAdapter.getViewTypeCount()) - // - // - Type for "all" section's account header - // It should have the exact index - // mContactTileAdapter.getViewTypeCount()+ mContactEntryListAdapter.getViewTypeCount() - // - // - Type for "loading" view used during "all" section is being loaded. - // It should have the exact index - // mContactTileAdapter.getViewTypeCount()+ mContactEntryListAdapter.getViewTypeCount() + 1 - // - // As an exception, IGNORE_ITEM_VIEW_TYPE (-1) will be remained as is, which will be used - // by framework's Adapter implementation and thus should be left as is. - if (position < contactTileAdapterCount) { // For "tile" and "frequent" sections - return mContactTileAdapter.getItemViewType(position); - } else if (position == contactTileAdapterCount) { // For "all" section's account header - return mContactTileAdapter.getViewTypeCount() - + mContactEntryListAdapter.getViewTypeCount(); - } else { // For "all" section - if (mContactEntryListAdapter.isLoading()) { // "All" section is being loaded. - return mContactTileAdapter.getViewTypeCount() - + mContactEntryListAdapter.getViewTypeCount() + 1; - } else { - // "-1" for mAccountFilterHeaderContainer - final int localPosition = position - contactTileAdapterCount - 1; - final int type = mContactEntryListAdapter.getItemViewType(localPosition); - // IGNORE_ITEM_VIEW_TYPE must be handled differently. - return (type < 0) ? type : type + mContactTileAdapter.getViewTypeCount(); - } + if (position < callLogAdapterCount) { + // View type of the call log adapter is the last view type of the contact tile adapter + // + 1 + return mContactTileAdapter.getViewTypeCount(); + } else { + return mContactTileAdapter.getItemViewType( + getAdjustedFavoritePosition(position, callLogAdapterCount)); } } @@ -235,12 +129,8 @@ public class NewPhoneFavoriteMergedAdapter extends BaseAdapter implements Sectio public View getView(int position, View convertView, ViewGroup parent) { final int contactTileAdapterCount = mContactTileAdapter.getCount(); - final int contactEntryListAdapterCount = mShowAllContacts ? - mContactEntryListAdapter.getCount() : 0; - final int callLogAdapterCount = mCallLogAdapter.getCount(); - // TODO krelease: Handle the new callLogAdapterCount and position offsets properly if (callLogAdapterCount > 0) { if (position == 0) { final FrameLayout wrapper; @@ -270,42 +160,22 @@ public class NewPhoneFavoriteMergedAdapter extends BaseAdapter implements Sectio return wrapper; } - position -= callLogAdapterCount; + // Set position to the position of the actual favorite contact in the + // favorites adapter + position = getAdjustedFavoritePosition(position, callLogAdapterCount); } - // Obtain a View relevant for that position, and adjust its horizontal padding. Each - // View has different implementation, so we use different way to control those padding. - if (position < contactTileAdapterCount) { // For "tile" and "frequent" sections - final View view = mContactTileAdapter.getView(position, convertView, parent); - final int frequentHeaderPosition = mContactTileAdapter.getFrequentHeaderPosition(); - // TODO krelease: Get rid of frequent header position, we don't need it anymore - if (position >= frequentHeaderPosition) { - final FrameLayout frameLayout = (FrameLayout) view; - final View child = frameLayout.getChildAt(0); - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( - FrameLayout.LayoutParams.WRAP_CONTENT, - FrameLayout.LayoutParams.WRAP_CONTENT); - child.setLayoutParams(params); - } - return view; - } else { // For "all" section - if (mShowAllContacts && mContactEntryListAdapter.isLoading()) { - // "All" section is being loaded. - mLoadingView.setPadding(mItemPaddingLeft, - mLoadingView.getPaddingTop(), - mItemPaddingRight, - mLoadingView.getPaddingBottom()); - return mLoadingView; - } else { - final int localPosition = position - contactTileAdapterCount; - final ContactListItemView itemView = (ContactListItemView) - mContactEntryListAdapter.getView(localPosition, convertView, null); - itemView.setPadding(mItemPaddingLeft, itemView.getPaddingTop(), - mItemPaddingRight, itemView.getPaddingBottom()); - itemView.setSelectionBoundsHorizontalMargin(mItemPaddingLeft, mItemPaddingRight); - return itemView; - } + // Favorites section + final View view = mContactTileAdapter.getView(position, convertView, parent); + if (position >= mContactTileAdapter.getMaxTiledRows()) { + final FrameLayout frameLayout = (FrameLayout) view; + final View child = frameLayout.getChildAt(0); + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.WRAP_CONTENT, + FrameLayout.LayoutParams.WRAP_CONTENT); + child.setLayoutParams(params); } + return view; } @Override @@ -313,58 +183,23 @@ public class NewPhoneFavoriteMergedAdapter extends BaseAdapter implements Sectio // If "all" section is being loaded we'll show mLoadingView, which is not enabled. // Otherwise check the all the other components in the ListView and return appropriate // result. - return !mContactEntryListAdapter.isLoading() - && (mContactTileAdapter.areAllItemsEnabled() - && mAccountFilterHeaderContainer.isEnabled() - && mContactEntryListAdapter.areAllItemsEnabled()); + return mCallLogAdapter.areAllItemsEnabled() && mContactTileAdapter.areAllItemsEnabled(); } @Override public boolean isEnabled(int position) { + final int callLogAdapterCount = mCallLogAdapter.getCount(); final int contactTileAdapterCount = mContactTileAdapter.getCount(); - final int contactEntryListAdapterCount = mContactEntryListAdapter.getCount(); - if (position < contactTileAdapterCount) { // For "tile" and "frequent" sections - return mContactTileAdapter.isEnabled(position); - } else if (position == contactTileAdapterCount) { // For "all" section's account header - // This will be handled by View's onClick event instead of ListView's onItemClick event. - return false; - } else { // For "all" section - if (mContactEntryListAdapter.isLoading()) { // "All" section is being loaded. - return false; - } else { - // "-1" for mAccountFilterHeaderContainer - final int localPosition = position - contactTileAdapterCount - 1; - return mContactEntryListAdapter.isEnabled(localPosition); - } - } - } - - @Override - public int getPositionForSection(int sectionIndex) { - // frequent header view. - final int contactTileAdapterCount = mContactTileAdapter.getCount(); - final int localPosition = mContactEntryListAdapter.getPositionForSection(sectionIndex); - return contactTileAdapterCount + localPosition; - } - - @Override - public int getSectionForPosition(int position) { - final int contactTileAdapterCount = mContactTileAdapter.getCount(); - if (position <= contactTileAdapterCount) { - return 0; - } else { - final int localPosition = position - contactTileAdapterCount; - return mContactEntryListAdapter.getSectionForPosition(localPosition); + if (position < callLogAdapterCount) { + return mCallLogAdapter.isEnabled(position); + } else { // For favorites section + return mContactTileAdapter.isEnabled( + getAdjustedFavoritePosition(position, callLogAdapterCount)); } } - @Override - public Object[] getSections() { - return mContactEntryListAdapter.getSections(); + private int getAdjustedFavoritePosition(int position, int callLogAdapterCount) { + return position - callLogAdapterCount; } - public boolean shouldShowFirstScroller(int firstVisibleItem) { - final int contactTileAdapterCount = mContactTileAdapter.getCount(); - return firstVisibleItem > contactTileAdapterCount; - } } diff --git a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java index f859e855d..36579061a 100644 --- a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java +++ b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java @@ -225,6 +225,10 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter { return total - (mMaxTiledRows * (mColumnCount - 1)); } + public int getMaxTiledRows() { + return mMaxTiledRows; + } + /** * Returns the number of rows required to show the provided number of entries * with the current number of columns. |