85 lines
3.4 KiB
Java
85 lines
3.4 KiB
Java
package com.shayu.onetoone.utils;
|
|
|
|
import android.app.Dialog;
|
|
import android.content.Context;
|
|
import android.os.Bundle;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.shayu.onetoone.R;
|
|
import com.shayu.onetoone.activity.message.ChatActivity;
|
|
import com.shayu.onetoone.bean.SendConsumeBean;
|
|
import com.shayu.onetoone.dialog.TipsDialog;
|
|
import com.shayu.onetoone.listener.OnDialogClickListener;
|
|
import com.shayu.onetoone.listener.OnSendMessageListener;
|
|
import com.shayu.onetoone.manager.SendMessageManager;
|
|
import com.yunbao.common.utils.ToastUtil;
|
|
import com.yunbao.common.utils.WordUtil;
|
|
|
|
import io.rong.imkit.utils.RouteUtils;
|
|
import io.rong.imlib.model.Conversation;
|
|
import io.rong.imlib.model.ConversationIdentifier;
|
|
|
|
/**
|
|
* 跳转到会话页面
|
|
*/
|
|
public class ConversationUtils {
|
|
public static void startConversation(Context mContext, String targetId) {
|
|
startConversation(mContext, targetId, new Bundle());
|
|
}
|
|
|
|
public static void startConversation(Context mContext, String targetId, Bundle bundle) {
|
|
if (targetId.equals(UserManager.getUserBean().getUser().getId() + "")) {
|
|
ToastUtil.show("不能与自己对话");
|
|
return;
|
|
}
|
|
bundle.putString("test","ssssssssssss");
|
|
ConversationIdentifier conversationIdentifier = new ConversationIdentifier(Conversation.ConversationType.PRIVATE, targetId);
|
|
RouteUtils.routeToConversationActivity(mContext, conversationIdentifier, false, bundle);
|
|
}
|
|
|
|
/**
|
|
* 搭讪
|
|
*/
|
|
public static void hitOn(Context mContext, String targetId, OnSendMessageListener listener) {
|
|
SendMessageManager.chatUp(targetId + "", new OnSendMessageListener() {
|
|
@Override
|
|
public void onSuccess(String token, SendConsumeBean bean) {
|
|
super.onSuccess(token, bean);
|
|
System.out.println("搭讪回调:" + JSONObject.toJSONString(bean));
|
|
Bundle bundle = new Bundle();
|
|
bundle.putString("token", token);
|
|
bundle.putInt("type", ChatActivity.CALL_CHAT_TYPE_CHAT_UP);
|
|
bundle.putString("data", JSONObject.toJSONString(bean));
|
|
ConversationUtils.startConversation(mContext, targetId, bundle);
|
|
if (listener != null) {
|
|
listener.onSuccess(token, bean);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onError(int status, String msg, SendConsumeBean bean) {
|
|
super.onError(status, msg, bean);
|
|
if (listener != null) {
|
|
listener.onError(status, msg, bean);
|
|
}
|
|
if (status == OnSendMessageListener.STATUS_NOT_PRICE) {
|
|
new TipsDialog(mContext)
|
|
.setTitle(WordUtil.getNewString(R.string.money_title))
|
|
.setApplyText(WordUtil.getNewString(R.string.money_apply))
|
|
.setOnDialogClickListener(new OnDialogClickListener() {
|
|
@Override
|
|
public void onApply(Dialog dialog) {
|
|
super.onApply(dialog);
|
|
}
|
|
})
|
|
.showDialog();
|
|
} else {
|
|
new TipsDialog(mContext)
|
|
.setTitle(msg)
|
|
.showDialog();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|