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