Commit 4eea9523 by YKai

feat:聊天界面切换到客服界面

parent 211e8dd3
package com.yidianling.im.bean
/**
* Created by Ykai on 2021/1/25.
*
* 转接客服bean
*/
data class ServiceBean(
var data:DataBean?,
var business:String=""
)
data class DataBean(
var toUid:Long,
var fromUid:Long,
var name:String?,
var chatType:String?
)
\ No newline at end of file
......@@ -237,7 +237,7 @@ public class SessionHelper {
//====================Get Customization====================
private static SessionCustomization getP2pCustomization(int user_type) {
public static SessionCustomization getP2pCustomization(int user_type) {
if (last_user_type != user_type) {
last_user_type = user_type;
......
......@@ -111,7 +111,7 @@ public abstract class YDLBaseMessageActivity extends UI {
@SuppressLint("CheckResult")
public void setToolBar(int toolBarId) {
tb = (TitleBarBottom) findViewById(toolBarId);
tb = findViewById(toolBarId);
if (ActionHandlerStorage.getL(sessionId) != null && ActionHandlerStorage.getL(sessionId).getInfo() != null) {
tb.setTitle(ActionHandlerStorage.getL(sessionId).getInfo().name);
}
......
......@@ -4,10 +4,12 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.Observer;
import com.netease.nimlib.sdk.msg.MsgService;
......@@ -17,6 +19,12 @@ import com.netease.nimlib.sdk.msg.model.CustomNotification;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.im.R;
import com.yidianling.im.api.bean.IMRegisterObserverCustomNotificationCallBack;
import com.yidianling.im.bean.ServiceBean;
import com.yidianling.im.bridge.P2PCustomActionHandlerImpl;
import com.yidianling.im.config.constants.ImConstants;
import com.yidianling.im.helper.ImObserversHelper;
import com.yidianling.im.session.SessionHelper;
import com.yidianling.nimbase.api.model.session.SessionCustomization;
import com.yidianling.nimbase.api.model.user.UserInfoObserver;
import com.yidianling.nimbase.business.session.constant.Extras;
......@@ -27,6 +35,8 @@ import com.yidianling.uikit.business.session.fragment.YDLMessageFragment;
import com.yidianling.uikit.custom.bridge.ActionHandlerStorage;
import com.yidianling.uikit.custom.bridge.IP2PCustomActionHandler;
import org.jetbrains.annotations.NotNull;
import java.util.List;
......@@ -41,6 +51,7 @@ public class YDLP2PMessageActivity extends YDLBaseMessageActivity {
private int screenWidth;
private int screenHeight;
protected YDLMessageFragment messageFragment;
private boolean isChangeDoctor = false;
/**
* @param context
......@@ -54,11 +65,33 @@ public class YDLP2PMessageActivity extends YDLBaseMessageActivity {
intent.putExtra(Extras.EXTRA_ACCOUNT, contactId);
intent.putExtra(Extras.EXTRA_CUSTOMIZATION, customization);
if(ActionHandlerStorage.getL(contactId) != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
if (ActionHandlerStorage.getL(contactId) != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
} else if (contactId.equals(ImConstants.KEFUXIAOYI)) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
}
ActionHandlerStorage.setL(contactId,l);
ActionHandlerStorage.setL(contactId, l);
if (anchor != null) {
intent.putExtra(Extras.EXTRA_ANCHOR, anchor);
}
intent.setClass(context, YDLP2PMessageActivity.class);
context.startActivity(intent);
}
/**
* 切换到客服界面
*
*/
public static void startChangeDoctor(Context context, String contactId, SessionCustomization customization, IMMessage anchor, IP2PCustomActionHandler l){
Intent intent = new Intent();
intent.putExtra(Extras.EXTRA_ACCOUNT, contactId);
intent.putExtra(Extras.EXTRA_CUSTOMIZATION, customization);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
ActionHandlerStorage.setL(contactId, l);
if (anchor != null) {
intent.putExtra(Extras.EXTRA_ANCHOR, anchor);
......@@ -67,6 +100,15 @@ public class YDLP2PMessageActivity extends YDLBaseMessageActivity {
context.startActivity(intent);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// 如果isChangeDoctor为true表示切换客服
if (isChangeDoctor) {
messageFragment = (YDLMessageFragment) switchContent(switchServiceFragment(intent));
isChangeDoctor=false;
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -85,6 +127,20 @@ public class YDLP2PMessageActivity extends YDLBaseMessageActivity {
registerObservers(true);
NIMClient.getService(MsgService.class).clearUnreadCount(sessionId, SessionTypeEnum.P2P);
// 转客服通知监听
ImObserversHelper.Companion.getInstance().setImCustomNotificationCallBack(new IMRegisterObserverCustomNotificationCallBack() {
@Override
public void onObserverCustomNotification(@NotNull String fromUid, @NotNull String toUid, @NotNull String content) {
ServiceBean serviceBean = new Gson().fromJson(content, ServiceBean.class);
// 切换到客服
if (serviceBean != null && serviceBean.getData() != null && serviceBean.getBusiness().equals("change_doctor")) {
isChangeDoctor = true;
String serviceUid = String.valueOf(serviceBean.getData().getToUid());
tb.setTitle(serviceBean.getData().getName());
YDLP2PMessageActivity.startChangeDoctor(YDLP2PMessageActivity.this, serviceUid, SessionHelper.getP2pCustomization(-1), null,new P2PCustomActionHandlerImpl(serviceUid, serviceBean.getData().getName(), serviceUid));
}
}
});
}
@Override
......@@ -110,7 +166,7 @@ public class YDLP2PMessageActivity extends YDLBaseMessageActivity {
messageFragment.getInputPanel().setInputContent(ActionHandlerStorage.getL(sessionId).getImTempData(sessionId));
}
if (ActionHandlerStorage.needLoadNewMsg) {
((BaseFetchLoadAdapter.RequestFetchMoreListener)messageFragment.getMessageListPanelEx().getMessageLoder(null)).onFetchMoreRequested();
((BaseFetchLoadAdapter.RequestFetchMoreListener) messageFragment.getMessageListPanelEx().getMessageLoder(null)).onFetchMoreRequested();
ActionHandlerStorage.needLoadNewMsg = false;
}
}
......@@ -183,7 +239,7 @@ public class YDLP2PMessageActivity extends YDLBaseMessageActivity {
protected YDLMessageFragment fragment() {
Bundle arguments = getIntent().getExtras();
arguments.putSerializable(Extras.EXTRA_TYPE, SessionTypeEnum.P2P);
if (messageFragment==null){
if (messageFragment == null) {
messageFragment = new YDLMessageFragment();
messageFragment.setArguments(arguments);
messageFragment.setContainerId(R.id.message_fragment_container);
......@@ -191,6 +247,20 @@ public class YDLP2PMessageActivity extends YDLBaseMessageActivity {
return messageFragment;
}
/**
* 切换到客服fragment
*
* @return
*/
private YDLMessageFragment switchServiceFragment(Intent intent) {
Bundle arguments = intent.getExtras();
arguments.putSerializable(Extras.EXTRA_TYPE, SessionTypeEnum.P2P);
messageFragment = new YDLMessageFragment();
messageFragment.setArguments(arguments);
messageFragment.setContainerId(R.id.message_fragment_container);
return messageFragment;
}
@Override
protected int getContentViewId() {
return R.layout.im_ydl_nim_message_activity;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment