Update Linphone + searchContactAdapter

This commit is contained in:
Erwan Croze 2017-09-14 11:43:22 +02:00
parent d915a07f3e
commit 50dd5520b3
3 changed files with 26 additions and 23 deletions

View file

@ -74,12 +74,12 @@ public class AboutFragment extends Fragment implements OnClickListener {
resetLogButton = view.findViewById(R.id.reset_log); resetLogButton = view.findViewById(R.id.reset_log);
resetLogButton.setOnClickListener(this); resetLogButton.setOnClickListener(this);
resetLogButton.setVisibility(LinphonePreferences.instance().isDebugEnabled() ? View.VISIBLE : View.GONE); resetLogButton.setVisibility(LinphonePreferences.instance().isDebugEnabled() ? View.VISIBLE : View.GONE);
mListener = new LinphoneCoreListenerBase() { mListener = new LinphoneCoreListenerBase() {
@Override @Override
public void uploadProgressIndication(LinphoneCore lc, int offset, int total) { public void uploadProgressIndication(LinphoneCore lc, int offset, int total) {
} }
@Override @Override
public void uploadStateChanged(LinphoneCore lc, LogCollectionUploadState state, String info) { public void uploadStateChanged(LinphoneCore lc, LogCollectionUploadState state, String info) {
if (state == LogCollectionUploadState.LogCollectionUploadStateInProgress) { if (state == LogCollectionUploadState.LogCollectionUploadStateInProgress) {
@ -96,13 +96,13 @@ public class AboutFragment extends Fragment implements OnClickListener {
return view; return view;
} }
private void displayUploadLogsInProgress() { private void displayUploadLogsInProgress() {
if (uploadInProgress) { if (uploadInProgress) {
return; return;
} }
uploadInProgress = true; uploadInProgress = true;
progress = ProgressDialog.show(LinphoneActivity.instance(), null, null); progress = ProgressDialog.show(LinphoneActivity.instance(), null, null);
Drawable d = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.colorE)); Drawable d = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.colorE));
d.setAlpha(200); d.setAlpha(200);
@ -134,7 +134,7 @@ public class AboutFragment extends Fragment implements OnClickListener {
if (lc != null) { if (lc != null) {
lc.removeListener(mListener); lc.removeListener(mListener);
} }
super.onPause(); super.onPause();
} }
@ -144,11 +144,11 @@ public class AboutFragment extends Fragment implements OnClickListener {
if (lc != null) { if (lc != null) {
lc.addListener(mListener); lc.addListener(mListener);
} }
if (LinphoneActivity.isInstanciated()) { if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().selectMenu(FragmentsAvailable.ABOUT); LinphoneActivity.instance().selectMenu(FragmentsAvailable.ABOUT);
} }
super.onResume(); super.onResume();
} }
@ -169,7 +169,7 @@ public class AboutFragment extends Fragment implements OnClickListener {
} }
} }
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();

View file

@ -28,6 +28,8 @@ import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import org.linphone.core.LinphoneAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -58,6 +60,7 @@ public class SearchContactsListAdapter extends BaseAdapter {
private ProgressBar progressBar; private ProgressBar progressBar;
private boolean mOnlySipContact = false; private boolean mOnlySipContact = false;
private View.OnClickListener listener; private View.OnClickListener listener;
private int oldSize;
public List<ContactAddress> getContacts() { public List<ContactAddress> getContacts() {
return contacts; return contacts;
@ -76,6 +79,7 @@ public class SearchContactsListAdapter extends BaseAdapter {
progressBar = pB; progressBar = pB;
setContactsSelectedList(null); setContactsSelectedList(null);
setContactsList(contactsList); setContactsList(contactsList);
oldSize = 0;
} }
public void setContactsList(List<ContactAddress> contactsList) { public void setContactsList(List<ContactAddress> contactsList) {
@ -99,18 +103,16 @@ public class SearchContactsListAdapter extends BaseAdapter {
public List<ContactAddress> getContactsList() { public List<ContactAddress> getContactsList() {
List<ContactAddress> list = new ArrayList<ContactAddress>(); List<ContactAddress> list = new ArrayList<ContactAddress>();
if(ContactsManager.getInstance().hasContacts()) { if(ContactsManager.getInstance().hasContacts()) {
for (LinphoneContact con : (mOnlySipContact) for (LinphoneAddress addr : LinphoneManager.getLc().findContactsByChar("", mOnlySipContact)) {
? ContactsManager.getInstance().getSIPContacts() : ContactsManager.getInstance().getContacts()) { LinphoneContact cont = ContactsManager.getInstance().findContactFromAddress(addr);
for (LinphoneNumberOrAddress noa : con.getNumbersOrAddresses()) { if (cont == null) {
String value = noa.getValue(); cont = new LinphoneContact();
// Fix for sip:username compatibility issue cont.setFullName(addr.getUserName());
if (value.startsWith("sip:") && !value.contains("@")) {
value = value.substring(4);
value = LinphoneUtils.getFullAddressFromUsername(value);
}
ContactAddress ca = new ContactAddress(con, value, con.isInLinphoneFriendList());
list.add(ca);
} }
// TODO Rechercher si un contact est associé à cette sip uri
// TODO Rechercher si un displayname est associé à cette sip uri
ContactAddress ca = new ContactAddress(cont , addr.asString(), cont.isLinphoneFriend());
list.add(ca);
} }
} }
@ -143,12 +145,13 @@ public class SearchContactsListAdapter extends BaseAdapter {
if (search == null || search.length() == 0) { if (search == null || search.length() == 0) {
contacts = getContactsList(); contacts = getContactsList();
resultContactsSearch.setAdapter(this); resultContactsSearch.setAdapter(this);
oldSize = 0;
return; return;
} }
List<ContactAddress> result = new ArrayList<ContactAddress>(); List<ContactAddress> result = new ArrayList<ContactAddress>();
if(search != null) { if(search != null) {
for (ContactAddress c : getContacts()) { for (ContactAddress c : (search.length() < oldSize) ? getContactsList() : getContacts()) {
String address = c.getAddress(); String address = c.getAddress();
if (address.startsWith("sip:")) address = address.substring(4); if (address.startsWith("sip:")) address = address.substring(4);
if (c.getContact().getFullName() != null if (c.getContact().getFullName() != null
@ -158,8 +161,8 @@ public class SearchContactsListAdapter extends BaseAdapter {
} }
} }
} }
oldSize = search.length();
setContactsList(result); contacts = result;
resultContactsSearch.setAdapter(this); resultContactsSearch.setAdapter(this);
this.notifyDataSetChanged(); this.notifyDataSetChanged();
} }

@ -1 +1 @@
Subproject commit e095830bb6a6dda714f2ca9889888e2132659f91 Subproject commit 91dad233b55c66d9968771fd613812d0539097a9