aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui/adapter
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-01-27 14:56:20 +0100
committerChristian Schneppe <christian@pix-art.de>2019-01-27 14:56:20 +0100
commit71f8e656db044a3b3e28cb82a954521699fe9602 (patch)
treec65950352826fad22fa90e03773f9f72c5007391 /src/main/java/de/pixart/messenger/ui/adapter
parent712c6d32d205fb12bf8b61b3ee544a451dd117ca (diff)
refactored group chat members into seperate screen
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui/adapter')
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/UserAdapter.java146
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/UserPreviewAdapter.java72
2 files changed, 218 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/UserAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/UserAdapter.java
new file mode 100644
index 000000000..f6a15aff4
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/ui/adapter/UserAdapter.java
@@ -0,0 +1,146 @@
+package de.pixart.messenger.ui.adapter;
+
+import android.app.PendingIntent;
+import android.content.IntentSender;
+import android.databinding.DataBindingUtil;
+import android.support.annotation.NonNull;
+import android.support.v7.recyclerview.extensions.ListAdapter;
+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 de.pixart.messenger.R;
+import de.pixart.messenger.crypto.PgpEngine;
+import de.pixart.messenger.databinding.ContactBinding;
+import de.pixart.messenger.entities.Contact;
+import de.pixart.messenger.entities.MucOptions;
+import de.pixart.messenger.services.XmppConnectionService;
+import de.pixart.messenger.ui.ConferenceDetailsActivity;
+import de.pixart.messenger.ui.XmppActivity;
+import de.pixart.messenger.ui.util.AvatarWorkerTask;
+import de.pixart.messenger.ui.util.MucDetailsContextMenuHelper;
+
+public class UserAdapter extends ListAdapter<MucOptions.User, UserAdapter.ViewHolder> implements View.OnCreateContextMenuListener {
+
+ private MucOptions.User selectedUser = null;
+
+ static final DiffUtil.ItemCallback<MucOptions.User> DIFF = new DiffUtil.ItemCallback<MucOptions.User>() {
+ @Override
+ public boolean areItemsTheSame(@NonNull MucOptions.User a, @NonNull MucOptions.User b) {
+ return a == b;
+ }
+
+ @Override
+ public boolean areContentsTheSame(@NonNull MucOptions.User a, @NonNull MucOptions.User b) {
+ return a.equals(b);
+ }
+ };
+ private final boolean advancedMode;
+
+ public UserAdapter(final boolean advancedMode) {
+ super(DIFF);
+ this.advancedMode = advancedMode;
+ }
+
+ @NonNull
+ @Override
+ public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int position) {
+ return new ViewHolder(DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), R.layout.contact, viewGroup, false));
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
+ final MucOptions.User user = getItem(position);
+ AvatarWorkerTask.loadAvatar(user, viewHolder.binding.contactPhoto, R.dimen.avatar);
+ viewHolder.binding.getRoot().setOnClickListener(v -> {
+ final XmppActivity activity = XmppActivity.find(v);
+ if (activity != null) {
+ activity.highlightInMuc(user.getConversation(), user.getName());
+ }
+ });
+ viewHolder.binding.getRoot().setTag(user);
+ viewHolder.binding.getRoot().setOnCreateContextMenuListener(this);
+ viewHolder.binding.getRoot().setOnLongClickListener(v -> {
+ selectedUser = user;
+ return false;
+ });
+ final String name = user.getName();
+ final Contact contact = user.getContact();
+ if (contact != null) {
+ viewHolder.binding.contactDisplayName.setText(contact.getDisplayName());
+ if (name != null) {
+ 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));
+ }
+ } else {
+ viewHolder.binding.contactDisplayName.setText(name == null ? "" : name);
+ viewHolder.binding.contactJid.setText(ConferenceDetailsActivity.getStatus(viewHolder.binding.getRoot().getContext(), user, advancedMode));
+ }
+ if (advancedMode && user.getPgpKeyId() != 0) {
+ viewHolder.binding.key.setVisibility(View.VISIBLE);
+ viewHolder.binding.key.setOnClickListener(v -> {
+ final XmppActivity activity = XmppActivity.find(v);
+ final XmppConnectionService service = activity == null ? null : activity.xmppConnectionService;
+ final PgpEngine pgpEngine = service == null ? null : service.getPgpEngine();
+ if (pgpEngine != null) {
+ PendingIntent intent = pgpEngine.getIntentForKey(user.getPgpKeyId());
+ if (intent != null) {
+ try {
+ activity.startIntentSenderForResult(intent.getIntentSender(), 0, null, 0, 0, 0);
+ } catch (IntentSender.SendIntentException ignored) {
+
+ }
+ }
+ }
+ });
+ viewHolder.binding.key.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
+ }
+
+
+ }
+
+ public MucOptions.User getSelectedUser() {
+ return selectedUser;
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
+ 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);
+ }
+ }
+
+ class ViewHolder extends RecyclerView.ViewHolder {
+
+ private final ContactBinding binding;
+
+ private ViewHolder(ContactBinding binding) {
+ super(binding.getRoot());
+ this.binding = binding;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/UserPreviewAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/UserPreviewAdapter.java
new file mode 100644
index 000000000..5104ef86c
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/ui/adapter/UserPreviewAdapter.java
@@ -0,0 +1,72 @@
+package de.pixart.messenger.ui.adapter;
+
+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.LayoutInflater;
+import android.view.Menu;
+import android.view.ViewGroup;
+import android.widget.PopupMenu;
+
+import java.util.List;
+
+import de.pixart.messenger.R;
+import de.pixart.messenger.databinding.UserPreviewBinding;
+import de.pixart.messenger.entities.MucOptions;
+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 UserPreviewAdapter() {
+ super(UserAdapter.DIFF);
+ }
+
+ @NonNull
+ @Override
+ public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int position) {
+ return new ViewHolder(DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), R.layout.user_preview, viewGroup, false));
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
+ final MucOptions.User user = getItem(position);
+ AvatarWorkerTask.loadAvatar(user, viewHolder.binding.avatar, R.dimen.media_size);
+ viewHolder.binding.getRoot().setOnClickListener(v -> {
+ final XmppActivity activity = XmppActivity.find(v);
+ if (activity != null) {
+ activity.highlightInMuc(user.getConversation(), user.getName());
+ }
+ });
+ 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;
+ });
+ }
+
+ public void setUserList(List<MucOptions.User> users) {
+ submitList(users);
+ }
+
+
+ class ViewHolder extends RecyclerView.ViewHolder {
+
+ private final UserPreviewBinding binding;
+
+ private ViewHolder(UserPreviewBinding binding) {
+ super(binding.getRoot());
+ this.binding = binding;
+ }
+ }
+} \ No newline at end of file