173 lines
5.8 KiB
Java
173 lines
5.8 KiB
Java
package com.shayu.onetoone.dialog;
|
|
|
|
import android.content.Context;
|
|
import android.widget.Button;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.lxj.xpopup.XPopup;
|
|
import com.shayu.onetoone.R;
|
|
import com.shayu.onetoone.adapter.GiftListAdapter;
|
|
import com.shayu.onetoone.bean.GiftBean;
|
|
import com.shayu.onetoone.bean.MessageChatGiftContent;
|
|
import com.shayu.onetoone.bean.PurseBean;
|
|
import com.shayu.onetoone.bean.SendConsumeBean;
|
|
import com.shayu.onetoone.listener.OnSendMessageListener;
|
|
import com.shayu.onetoone.manager.OTONetManager;
|
|
import com.shayu.onetoone.manager.SendMessageManager;
|
|
import com.shayu.onetoone.view.MsgInputPanelForGift;
|
|
import com.shayu.onetoone.widget.PagerConfig;
|
|
import com.shayu.onetoone.widget.PagerGridLayoutManager;
|
|
import com.shayu.onetoone.widget.PagerGridSnapHelper;
|
|
import com.yunbao.common.dialog.AbsDialogPopupWindow;
|
|
import com.yunbao.common.http.base.HttpCallback;
|
|
import com.yunbao.common.interfaces.OnItemClickListener;
|
|
import com.yunbao.common.manager.IMLoginManager;
|
|
import com.yunbao.common.utils.ToastUtil;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import io.rong.imkit.IMCenter;
|
|
import io.rong.imlib.IRongCallback;
|
|
import io.rong.imlib.RongIMClient;
|
|
import io.rong.imlib.model.Conversation;
|
|
import io.rong.imlib.model.Message;
|
|
|
|
public class GiftDialog extends AbsDialogPopupWindow {
|
|
RecyclerView gifList;
|
|
GiftListAdapter mAdapter;
|
|
TextView money;
|
|
Button topUpBtn;
|
|
Button sendBtn;
|
|
String token;
|
|
String targetId;
|
|
OnItemClickListener<GiftBean> onItemClickListener;
|
|
|
|
|
|
public GiftDialog(@NonNull Context context) {
|
|
super(context);
|
|
}
|
|
|
|
@Override
|
|
public void buildDialog(XPopup.Builder builder) {
|
|
|
|
}
|
|
|
|
public GiftDialog setTargetId(String targetId) {
|
|
this.targetId = targetId;
|
|
return this;
|
|
}
|
|
|
|
public GiftDialog setOnItemClickListener(OnItemClickListener<GiftBean> onItemClickListener) {
|
|
this.onItemClickListener = onItemClickListener;
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public int bindLayoutId() {
|
|
return R.layout.view_message_input_gift;
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate() {
|
|
super.onCreate();
|
|
gifList = findViewById(R.id.gift_list);
|
|
money = findViewById(R.id.money);
|
|
topUpBtn = findViewById(R.id.top_up_btn);
|
|
sendBtn = findViewById(R.id.send_btn);
|
|
mAdapter = new GiftListAdapter(mContext);
|
|
PagerGridLayoutManager manager = new PagerGridLayoutManager(2, 4, PagerGridLayoutManager.HORIZONTAL);
|
|
gifList.setLayoutManager(manager);
|
|
PagerGridSnapHelper pageSnapHelper = new PagerGridSnapHelper();
|
|
pageSnapHelper.attachToRecyclerView(gifList);
|
|
manager.setAllowContinuousScroll(false);
|
|
PagerConfig.setMillisecondsPreInch(150);
|
|
gifList.setAdapter(mAdapter);
|
|
initData();
|
|
sendBtn.setOnClickListener(v -> {
|
|
SendMessageManager.sendMessageForGift(targetId, mAdapter.getItem().getId() + "", new OnSendMessageListener() {
|
|
@Override
|
|
public void onSuccess(String token, SendConsumeBean bean) {
|
|
super.onSuccess(token,bean);
|
|
GiftDialog.this.token = token;
|
|
sendGift(mAdapter.getItem());
|
|
|
|
}
|
|
|
|
@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() + "");
|
|
bean.setExtra(JSONObject.toJSONString(item));
|
|
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) {
|
|
iniPurse();
|
|
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() {
|
|
iniPurse();
|
|
OTONetManager.getInstance(mContext)
|
|
.getGiftList(new HttpCallback<List<GiftBean>>() {
|
|
@Override
|
|
public void onSuccess(List<GiftBean> data) {
|
|
mAdapter.setList(data);
|
|
}
|
|
|
|
@Override
|
|
public void onError(String error) {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
private void iniPurse() {
|
|
OTONetManager.getInstance(mContext)
|
|
.getPurseInfo(new HttpCallback<PurseBean>() {
|
|
@Override
|
|
public void onSuccess(PurseBean data) {
|
|
money.setText(data.getStart() + "");
|
|
}
|
|
|
|
@Override
|
|
public void onError(String error) {
|
|
|
|
}
|
|
});
|
|
}
|
|
}
|