2019-05-13 03:19:17 +02:00
|
|
|
package org.mercury_im.messenger.ui.roster;
|
2019-04-14 18:12:04 +02:00
|
|
|
|
2019-06-21 03:45:33 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2019-06-24 01:41:17 +02:00
|
|
|
import android.os.Build;
|
2019-04-14 18:12:04 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2019-06-29 19:06:07 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.core.app.ActivityOptionsCompat;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2019-07-02 00:46:40 +02:00
|
|
|
import org.jivesoftware.smackx.colors.ConsistentColor;
|
2019-06-21 03:45:33 +02:00
|
|
|
import org.jxmpp.jid.EntityBareJid;
|
2019-05-13 03:19:17 +02:00
|
|
|
import org.mercury_im.messenger.R;
|
2019-08-01 00:17:27 +02:00
|
|
|
import org.mercury_im.messenger.persistence.room.model.RoomContactModel;
|
2019-06-21 03:45:33 +02:00
|
|
|
import org.mercury_im.messenger.ui.chat.ChatActivity;
|
2019-06-30 13:37:36 +02:00
|
|
|
import org.mercury_im.messenger.util.ColorUtil;
|
2019-04-14 18:12:04 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-06-03 01:16:49 +02:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
2019-06-24 01:41:17 +02:00
|
|
|
import de.hdodenhof.circleimageview.CircleImageView;
|
2019-06-03 01:16:49 +02:00
|
|
|
|
2019-05-04 00:27:02 +02:00
|
|
|
public class RosterRecyclerViewAdapter
|
2019-06-20 17:20:23 +02:00
|
|
|
extends RecyclerView.Adapter<RosterRecyclerViewAdapter.RosterItemViewHolder> {
|
2019-04-14 18:12:04 +02:00
|
|
|
|
2019-08-01 00:17:27 +02:00
|
|
|
private List<RoomContactModel> entryModelList;
|
2019-04-14 18:12:04 +02:00
|
|
|
|
2019-08-01 00:17:27 +02:00
|
|
|
public RosterRecyclerViewAdapter(List<RoomContactModel> entryModelList) {
|
2019-04-14 18:12:04 +02:00
|
|
|
this.entryModelList = entryModelList;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
2019-06-20 17:20:23 +02:00
|
|
|
public RosterItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
2019-06-21 03:45:33 +02:00
|
|
|
return new RosterItemViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext())
|
2019-06-20 17:20:23 +02:00
|
|
|
.inflate(R.layout.recycler_view_item_roster_entry, parent, false));
|
2019-04-14 18:12:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-20 17:20:23 +02:00
|
|
|
public void onBindViewHolder(@NonNull RosterItemViewHolder holder, int position) {
|
2019-08-01 00:17:27 +02:00
|
|
|
RoomContactModel model = entryModelList.get(position);
|
2019-06-20 17:20:23 +02:00
|
|
|
holder.bind(model);
|
2019-04-14 18:12:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return entryModelList.size();
|
|
|
|
}
|
|
|
|
|
2019-08-01 00:17:27 +02:00
|
|
|
public void setItems(List<RoomContactModel> rosterEntryModels) {
|
2019-04-14 18:12:04 +02:00
|
|
|
this.entryModelList = rosterEntryModels;
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2019-06-20 17:20:23 +02:00
|
|
|
public class RosterItemViewHolder extends RecyclerView.ViewHolder {
|
2019-06-03 01:16:49 +02:00
|
|
|
|
2019-06-20 17:20:23 +02:00
|
|
|
private View view;
|
2019-06-03 01:16:49 +02:00
|
|
|
|
2019-06-24 01:41:17 +02:00
|
|
|
@BindView(R.id.roster_entry__jid)
|
2019-06-03 01:16:49 +02:00
|
|
|
TextView jidView;
|
2019-04-14 18:12:04 +02:00
|
|
|
|
2019-06-24 01:41:17 +02:00
|
|
|
@BindView(R.id.roster_entry__nickname)
|
2019-06-03 01:16:49 +02:00
|
|
|
TextView nicknameView;
|
2019-04-14 18:12:04 +02:00
|
|
|
|
2019-06-24 01:41:17 +02:00
|
|
|
@BindView(R.id.roster_entry__avatar)
|
|
|
|
CircleImageView avatarView;
|
|
|
|
|
2019-06-21 03:45:33 +02:00
|
|
|
Context context;
|
|
|
|
|
|
|
|
public RosterItemViewHolder(Context context, View itemView) {
|
2019-04-14 18:12:04 +02:00
|
|
|
super(itemView);
|
2019-06-21 03:45:33 +02:00
|
|
|
this.context = context;
|
2019-06-20 17:20:23 +02:00
|
|
|
this.view = itemView;
|
2019-06-24 01:41:17 +02:00
|
|
|
ButterKnife.bind(this, view);
|
2019-06-03 01:16:49 +02:00
|
|
|
}
|
|
|
|
|
2019-08-01 00:17:27 +02:00
|
|
|
void bind(RoomContactModel contactModel) {
|
2019-08-19 02:36:31 +02:00
|
|
|
String nick = contactModel.getNickname();
|
2019-06-20 17:20:23 +02:00
|
|
|
nicknameView.setText(nick != null ? nick : "");
|
2019-06-21 03:45:33 +02:00
|
|
|
EntityBareJid jid = contactModel.getEntity().getJid();
|
|
|
|
jidView.setText(jid.toString());
|
2019-07-02 00:46:40 +02:00
|
|
|
jidView.setTextColor(ColorUtil.consistentColor(jid.toString(), new ConsistentColor.ConsistentColorSettings(ConsistentColor.Deficiency.none)));
|
2019-06-21 03:45:33 +02:00
|
|
|
view.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2019-06-24 01:41:17 +02:00
|
|
|
|
2019-06-21 03:45:33 +02:00
|
|
|
Intent intent = new Intent(context, ChatActivity.class);
|
|
|
|
intent.putExtra("JID", jid.toString());
|
|
|
|
intent.putExtra("ACCOUNT", contactModel.getEntity().getAccountId());
|
|
|
|
|
2019-06-24 01:41:17 +02:00
|
|
|
// Animation
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
ActivityOptionsCompat options = ActivityOptionsCompat
|
|
|
|
.makeSceneTransitionAnimation((AppCompatActivity) context, avatarView, "avatar");
|
|
|
|
context.startActivity(intent, options.toBundle());
|
|
|
|
} else {
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
2019-06-21 03:45:33 +02:00
|
|
|
}
|
|
|
|
});
|
2019-04-14 18:12:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|