|
@@ -1,39 +1,76 @@
|
|
package cn.org.bjca.trust.android.imdemo.ui.adapter;
|
|
package cn.org.bjca.trust.android.imdemo.ui.adapter;
|
|
|
|
|
|
|
|
+import android.content.Context;
|
|
|
|
+import android.view.LayoutInflater;
|
|
|
|
+import android.widget.LinearLayout;
|
|
|
|
+
|
|
|
|
+import androidx.databinding.DataBindingUtil;
|
|
|
|
+
|
|
import com.xuqm.base.adapter.BaseNormalAdapter;
|
|
import com.xuqm.base.adapter.BaseNormalAdapter;
|
|
import com.xuqm.base.adapter.ItemViewDelegate;
|
|
import com.xuqm.base.adapter.ItemViewDelegate;
|
|
import com.xuqm.base.adapter.ViewHolder;
|
|
import com.xuqm.base.adapter.ViewHolder;
|
|
-import com.xuqm.base.common.LogHelper;
|
|
|
|
|
|
+import com.xuqm.base.common.TimeHelper;
|
|
|
|
|
|
import cn.org.bjca.trust.android.imdemo.R;
|
|
import cn.org.bjca.trust.android.imdemo.R;
|
|
-import cn.org.bjca.trust.android.lib.im.enums.MsgType;
|
|
|
|
|
|
+import cn.org.bjca.trust.android.imdemo.databinding.ChatViewTextBinding;
|
|
|
|
+import cn.org.bjca.trust.android.lib.im.SZYXImSdk;
|
|
import cn.org.bjca.trust.android.lib.im.im.msg.message.SZYXMessage;
|
|
import cn.org.bjca.trust.android.lib.im.im.msg.message.SZYXMessage;
|
|
|
|
|
|
public class ChatAdapter extends BaseNormalAdapter<SZYXMessage> {
|
|
public class ChatAdapter extends BaseNormalAdapter<SZYXMessage> {
|
|
- public ChatAdapter() {
|
|
|
|
|
|
+ private Context mContext;
|
|
|
|
+
|
|
|
|
+ public ChatAdapter(Context context) {
|
|
|
|
+ this.mContext = context;
|
|
|
|
+ addItemViewDelegate(new ItemViewDelegate<SZYXMessage>() {
|
|
|
|
+ @Override
|
|
|
|
+ public int getItemViewLayoutId() {
|
|
|
|
+ return R.layout.chat_view_root_l;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean isForViewType(SZYXMessage item, int position) {
|
|
|
|
+ return item.isArrive();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void convert(ViewHolder holder, SZYXMessage item, int position) {
|
|
|
|
+ holder.setImage(R.id.avatar, item.getFromClient().getFaceUrl());
|
|
|
|
+ holder.setText(R.id.name, item.getFromClient().getNickName());
|
|
|
|
+ ChatAdapter.this.convert(holder, item, position);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
addItemViewDelegate(new ItemViewDelegate<SZYXMessage>() {
|
|
addItemViewDelegate(new ItemViewDelegate<SZYXMessage>() {
|
|
@Override
|
|
@Override
|
|
public int getItemViewLayoutId() {
|
|
public int getItemViewLayoutId() {
|
|
- return R.layout.chat_view_text;
|
|
|
|
|
|
+ return R.layout.chat_view_root_r;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public boolean isForViewType(SZYXMessage item, int position) {
|
|
public boolean isForViewType(SZYXMessage item, int position) {
|
|
- return item.getMsgType().equals(MsgType.Text);
|
|
|
|
|
|
+ return !item.isArrive();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void convert(ViewHolder holder, SZYXMessage item, int position) {
|
|
public void convert(ViewHolder holder, SZYXMessage item, int position) {
|
|
- if (item.isArrive()) {
|
|
|
|
- holder.setText(R.id.left, item.getTextMessage().getText());
|
|
|
|
- holder.setVisibility(R.id.left, true);
|
|
|
|
- holder.setVisibility(R.id.right, false);
|
|
|
|
- } else {
|
|
|
|
- holder.setText(R.id.right, item.getTextMessage().getText());
|
|
|
|
- holder.setVisibility(R.id.left, false);
|
|
|
|
- holder.setVisibility(R.id.right, true);
|
|
|
|
- }
|
|
|
|
|
|
+ holder.setImage(R.id.avatar, SZYXImSdk.getInstance().getUser().getFaceUrl());
|
|
|
|
+ ChatAdapter.this.convert(holder, item, position);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void convert(ViewHolder holder, SZYXMessage item, int position) {
|
|
|
|
+ holder.setText(R.id.time, TimeHelper.getStringFormMillis(item.getTimestamp(), "yyyy-MM-dd HH:mm"));
|
|
|
|
+ LinearLayout root = holder.getView(R.id.content);
|
|
|
|
+ switch (item.getMsgType()) {
|
|
|
|
+ case Text:
|
|
|
|
+ ChatViewTextBinding text = DataBindingUtil.inflate(LayoutInflater.from(this.mContext), R.layout.chat_view_text, root, true);
|
|
|
|
+ text.text.setText(item.getTextMessage().getText());
|
|
|
|
+ break;
|
|
|
|
+ case Image:
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ DataBindingUtil.inflate(LayoutInflater.from(this.mContext), R.layout.chat_view_unknown, root, true);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|