summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Lee <anwlee@google.com>2015-09-01 17:59:10 -0700
committerAndrew Lee <anwlee@google.com>2015-09-01 18:22:49 -0700
commitab90a18e2f05c7ae4158b770a9fbe9cbe4544597 (patch)
tree8582caa28ef33d2ed89b090ccf9357c015da26ac
parent0599e880630892becf1a1991e6712e0e6d9df3c8 (diff)
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
-rw-r--r--res/layout/voicemail_promo_card.xml8
-rw-r--r--src/com/android/dialer/calllog/CallLogAdapter.java14
-rw-r--r--src/com/android/dialer/calllog/GroupingListAdapter.java4
-rw-r--r--src/com/android/dialer/calllog/PromoCardViewHolder.java32
4 files changed, 29 insertions, 29 deletions
diff --git a/res/layout/voicemail_promo_card.xml b/res/layout/voicemail_promo_card.xml
index 103fa30b3..891f09693 100644
--- a/res/layout/voicemail_promo_card.xml
+++ b/res/layout/voicemail_promo_card.xml
@@ -79,20 +79,20 @@
android:gravity="end">
<TextView
- android:id="@+id/settings_action"
+ android:id="@+id/secondary_action"
style="@style/PromoCardActionStyle"
android:background="?android:attr/selectableItemBackground"
android:text="@string/visual_voicemail_settings"
android:nextFocusLeft="@+id/promo_card"
- android:nextFocusRight="@+id/ok_action"
+ android:nextFocusRight="@+id/primary_action"
android:paddingEnd="@dimen/promo_card_action_between_padding"/>
<TextView
- android:id="@+id/ok_action"
+ android:id="@+id/primary_action"
style="@style/PromoCardActionStyle"
android:background="?android:attr/selectableItemBackground"
android:text="@android:string/ok"
- android:nextFocusLeft="@+id/settings_action"
+ android:nextFocusLeft="@+id/secondary_action"
android:nextFocusRight="@+id/promo_card"/>
</LinearLayout>
</LinearLayout>
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;
}
}