diff options
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/MucUsersActivity.java | 85 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/adapter/UserAdapter.java | 5 | ||||
-rw-r--r-- | src/main/res/menu/muc_users_activity.xml | 11 | ||||
-rw-r--r-- | src/main/res/values/strings.xml | 1 |
4 files changed, 96 insertions, 6 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/MucUsersActivity.java b/src/main/java/de/pixart/messenger/ui/MucUsersActivity.java index 9961e5512..b8bc57b87 100644 --- a/src/main/java/de/pixart/messenger/ui/MucUsersActivity.java +++ b/src/main/java/de/pixart/messenger/ui/MucUsersActivity.java @@ -1,17 +1,27 @@ package de.pixart.messenger.ui; +import android.content.Context; import android.content.Intent; import android.databinding.DataBindingUtil; import android.os.Bundle; import android.support.v7.widget.Toolbar; +import android.text.Editable; +import android.text.TextUtils; +import android.text.TextWatcher; +import android.view.Menu; import android.view.MenuItem; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; import android.widget.Toast; import java.util.ArrayList; import java.util.Collections; +import java.util.Locale; import de.pixart.messenger.R; import de.pixart.messenger.databinding.ActivityMucUsersBinding; +import de.pixart.messenger.entities.Contact; import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.MucOptions; import de.pixart.messenger.services.XmppConnectionService; @@ -19,12 +29,16 @@ import de.pixart.messenger.ui.adapter.UserAdapter; import de.pixart.messenger.ui.util.MucDetailsContextMenuHelper; import rocks.xmpp.addr.Jid; -public class MucUsersActivity extends XmppActivity implements XmppConnectionService.OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged { +public class MucUsersActivity extends XmppActivity implements XmppConnectionService.OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, MenuItem.OnActionExpandListener, TextWatcher { private UserAdapter userAdapter; private Conversation mConversation = null; + private EditText mSearchEditText; + + private ArrayList<MucOptions.User> allUsers = new ArrayList<>(); + @Override protected void refreshUiReal() { } @@ -41,9 +55,26 @@ public class MucUsersActivity extends XmppActivity implements XmppConnectionServ private void loadAndSubmitUsers() { if (mConversation != null) { - ArrayList<MucOptions.User> users = mConversation.getMucOptions().getUsers(); - Collections.sort(users); - userAdapter.submitList(users); + allUsers = mConversation.getMucOptions().getUsers(); + Collections.sort(allUsers); + submitFilteredList(mSearchEditText != null ? mSearchEditText.getText().toString() : null); + } + } + + private void submitFilteredList(String search) { + if (TextUtils.isEmpty(search)) { + userAdapter.submitList(allUsers); + } else { + final String needle = search.toLowerCase(Locale.getDefault()); + ArrayList<MucOptions.User> filtered = new ArrayList<>(); + for (MucOptions.User user : allUsers) { + final String name = user.getName(); + final Contact contact = user.getContact(); + if (name != null && name.toLowerCase(Locale.getDefault()).contains(needle) || contact != null && contact.getDisplayName().toLowerCase(Locale.getDefault()).contains(needle)) { + filtered.add(user); + } + } + userAdapter.submitList(filtered); } } @@ -84,4 +115,50 @@ public class MucUsersActivity extends XmppActivity implements XmppConnectionServ public void onAffiliationChangeFailed(Jid jid, int resId) { displayToast(getString(resId, jid.asBareJid().toString())); } + + @Override + public boolean onCreateOptionsMenu(final Menu menu) { + getMenuInflater().inflate(R.menu.muc_users_activity, menu); + final MenuItem menuSearchView = menu.findItem(R.id.action_search); + final View mSearchView = menuSearchView.getActionView(); + mSearchEditText = mSearchView.findViewById(R.id.search_field); + mSearchEditText.addTextChangedListener(this); + mSearchEditText.setHint(R.string.search_participants); + menuSearchView.setOnActionExpandListener(this); + return true; + } + + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + mSearchEditText.post(() -> { + mSearchEditText.requestFocus(); + final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mSearchEditText, InputMethodManager.SHOW_IMPLICIT); + }); + return true; + } + + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(mSearchEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); + mSearchEditText.setText(""); + submitFilteredList(""); + return true; + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + submitFilteredList(s.toString()); + } }
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/adapter/UserAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/UserAdapter.java index e615f2f42..9677aa61d 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/UserAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/UserAdapter.java @@ -82,8 +82,9 @@ public class UserAdapter extends ListAdapter<MucOptions.User, UserAdapter.ViewHo final String name = user.getName(); final Contact contact = user.getContact(); if (contact != null) { - viewHolder.binding.contactDisplayName.setText(contact.getDisplayName()); - if (name != null) { + final String displayName = contact.getDisplayName(); + viewHolder.binding.contactDisplayName.setText(displayName); + if (name != null && !name.equals(displayName)) { viewHolder.binding.contactJid.setText(String.format("%s \u2022 %s", name, ConferenceDetailsActivity.getStatus(viewHolder.binding.getRoot().getContext(), user, advancedMode))); } else { viewHolder.binding.contactJid.setText(ConferenceDetailsActivity.getStatus(viewHolder.binding.getRoot().getContext(), user, advancedMode)); diff --git a/src/main/res/menu/muc_users_activity.xml b/src/main/res/menu/muc_users_activity.xml new file mode 100644 index 000000000..93e044f27 --- /dev/null +++ b/src/main/res/menu/muc_users_activity.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> + + <item + android:id="@+id/action_search" + android:icon="?attr/icon_search" + android:title="@string/search" + app:actionLayout="@layout/actionview_search" + app:showAsAction="collapseActionView|always" /> +</menu>
\ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index dee4f8be5..c75542585 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -885,4 +885,5 @@ <string name="notification_backup_created_subtitle">The backup files were stored in %s</string> <string name="notification_backup_failed_title">Backup failed</string> <string name="notification_backup_failed_subtitle">The backup files could not be stored in %s</string> + <string name="search_participants">Search participants</string> </resources> |