From 492cd7371c6d8fddc4de85887a4ed9a89d602767 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Wed, 8 Apr 2015 14:58:45 -0700 Subject: Replace ListView with RecyclerView in call log. Yay, finally! + Replace ListView with RecyclerView in layout and fragment files. + Change GroupingListAdapter to extend RecyclerView.Adapter instead of BaseAdapter. + Change CallLogListItemViews to extend RecyclerView.ViewHolder. + Adapt onBindViewHolder and onCreateViewHolder methods in the CallLogAdapter. + Update/rework tests for related classes. + Fix a bug in the GroupingListAdapter, where childCount was not updated for standalone views, and the previously cached group size was used instead. Set childCount to 1 for standalone views. - Removed the idea of creating different views for standalone vs group vs group headers from the adapters. This logic has not been used for quite some time and all these functions funneled into createView/bindView methods anyways, so there is no logical difference. If we need to create custom views in the future, we can leverage onCreateViewHolder's viewType parameter. Bug: 19372817 Change-Id: I1b7289340600609669db22d8bc89265240d0b561 --- .../android/dialer/calllog/CallLogAdapterTest.java | 16 ++- .../dialer/calllog/CallLogFragmentTest.java | 111 +++++++++++---------- .../dialer/calllog/GroupingListAdapterTests.java | 53 ++++------ 3 files changed, 91 insertions(+), 89 deletions(-) (limited to 'tests/src') diff --git a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java index 845e279c9..bffbe5cf5 100644 --- a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java @@ -87,7 +87,8 @@ public class CallLogAdapterTest extends AndroidTestCase { mCursor.addRow(createCallLogEntry()); // Bind the views of a single row. - mAdapter.bindStandAloneView(mView, getContext(), mCursor); + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(CallLogListItemViews.fromView(getContext(), mView), 0); // There is one request for contact details. assertEquals(1, mAdapter.getContactInfoCache().requests.size()); @@ -105,7 +106,8 @@ public class CallLogAdapterTest extends AndroidTestCase { mCursor.addRow(createCallLogEntryWithCachedValues()); // Bind the views of a single row. - mAdapter.bindStandAloneView(mView, getContext(), mCursor); + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(CallLogListItemViews.fromView(getContext(), mView), 0); // There is one request for contact details. assertEquals(1, mAdapter.getContactInfoCache().requests.size()); @@ -123,7 +125,9 @@ public class CallLogAdapterTest extends AndroidTestCase { mAdapter.injectContactInfoForTest(TEST_NUMBER, TEST_COUNTRY_ISO, createContactInfo()); // Bind the views of a single row. - mAdapter.bindStandAloneView(mView, getContext(), mCursor); + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder( + CallLogListItemViews.fromView(getContext(), mView), 0); // There is one request for contact details. assertEquals(1, mAdapter.getContactInfoCache().requests.size()); @@ -138,7 +142,8 @@ public class CallLogAdapterTest extends AndroidTestCase { mAdapter.injectContactInfoForTest(TEST_NUMBER, TEST_COUNTRY_ISO, createContactInfo()); // Bind the views of a single row. - mAdapter.bindStandAloneView(mView, getContext(), mCursor); + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(CallLogListItemViews.fromView(getContext(), mView), 0); // Cache and call log are up-to-date: no need to request update. assertEquals(0, mAdapter.getContactInfoCache().requests.size()); @@ -153,7 +158,8 @@ public class CallLogAdapterTest extends AndroidTestCase { mAdapter.injectContactInfoForTest(TEST_NUMBER, TEST_COUNTRY_ISO, info); // Bind the views of a single row. - mAdapter.bindStandAloneView(mView, getContext(), mCursor); + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(CallLogListItemViews.fromView(getContext(), mView), 0); // There is one request for contact details. assertEquals(1, mAdapter.getContactInfoCache().requests.size()); diff --git a/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java b/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java index b57489d55..fe14f8709 100644 --- a/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogFragmentTest.java @@ -30,6 +30,7 @@ import android.net.Uri; import android.provider.CallLog.Calls; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.VoicemailContract; +import android.support.v7.widget.RecyclerView.ViewHolder; import android.telephony.PhoneNumberUtils; import android.telephony.TelephonyManager; import android.test.ActivityInstrumentationTestCase2; @@ -94,9 +95,9 @@ public class CallLogFragmentTest extends ActivityInstrumentationTestCase2