diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui/adapter/UserPreviewAdapter.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/adapter/UserPreviewAdapter.java | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/UserPreviewAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/UserPreviewAdapter.java index 5104ef86c..105503243 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/UserPreviewAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/UserPreviewAdapter.java @@ -4,8 +4,10 @@ import android.databinding.DataBindingUtil; import android.support.annotation.NonNull; import android.support.v7.recyclerview.extensions.ListAdapter; 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; @@ -18,7 +20,9 @@ import de.pixart.messenger.ui.XmppActivity; import de.pixart.messenger.ui.util.AvatarWorkerTask; import de.pixart.messenger.ui.util.MucDetailsContextMenuHelper; -public class UserPreviewAdapter extends ListAdapter<MucOptions.User, UserPreviewAdapter.ViewHolder> { +public class UserPreviewAdapter extends ListAdapter<MucOptions.User, UserPreviewAdapter.ViewHolder> implements View.OnCreateContextMenuListener { + + private MucOptions.User selectedUser = null; public UserPreviewAdapter() { super(UserAdapter.DIFF); @@ -40,23 +44,21 @@ public class UserPreviewAdapter extends ListAdapter<MucOptions.User, UserPreview activity.highlightInMuc(user.getConversation(), user.getName()); } }); + viewHolder.binding.getRoot().setOnCreateContextMenuListener(this); + viewHolder.binding.getRoot().setTag(user); viewHolder.binding.getRoot().setOnLongClickListener(v -> { - 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<MucOptions.User> users) { - submitList(users); + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + MucDetailsContextMenuHelper.onCreateContextMenu(menu, v); + } + + public MucOptions.User getSelectedUser() { + return selectedUser; } |