diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 837e4e92d..82fa7d2b2 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -40,6 +40,7 @@ import eu.siacs.conversations.ui.util.Attachment; import eu.siacs.conversations.ui.util.AvatarWorkerTask; import eu.siacs.conversations.ui.util.GridManager; import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; +import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper; import eu.siacs.conversations.ui.util.MyLinkify; import eu.siacs.conversations.ui.util.SoftKeyboardUtils; import eu.siacs.conversations.utils.AccountUtils; @@ -290,6 +291,14 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers return super.onOptionsItemSelected(menuItem); } + @Override + public boolean onContextItemSelected(MenuItem item) { + if (!MucDetailsContextMenuHelper.onContextItemSelected(item, mUserPreviewAdapter.getSelectedUser(), this)) { + return super.onContextItemSelected(item); + } + return true; + } + public void onMucEditButtonClicked(View v) { if (this.binding.mucEditor.getVisibility() == View.GONE) { final MucOptions mucOptions = mConversation.getMucOptions(); @@ -558,7 +567,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers } } }); - this.mUserPreviewAdapter.setUserList(MucOptions.sub(users, GridManager.getCurrentColumnCount(binding.users))); + this.mUserPreviewAdapter.submitList(MucOptions.sub(users, GridManager.getCurrentColumnCount(binding.users))); this.binding.invite.setVisibility(mucOptions.canInvite() ? View.VISIBLE : View.GONE); } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 8630e6713..b345d9fc3 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -2740,7 +2740,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke popupMenu.inflate(R.menu.muc_details_context); final Menu menu = popupMenu.getMenu(); MucDetailsContextMenuHelper.configureMucDetailsContextMenu(activity, menu, conversation, user); - popupMenu.setOnMenuItemClickListener(menuItem -> MucDetailsContextMenuHelper.onContextItemSelected(menuItem, user, conversation, activity)); + popupMenu.setOnMenuItemClickListener(menuItem -> MucDetailsContextMenuHelper.onContextItemSelected(menuItem, user, activity)); } else { final Contact contact = message.getContact(); if (contact.isSelf()) { diff --git a/src/main/java/eu/siacs/conversations/ui/MucUsersActivity.java b/src/main/java/eu/siacs/conversations/ui/MucUsersActivity.java index 275336f14..86f099b7a 100644 --- a/src/main/java/eu/siacs/conversations/ui/MucUsersActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/MucUsersActivity.java @@ -5,10 +5,12 @@ import android.databinding.DataBindingUtil; import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.view.MenuItem; +import android.widget.Toast; import java.util.ArrayList; import java.util.Collections; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.databinding.ActivityMucUsersBinding; import eu.siacs.conversations.entities.Conversation; @@ -16,8 +18,9 @@ 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; +import rocks.xmpp.addr.Jid; -public class MucUsersActivity extends XmppActivity implements XmppConnectionService.OnRosterUpdate { +public class MucUsersActivity extends XmppActivity implements XmppConnectionService.OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged { private UserAdapter userAdapter; @@ -45,9 +48,9 @@ public class MucUsersActivity extends XmppActivity implements XmppConnectionServ } } - @Override + @Override public boolean onContextItemSelected(MenuItem item) { - if (!MucDetailsContextMenuHelper.onContextItemSelected(item, userAdapter.getSelectedUser(), mConversation, this)) { + if (!MucDetailsContextMenuHelper.onContextItemSelected(item, userAdapter.getSelectedUser(), this)) { return super.onContextItemSelected(item); } return true; @@ -59,13 +62,37 @@ public class MucUsersActivity extends XmppActivity implements XmppConnectionServ ActivityMucUsersBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_muc_users); setSupportActionBar((Toolbar) binding.toolbar); configureActionBar(getSupportActionBar(), true); - this.userAdapter = new UserAdapter(true); + this.userAdapter = new UserAdapter(getPreferences().getBoolean("advanced_muc_mode", false)); binding.list.setAdapter(this.userAdapter); } @Override - public void onRosterUpdate() { + public void onMucRosterUpdate() { loadAndSubmitUsers(); } + + 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())); + } + + @Override + public void onRoleChangedSuccessful(String nick) { + + } + + @Override + public void onRoleChangeFailed(String nick, int resId) { + displayToast(getString(resId, nick)); + } } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java index 8507d8da1..9f700d54a 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java @@ -27,8 +27,10 @@ import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.ui.SettingsActivity; import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.ui.util.AvatarWorkerTask; +import eu.siacs.conversations.ui.util.StyledAttributes; import eu.siacs.conversations.utils.EmojiWrapper; import eu.siacs.conversations.utils.IrregularUnicodeDetector; +import eu.siacs.conversations.utils.ThemeHelper; import eu.siacs.conversations.utils.UIHelper; import rocks.xmpp.addr.Jid; @@ -68,6 +70,7 @@ public class ListItemAdapter extends ArrayAdapter { } else { viewHolder = (ViewHolder) view.getTag(); } + view.setBackground(StyledAttributes.getDrawable(view.getContext(),R.attr.list_item_background)); List tags = item.getTags(activity); if (tags.size() == 0 || !this.showDynamicTags) { diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/UserAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/UserAdapter.java index 753027d56..b72d8292e 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/UserAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/UserAdapter.java @@ -9,19 +9,14 @@ import android.support.v7.util.DiffUtil; import android.support.v7.widget.RecyclerView; import android.view.ContextMenu; import android.view.LayoutInflater; -import android.view.Menu; import android.view.View; import android.view.ViewGroup; -import android.widget.PopupMenu; import org.openintents.openpgp.util.OpenPgpUtils; -import java.util.List; - import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.databinding.ContactBinding; -import eu.siacs.conversations.databinding.UserPreviewBinding; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.services.XmppConnectionService; @@ -29,15 +24,24 @@ import eu.siacs.conversations.ui.ConferenceDetailsActivity; import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.ui.util.AvatarWorkerTask; import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper; +import rocks.xmpp.addr.Jid; public class UserAdapter extends ListAdapter implements View.OnCreateContextMenuListener { - private MucOptions.User selectedUser = null; - static final DiffUtil.ItemCallback DIFF = new DiffUtil.ItemCallback() { @Override public boolean areItemsTheSame(@NonNull MucOptions.User a, @NonNull MucOptions.User b) { - return a == b; + final Jid fullA = a.getFullJid(); + final Jid fullB = b.getFullJid(); + final Jid realA = a.getRealJid(); + final Jid realB = b.getRealJid(); + if (fullA != null && fullB != null) { + return fullA.equals(fullB); + } else if (realA != null && realB != null) { + return realA.equals(realB); + } else { + return false; + } } @Override @@ -46,6 +50,7 @@ public class UserAdapter extends ListAdapter { +public class UserPreviewAdapter extends ListAdapter implements View.OnCreateContextMenuListener { + + private MucOptions.User selectedUser = null; public UserPreviewAdapter() { super(UserAdapter.DIFF); @@ -41,25 +40,22 @@ public class UserPreviewAdapter extends ListAdapter { - final XmppActivity activity = XmppActivity.find(v); - if (activity == null) { - return true; - } - final PopupMenu popupMenu = new PopupMenu(activity, v); - popupMenu.inflate(R.menu.muc_details_context); - final Menu menu = popupMenu.getMenu(); - MucDetailsContextMenuHelper.configureMucDetailsContextMenu(activity, menu, user.getConversation(), user); - popupMenu.setOnMenuItemClickListener(menuItem -> MucDetailsContextMenuHelper.onContextItemSelected(menuItem, user, user.getConversation(), activity)); - popupMenu.show(); - return true; + selectedUser = user; + return false; }); } - public void setUserList(List users) { - submitList(users); + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + MucDetailsContextMenuHelper.onCreateContextMenu(menu, v); } + public MucOptions.User getSelectedUser() { + return selectedUser; + } class ViewHolder extends RecyclerView.ViewHolder { diff --git a/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java b/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java index 85e1d16c1..d864fe643 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java +++ b/src/main/java/eu/siacs/conversations/ui/util/MucDetailsContextMenuHelper.java @@ -7,8 +7,10 @@ import android.support.v7.app.AlertDialog; import android.text.SpannableString; import android.text.Spanned; import android.text.style.TypefaceSpan; +import android.view.ContextMenu; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import eu.siacs.conversations.Config; import eu.siacs.conversations.entities.Contact; @@ -20,11 +22,33 @@ import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.ui.ConferenceDetailsActivity; import eu.siacs.conversations.ui.ConversationFragment; import eu.siacs.conversations.ui.ConversationsActivity; +import eu.siacs.conversations.ui.MucUsersActivity; import eu.siacs.conversations.ui.XmppActivity; import rocks.xmpp.addr.Jid; public final class MucDetailsContextMenuHelper { + + public static void onCreateContextMenu(ContextMenu menu, View v) { + final XmppActivity activity = XmppActivity.find(v); + final Object tag = v.getTag(); + if (tag instanceof MucOptions.User && activity != null) { + activity.getMenuInflater().inflate(R.menu.muc_details_context, menu); + final MucOptions.User user = (MucOptions.User) tag; + String name; + final Contact contact = user.getContact(); + if (contact != null && contact.showInContactList()) { + name = contact.getDisplayName(); + } else if (user.getRealJid() != null) { + name = user.getRealJid().asBareJid().toString(); + } else { + name = user.getName(); + } + menu.setHeaderTitle(name); + MucDetailsContextMenuHelper.configureMucDetailsContextMenu(activity, menu, user.getConversation(), user); + } + } + public static void configureMucDetailsContextMenu(Activity activity, Menu menu, Conversation conversation, User user) { final MucOptions mucOptions = conversation.getMucOptions(); final boolean advancedMode = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("advanced_muc_mode", false); @@ -45,7 +69,7 @@ public final class MucDetailsContextMenuHelper { if (contact != null && contact.showInRoster()) { showContactDetails.setVisible(!contact.isSelf()); } - if (activity instanceof ConferenceDetailsActivity && user.getRole() == MucOptions.Role.NONE) { + if ((activity instanceof ConferenceDetailsActivity || activity instanceof MucUsersActivity) && user.getRole() == MucOptions.Role.NONE) { invite.setVisible(true); } if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && @@ -77,7 +101,8 @@ public final class MucDetailsContextMenuHelper { } } - public static boolean onContextItemSelected(MenuItem item, User user, Conversation conversation, XmppActivity activity) { + public static boolean onContextItemSelected(MenuItem item, User user, XmppActivity activity) { + final Conversation conversation = user.getConversation(); final XmppConnectionService.OnAffiliationChanged onAffiliationChanged = activity instanceof XmppConnectionService.OnAffiliationChanged ? (XmppConnectionService.OnAffiliationChanged) activity : null; final XmppConnectionService.OnRoleChanged onRoleChanged = activity instanceof XmppConnectionService.OnRoleChanged ? (XmppConnectionService.OnRoleChanged) activity : null; Jid jid = user.getRealJid(); @@ -89,7 +114,7 @@ public final class MucDetailsContextMenuHelper { } return true; case R.id.start_conversation: - startConversation(user, conversation, activity); + startConversation(user, activity); return true; case R.id.give_admin_privileges: activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.ADMIN, onAffiliationChanged); @@ -104,7 +129,7 @@ public final class MucDetailsContextMenuHelper { activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.MEMBER, onAffiliationChanged); return true; case R.id.remove_from_room: - removeFromRoom(user, conversation, activity, onAffiliationChanged, onRoleChanged); + removeFromRoom(user, activity, onAffiliationChanged, onRoleChanged); return true; case R.id.ban_from_conference: activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.OUTCAST, onAffiliationChanged); @@ -130,7 +155,8 @@ public final class MucDetailsContextMenuHelper { } } - public static void removeFromRoom(final User user, Conversation conversation, XmppActivity activity, XmppConnectionService.OnAffiliationChanged onAffiliationChanged, XmppConnectionService.OnRoleChanged onRoleChanged) { + private static void removeFromRoom(final User user, XmppActivity activity, XmppConnectionService.OnAffiliationChanged onAffiliationChanged, XmppConnectionService.OnRoleChanged onRoleChanged) { + final Conversation conversation = user.getConversation(); if (conversation.getMucOptions().membersOnly()) { activity.xmppConnectionService.changeAffiliationInConference(conversation, user.getRealJid(), MucOptions.Affiliation.NONE, onAffiliationChanged); if (user.getRole() != MucOptions.Role.NONE) { @@ -157,9 +183,9 @@ public final class MucDetailsContextMenuHelper { } } - public static void startConversation(User user, Conversation conversation, XmppActivity activity) { + private static void startConversation(User user, XmppActivity activity) { if (user.getRealJid() != null) { - Conversation newConversation = activity.xmppConnectionService.findOrCreateConversation(conversation.getAccount(), user.getRealJid().asBareJid(), false, true); + Conversation newConversation = activity.xmppConnectionService.findOrCreateConversation(user.getAccount(), user.getRealJid().asBareJid(), false, true); activity.switchToConversation(newConversation); } }