Started improvements on how we use the magic search bar
This commit is contained in:
parent
e333e5a58a
commit
31e81fdd91
6 changed files with 126 additions and 201 deletions
|
@ -521,7 +521,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
if (!to.startsWith("sip:") || !to.contains("@")) {
|
||||
LinphoneContact contact = ContactsManager.getInstance().findContactFromPhoneNumber(to);
|
||||
if (contact != null) {
|
||||
String alias = contact.getPresenceModelForUriOrTel(to);
|
||||
String alias = contact.getContactFromPresenceModelForUriOrTel(to);
|
||||
if (alias != null) {
|
||||
to = alias;
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ import org.linphone.core.ChatRoomListenerStub;
|
|||
import org.linphone.core.Core;
|
||||
import org.linphone.core.FriendCapability;
|
||||
import org.linphone.core.ProxyConfig;
|
||||
import org.linphone.core.SearchResult;
|
||||
import org.linphone.fragments.FragmentsAvailable;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.settings.LinphonePreferences;
|
||||
|
@ -132,15 +133,9 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
mSearchLayout = view.findViewById(R.id.layoutSearchField);
|
||||
|
||||
mContactsFetchInProgress = view.findViewById(R.id.contactsFetchInProgress);
|
||||
mContactsFetchInProgress.setVisibility(View.VISIBLE);
|
||||
mContactsFetchInProgress.setVisibility(View.GONE);
|
||||
|
||||
mSearchAdapter =
|
||||
new SearchContactsAdapter(
|
||||
null,
|
||||
mContactsFetchInProgress,
|
||||
this,
|
||||
!mCreateGroupChatRoom,
|
||||
mChatRoomEncrypted);
|
||||
mSearchAdapter = new SearchContactsAdapter(this, !mCreateGroupChatRoom, mChatRoomEncrypted);
|
||||
|
||||
mSearchField = view.findViewById(R.id.searchField);
|
||||
mSearchField.setOnQueryTextListener(
|
||||
|
@ -152,7 +147,7 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
mSearchAdapter.searchContacts(newText, mContactsList);
|
||||
mSearchAdapter.searchContacts(newText);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -216,7 +211,8 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
&& savedInstanceState.getStringArrayList("mContactsSelected") != null) {
|
||||
mContactsSelectedLayout.removeAllViews();
|
||||
// We need to get all contacts not only sip
|
||||
for (String uri : savedInstanceState.getStringArrayList("mContactsSelected")) {
|
||||
// TODO
|
||||
/*for (String uri : savedInstanceState.getStringArrayList("mContactsSelected")) {
|
||||
for (ContactAddress ca : mSearchAdapter.getContactsList()) {
|
||||
if (ca.getAddressAsDisplayableString().compareTo(uri) == 0) {
|
||||
ca.setView(null);
|
||||
|
@ -224,7 +220,7 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
updateList();
|
||||
updateListSelected();
|
||||
}
|
||||
|
@ -382,7 +378,7 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
}
|
||||
|
||||
private void updateList() {
|
||||
mSearchAdapter.searchContacts(mSearchField.getQuery().toString(), mContactsList);
|
||||
mSearchAdapter.searchContacts(mSearchField.getQuery().toString());
|
||||
mSearchAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
@ -411,7 +407,7 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
|
||||
private void resetAndResearch() {
|
||||
ContactsManager.getInstance().getMagicSearch().resetSearchCache();
|
||||
mSearchAdapter.searchContacts(mSearchField.getQuery().toString(), mContactsList);
|
||||
mSearchAdapter.searchContacts(mSearchField.getQuery().toString());
|
||||
}
|
||||
|
||||
private void addSelectedContactAddress(ContactAddress ca) {
|
||||
|
@ -532,7 +528,7 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
}
|
||||
} else if (id == R.id.clearSearchField) {
|
||||
mSearchField.setQuery("", false);
|
||||
mSearchAdapter.searchContacts("", mContactsList);
|
||||
mSearchAdapter.searchContacts("");
|
||||
} else if (id == R.id.contactChatDelete) {
|
||||
ContactAddress ca = (ContactAddress) view.getTag();
|
||||
addOrRemoveContactFromSelection(ca);
|
||||
|
@ -541,21 +537,22 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
|
||||
@Override
|
||||
public void onItemClicked(int position) {
|
||||
ContactAddress ca = mSearchAdapter.getContacts().get(position);
|
||||
SearchResult searchResult = mSearchAdapter.getContacts().get(position);
|
||||
Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
ProxyConfig lpc = lc.getDefaultProxyConfig();
|
||||
boolean createEncryptedChatRoom = mSecurityToggle.isChecked();
|
||||
|
||||
if (createEncryptedChatRoom && !ca.hasCapability(FriendCapability.LimeX3Dh)) {
|
||||
if (createEncryptedChatRoom && !searchResult.hasCapability(FriendCapability.LimeX3Dh)) {
|
||||
Log.w(
|
||||
"[Chat Room Creation] Contact "
|
||||
+ ca.getContact()
|
||||
+ searchResult.getFriend()
|
||||
+ " doesn't have LIME X3DH capability !");
|
||||
return;
|
||||
} else if (mCreateGroupChatRoom && !ca.hasCapability(FriendCapability.GroupChat)) {
|
||||
} else if (mCreateGroupChatRoom
|
||||
&& !searchResult.hasCapability(FriendCapability.GroupChat)) {
|
||||
Log.w(
|
||||
"[Chat Room Creation] Contact "
|
||||
+ ca.getContact()
|
||||
+ searchResult.getFriend()
|
||||
+ " doesn't have group chat capability !");
|
||||
return;
|
||||
}
|
||||
|
@ -563,7 +560,8 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
if (lpc == null || lpc.getConferenceFactoryUri() == null || !mCreateGroupChatRoom) {
|
||||
if (createEncryptedChatRoom && lpc != null && lpc.getConferenceFactoryUri() != null) {
|
||||
mChatRoom =
|
||||
lc.findOneToOneChatRoom(lpc.getIdentityAddress(), ca.getAddress(), true);
|
||||
lc.findOneToOneChatRoom(
|
||||
lpc.getIdentityAddress(), searchResult.getAddress(), true);
|
||||
if (mChatRoom != null) {
|
||||
LinphoneActivity.instance()
|
||||
.goToChat(mChatRoom.getPeerAddress().asStringUriOnly(), mShareInfos);
|
||||
|
@ -575,7 +573,7 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
createEncryptedChatRoom);
|
||||
mChatRoom.addListener(mChatRoomCreationListener);
|
||||
Address participants[] = new Address[1];
|
||||
participants[0] = ca.getAddress();
|
||||
participants[0] = searchResult.getAddress();
|
||||
mChatRoom.addParticipants(participants);
|
||||
}
|
||||
} else {
|
||||
|
@ -584,7 +582,7 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
&& !LinphonePreferences.instance().useBasicChatRoomFor1To1()) {
|
||||
mChatRoom =
|
||||
lc.findOneToOneChatRoom(
|
||||
lpc.getIdentityAddress(), ca.getAddress(), false);
|
||||
lpc.getIdentityAddress(), searchResult.getAddress(), false);
|
||||
if (mChatRoom == null) {
|
||||
mWaitLayout.setVisibility(View.VISIBLE);
|
||||
mChatRoom =
|
||||
|
@ -592,7 +590,7 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
getString(R.string.dummy_group_chat_subject), true);
|
||||
mChatRoom.addListener(mChatRoomCreationListener);
|
||||
Address participants[] = new Address[1];
|
||||
participants[0] = ca.getAddress();
|
||||
participants[0] = searchResult.getAddress();
|
||||
mChatRoom.addParticipants(participants);
|
||||
} else {
|
||||
LinphoneActivity.instance()
|
||||
|
@ -600,13 +598,14 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
mChatRoom.getPeerAddress().asStringUriOnly(), mShareInfos);
|
||||
}
|
||||
} else {
|
||||
ChatRoom chatRoom = lc.getChatRoom(ca.getAddress());
|
||||
ChatRoom chatRoom = lc.getChatRoom(searchResult.getAddress());
|
||||
LinphoneActivity.instance()
|
||||
.goToChat(chatRoom.getPeerAddress().asStringUriOnly(), mShareInfos);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
addOrRemoveContactFromSelection(ca);
|
||||
// TODO
|
||||
// addOrRemoveContactFromSelection(searchResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ public class ContactAddress implements Serializable {
|
|||
|
||||
public Address getAddress() {
|
||||
String presence =
|
||||
mContact.getPresenceModelForUriOrTel(
|
||||
mContact.getContactFromPresenceModelForUriOrTel(
|
||||
(mPhoneNumber != null && !mPhoneNumber.isEmpty())
|
||||
? mPhoneNumber
|
||||
: mAddress);
|
||||
|
@ -115,10 +115,6 @@ public class ContactAddress implements Serializable {
|
|||
return mPhoneNumber;
|
||||
}
|
||||
|
||||
public boolean isLinphoneContact() {
|
||||
return mIsLinphoneContact;
|
||||
}
|
||||
|
||||
public boolean hasCapability(FriendCapability capability) {
|
||||
return mContact.hasFriendCapability(capability);
|
||||
}
|
||||
|
|
|
@ -276,7 +276,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
|||
});
|
||||
}
|
||||
|
||||
String contactAddress = mContact.getPresenceModelForUriOrTel(noa.getValue());
|
||||
String contactAddress = mContact.getContactFromPresenceModelForUriOrTel(noa.getValue());
|
||||
if (!mDisplayChatAddressOnly) {
|
||||
v.findViewById(R.id.contact_call).setOnClickListener(mDialListener);
|
||||
if (contactAddress != null) {
|
||||
|
@ -299,8 +299,8 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
|||
}
|
||||
|
||||
if (v.findViewById(R.id.friendLinphone).getVisibility() == View.VISIBLE
|
||||
&& lpc.getConferenceFactoryUri() != null
|
||||
&& mContact.hasFriendCapability(FriendCapability.LimeX3Dh)) {
|
||||
&& mContact.hasPresenceModelForUriOrTelCapability(
|
||||
noa.getValue(), FriendCapability.LimeX3Dh)) {
|
||||
v.findViewById(R.id.contact_chat_secured).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
v.findViewById(R.id.contact_chat_secured).setVisibility(View.GONE);
|
||||
|
|
|
@ -403,13 +403,27 @@ public class LinphoneContact extends AndroidContact
|
|||
return false;
|
||||
}
|
||||
|
||||
public String getPresenceModelForUriOrTel(String uri) {
|
||||
public String getContactFromPresenceModelForUriOrTel(String uri) {
|
||||
if (mFriend != null && mFriend.getPresenceModelForUriOrTel(uri) != null) {
|
||||
return mFriend.getPresenceModelForUriOrTel(uri).getContact();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PresenceBasicStatus getBasicStatusFromPresenceModelForUriOrTel(String uri) {
|
||||
if (mFriend != null && mFriend.getPresenceModelForUriOrTel(uri) != null) {
|
||||
return mFriend.getPresenceModelForUriOrTel(uri).getBasicStatus();
|
||||
}
|
||||
return PresenceBasicStatus.Closed;
|
||||
}
|
||||
|
||||
public boolean hasPresenceModelForUriOrTelCapability(String uri, FriendCapability capability) {
|
||||
if (mFriend != null && mFriend.getPresenceModelForUriOrTel(uri) != null) {
|
||||
return mFriend.getPresenceModelForUriOrTel(uri).hasCapability(capability);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void createFriend() {
|
||||
LinphoneContact contact = new LinphoneContact();
|
||||
Friend friend = LinphoneManager.getLc().createFriend();
|
||||
|
|
|
@ -22,7 +22,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import java.util.ArrayList;
|
||||
|
@ -31,21 +30,20 @@ import org.linphone.LinphoneActivity;
|
|||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.R;
|
||||
import org.linphone.core.Address;
|
||||
import org.linphone.core.Factory;
|
||||
import org.linphone.core.FriendCapability;
|
||||
import org.linphone.core.PresenceBasicStatus;
|
||||
import org.linphone.core.PresenceModel;
|
||||
import org.linphone.core.ProxyConfig;
|
||||
import org.linphone.core.SearchResult;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.views.ContactAvatar;
|
||||
|
||||
public class SearchContactsAdapter extends RecyclerView.Adapter<SearchContactViewHolder> {
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = SearchContactsAdapter.class.getSimpleName();
|
||||
|
||||
private List<ContactAddress> mContacts;
|
||||
private List<SearchResult> mContacts;
|
||||
private List<ContactAddress> mContactsSelected;
|
||||
private final ProgressBar mProgressBar;
|
||||
private boolean mOnlySipContact = false;
|
||||
private SearchContactViewHolder.ClickListener mListener;
|
||||
private final boolean mIsOnlyOnePersonSelection;
|
||||
|
@ -53,21 +51,18 @@ public class SearchContactsAdapter extends RecyclerView.Adapter<SearchContactVie
|
|||
private boolean mSecurityEnabled;
|
||||
|
||||
public SearchContactsAdapter(
|
||||
List<ContactAddress> contactsList,
|
||||
ProgressBar pB,
|
||||
SearchContactViewHolder.ClickListener clickListener,
|
||||
boolean hideSelectionMark,
|
||||
boolean isSecurityEnabled) {
|
||||
mIsOnlyOnePersonSelection = hideSelectionMark;
|
||||
mListener = clickListener;
|
||||
mProgressBar = pB;
|
||||
setContactsSelectedList(null);
|
||||
setContactsList(contactsList);
|
||||
mPreviousSearch = null;
|
||||
mSecurityEnabled = isSecurityEnabled;
|
||||
mContacts = new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<ContactAddress> getContacts() {
|
||||
public List<SearchResult> getContacts() {
|
||||
return mContacts;
|
||||
}
|
||||
|
||||
|
@ -91,47 +86,59 @@ public class SearchContactsAdapter extends RecyclerView.Adapter<SearchContactVie
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull SearchContactViewHolder holder, int position) {
|
||||
ContactAddress contact = getItem(position);
|
||||
final String a =
|
||||
(contact.getAddressAsDisplayableString().isEmpty())
|
||||
? contact.getPhoneNumber()
|
||||
: contact.getAddressAsDisplayableString();
|
||||
LinphoneContact c = contact.getContact();
|
||||
SearchResult searchResult = getItem(position);
|
||||
|
||||
String address = contact.getAddressAsDisplayableString();
|
||||
if (c != null && c.getFullName() != null) {
|
||||
if (address == null) address = c.getPresenceModelForUriOrTel(a);
|
||||
LinphoneContact contact;
|
||||
if (searchResult.getAddress() == null) {
|
||||
contact =
|
||||
ContactsManager.getInstance()
|
||||
.findContactFromPhoneNumber(searchResult.getPhoneNumber());
|
||||
} else {
|
||||
contact =
|
||||
ContactsManager.getInstance().findContactFromAddress(searchResult.getAddress());
|
||||
}
|
||||
|
||||
final String numberOrAddress =
|
||||
(searchResult.getPhoneNumber() != null)
|
||||
? searchResult.getPhoneNumber()
|
||||
: searchResult.getAddress().asStringUriOnly();
|
||||
|
||||
holder.name.setVisibility(View.GONE);
|
||||
if (contact != null && contact.getFullName() != null) {
|
||||
holder.name.setVisibility(View.VISIBLE);
|
||||
holder.name.setText(c.getFullName());
|
||||
} else if (contact.getAddress() != null) {
|
||||
if (contact.getAddress().getUsername() != null) {
|
||||
holder.name.setText(contact.getFullName());
|
||||
} else if (searchResult.getAddress() != null) {
|
||||
if (searchResult.getAddress().getUsername() != null) {
|
||||
holder.name.setVisibility(View.VISIBLE);
|
||||
holder.name.setText(contact.getAddress().getUsername());
|
||||
} else if (contact.getAddress().getDisplayName() != null) {
|
||||
holder.name.setText(searchResult.getAddress().getUsername());
|
||||
} else if (searchResult.getAddress().getDisplayName() != null) {
|
||||
holder.name.setVisibility(View.VISIBLE);
|
||||
holder.name.setText(contact.getAddress().getDisplayName());
|
||||
holder.name.setText(searchResult.getAddress().getDisplayName());
|
||||
}
|
||||
} else if (address != null) {
|
||||
Address tmpAddr = Factory.instance().createAddress(address);
|
||||
} else if (searchResult.getAddress() != null) {
|
||||
holder.name.setVisibility(View.VISIBLE);
|
||||
holder.name.setText(
|
||||
(tmpAddr.getDisplayName() != null)
|
||||
? tmpAddr.getDisplayName()
|
||||
: tmpAddr.getUsername());
|
||||
} else {
|
||||
holder.name.setVisibility(View.GONE);
|
||||
(searchResult.getAddress().getDisplayName() != null)
|
||||
? searchResult.getAddress().getDisplayName()
|
||||
: searchResult.getAddress().getUsername());
|
||||
}
|
||||
|
||||
holder.disabled.setVisibility(View.GONE);
|
||||
if (c != null) {
|
||||
if (c.getFullName() == null && c.getFirstName() == null && c.getLastName() == null) {
|
||||
c.setFullName(holder.name.getText().toString());
|
||||
if (contact != null) {
|
||||
if (contact.getFullName() == null
|
||||
&& contact.getFirstName() == null
|
||||
&& contact.getLastName() == null) {
|
||||
contact.setFullName(holder.name.getText().toString());
|
||||
}
|
||||
ContactAvatar.displayAvatar(
|
||||
c, c.hasFriendCapability(FriendCapability.LimeX3Dh), holder.avatarLayout);
|
||||
contact,
|
||||
contact.hasFriendCapability(FriendCapability.LimeX3Dh),
|
||||
holder.avatarLayout);
|
||||
|
||||
if ((!mIsOnlyOnePersonSelection && !c.hasFriendCapability(FriendCapability.GroupChat))
|
||||
|| (mSecurityEnabled && !c.hasFriendCapability(FriendCapability.LimeX3Dh))) {
|
||||
if ((!mIsOnlyOnePersonSelection
|
||||
&& !searchResult.hasCapability(FriendCapability.GroupChat))
|
||||
|| (mSecurityEnabled
|
||||
&& !searchResult.hasCapability(FriendCapability.LimeX3Dh))) {
|
||||
// Disable row, contact doesn't have the required capabilities
|
||||
holder.disabled.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
@ -139,16 +146,18 @@ public class SearchContactsAdapter extends RecyclerView.Adapter<SearchContactVie
|
|||
ContactAvatar.displayAvatar(holder.name.getText().toString(), holder.avatarLayout);
|
||||
}
|
||||
|
||||
holder.address.setText(a);
|
||||
holder.address.setText(numberOrAddress);
|
||||
if (holder.linphoneContact != null) {
|
||||
if (contact.isLinphoneContact() && c != null && c.isInFriendList() && address != null) {
|
||||
holder.linphoneContact.setVisibility(View.GONE);
|
||||
if (searchResult.getFriend() != null
|
||||
&& contact != null
|
||||
&& contact.getBasicStatusFromPresenceModelForUriOrTel(numberOrAddress)
|
||||
== PresenceBasicStatus.Open) {
|
||||
holder.linphoneContact.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.linphoneContact.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
if (holder.isSelect != null) {
|
||||
if (contactIsSelected(contact)) {
|
||||
if (contactIsSelected(searchResult)) {
|
||||
holder.isSelect.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.isSelect.setVisibility(View.INVISIBLE);
|
||||
|
@ -163,15 +172,16 @@ public class SearchContactsAdapter extends RecyclerView.Adapter<SearchContactVie
|
|||
return position;
|
||||
}
|
||||
|
||||
private boolean contactIsSelected(ContactAddress ca) {
|
||||
private boolean contactIsSelected(SearchResult sr) {
|
||||
for (ContactAddress c : mContactsSelected) {
|
||||
Address addr = c.getAddress();
|
||||
if (addr.getUsername() != null && ca.getAddress() != null) {
|
||||
if (addr.asStringUriOnly().compareTo(ca.getAddress().asStringUriOnly()) == 0)
|
||||
if (addr != null && sr.getAddress() != null) {
|
||||
if (addr.weakEqual(sr.getAddress())) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (c.getPhoneNumber() != null && ca.getPhoneNumber() != null) {
|
||||
if (c.getPhoneNumber().compareTo(ca.getPhoneNumber()) == 0) return true;
|
||||
if (c.getPhoneNumber() != null && sr.getPhoneNumber() != null) {
|
||||
if (c.getPhoneNumber().compareTo(sr.getPhoneNumber()) == 0) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -190,63 +200,7 @@ public class SearchContactsAdapter extends RecyclerView.Adapter<SearchContactVie
|
|||
}
|
||||
}
|
||||
|
||||
public List<ContactAddress> getContactsList() {
|
||||
List<ContactAddress> list = new ArrayList<>();
|
||||
if (ContactsManager.getInstance().hasContacts()) {
|
||||
List<LinphoneContact> contacts =
|
||||
mOnlySipContact
|
||||
? ContactsManager.getInstance().getSIPContacts()
|
||||
: ContactsManager.getInstance().getContacts();
|
||||
for (LinphoneContact contact : contacts) {
|
||||
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
|
||||
if (!mOnlySipContact
|
||||
|| (mOnlySipContact
|
||||
&& (noa.isSIPAddress()
|
||||
|| contact.getPresenceModelForUriOrTel(noa.getValue())
|
||||
!= null))) {
|
||||
ContactAddress ca = null;
|
||||
if (noa.isSIPAddress()) {
|
||||
Address address = LinphoneManager.getLc().interpretUrl(noa.getValue());
|
||||
if (address != null) {
|
||||
ca =
|
||||
new ContactAddress(
|
||||
contact,
|
||||
address.asString(),
|
||||
"",
|
||||
contact.isFriend());
|
||||
}
|
||||
} else {
|
||||
ProxyConfig prx = LinphoneManager.getLc().getDefaultProxyConfig();
|
||||
String number =
|
||||
(prx != null)
|
||||
? prx.normalizePhoneNumber(noa.getValue())
|
||||
: noa.getValue();
|
||||
ca = new ContactAddress(contact, "", number, contact.isFriend());
|
||||
}
|
||||
if (ca != null) list.add(ca);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ContactAddress caS : mContactsSelected) {
|
||||
for (ContactAddress ca : list) {
|
||||
if (ca.equals(caS)) ca.setSelect(true);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void setContactsList(List<ContactAddress> contactsList) {
|
||||
if (contactsList == null) {
|
||||
mContacts = getContactsList();
|
||||
if (mProgressBar != null) mProgressBar.setVisibility(View.GONE);
|
||||
} else {
|
||||
mContacts = contactsList;
|
||||
}
|
||||
}
|
||||
|
||||
private ContactAddress getItem(int position) {
|
||||
private SearchResult getItem(int position) {
|
||||
return mContacts.get(position);
|
||||
}
|
||||
|
||||
|
@ -255,8 +209,8 @@ public class SearchContactsAdapter extends RecyclerView.Adapter<SearchContactVie
|
|||
return mContacts.size();
|
||||
}
|
||||
|
||||
public void searchContacts(String search, RecyclerView resultContactsSearch) {
|
||||
List<ContactAddress> result = new ArrayList<>();
|
||||
public void searchContacts(String search) {
|
||||
List<SearchResult> result = new ArrayList<>();
|
||||
|
||||
if (mPreviousSearch != null) {
|
||||
if (mPreviousSearch.length() > search.length()) {
|
||||
|
@ -268,77 +222,39 @@ public class SearchContactsAdapter extends RecyclerView.Adapter<SearchContactVie
|
|||
String domain = "";
|
||||
ProxyConfig prx = LinphoneManager.getLc().getDefaultProxyConfig();
|
||||
if (prx != null) domain = prx.getDomain();
|
||||
SearchResult[] results =
|
||||
SearchResult[] searchResults =
|
||||
ContactsManager.getInstance()
|
||||
.getMagicSearch()
|
||||
.getContactListFromFilter(search, mOnlySipContact ? domain : "");
|
||||
for (SearchResult sr : results) {
|
||||
boolean found = false;
|
||||
LinphoneContact contact =
|
||||
ContactsManager.getInstance().findContactFromAddress(sr.getAddress());
|
||||
if (contact == null) {
|
||||
contact = new LinphoneContact();
|
||||
|
||||
for (SearchResult sr : searchResults) {
|
||||
if (sr.getAddress() != null) {
|
||||
Log.e("### " + sr.getPhoneNumber() + " / " + sr.getAddress().asString());
|
||||
} else {
|
||||
Log.e("### " + sr.getPhoneNumber());
|
||||
}
|
||||
if (LinphoneActivity.instance()
|
||||
.getResources()
|
||||
.getBoolean(R.bool.hide_sip_contacts_without_presence)) {
|
||||
if (sr.getFriend() != null) {
|
||||
contact.setFriend(sr.getFriend());
|
||||
contact.refresh();
|
||||
}
|
||||
}
|
||||
if (sr.getAddress() != null || sr.getPhoneNumber() != null) {
|
||||
for (ContactAddress ca : result) {
|
||||
String normalizedPhoneNumber =
|
||||
(ca != null && ca.getPhoneNumber() != null && prx != null)
|
||||
? prx.normalizePhoneNumber(ca.getPhoneNumber())
|
||||
: null;
|
||||
if ((sr.getAddress() != null
|
||||
&& ca.getAddress() != null
|
||||
&& ca.getAddress()
|
||||
.asStringUriOnly()
|
||||
.equals(sr.getAddress().asStringUriOnly()))
|
||||
|| (sr.getPhoneNumber() != null
|
||||
&& normalizedPhoneNumber != null
|
||||
&& sr.getPhoneNumber().equals(normalizedPhoneNumber))) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
if (LinphoneActivity.instance()
|
||||
.getResources()
|
||||
.getBoolean(R.bool.hide_sip_contacts_without_presence)) {
|
||||
if (contact.getFriend() != null) {
|
||||
for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
|
||||
PresenceModel pm =
|
||||
contact.getFriend().getPresenceModelForUriOrTel(noa.getValue());
|
||||
if (pm != null
|
||||
&& pm.getBasicStatus().equals(PresenceBasicStatus.Open)) {
|
||||
result.add(
|
||||
new ContactAddress(
|
||||
contact,
|
||||
(sr.getAddress() != null)
|
||||
? sr.getAddress().asStringUriOnly()
|
||||
: "",
|
||||
sr.getPhoneNumber(),
|
||||
contact.isFriend()));
|
||||
break;
|
||||
}
|
||||
PresenceModel pm =
|
||||
sr.getFriend()
|
||||
.getPresenceModelForUriOrTel(sr.getAddress().asStringUriOnly());
|
||||
if (pm != null && pm.getBasicStatus().equals(PresenceBasicStatus.Open)) {
|
||||
result.add(sr);
|
||||
} else {
|
||||
pm = sr.getFriend().getPresenceModelForUriOrTel(sr.getPhoneNumber());
|
||||
if (pm != null && pm.getBasicStatus().equals(PresenceBasicStatus.Open)) {
|
||||
result.add(sr);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result.add(
|
||||
new ContactAddress(
|
||||
contact,
|
||||
(sr.getAddress() != null)
|
||||
? sr.getAddress().asStringUriOnly()
|
||||
: "",
|
||||
sr.getPhoneNumber(),
|
||||
contact.isFriend()));
|
||||
}
|
||||
} else {
|
||||
result.add(sr);
|
||||
}
|
||||
}
|
||||
|
||||
mContacts = result;
|
||||
resultContactsSearch.setAdapter(this);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue