diff options
author | Yorke Lee <yorkelee@google.com> | 2013-09-09 12:29:28 -0700 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2013-09-11 15:59:35 -0700 |
commit | 18e7fdd55f67e3636c161462cb54e7f5555a04de (patch) | |
tree | 7c830edacb5abe0973ac06dc6bbf4eeb2362f8f6 /src | |
parent | e44b3c6a990f41d3e58406310183b16db0dab3ea (diff) |
Add no contacts view to Dialer
Bug: 10330508
Change-Id: I5f73a63118558e734cd36e681c59f4b82050a49c
Diffstat (limited to 'src')
3 files changed, 28 insertions, 20 deletions
diff --git a/src/com/android/dialer/list/PhoneFavoriteFragment.java b/src/com/android/dialer/list/PhoneFavoriteFragment.java index d7c387e57..c2a1b03b7 100644 --- a/src/com/android/dialer/list/PhoneFavoriteFragment.java +++ b/src/com/android/dialer/list/PhoneFavoriteFragment.java @@ -144,18 +144,17 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen private CallLogAdapter mCallLogAdapter; private CallLogQueryHandler mCallLogQueryHandler; - private TextView mEmptyView; private PhoneFavoriteListView mListView; + private View mShowAllContactsButton; private final HashMap<Long, Integer> mItemIdTopMap = new HashMap<Long, Integer>(); private final HashMap<Long, Integer> mItemIdLeftMap = new HashMap<Long, Integer>(); /** - * Layout used when contacts load is slower than expected and thus "loading" view should be - * shown. + * Layout used when there are no favorites. */ - private View mLoadingView; + private View mEmptyView; private final ContactTileView.Listener mContactTileAdapterListener = new ContactTileAdapterListener(); @@ -171,7 +170,6 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen // Construct two base adapters which will become part of PhoneFavoriteMergedAdapter. // We don't construct the resultant adapter at this moment since it requires LayoutInflater // that will be available on onCreateView(). - mContactTileAdapter = new PhoneFavoritesTileAdapter(activity, mContactTileAdapterListener, this, getResources().getInteger(R.integer.contact_tile_column_count_in_favorites_new), @@ -214,7 +212,8 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY); mListView.setOnItemSwipeListener(mContactTileAdapter); - mLoadingView = inflater.inflate(R.layout.phone_loading_contacts, mListView, false); + mEmptyView = inflater.inflate(R.layout.phone_no_favorites, mListView, false); + mShowAllContactsButton = inflater.inflate(R.layout.show_all_contact_button, mListView, false); mShowAllContactsButton.setOnClickListener(new OnClickListener() { @@ -224,8 +223,9 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen } }); + mContactTileAdapter.setEmptyView(mEmptyView); mAdapter = new PhoneFavoriteMergedAdapter(getActivity(), mContactTileAdapter, - mCallLogAdapter, mLoadingView, mShowAllContactsButton); + mCallLogAdapter, mShowAllContactsButton); mListView.setAdapter(mAdapter); @@ -233,10 +233,6 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen 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); - return listLayout; } diff --git a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java index 57ae2c147..575ef0a24 100644 --- a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java +++ b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java @@ -52,7 +52,6 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { private static final int ALL_CONTACTS_BUTTON_ITEM_ID = -1; private final PhoneFavoritesTileAdapter mContactTileAdapter; private final CallLogAdapter mCallLogAdapter; - private final View mLoadingView; private final View mShowAllContactsButton; private final int mCallLogPadding; @@ -99,7 +98,6 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { public PhoneFavoriteMergedAdapter(Context context, PhoneFavoritesTileAdapter contactTileAdapter, CallLogAdapter callLogAdapter, - View loadingView, View showAllContactsButton) { final Resources resources = context.getResources(); mContext = context; @@ -109,7 +107,6 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { mObserver = new CustomDataSetObserver(); mCallLogAdapter.registerDataSetObserver(mObserver); mContactTileAdapter.registerDataSetObserver(mObserver); - mLoadingView = loadingView; mShowAllContactsButton = showAllContactsButton; mCallLogQueryHandler = new CallLogQueryHandler(mContext.getContentResolver(), mCallLogQueryHandlerListener); @@ -242,9 +239,6 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { @Override public boolean areAllItemsEnabled() { - // 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 mCallLogAdapter.areAllItemsEnabled() && mContactTileAdapter.areAllItemsEnabled(); } diff --git a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java index 91acc6fe0..966233862 100644 --- a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java +++ b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java @@ -74,6 +74,8 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements private Context mContext; private Resources mResources; + private View mEmptyView; + /** Contact data stored in cache. This is used to populate the associated view. */ protected ArrayList<ContactEntry> mContactEntries = null; /** Back up of the temporarily removed Contact during dragging. */ @@ -367,10 +369,15 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements return mNumFrequents; } + private boolean isEmptyView(int position) { + return position == 0 && (mContactEntries == null || mContactEntries.isEmpty()); + } + @Override public int getCount() { if (mContactEntries == null || mContactEntries.isEmpty()) { - return 0; + // empty view + return 1; } int total = mContactEntries.size(); @@ -493,7 +500,7 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements @Override public boolean isEnabled(int position) { - return true; + return !isEmptyView(position); } @Override @@ -509,8 +516,13 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements if (DEBUG) { Log.v(TAG, "get view for " + String.valueOf(position)); } + int itemViewType = getItemViewType(position); + if (itemViewType == ViewTypes.EMPTY) { + return mEmptyView; + } + ContactTileRow contactTileRowView = (ContactTileRow) convertView; ArrayList<ContactEntry> contactList = getItem(position); @@ -542,6 +554,7 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements @Override public int getItemViewType(int position) { + if (isEmptyView(position)) return ViewTypes.EMPTY; if (position < getRowCount(getMaxContactsInTiles())) { return ViewTypes.TOP; } else { @@ -1129,9 +1142,10 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements } protected static class ViewTypes { - public static final int COUNT = 2; + public static final int COUNT = 3; public static final int FREQUENT = 0; public static final int TOP = 1; + public static final int EMPTY = 2; } @Override @@ -1158,4 +1172,8 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements public boolean isSwipeEnabled() { return !mAwaitingRemove; } + + public void setEmptyView(View emptyView) { + mEmptyView = emptyView; + } } |