2019-01-25 16:58:23 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2019-02-15 13:00:42 +00:00
|
|
|
import android.content.Context;
|
2019-01-25 16:58:23 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.databinding.DataBindingUtil;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.v7.widget.Toolbar;
|
2019-02-15 13:00:42 +00:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.view.Menu;
|
2019-01-25 16:58:23 +00:00
|
|
|
import android.view.MenuItem;
|
2019-02-15 13:00:42 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import android.widget.EditText;
|
2019-01-26 19:31:52 +00:00
|
|
|
import android.widget.Toast;
|
2019-01-25 16:58:23 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
2019-02-15 13:00:42 +00:00
|
|
|
import java.util.Locale;
|
2019-01-25 16:58:23 +00:00
|
|
|
|
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import eu.siacs.conversations.databinding.ActivityMucUsersBinding;
|
2019-02-15 13:00:42 +00:00
|
|
|
import eu.siacs.conversations.entities.Contact;
|
2019-01-25 16:58:23 +00:00
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
|
|
|
import eu.siacs.conversations.entities.MucOptions;
|
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
|
|
|
import eu.siacs.conversations.ui.adapter.UserAdapter;
|
|
|
|
import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper;
|
2020-05-15 15:06:16 +00:00
|
|
|
import eu.siacs.conversations.xmpp.Jid;
|
2019-01-25 16:58:23 +00:00
|
|
|
|
2019-02-15 13:00:42 +00:00
|
|
|
public class MucUsersActivity extends XmppActivity implements XmppConnectionService.OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, MenuItem.OnActionExpandListener, TextWatcher {
|
2019-01-25 16:58:23 +00:00
|
|
|
|
|
|
|
private UserAdapter userAdapter;
|
|
|
|
|
|
|
|
private Conversation mConversation = null;
|
|
|
|
|
2019-02-15 13:00:42 +00:00
|
|
|
private EditText mSearchEditText;
|
|
|
|
|
|
|
|
private ArrayList<MucOptions.User> allUsers = new ArrayList<>();
|
|
|
|
|
2019-01-25 16:58:23 +00:00
|
|
|
@Override
|
|
|
|
protected void refreshUiReal() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void onBackendConnected() {
|
|
|
|
final Intent intent = getIntent();
|
|
|
|
final String uuid = intent == null ? null : intent.getStringExtra("uuid");
|
|
|
|
if (uuid != null) {
|
|
|
|
mConversation = xmppConnectionService.findConversationByUuid(uuid);
|
|
|
|
}
|
|
|
|
loadAndSubmitUsers();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadAndSubmitUsers() {
|
|
|
|
if (mConversation != null) {
|
2019-02-15 13:00:42 +00:00
|
|
|
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);
|
2019-01-25 16:58:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:31:52 +00:00
|
|
|
@Override
|
2019-01-25 16:58:23 +00:00
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
2019-01-26 19:31:52 +00:00
|
|
|
if (!MucDetailsContextMenuHelper.onContextItemSelected(item, userAdapter.getSelectedUser(), this)) {
|
2019-01-25 16:58:23 +00:00
|
|
|
return super.onContextItemSelected(item);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
ActivityMucUsersBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_muc_users);
|
|
|
|
setSupportActionBar((Toolbar) binding.toolbar);
|
|
|
|
configureActionBar(getSupportActionBar(), true);
|
2019-01-26 19:31:52 +00:00
|
|
|
this.userAdapter = new UserAdapter(getPreferences().getBoolean("advanced_muc_mode", false));
|
2019-01-25 16:58:23 +00:00
|
|
|
binding.list.setAdapter(this.userAdapter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-01-26 19:31:52 +00:00
|
|
|
public void onMucRosterUpdate() {
|
2019-01-25 16:58:23 +00:00
|
|
|
loadAndSubmitUsers();
|
|
|
|
}
|
2019-01-26 19:31:52 +00:00
|
|
|
|
|
|
|
private void displayToast(final String msg) {
|
|
|
|
runOnUiThread(() -> Toast.makeText(this, msg, Toast.LENGTH_SHORT).show());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAffiliationChangedSuccessful(Jid jid) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAffiliationChangeFailed(Jid jid, int resId) {
|
|
|
|
displayToast(getString(resId, jid.asBareJid().toString()));
|
|
|
|
}
|
|
|
|
|
2019-02-15 13:00:42 +00:00
|
|
|
@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());
|
|
|
|
}
|
2019-01-25 16:58:23 +00:00
|
|
|
}
|