From f3a6e1c66fa5330f2af689ebf33c5e700e6aeeeb Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 21 Mar 2016 17:08:19 +0100 Subject: [PATCH] Added back fastscroll in contacts list --- res/layout/contacts_list.xml | 1 + src/org/linphone/ContactsListFragment.java | 53 +++++++++++++++++++--- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/res/layout/contacts_list.xml b/res/layout/contacts_list.xml index e8c8480aa..85b926589 100644 --- a/res/layout/contacts_list.xml +++ b/res/layout/contacts_list.xml @@ -126,6 +126,7 @@ android:divider="@color/colorE" android:fastScrollAlwaysVisible="true" android:fastScrollEnabled="true" + android:scrollbarStyle="outsideOverlay" android:dividerHeight="1dp" /> contacts; + String[] sections; + ArrayList sectionsList; + Mapmap = new LinkedHashMap(); ContactsListAdapter(List contactsList) { contacts = contactsList; + + map = new LinkedHashMap(); + String prevLetter = null; + for (int i = 0; i < contacts.size(); i++) { + LinphoneContact contact = contacts.get(i); + String firstLetter = contact.getFullName().substring(0, 1).toUpperCase(Locale.getDefault()); + if (!firstLetter.equals(prevLetter)) { + prevLetter = firstLetter; + map.put(firstLetter, i); + } + } + sectionsList = new ArrayList(map.keySet()); + sections = new String[sectionsList.size()]; + sectionsList.toArray(sections); } public int getCount() { @@ -456,7 +474,13 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O name.setText(contact.getFullName()); LinearLayout separator = (LinearLayout) view.findViewById(R.id.separator); - separator.setVisibility(View.GONE); + TextView separatorText = (TextView) view.findViewById(R.id.separator_text); + if (getPositionForSection(getSectionForPosition(position)) != position) { + separator.setVisibility(View.GONE); + } else { + separator.setVisibility(View.VISIBLE); + separatorText.setText(String.valueOf(contact.getFullName().charAt(0))); + } ImageView icon = (ImageView) view.findViewById(R.id.contact_picture); if (contact.hasPhoto()) { @@ -519,5 +543,22 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O return view; } + + @Override + public Object[] getSections() { + return sections; + } + + @Override + public int getPositionForSection(int sectionIndex) { + return map.get(sections[sectionIndex]); + } + + @Override + public int getSectionForPosition(int position) { + LinphoneContact contact = contacts.get(position); + String letter = contact.getFullName().substring(0, 1); + return sectionsList.indexOf(letter); + } } }