update 送礼
This commit is contained in:
parent
6d495d11fd
commit
fd377b5280
@ -10,6 +10,7 @@ import com.alibaba.android.arouter.launcher.ARouter;
|
|||||||
import com.facebook.FacebookSdk;
|
import com.facebook.FacebookSdk;
|
||||||
import com.shayu.onetoone.activity.fragments.message.ChatMessageFragment;
|
import com.shayu.onetoone.activity.fragments.message.ChatMessageFragment;
|
||||||
import com.shayu.onetoone.activity.message.ChatActivity;
|
import com.shayu.onetoone.activity.message.ChatActivity;
|
||||||
|
import com.shayu.onetoone.bean.MessageChatGiftContent;
|
||||||
import com.shayu.onetoone.bean.MessageChatTipsContent;
|
import com.shayu.onetoone.bean.MessageChatTipsContent;
|
||||||
import com.shayu.onetoone.provider.CustomConversationProvider;
|
import com.shayu.onetoone.provider.CustomConversationProvider;
|
||||||
import com.shayu.onetoone.provider.MessageChatReceiveGiftItemProvider;
|
import com.shayu.onetoone.provider.MessageChatReceiveGiftItemProvider;
|
||||||
@ -78,6 +79,7 @@ public class AppContext extends CommonAppContext {
|
|||||||
|
|
||||||
ArrayList<Class<? extends MessageContent>> myMessages = new ArrayList<>();
|
ArrayList<Class<? extends MessageContent>> myMessages = new ArrayList<>();
|
||||||
myMessages.add(MessageChatTipsContent.class);
|
myMessages.add(MessageChatTipsContent.class);
|
||||||
|
myMessages.add(MessageChatGiftContent.class);
|
||||||
RongIMClient.registerMessageType(myMessages);
|
RongIMClient.registerMessageType(myMessages);
|
||||||
|
|
||||||
RongConfigCenter.conversationConfig().addMessageProvider(new InstructorSendRewardProvider(getApplicationContext()));
|
RongConfigCenter.conversationConfig().addMessageProvider(new InstructorSendRewardProvider(getApplicationContext()));
|
||||||
|
@ -1,30 +1,23 @@
|
|||||||
package com.shayu.onetoone.activity.fragments.message;
|
package com.shayu.onetoone.activity.fragments.message;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowInsets;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
|
|
||||||
import com.makeramen.roundedimageview.RoundedImageView;
|
import com.makeramen.roundedimageview.RoundedImageView;
|
||||||
import com.shayu.onetoone.R;
|
import com.shayu.onetoone.R;
|
||||||
import com.shayu.onetoone.bean.MessageChatTipsContent;
|
import com.shayu.onetoone.bean.MessageChatTipsContent;
|
||||||
import com.shayu.onetoone.bean.UserBean;
|
import com.shayu.onetoone.bean.UserBean;
|
||||||
import com.shayu.onetoone.dialog.GiftDialog;
|
|
||||||
import com.shayu.onetoone.dialog.TipsDialog;
|
import com.shayu.onetoone.dialog.TipsDialog;
|
||||||
import com.shayu.onetoone.listener.OnDialogClickListener;
|
import com.shayu.onetoone.listener.OnDialogClickListener;
|
||||||
import com.shayu.onetoone.listener.OnSendMessageListener;
|
import com.shayu.onetoone.listener.OnSendMessageListener;
|
||||||
@ -45,12 +38,7 @@ import java.lang.reflect.Field;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import io.rong.imkit.IMCenter;
|
import io.rong.imkit.IMCenter;
|
||||||
import io.rong.imkit.conversation.ConversationFragment;
|
|
||||||
import io.rong.imkit.manager.AudioPlayManager;
|
|
||||||
import io.rong.imkit.manager.AudioRecordManager;
|
|
||||||
import io.rong.imkit.model.UiMessage;
|
import io.rong.imkit.model.UiMessage;
|
||||||
import io.rong.imkit.utils.PermissionCheckUtil;
|
|
||||||
import io.rong.imkit.utils.RongOperationPermissionUtils;
|
|
||||||
import io.rong.imlib.IRongCallback;
|
import io.rong.imlib.IRongCallback;
|
||||||
import io.rong.imlib.RongIMClient;
|
import io.rong.imlib.RongIMClient;
|
||||||
import io.rong.imlib.model.Conversation;
|
import io.rong.imlib.model.Conversation;
|
||||||
|
@ -48,6 +48,10 @@ public class GiftListAdapter extends RecyclerView.Adapter<GiftListAdapter.ViewHo
|
|||||||
return list.size();
|
return list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GiftBean getItem() {
|
||||||
|
return list.get(selectPosition);
|
||||||
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
private ImageView giftIcon;
|
private ImageView giftIcon;
|
||||||
private TextView giftName;
|
private TextView giftName;
|
||||||
|
@ -97,7 +97,6 @@ public class MsgMessageRecyclerViewAdapter extends ConversationListAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(BaseUiConversation baseUiConversation, BaseUiConversation t1) {
|
public int compare(BaseUiConversation baseUiConversation, BaseUiConversation t1) {
|
||||||
System.out.println(" " + t1.mCore.getSentTime() + "|" + baseUiConversation.mCore.getSentTime() + " " + baseUiConversation.mCore.getConversationTitle() + "|" + t1.mCore.getConversationTitle());
|
|
||||||
return (int) (t1.mCore.getSentTime() - baseUiConversation.mCore.getSentTime());
|
return (int) (t1.mCore.getSentTime() - baseUiConversation.mCore.getSentTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import io.rong.common.ParcelUtils;
|
import io.rong.common.ParcelUtils;
|
||||||
import io.rong.imlib.MessageTag;
|
import io.rong.imlib.MessageTag;
|
||||||
@ -16,9 +17,9 @@ import io.rong.imlib.model.MessageContent;
|
|||||||
|
|
||||||
@MessageTag(value = "MessageChatGiftContent", flag = MessageTag.ISPERSISTED)
|
@MessageTag(value = "MessageChatGiftContent", flag = MessageTag.ISPERSISTED)
|
||||||
public class MessageChatGiftContent extends MessageContent implements Parcelable {
|
public class MessageChatGiftContent extends MessageContent implements Parcelable {
|
||||||
private String content;
|
private String gift;
|
||||||
private String title;
|
private String number;
|
||||||
private String imageUrl;
|
private String sendUid;
|
||||||
|
|
||||||
private MessageChatGiftContent() {
|
private MessageChatGiftContent() {
|
||||||
}
|
}
|
||||||
@ -28,13 +29,7 @@ public class MessageChatGiftContent extends MessageContent implements Parcelable
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String jsonStr = null;
|
String jsonStr = null;
|
||||||
try {
|
jsonStr = new String(data, StandardCharsets.UTF_8);
|
||||||
jsonStr = new String(data, "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
}
|
|
||||||
if (jsonStr == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObj = new JSONObject(jsonStr);
|
JSONObject jsonObj = new JSONObject(jsonStr);
|
||||||
@ -47,53 +42,57 @@ public class MessageChatGiftContent extends MessageContent implements Parcelable
|
|||||||
setMentionedInfo(parseJsonToMentionInfo(jsonObj.getJSONObject("mentionedInfo")));
|
setMentionedInfo(parseJsonToMentionInfo(jsonObj.getJSONObject("mentionedInfo")));
|
||||||
}
|
}
|
||||||
// 将所有自定义变量从收到的 json 解析并赋值
|
// 将所有自定义变量从收到的 json 解析并赋值
|
||||||
if (jsonObj.has("content")) {
|
if (jsonObj.has("gift")) {
|
||||||
content = jsonObj.optString("content");
|
gift = jsonObj.optString("gift");
|
||||||
title = jsonObj.optString("title");
|
number = jsonObj.optString("number");
|
||||||
imageUrl = jsonObj.optString("imageUrl");
|
sendUid = jsonObj.optString("sendUid");
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageChatGiftContent setContent(String content) {
|
public MessageChatGiftContent setGift(String gift) {
|
||||||
this.content = content;
|
this.gift = gift;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageChatGiftContent setTitle(String title) {
|
public MessageChatGiftContent setNumber(String number) {
|
||||||
this.title = title;
|
this.number = number;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageChatGiftContent setImageUrl(String imageUrl) {
|
public String getSendUid() {
|
||||||
this.imageUrl = imageUrl;
|
return sendUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageChatGiftContent setSendUid(String sendUid) {
|
||||||
|
this.sendUid = sendUid;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getNumber() {
|
||||||
return title;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getImageUrl() {
|
|
||||||
return imageUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContent() {
|
public String getGift() {
|
||||||
return content;
|
return gift;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MessageChatGiftContent(Parcel in) {
|
protected MessageChatGiftContent(Parcel in) {
|
||||||
setExtra(ParcelUtils.readFromParcel(in));
|
setExtra(ParcelUtils.readFromParcel(in));
|
||||||
setContent(ParcelUtils.readFromParcel(in));
|
setGift(ParcelUtils.readFromParcel(in));
|
||||||
|
setNumber(ParcelUtils.readFromParcel(in));
|
||||||
|
setSendUid(ParcelUtils.readFromParcel(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 快速构建消息对象方法
|
// 快速构建消息对象方法
|
||||||
public static MessageChatGiftContent obtain(String title, String content, String imageUrl) {
|
public static MessageChatGiftContent obtain(String gift, String number, String sendUid) {
|
||||||
MessageChatGiftContent msg = new MessageChatGiftContent();
|
MessageChatGiftContent msg = new MessageChatGiftContent();
|
||||||
msg.content = content;
|
msg.gift = gift;
|
||||||
msg.title = title;
|
msg.number = number;
|
||||||
msg.imageUrl = imageUrl;
|
msg.sendUid = sendUid;
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,17 +122,15 @@ public class MessageChatGiftContent extends MessageContent implements Parcelable
|
|||||||
jsonObj.putOpt("mentionedInfo", getJsonMentionInfo());
|
jsonObj.putOpt("mentionedInfo", getJsonMentionInfo());
|
||||||
}
|
}
|
||||||
// 将所有自定义消息的内容,都序列化至 json 对象中
|
// 将所有自定义消息的内容,都序列化至 json 对象中
|
||||||
jsonObj.put("content", this.content);
|
jsonObj.put("gift", gift);
|
||||||
jsonObj.put("title", this.title);
|
jsonObj.put("number", number);
|
||||||
jsonObj.put("imageUrl", this.imageUrl);
|
jsonObj.put("sendUid", sendUid);
|
||||||
|
System.out.println("发送礼物JSON:"+ jsonObj.toString());
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return jsonObj.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
return jsonObj.toString().getBytes("UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -144,8 +141,8 @@ public class MessageChatGiftContent extends MessageContent implements Parcelable
|
|||||||
@Override
|
@Override
|
||||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||||
ParcelUtils.writeToParcel(dest, getExtra());
|
ParcelUtils.writeToParcel(dest, getExtra());
|
||||||
ParcelUtils.writeToParcel(dest, content);
|
ParcelUtils.writeToParcel(dest, gift);
|
||||||
ParcelUtils.writeToParcel(dest, title);
|
ParcelUtils.writeToParcel(dest, number);
|
||||||
ParcelUtils.writeToParcel(dest, imageUrl);
|
ParcelUtils.writeToParcel(dest, sendUid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,15 @@ import java.util.UUID;
|
|||||||
public class SendMessageManager {
|
public class SendMessageManager {
|
||||||
private static final Map<String, SendData> cache = new HashMap<>();
|
private static final Map<String, SendData> cache = new HashMap<>();
|
||||||
|
|
||||||
|
public static void sendMessageForGift(String toUid,String giftId,OnSendMessageListener listener){
|
||||||
|
SendData sendData = new SendData(Integer.parseInt(toUid),
|
||||||
|
3,
|
||||||
|
giftId,
|
||||||
|
"礼物消息",
|
||||||
|
"1",
|
||||||
|
1);
|
||||||
|
send(sendData, listener);
|
||||||
|
}
|
||||||
public static void sendMessageForAudio(String toUid,OnSendMessageListener listener){
|
public static void sendMessageForAudio(String toUid,OnSendMessageListener listener){
|
||||||
SendData sendData = new SendData(Integer.parseInt(toUid),
|
SendData sendData = new SendData(Integer.parseInt(toUid),
|
||||||
1,
|
1,
|
||||||
|
@ -2,30 +2,42 @@ package com.shayu.onetoone.provider;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.shayu.onetoone.R;
|
import com.shayu.onetoone.R;
|
||||||
import com.shayu.onetoone.bean.MessageChatGiftContent;
|
import com.shayu.onetoone.bean.GiftBean;
|
||||||
import com.shayu.onetoone.bean.MessageChatGiftContent;
|
import com.shayu.onetoone.bean.MessageChatGiftContent;
|
||||||
import com.yunbao.common.glide.ImgLoader;
|
import com.yunbao.common.glide.ImgLoader;
|
||||||
|
import com.yunbao.common.manager.IMLoginManager;
|
||||||
|
import com.yunbao.common.utils.ToastUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.rong.common.RLog;
|
||||||
import io.rong.imkit.conversation.messgelist.provider.BaseMessageItemProvider;
|
import io.rong.imkit.conversation.messgelist.provider.BaseMessageItemProvider;
|
||||||
import io.rong.imkit.model.UiMessage;
|
import io.rong.imkit.model.UiMessage;
|
||||||
import io.rong.imkit.widget.adapter.IViewProviderListener;
|
import io.rong.imkit.widget.adapter.IViewProviderListener;
|
||||||
import io.rong.imkit.widget.adapter.ViewHolder;
|
import io.rong.imkit.widget.adapter.ViewHolder;
|
||||||
|
import io.rong.imlib.model.Message;
|
||||||
import io.rong.imlib.model.MessageContent;
|
import io.rong.imlib.model.MessageContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天送礼适配器
|
||||||
|
*/
|
||||||
public class MessageChatReceiveGiftItemProvider extends BaseMessageItemProvider<MessageChatGiftContent> {
|
public class MessageChatReceiveGiftItemProvider extends BaseMessageItemProvider<MessageChatGiftContent> {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
public MessageChatReceiveGiftItemProvider(Context mContext) {
|
public MessageChatReceiveGiftItemProvider(Context mContext) {
|
||||||
this.mContext = mContext;
|
this.mContext = mContext;
|
||||||
mConfig.showPortrait = false;
|
mConfig.showPortrait = true;
|
||||||
mConfig.showSummaryWithName = false;
|
mConfig.showSummaryWithName = false;
|
||||||
mConfig.showContentBubble = false;
|
mConfig.showContentBubble = false;
|
||||||
mConfig.centerInHorizontal = true;
|
mConfig.centerInHorizontal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -33,11 +45,47 @@ public class MessageChatReceiveGiftItemProvider extends BaseMessageItemProvider<
|
|||||||
return ViewHolder.createViewHolder(mContext, parent, R.layout.view_message_chat_receive_gift);
|
return ViewHolder.createViewHolder(mContext, parent, R.layout.view_message_chat_receive_gift);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindViewHolder(ViewHolder holder, UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
|
||||||
|
if (holder instanceof MessageViewHolder) {
|
||||||
|
try {
|
||||||
|
MessageContent content = uiMessage.getMessage().getContent();
|
||||||
|
if (content instanceof MessageChatGiftContent) {
|
||||||
|
MessageChatGiftContent messageChatGiftContent = (MessageChatGiftContent) content;
|
||||||
|
if (messageChatGiftContent.getSendUid().equals(IMLoginManager.get(mContext).getUserInfo().getId() + "")) {
|
||||||
|
uiMessage.getMessage().setMessageDirection(Message.MessageDirection.SEND);
|
||||||
|
} else {
|
||||||
|
uiMessage.getMessage().setMessageDirection(Message.MessageDirection.RECEIVE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ClassCastException var10) {
|
||||||
|
RLog.e("BaseMessageItemProvider", "bindViewHolder MessageContent cast Exception, e:" + var10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.bindViewHolder(holder, uiMessage, position, list, listener);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void bindMessageContentViewHolder(ViewHolder holder, ViewHolder parentHolder, MessageChatGiftContent messageChatGiftContent, UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
|
protected void bindMessageContentViewHolder(ViewHolder holder, ViewHolder parentHolder, MessageChatGiftContent messageChatGiftContent, UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
|
||||||
holder.setText(R.id.title, messageChatGiftContent.getTitle());
|
GiftBean item = JSONObject.parseObject(messageChatGiftContent.getGift(), GiftBean.class);
|
||||||
holder.setText(R.id.description, messageChatGiftContent.getContent());
|
|
||||||
ImgLoader.display(mContext, messageChatGiftContent.getImageUrl(), holder.getView(R.id.giftIcon));
|
holder.setText(R.id.description, item.getGiftname() + " x" + messageChatGiftContent.getNumber());
|
||||||
|
ImgLoader.display(mContext, item.getGifticon(), holder.getView(R.id.giftIcon));
|
||||||
|
LinearLayout holderView = holder.getView(R.id.layout_root);
|
||||||
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
if (messageChatGiftContent.getSendUid().equals(IMLoginManager.get(mContext).getUserInfo().getId() + "")) {
|
||||||
|
params.gravity = Gravity.END;
|
||||||
|
uiMessage.setMessageDirection(Message.MessageDirection.SEND);
|
||||||
|
} else {
|
||||||
|
uiMessage.setMessageDirection(Message.MessageDirection.RECEIVE);
|
||||||
|
params.gravity = Gravity.START;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
holderView.setLayoutParams(params);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,29 +5,46 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.shayu.onetoone.R;
|
import com.shayu.onetoone.R;
|
||||||
import com.shayu.onetoone.adapter.GiftListAdapter;
|
import com.shayu.onetoone.adapter.GiftListAdapter;
|
||||||
import com.shayu.onetoone.bean.GiftBean;
|
import com.shayu.onetoone.bean.GiftBean;
|
||||||
|
import com.shayu.onetoone.bean.MessageChatGiftContent;
|
||||||
|
import com.shayu.onetoone.bean.MessageChatTipsContent;
|
||||||
|
import com.shayu.onetoone.listener.OnSendMessageListener;
|
||||||
import com.shayu.onetoone.manager.OTONetManager;
|
import com.shayu.onetoone.manager.OTONetManager;
|
||||||
|
import com.shayu.onetoone.manager.SendMessageManager;
|
||||||
import com.shayu.onetoone.widget.PagerConfig;
|
import com.shayu.onetoone.widget.PagerConfig;
|
||||||
import com.shayu.onetoone.widget.PagerGridLayoutManager;
|
import com.shayu.onetoone.widget.PagerGridLayoutManager;
|
||||||
import com.shayu.onetoone.widget.PagerGridSnapHelper;
|
import com.shayu.onetoone.widget.PagerGridSnapHelper;
|
||||||
|
import com.yunbao.common.CommonAppConfig;
|
||||||
import com.yunbao.common.http.base.HttpCallback;
|
import com.yunbao.common.http.base.HttpCallback;
|
||||||
|
import com.yunbao.common.manager.IMLoginManager;
|
||||||
import com.yunbao.common.utils.ToastUtil;
|
import com.yunbao.common.utils.ToastUtil;
|
||||||
|
import com.yunbao.common.utils.WordUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import io.rong.imkit.conversation.extension.RongExtension;
|
|
||||||
|
|
||||||
public class MsgInputPanelForGift extends AbsInputPanel{
|
import io.rong.imkit.IMCenter;
|
||||||
|
import io.rong.imkit.conversation.extension.RongExtension;
|
||||||
|
import io.rong.imlib.IRongCallback;
|
||||||
|
import io.rong.imlib.RongIMClient;
|
||||||
|
import io.rong.imlib.model.Conversation;
|
||||||
|
import io.rong.imlib.model.Message;
|
||||||
|
import io.rong.imlib.model.SendMessageOption;
|
||||||
|
import kotlinx.coroutines.channels.Send;
|
||||||
|
|
||||||
|
public class MsgInputPanelForGift extends AbsInputPanel {
|
||||||
RecyclerView gifList;
|
RecyclerView gifList;
|
||||||
GiftListAdapter mAdapter;
|
GiftListAdapter mAdapter;
|
||||||
TextView money;
|
TextView money;
|
||||||
Button topUpBtn;
|
Button topUpBtn;
|
||||||
Button sendBtn;
|
Button sendBtn;
|
||||||
|
String token;
|
||||||
|
|
||||||
public MsgInputPanelForGift(String targetId, FragmentActivity fragmentActivity, RongExtension mRongExtension) {
|
public MsgInputPanelForGift(String targetId, FragmentActivity fragmentActivity, RongExtension mRongExtension) {
|
||||||
super(targetId, fragmentActivity, mRongExtension, R.layout.view_message_input_gift);
|
super(targetId, fragmentActivity, mRongExtension, R.layout.view_message_input_gift);
|
||||||
@ -43,7 +60,7 @@ public class MsgInputPanelForGift extends AbsInputPanel{
|
|||||||
gifList = viewGroup.findViewById(R.id.gift_list);
|
gifList = viewGroup.findViewById(R.id.gift_list);
|
||||||
money = viewGroup.findViewById(R.id.money);
|
money = viewGroup.findViewById(R.id.money);
|
||||||
topUpBtn = viewGroup.findViewById(R.id.top_up_btn);
|
topUpBtn = viewGroup.findViewById(R.id.top_up_btn);
|
||||||
sendBtn =viewGroup.findViewById(R.id.send_btn);
|
sendBtn = viewGroup.findViewById(R.id.send_btn);
|
||||||
mAdapter = new GiftListAdapter(mContext);
|
mAdapter = new GiftListAdapter(mContext);
|
||||||
PagerGridLayoutManager manager = new PagerGridLayoutManager(2, 4, PagerGridLayoutManager.HORIZONTAL);
|
PagerGridLayoutManager manager = new PagerGridLayoutManager(2, 4, PagerGridLayoutManager.HORIZONTAL);
|
||||||
gifList.setLayoutManager(manager);
|
gifList.setLayoutManager(manager);
|
||||||
@ -53,17 +70,66 @@ public class MsgInputPanelForGift extends AbsInputPanel{
|
|||||||
PagerConfig.setMillisecondsPreInch(150);
|
PagerConfig.setMillisecondsPreInch(150);
|
||||||
gifList.setAdapter(mAdapter);
|
gifList.setAdapter(mAdapter);
|
||||||
initData();
|
initData();
|
||||||
|
sendBtn.setOnClickListener(v -> {
|
||||||
|
GiftBean item = mAdapter.getItem();
|
||||||
|
SendMessageManager.sendMessageForGift(targetId, item.getId() + "", new OnSendMessageListener() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(String token) {
|
||||||
|
super.onSuccess(token);
|
||||||
|
MsgInputPanelForGift.this.token = token;
|
||||||
|
sendGift(item);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(int status, String msg) {
|
||||||
|
super.onError(status, msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendGift(GiftBean item) {
|
||||||
|
MessageChatGiftContent bean = MessageChatGiftContent.obtain(JSONObject.toJSONString(item), "1", IMLoginManager.get(mContext).getUserInfo().getId() + "");
|
||||||
|
IMCenter.getInstance().sendMessage(Message.obtain(targetId, Conversation.ConversationType.PRIVATE, bean),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
new IRongCallback.ISendMessageCallback() {
|
||||||
|
@Override
|
||||||
|
public void onAttached(Message message) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Message message) {
|
||||||
|
SendMessageManager.onCallSuccess(token, new OnSendMessageListener() {
|
||||||
|
@Override
|
||||||
|
public void onError(int status, String msg) {
|
||||||
|
super.onError(status, msg);
|
||||||
|
ToastUtil.show(msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Message message, RongIMClient.ErrorCode errorCode) {
|
||||||
|
System.out.println("失败:" + errorCode.getMessage());
|
||||||
|
System.out.println("失败:" + errorCode.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private void initData() {
|
private void initData() {
|
||||||
OTONetManager.getInstance(mContext)
|
OTONetManager.getInstance(mContext)
|
||||||
.getGiftList(new HttpCallback<List<GiftBean>>() {
|
.getGiftList(new HttpCallback<List<GiftBean>>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(List<GiftBean> data) {
|
public void onSuccess(List<GiftBean> data) {
|
||||||
List<GiftBean> list=new ArrayList<>();
|
List<GiftBean> list = new ArrayList<>();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
list.addAll(data);
|
list.addAll(data);
|
||||||
}
|
}
|
||||||
mAdapter.setList(list);
|
mAdapter.setList(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,45 +1,52 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/layout_root"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="50dp"
|
android:layout_height="wrap_content">
|
||||||
android:background="@drawable/bg_chat_gift">
|
|
||||||
|
|
||||||
<TextView
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/title"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="12dp"
|
|
||||||
android:layout_marginTop="11dp"
|
|
||||||
android:textColor="#333333"
|
|
||||||
android:textSize="12sp"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
tools:text="送給你" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/description"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="12dp"
|
|
||||||
android:layout_marginTop="4dp"
|
|
||||||
android:layout_marginBottom="2dp"
|
|
||||||
android:textColor="#888888"
|
|
||||||
android:textSize="10sp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toStartOf="@+id/giftIcon"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/title"
|
|
||||||
tools:text="「戀愛小氣球」✖️1" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/giftIcon"
|
|
||||||
android:layout_width="50dp"
|
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:layout_marginBottom="4dp"
|
android:background="@drawable/bg_chat_gift">
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
<TextView
|
||||||
app:srcCompat="@mipmap/apple" />
|
android:id="@+id/title"
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:layout_marginTop="11dp"
|
||||||
|
android:text="送給你"
|
||||||
|
android:textColor="#333333"
|
||||||
|
android:textSize="12sp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/description"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:layout_marginBottom="2dp"
|
||||||
|
android:textColor="#888888"
|
||||||
|
android:textSize="10sp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/giftIcon"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/title"
|
||||||
|
tools:text="「戀愛小氣球」✖️1" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/giftIcon"
|
||||||
|
android:layout_width="50dp"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:layout_marginBottom="4dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:srcCompat="@mipmap/apple" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</LinearLayout>
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:background="@color/white"
|
android:background="@color/white"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="210dp">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/gift_list"
|
android:id="@+id/gift_list"
|
||||||
@ -25,8 +25,6 @@
|
|||||||
android:layout_height="30dp"
|
android:layout_height="30dp"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginBottom="22dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/gift_list">
|
app:layout_constraintTop_toBottomOf="@+id/gift_list">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user