Improved search bars + disable some features if default proxy config domain isn't sip.linphone.org

This commit is contained in:
Sylvain Berfini 2018-11-02 15:02:24 +01:00
parent a404543789
commit a5287df9c8
7 changed files with 55 additions and 87 deletions

View file

@ -132,28 +132,18 @@
android:layout_height="wrap_content"
android:layout_margin="10dp">
<EditText
<SearchView
android:id="@+id/searchField"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/resizable_textfield"
android:hint="@string/chat_room_creation_filter_hint"
android:contentDescription="@string/content_description_search_contact"
android:gravity="center"
android:inputType="textPersonName"
android:paddingRight="5dp"
android:iconifiedByDefault="false"
android:queryBackground="@android:color/transparent"
android:queryHint="@string/chat_room_creation_filter_hint"
android:textColor="@android:color/black"
android:textCursorDrawable="@null"/>
<ImageView
android:id="@+id/clearSearchField"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="@drawable/clean_field"/>
android:background="@drawable/resizable_textfield"
android:inputType="textPersonName"/>
</RelativeLayout>

View file

@ -92,29 +92,19 @@
android:layout_height="wrap_content"
android:layout_margin="10dp">
<EditText
android:contentDescription="@string/content_description_search_contact"
android:hint="@string/chat_room_creation_filter_hint"
android:textCursorDrawable="@null"
<SearchView
android:id="@+id/searchField"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textColor="@android:color/black"
android:background="@drawable/resizable_textfield"
android:gravity="center"
android:paddingRight="5dp"
android:iconifiedByDefault="false"
android:queryBackground="@android:color/transparent"
android:queryHint="@string/chat_room_creation_filter_hint"
android:textColor="@android:color/black"
android:background="@drawable/resizable_textfield"
android:inputType="textPersonName"/>
<ImageView
android:id="@+id/clearSearchField"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/clean_field_default"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:paddingLeft="5dp"
android:paddingRight="5dp"/>
</RelativeLayout>
<RelativeLayout

View file

@ -30,12 +30,12 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.SearchView;
import android.widget.Switch;
import android.widget.TextView;
@ -65,11 +65,11 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
private LinearLayout mContactsSelectedLayout;
private HorizontalScrollView mContactsSelectLayout;
private ArrayList<ContactAddress> mContactsSelected;
private ImageView mAllContactsButton, mLinphoneContactsButton, mClearSearchFieldButton, mBackButton, mNextButton;
private ImageView mAllContactsButton, mLinphoneContactsButton, mBackButton, mNextButton;
private boolean mOnlyDisplayLinphoneContacts;
private View mAllContactsSelected, mLinphoneContactsSelected;
private RelativeLayout mSearchLayout, mWaitLayout, mLinphoneContactsToggle, mAllContactsToggle;
private EditText mSearchField;
private SearchView mSearchField;
private ProgressBar mContactsFetchInProgress;
private SearchContactsListAdapter mSearchAdapter;
private String mChatRoomSubject, mChatRoomAddress;
@ -125,31 +125,22 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
mNextButton.setEnabled(false);
mSearchLayout = view.findViewById(R.id.layoutSearchField);
mClearSearchFieldButton = view.findViewById(R.id.clearSearchField);
mClearSearchFieldButton.setOnClickListener(this);
mContactsFetchInProgress = view.findViewById(R.id.contactsFetchInProgress);
mContactsFetchInProgress.setVisibility(View.VISIBLE);
mSearchAdapter = new SearchContactsListAdapter(null, mContactsFetchInProgress, this, mCreateGroupChatRoom == false);
mSearchField = view.findViewById(R.id.searchField);
mSearchField.addTextChangedListener(new TextWatcher() {
mSearchField.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (before > count) {
ContactsManager.getInstance().getMagicSearch().resetSearchCache();
}
public boolean onQueryTextSubmit(String query) {
return true;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
mSearchAdapter.searchContacts(mSearchField.getText().toString(), mContactsList);
public boolean onQueryTextChange(String newText) {
mSearchAdapter.searchContacts(newText, mContactsList);
return true;
}
});
@ -326,7 +317,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
}
private void updateList() {
mSearchAdapter.searchContacts(mSearchField.getText().toString(), mContactsList);
mSearchAdapter.searchContacts(mSearchField.getQuery().toString(), mContactsList);
mSearchAdapter.notifyDataSetChanged();
}
@ -354,7 +345,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
private void resetAndResearch() {
ContactsManager.getInstance().getMagicSearch().resetSearchCache();
mSearchAdapter.searchContacts(mSearchField.getText().toString(), mContactsList);
mSearchAdapter.searchContacts(mSearchField.getQuery().toString(), mContactsList);
}
private void addSelectedContactAddress(ContactAddress ca) {
@ -453,7 +444,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
LinphoneActivity.instance().goToChatGroupInfos(mChatRoomAddress, mContactsSelected, mChatRoomSubject, true, true, mShareInfos, mSecurityToggle.isChecked());
}
} else if (id == R.id.clearSearchField) {
mSearchField.setText("");
mSearchField.setQuery("", false);
mSearchAdapter.searchContacts("", mContactsList);
} else if (id == R.id.contactChatDelete) {
ContactAddress ca = (ContactAddress) view.getTag();

View file

@ -42,6 +42,7 @@ import org.linphone.core.ChatRoomListenerStub;
import org.linphone.core.Core;
import org.linphone.core.CoreListenerStub;
import org.linphone.core.EventLog;
import org.linphone.core.ProxyConfig;
import org.linphone.fragments.FragmentsAvailable;
import org.linphone.mediastream.Log;
import org.linphone.ui.SelectableHelper;
@ -210,6 +211,9 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
}
refreshChatRoomsList();
ProxyConfig lpc = lc.getDefaultProxyConfig();
mNewGroupDiscussionButton.setEnabled(lpc != null && lpc.getConferenceFactoryUri() != null);
}
@Override

