Fix fast scroll issue in contacts
This commit is contained in:
parent
a4d2ed86bb
commit
cd098600f7
3 changed files with 23 additions and 12 deletions
|
@ -48,6 +48,7 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:divider="@android:color/darker_gray"
|
android:divider="@android:color/darker_gray"
|
||||||
android:fastScrollAlwaysVisible="true"
|
android:fastScrollAlwaysVisible="true"
|
||||||
|
android:fastScrollEnabled="true"
|
||||||
android:dividerHeight="1dp" />
|
android:dividerHeight="1dp" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class Contact implements Serializable {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
private Uri photoUri;
|
private transient Uri photoUri;
|
||||||
private transient Bitmap photo;
|
private transient Bitmap photo;
|
||||||
private List<String> numerosOrAddresses;
|
private List<String> numerosOrAddresses;
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
private ImageView allContacts, linphoneContacts, newContact;
|
private ImageView allContacts, linphoneContacts, newContact;
|
||||||
private boolean onlyDisplayLinphoneContacts;
|
private boolean onlyDisplayLinphoneContacts;
|
||||||
private int lastKnownPosition;
|
private int lastKnownPosition;
|
||||||
|
private AlphabetIndexer indexer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
@ -62,8 +63,10 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
|
|
||||||
allContacts = (ImageView) view.findViewById(R.id.allContacts);
|
allContacts = (ImageView) view.findViewById(R.id.allContacts);
|
||||||
allContacts.setOnClickListener(this);
|
allContacts.setOnClickListener(this);
|
||||||
|
|
||||||
linphoneContacts = (ImageView) view.findViewById(R.id.linphoneContacts);
|
linphoneContacts = (ImageView) view.findViewById(R.id.linphoneContacts);
|
||||||
linphoneContacts.setOnClickListener(this);
|
linphoneContacts.setOnClickListener(this);
|
||||||
|
|
||||||
newContact = (ImageView) view.findViewById(R.id.newContact);
|
newContact = (ImageView) view.findViewById(R.id.newContact);
|
||||||
newContact.setOnClickListener(this);
|
newContact.setOnClickListener(this);
|
||||||
newContact.setEnabled(!LinphoneActivity.instance().isInCallLayout());
|
newContact.setEnabled(!LinphoneActivity.instance().isInCallLayout());
|
||||||
|
@ -82,13 +85,14 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
allContacts.setEnabled(false);
|
allContacts.setEnabled(false);
|
||||||
linphoneContacts.setEnabled(true);
|
linphoneContacts.setEnabled(true);
|
||||||
onlyDisplayLinphoneContacts = false;
|
onlyDisplayLinphoneContacts = false;
|
||||||
contactsList.setAdapter(new ContactsListAdapter(LinphoneActivity.instance().getAllContacts(), LinphoneActivity.instance().getAllContactsCursor()));
|
changeContactsAdapter();
|
||||||
}
|
}
|
||||||
else if (id == R.id.linphoneContacts) {
|
else if (id == R.id.linphoneContacts) {
|
||||||
allContacts.setEnabled(true);
|
allContacts.setEnabled(true);
|
||||||
linphoneContacts.setEnabled(false);
|
linphoneContacts.setEnabled(false);
|
||||||
onlyDisplayLinphoneContacts = true;
|
onlyDisplayLinphoneContacts = true;
|
||||||
contactsList.setAdapter(new ContactsListAdapter(LinphoneActivity.instance().getSIPContacts(), LinphoneActivity.instance().getSIPContactsCursor()));
|
changeContactsAdapter();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (id == R.id.newContact) {
|
else if (id == R.id.newContact) {
|
||||||
Intent intent = Compatibility.prepareAddContactIntent(null, null);
|
Intent intent = Compatibility.prepareAddContactIntent(null, null);
|
||||||
|
@ -96,6 +100,19 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void changeContactsAdapter() {
|
||||||
|
Cursor allContactsCursor = LinphoneActivity.instance().getAllContactsCursor();
|
||||||
|
Cursor sipContactsCursor = LinphoneActivity.instance().getSIPContactsCursor();
|
||||||
|
|
||||||
|
if (onlyDisplayLinphoneContacts) {
|
||||||
|
indexer = new AlphabetIndexer(sipContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(sipContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
|
contactsList.setAdapter(new ContactsListAdapter(LinphoneActivity.instance().getSIPContacts(), sipContactsCursor));
|
||||||
|
} else {
|
||||||
|
indexer = new AlphabetIndexer(allContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(allContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
|
contactsList.setAdapter(new ContactsListAdapter(LinphoneActivity.instance().getAllContacts(), allContactsCursor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
|
||||||
lastKnownPosition = contactsList.getFirstVisiblePosition();
|
lastKnownPosition = contactsList.getFirstVisiblePosition();
|
||||||
|
@ -110,19 +127,13 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contactsList.getAdapter() == null) {
|
if (contactsList.getAdapter() == null) {
|
||||||
if (onlyDisplayLinphoneContacts) {
|
changeContactsAdapter();
|
||||||
contactsList.setAdapter(new ContactsListAdapter(LinphoneActivity.instance().getSIPContacts(), LinphoneActivity.instance().getSIPContactsCursor()));
|
|
||||||
} else {
|
|
||||||
contactsList.setAdapter(new ContactsListAdapter(LinphoneActivity.instance().getAllContacts(), LinphoneActivity.instance().getAllContactsCursor()));
|
|
||||||
}
|
|
||||||
contactsList.setFastScrollEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contactsList.setSelectionFromTop(lastKnownPosition, 0);
|
contactsList.setSelectionFromTop(lastKnownPosition, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContactsListAdapter extends BaseAdapter implements SectionIndexer {
|
class ContactsListAdapter extends BaseAdapter implements SectionIndexer {
|
||||||
private AlphabetIndexer indexer;
|
|
||||||
private int margin;
|
private int margin;
|
||||||
private Bitmap bitmapUnknown;
|
private Bitmap bitmapUnknown;
|
||||||
private List<Contact> contacts;
|
private List<Contact> contacts;
|
||||||
|
@ -132,7 +143,6 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
contacts = contactsList;
|
contacts = contactsList;
|
||||||
cursor = c;
|
cursor = c;
|
||||||
|
|
||||||
indexer = new AlphabetIndexer(cursor, Compatibility.getCursorDisplayNameColumnIndex(cursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
|
||||||
margin = LinphoneUtils.pixelsToDpi(getResources(), 10);
|
margin = LinphoneUtils.pixelsToDpi(getResources(), 10);
|
||||||
bitmapUnknown = BitmapFactory.decodeResource(getResources(), R.drawable.unknown_small);
|
bitmapUnknown = BitmapFactory.decodeResource(getResources(), R.drawable.unknown_small);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue