From ab90a18e2f05c7ae4158b770a9fbe9cbe4544597 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Tue, 1 Sep 2015 17:59:10 -0700 Subject: Genericize promo card. + Make ViewHolder generic to generic to promo cards with customized text or graphic layouts, as long as they implement two actions, now designated the primary and secondary action views. This resuses code which is logically similar between promo cards, and hopefully doesn't bite us back in the future if there is a divergence in promo card structure. + Make the GroupingListAdapter slightly "safer". Bug: 23422274 Change-Id: I60bced4dbc61fec2e225a1cae9726ac40ed679a5 --- src/com/android/dialer/calllog/CallLogAdapter.java | 14 ++++------ .../dialer/calllog/GroupingListAdapter.java | 4 +-- .../dialer/calllog/PromoCardViewHolder.java | 32 ++++++++++++---------- 3 files changed, 25 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index 4593e5e4d..bbaf77a7d 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -79,11 +79,9 @@ public class CallLogAdapter extends GroupingListAdapter private static final int NO_EXPANDED_LIST_ITEM = -1; private static final int VOICEMAIL_PROMO_CARD_POSITION = 0; - /** - * View type for voicemail promo card. Note: Numbering starts at 20 to avoid collision - * with {@link com.android.common.widget.GroupingListAdapter#ITEM_TYPE_IN_GROUP}. - */ - private static final int VIEW_TYPE_VOICEMAIL_PROMO_CARD = 20; + + protected static final int VIEW_TYPE_NORMAL = 0; + private static final int VIEW_TYPE_VOICEMAIL_PROMO_CARD = 1; /** * The key for the show voicemail promo card preference which will determine whether the promo @@ -481,9 +479,9 @@ public class CallLogAdapter extends GroupingListAdapter protected void bindVoicemailPromoCardViewHolder(ViewHolder viewHolder) { PromoCardViewHolder promoCardViewHolder = (PromoCardViewHolder) viewHolder; - promoCardViewHolder.getSettingsTextView().setOnClickListener( - mVoicemailSettingsActionListener); - promoCardViewHolder.getOkTextView().setOnClickListener(mOkActionListener); + promoCardViewHolder.getSecondaryActionView() + .setOnClickListener(mVoicemailSettingsActionListener); + promoCardViewHolder.getPrimaryActionView().setOnClickListener(mOkActionListener); } /** diff --git a/src/com/android/dialer/calllog/GroupingListAdapter.java b/src/com/android/dialer/calllog/GroupingListAdapter.java index 54dd5f679..70190df30 100644 --- a/src/com/android/dialer/calllog/GroupingListAdapter.java +++ b/src/com/android/dialer/calllog/GroupingListAdapter.java @@ -126,7 +126,7 @@ abstract class GroupingListAdapter extends RecyclerView.Adapter { * that position. */ public int getGroupSize(int listPosition) { - if (listPosition >= mGroupMetadata.size()) { + if (listPosition < 0 || listPosition >= mGroupMetadata.size()) { return 0; } @@ -138,7 +138,7 @@ abstract class GroupingListAdapter extends RecyclerView.Adapter { * corresponding to that position. */ public Object getItem(int listPosition) { - if (mCursor == null || listPosition >= mGroupMetadata.size()) { + if (mCursor == null || listPosition < 0 || listPosition >= mGroupMetadata.size()) { return null; } diff --git a/src/com/android/dialer/calllog/PromoCardViewHolder.java b/src/com/android/dialer/calllog/PromoCardViewHolder.java index 656b66938..f5a7501fc 100644 --- a/src/com/android/dialer/calllog/PromoCardViewHolder.java +++ b/src/com/android/dialer/calllog/PromoCardViewHolder.java @@ -24,7 +24,8 @@ import com.android.contacts.common.testing.NeededForTesting; import com.android.dialer.R; /** - * View holder class for a promo card which will appear in the voicemail tab. + * Generic ViewHolder class for a promo card with a primary and secondary action. + * Example: the promo card which appears in the voicemail tab. */ public class PromoCardViewHolder extends RecyclerView.ViewHolder { public static PromoCardViewHolder create(View rootView) { @@ -32,14 +33,15 @@ public class PromoCardViewHolder extends RecyclerView.ViewHolder { } /** - * The "Settings" button view. + * The primary action button view. */ - private View mSettingsTextView; + private View mPrimaryActionView; /** + * The secondary action button view. * The "Ok" button view. */ - private View mOkTextView; + private View mSecondaryActionView; /** * Creates an instance of the {@link ViewHolder}. @@ -49,33 +51,33 @@ public class PromoCardViewHolder extends RecyclerView.ViewHolder { private PromoCardViewHolder(View rootView) { super(rootView); - mSettingsTextView = rootView.findViewById(R.id.settings_action); - mOkTextView = rootView.findViewById(R.id.ok_action); + mPrimaryActionView = rootView.findViewById(R.id.primary_action); + mSecondaryActionView = rootView.findViewById(R.id.secondary_action); } - /** - * Retrieves the "Settings" button. + /** + * Retrieves the "primary" action button (eg. "OK"). * * @return The view. */ - public View getSettingsTextView() { - return mSettingsTextView; + public View getPrimaryActionView() { + return mPrimaryActionView; } /** - * Retrieves the "Ok" button. + * Retrieves the "secondary" action button (eg. "Cancel" or "More Info"). * * @return The view. */ - public View getOkTextView() { - return mOkTextView; + public View getSecondaryActionView() { + return mSecondaryActionView; } @NeededForTesting public static PromoCardViewHolder createForTest(Context context) { PromoCardViewHolder viewHolder = new PromoCardViewHolder(new View(context)); - viewHolder.mSettingsTextView = new View(context); - viewHolder.mOkTextView = new View(context); + viewHolder.mPrimaryActionView = new View(context); + viewHolder.mSecondaryActionView = new View(context); return viewHolder; } } -- cgit v1.2.3