diff --git a/app/src/main/java/com/yizhuan/erban/ui/im/ImInitHelper.java b/app/src/main/java/com/yizhuan/erban/ui/im/ImInitHelper.java index 17e56c3e8..7441cdded 100644 --- a/app/src/main/java/com/yizhuan/erban/ui/im/ImInitHelper.java +++ b/app/src/main/java/com/yizhuan/erban/ui/im/ImInitHelper.java @@ -22,6 +22,7 @@ import com.yizhuan.erban.ui.im.avtivity.NimP2PMessageActivity; import com.yizhuan.erban.ui.im.chat.MsgViewHolderAudioParty; import com.yizhuan.erban.ui.im.chat.MsgViewHolderChatHint; import com.yizhuan.erban.ui.im.chat.MsgViewHolderContent; +import com.yizhuan.erban.ui.im.chat.MsgViewHolderFairy; import com.yizhuan.erban.ui.im.chat.MsgViewHolderGift; import com.yizhuan.erban.ui.im.chat.MsgViewHolderHello; import com.yizhuan.erban.ui.im.chat.MsgViewHolderLevel; @@ -42,6 +43,7 @@ import com.yizhuan.xchat_android_core.im.custom.bean.CarAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.CarveUpGoldThirdLevelAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.ChatHintAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.CpInviteAttachment; +import com.yizhuan.xchat_android_core.im.custom.bean.FairySendAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.GiftAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.InAppSharingFamilyAttachment; import com.yizhuan.xchat_android_core.im.custom.bean.InAppSharingMiniWorldAttachment; @@ -166,6 +168,7 @@ public class ImInitHelper { NimUIKit.registerMsgItemViewHolder(SkillMsgAttachment.class, MsgViewHolderSkill.class); //CP NimUIKit.registerMsgItemViewHolder(CpInviteAttachment.class, MsgViewHolderText.class); + NimUIKit.registerMsgItemViewHolder(FairySendAttachment.class, MsgViewHolderFairy.class); NimUIKit.setSessionListener(listener); NimUIKit.setContactEventListener(listener1); } diff --git a/app/src/main/java/com/yizhuan/erban/ui/im/chat/MsgViewHolderFairy.java b/app/src/main/java/com/yizhuan/erban/ui/im/chat/MsgViewHolderFairy.java new file mode 100644 index 000000000..4df694adc --- /dev/null +++ b/app/src/main/java/com/yizhuan/erban/ui/im/chat/MsgViewHolderFairy.java @@ -0,0 +1,99 @@ +package com.yizhuan.erban.ui.im.chat; + +import android.annotation.SuppressLint; +import android.os.Bundle; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; +import com.netease.nim.uikit.business.session.viewholder.MsgViewHolderBase; +import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter; +import com.yizhuan.erban.R; +import com.yizhuan.erban.treasurefairy.dialog.MyFairySendDialog; +import com.yizhuan.erban.ui.utils.ImageLoadUtils; +import com.yizhuan.xchat_android_core.auth.AuthModel; +import com.yizhuan.xchat_android_core.gift.bean.SimpleUserInfo; +import com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment; +import com.yizhuan.xchat_android_core.im.custom.bean.FairySendAttachment; +import com.yizhuan.xchat_android_core.manager.IMNetEaseManager; +import com.yizhuan.xchat_android_core.treasurefairy.FairyInfo; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by chenran on 2018/1/2. + */ + +public class MsgViewHolderFairy extends MsgViewHolderBase implements View.OnClickListener { + private final static String IS_SEND = "afafagag"; + private TextView tvContent; + private ImageView ivFairyIcon; + private View flIconBg; + private View tvView; + + public MsgViewHolderFairy(BaseMultiItemFetchLoadAdapter adapter) { + super(adapter); + } + + @Override + protected int getContentResId() { + return R.layout.layout_msg_view_holder_fairy; + } + + @Override + protected void inflateContentView() { + tvContent = findViewById(R.id.tv_content); + ivFairyIcon = findViewById(R.id.iv_fairy_icon); + flIconBg = findViewById(R.id.fl_icon_bg); + tvView = findViewById(R.id.tv_view); + } + + @Override + protected void bindContentView() { + FairySendAttachment attachment = (FairySendAttachment) message.getAttachment(); + + tvContent.setText(attachment.getMsgContent()); + ImageLoadUtils.loadImage(context, attachment.getElfPicUrl(), ivFairyIcon); + if (isReceivedMessage()) { + flIconBg.setBackgroundResource(R.drawable.shape_white_8dp_round); + } else { + flIconBg.setBackgroundResource(R.drawable.shape_f5f4fa_8dp_round); + } + Map localExtension = message.getLocalExtension(); + boolean isSend = false; + if (localExtension != null && localExtension.containsKey(IS_SEND)) { + isSend = (boolean) localExtension.get(IS_SEND); + } + boolean isAskFor = attachment.getSecond() == CustomAttachment.CUSTOM_MSG_SUB_FAIRY_ASK_FOR; + + if (!isSend && isAskFor && attachment.getUid() != AuthModel.get().getCurrentUid()) { + tvView.setVisibility(View.VISIBLE); + contentContainer.setOnClickListener(this); + } else { + tvView.setVisibility(View.GONE); + contentContainer.setOnClickListener(null); + } + } + + @SuppressLint("CheckResult") + @Override + public void onClick(View v) { + FairySendAttachment attachment = (FairySendAttachment) message.getAttachment(); + SimpleUserInfo userInfo = new SimpleUserInfo(attachment.getNick(), attachment.getUid(), 0, "", ""); + FairyInfo fairyInfo = new FairyInfo(attachment.getElfId(), 1, 1, attachment.getElfName(), attachment.getElfPicUrl(), 0); + Bundle bundle = new Bundle(); + bundle.putSerializable("userInfo", userInfo); + bundle.putSerializable("fairyInfo", fairyInfo); + bundle.putBoolean("isSend", true); + MyFairySendDialog sendDialog = MyFairySendDialog.Companion.newInstance(bundle, userInfo); + sendDialog.setOnSendListener(() -> { + Map localExtension = message.getLocalExtension(); + if (localExtension == null) localExtension = new HashMap<>(); + localExtension.put(IS_SEND, true); + message.setLocalExtension(localExtension); + IMNetEaseManager.get().updateMessageToLocal(message); + return null; + }); + sendDialog.show(context); + } +} diff --git a/app/src/main/res/drawable/shape_f5f4fa_8dp_round.xml b/app/src/main/res/drawable/shape_f5f4fa_8dp_round.xml new file mode 100644 index 000000000..7dd1cb7b6 --- /dev/null +++ b/app/src/main/res/drawable/shape_f5f4fa_8dp_round.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_msg_view_holder_fairy.xml b/app/src/main/res/layout/layout_msg_view_holder_fairy.xml new file mode 100644 index 000000000..c59b6b0b0 --- /dev/null +++ b/app/src/main/res/layout/layout_msg_view_holder_fairy.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + +