diff options
author | calderwoodra <calderwoodra@google.com> | 2017-11-27 19:39:32 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-11-29 11:43:22 -0800 |
commit | af96139ce2bb384036f85654441b248b3b4ef77c (patch) | |
tree | fc3223552f96cbecba6d8ee0a1ad0ca09da63dcb /java/com/android/dialer/contactsfragment/ContactsAdapter.java | |
parent | 5e22e8009682c92b1b4bb44301da3c606b0090e8 (diff) |
Contact list no longer jumps to the top when the cp2 database updates.
The contacts fragment recycler view was rebuilding the adapter and layout
manager each time the Contacts.CONTENT_URI observered a content change. Now we
simply update the adapter's cursor and notifyDataSetChanged. This keeps the
recycler view in place through all changes (inserts, deletes and updates).
This change also fixes another bug replated to contacts fragment not refreshing
when the contacts permission was granted in another part of the UI.
Bug: 64044576,67781478,68179085
Test: manual
PiperOrigin-RevId: 177106761
Change-Id: Ib6a929efb047001d681cb008c3ede69860146836
Diffstat (limited to 'java/com/android/dialer/contactsfragment/ContactsAdapter.java')
-rw-r--r-- | java/com/android/dialer/contactsfragment/ContactsAdapter.java | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/java/com/android/dialer/contactsfragment/ContactsAdapter.java b/java/com/android/dialer/contactsfragment/ContactsAdapter.java index 481574e0c..8f2120cd7 100644 --- a/java/com/android/dialer/contactsfragment/ContactsAdapter.java +++ b/java/com/android/dialer/contactsfragment/ContactsAdapter.java @@ -49,22 +49,24 @@ final class ContactsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder private final ArrayMap<ContactViewHolder, Integer> holderMap = new ArrayMap<>(); private final Context context; - private final Cursor cursor; private final @Header int header; private final @ClickAction int clickAction; // List of contact sublist headers - private final String[] headers; - + private String[] headers = new String[0]; // Number of contacts that correspond to each header in {@code headers}. - private final int[] counts; + private int[] counts = new int[0]; + // Cursor with list of contacts + private Cursor cursor; - ContactsAdapter( - Context context, Cursor cursor, @Header int header, @ClickAction int clickAction) { + ContactsAdapter(Context context, @Header int header, @ClickAction int clickAction) { this.context = context; - this.cursor = cursor; this.header = header; this.clickAction = clickAction; + } + + void updateCursor(Cursor cursor) { + this.cursor = cursor; headers = cursor.getExtras().getStringArray(Contacts.EXTRA_ADDRESS_BOOK_INDEX_TITLES); counts = cursor.getExtras().getIntArray(Contacts.EXTRA_ADDRESS_BOOK_INDEX_COUNTS); if (counts != null) { @@ -78,6 +80,7 @@ final class ContactsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder "ContactsAdapter", "Count sum (%d) != cursor count (%d).", sum, cursor.getCount()); } } + notifyDataSetChanged(); } @Override |