2019-01-25 16:58:23 +00:00
|
|
|
package eu.siacs.conversations.ui.adapter;
|
|
|
|
|
|
|
|
import android.databinding.DataBindingUtil;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.v7.recyclerview.extensions.ListAdapter;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2019-01-26 19:31:52 +00:00
|
|
|
import android.view.ContextMenu;
|
2019-01-25 16:58:23 +00:00
|
|
|
import android.view.LayoutInflater;
|
2019-01-26 19:31:52 +00:00
|
|
|
import android.view.View;
|
2019-01-25 16:58:23 +00:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import eu.siacs.conversations.databinding.UserPreviewBinding;
|
|
|
|
import eu.siacs.conversations.entities.MucOptions;
|
|
|
|
import eu.siacs.conversations.ui.XmppActivity;
|
|
|
|
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
|
|
|
|
import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper;
|
|
|
|
|
2019-01-26 19:31:52 +00:00
|
|
|
public class UserPreviewAdapter extends ListAdapter<MucOptions.User, UserPreviewAdapter.ViewHolder> implements View.OnCreateContextMenuListener {
|
|
|
|
|
|
|
|
private MucOptions.User selectedUser = null;
|
2019-01-25 16:58:23 +00:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
});
|
2019-01-26 19:31:52 +00:00
|
|
|
viewHolder.binding.getRoot().setOnCreateContextMenuListener(this);
|
|
|
|
viewHolder.binding.getRoot().setTag(user);
|
2019-01-25 16:58:23 +00:00
|
|
|
viewHolder.binding.getRoot().setOnLongClickListener(v -> {
|
2019-01-26 19:31:52 +00:00
|
|
|
selectedUser = user;
|
|
|
|
return false;
|
2019-01-25 16:58:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:31:52 +00:00
|
|
|
@Override
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
|
|
|
MucDetailsContextMenuHelper.onCreateContextMenu(menu, v);
|
2019-01-25 16:58:23 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 19:31:52 +00:00
|
|
|
public MucOptions.User getSelectedUser() {
|
|
|
|
return selectedUser;
|
|
|
|
}
|
2019-01-25 16:58:23 +00:00
|
|
|
|
|
|
|
class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
|
|
|
private final UserPreviewBinding binding;
|
|
|
|
|
|
|
|
private ViewHolder(UserPreviewBinding binding) {
|
|
|
|
super(binding.getRoot());
|
|
|
|
this.binding = binding;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|