View file

@ -33,9 +33,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.SearchView;
import android.widget.TextView;
import org.linphone.LinphoneManager;
@ -56,8 +56,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
private int lastKnownPosition;
private boolean editOnClick = false, editConsumed = false, onlyDisplayChatAddress = false;
private String sipAddressToAdd, displayName = null;
private ImageView clearSearchField;
private EditText searchField;
private SearchView mSearchView;
private ProgressBar contactsFetchInProgress;
private LinearLayoutManager layoutManager;
private Context mContext;
@ -149,27 +148,17 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
}
}
clearSearchField = view.findViewById(R.id.clearSearchField);
clearSearchField.setOnClickListener(new View.OnClickListener() {
mSearchView = view.findViewById(R.id.searchField);
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public void onClick(View v) {
searchField.setText("");
}
});
searchField = view.findViewById(R.id.searchField);
searchField.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
public boolean onQueryTextSubmit(String query) {
return true;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
searchContacts(searchField.getText().toString());
public boolean onQueryTextChange(String newText) {
searchContacts(newText.toString());
return true;
}
});
@ -232,7 +221,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
noContact.setVisibility(View.GONE);
contactsList.setVisibility(View.VISIBLE);
boolean isEditionEnabled = false;
if (searchField.getText().toString() == "") {
if (mSearchView.getQuery().toString() == "") {
if (onlyDisplayLinphoneContacts) {
listContact = ContactsManager.getInstance().getSIPContacts();
} else {
@ -240,9 +229,9 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
}
} else {
if (onlyDisplayLinphoneContacts) {
listContact = ContactsManager.getInstance().getSIPContacts(searchField.getText().toString());
listContact = ContactsManager.getInstance().getSIPContacts(mSearchView.getQuery().toString());
} else {
listContact = ContactsManager.getInstance().getContacts(searchField.getText().toString());
listContact = ContactsManager.getInstance().getContacts(mSearchView.getQuery().toString());
}
}
@ -267,8 +256,6 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
} else if (onlyDisplayLinphoneContacts && mContactAdapter.getItemCount() == 0) {
noSipContact.setVisibility(View.VISIBLE);
}
ContactsManager.getInstance().setLinphoneContactsPrefered(onlyDisplayLinphoneContacts);
}
private void changeContactsToggle() {
@ -365,8 +352,8 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
}
public void invalidate() {
if (searchField != null && searchField.getText().toString().length() > 0) {
searchContacts(searchField.getText().toString());
if (mSearchView != null && mSearchView.getQuery().toString().length() > 0) {
searchContacts(mSearchView.getQuery().toString());
} else {
changeContactsAdapter();
}

View file

@ -76,7 +76,6 @@ public class ContactsManager extends ContentObserver implements FriendListListen
private List<LinphoneContact> mContacts, mSipContacts;
private MagicSearch magicSearch;
private boolean preferLinphoneContacts = false;
private Activity mActivity;
private HashMap<String, LinphoneContact> mAndroidContactsCache;
private Bitmap defaultAvatar;
@ -202,12 +201,10 @@ public class ContactsManager extends ContentObserver implements FriendListListen
return contactsR && !mActivity.getResources().getBoolean(R.bool.force_use_of_linphone_friends);
}
public void setLinphoneContactsPrefered(boolean isPrefered) {
preferLinphoneContacts = isPrefered;
}
public boolean isLinphoneContactsPrefered() {
return preferLinphoneContacts;
ProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
if (lpc != null && lpc.getIdentityAddress().getDomain().equals(getString(R.string.default_domain))) return true;
return false;
}
public void initializeContactManager(Activity activity) {

View file

@ -85,7 +85,8 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter<SearchContac
private ProgressBar progressBar;
private boolean mOnlySipContact = false;
private ViewHolder.ClickListener mListener;
private boolean mHideSelectionMark = false;
private boolean mHideSelectionMark;
private String mPreviousSearch;
public List<ContactAddress> getContacts() {
return contacts;
@ -105,6 +106,7 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter<SearchContac
progressBar = pB;
setContactsSelectedList(null);
setContactsList(contactsList);
mPreviousSearch = null;
}
@NonNull
@ -259,6 +261,13 @@ public class SearchContactsListAdapter extends RecyclerView.Adapter<SearchContac
public void searchContacts(String search, RecyclerView resultContactsSearch) {
List<ContactAddress> result = new ArrayList<>();
if (mPreviousSearch != null) {
if (mPreviousSearch.length() > search.length()) {
ContactsManager.getInstance().getMagicSearch().resetSearchCache();
}
}
mPreviousSearch = search;
String domain = "";
ProxyConfig prx = LinphoneManager.getLc().getDefaultProxyConfig();
if (prx != null) domain = prx.getDomain();