Commit 4ce3a7ca by 刘鹏

feat : 注销自定义消息类型,新增聊天页面,ui未更改,跳转参数未更改

parent ffef6da8
......@@ -73,6 +73,12 @@
android:screenOrientation="portrait"
android:theme="@style/platform_NoTitleTheme" />
<!--医疗聊天列表页-->
<activity
android:name=".ui.activity.MedicalChatActivity"
android:screenOrientation="portrait"
android:theme="@style/platform_NoTitleTheme" />
<!-- 云信 集成配置 -->
<!-- 声明云信后台服务 -->
<service
......
package com.yidianling.im.ui.activity
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.jcodecraeer.xrecyclerview.CustomFooterViewCallBack
import com.jcodecraeer.xrecyclerview.XRecyclerView
import com.ydl.ydlcommon.base.BaseActivity
import com.ydl.ydlcommon.data.http.RxUtils
import com.ydl.ydlcommon.utils.StatusBarUtils.Companion.setTransparentForImageView
import com.ydl.ydlcommon.utils.StatusBarUtils.Companion.statusBarLightMode
import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.R
import com.yidianling.im.event.MessageListRefreshEvent
import com.yidianling.im.helper.MsgReceiveHelper
import com.yidianling.im.http.ImHttpImpl
import com.yidianling.im.router.ImIn
import com.yidianling.im.ui.page.fragment.adapter.ChatAdapter
import com.yidianling.im.ui.page.fragment.bean.ChatItemBean
import com.yidianling.im.ui.page.fragment.bean.ChatModelBean
import com.yidianling.im.ui.page.fragment.view.ChatFooterItemView
import com.yidianling.im.ui.page.widget.ChatUnusualView
import com.yidianling.im.ui.param.ChatParam
import de.greenrobot.event.EventBus
import kotlinx.android.synthetic.main.im_chat_fragment_layout.*
@Route(path = "/im/medical")
class MedicalChatActivity : BaseActivity(), XRecyclerView.LoadingListener {
private var chatAdapter: ChatAdapter? = null
private var allChatData: ChatModelBean = ChatModelBean() //全部数据
private var showData: ArrayList<ChatItemBean> = ArrayList() // 最终展示的数据
private val mCompare: Comparator<ChatItemBean> = Comparator { o1, o2 ->
val res = o1.timestamp.compareTo(o2.timestamp)
when {
res == 0 -> 0
res > 0 -> -1
else -> 1
}
}
override fun layoutResId(): Int {
return R.layout.medical_chat_list
}
override fun initDataAndEvent() {
initStatus()
chatAdapter = ChatAdapter(mContext, showData, this@MedicalChatActivity)
chatAdapter?.setlistener(object : ChatAdapter.ChatRecyclerViewCallback {
override fun onRefresh() {
getChatMessageData()
}
})
chat_recyclerview.layoutManager = LinearLayoutManager(this@MedicalChatActivity)
chat_recyclerview.adapter = chatAdapter
chat_recyclerview.setLoadingListener(this@MedicalChatActivity)
chat_recyclerview.setFootView(
ChatFooterItemView(mContext),
object : CustomFooterViewCallBack {
override fun onSetNoMore(p0: View?, p1: Boolean) {
}
override fun onLoadingMore(p0: View?) {
}
override fun onLoadMoreComplete(p0: View?) {
}
})
}
private fun initStatus() {
setTransparentForImageView(this@MedicalChatActivity, null)
statusBarLightMode(this@MedicalChatActivity)
}
override fun onResume() {
super.onResume()
resetPageShow()
}
fun clearData() {
showData.clear()
chatAdapter?.notifyDataSetChanged()
resetPageShow()
}
/**
* 页面展示状态逻辑
*/
private fun resetPageShow() {
ll_chat_unusual_view?.let {
if (ImIn.isLogin()) {
//登录状态
if (showData.size != 0) {
//数据不为空
chat_recyclerview.visibility = View.VISIBLE
ll_chat_unusual_view.visibility = View.GONE
} else {
chat_recyclerview.visibility = View.GONE
ll_chat_unusual_view.visibility = View.VISIBLE
ll_chat_unusual_view.setUnusualType(ChatUnusualView.TYPE_CHAT_ALL_NO_DATA)
}
} else {
//未登录状态
chat_recyclerview.visibility = View.GONE
ll_chat_unusual_view.visibility = View.VISIBLE
ll_chat_unusual_view.setUnusualType(ChatUnusualView.TYPE_UNLOGIN)
ll_chat_unusual_view.setListener(object : ChatUnusualView.ChatUnusualListener {
override fun onButtonClick() {
ImIn.loginByOneKeyLogin(mContext, true)
}
})
}
}
}
override fun onRefresh() {
EventBus.getDefault().post(MessageListRefreshEvent(0))
getChatMessageData()
}
override fun onLoadMore() {
chat_recyclerview.setNoMore(true)
}
fun getChatMessageData() {
if (ImIn.getUserInfo()?.uid != "0") {
var dis = ImHttpImpl.getInstance()
.getAllChatMessage(ChatParam("${ImIn.getUserInfo()?.uid}", "${0}"))
.compose(RxUtils.applySchedulers(this))
.compose<ChatModelBean>(RxUtils.resultJavaData())
.subscribe({ it ->
if (it.before.data.size != 0 || it.nomal.data.size != 0) {
setData(it)
}
chat_recyclerview?.let {
chat_recyclerview.refreshComplete()
}
}, { t ->
ToastUtil.toastShort("您的网络出现了问题")
chat_recyclerview?.let {
chat_recyclerview.refreshComplete()
}
})
}
}
/**
* 设置全部数据
*/
fun setData(data: ChatModelBean) {
allChatData = data
setShowData()
}
/**
* 设置最终显示得数据,(优先置顶,再最近数据,再三周前的消息item,再三周前,其余按照时间排序)
*/
private fun setShowData() {
showData.clear()
chatAdapter?.notifyDataSetChanged()
selectTopData()
// 全部
showData.addAll(allChatData.topData.data.sortedWith(mCompare))
showData.addAll(allChatData.nomal.data.filter { it.is_top == 0 }
.sortedWith(mCompare))
if (allChatData.before.data.any { it.is_top == 0 }) {
showData.addAll(allChatData.before.data.filter { it.is_top == 0 }
.sortedWith(mCompare))
}
// 重置消息未读数
MsgReceiveHelper.reQueryUnreadNumber {
showData.forEachIndexed { index, _ ->
showData[index].unReadNum =
MsgReceiveHelper.getUnNum(showData[index].toUid.toString())
}
chatAdapter?.notifyDataSetChanged()
resetPageShow()
}
}
/**
* 将before数据和nomal数据里面的置顶数据筛选出来放入topData里面
*/
private fun selectTopData() {
allChatData.topData.data.clear()
allChatData.topData.data.addAll(allChatData.before.data.filter { it.is_top == 1 })
allChatData.topData.data.addAll(allChatData.nomal.data.filter { it.is_top == 1 })
}
}
\ No newline at end of file
......@@ -2,11 +2,11 @@ package com.yidianling.im.ui.page.fragment.adapter
import android.app.Dialog
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import android.text.TextUtils
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.netease.nimlib.sdk.NIMClient
import com.netease.nimlib.sdk.msg.MsgService
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum
......@@ -33,7 +33,11 @@ import de.greenrobot.event.EventBus
* 互动列表适配器
* Created by xj on 2019/10/14.
*/
class ChatAdapter(var context: Context, private var mList: ArrayList<ChatItemBean>,private var lifecycleable: ILifecycleable<*>): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class ChatAdapter(
var context: Context,
private var mList: ArrayList<ChatItemBean>,
private var lifecycleable: ILifecycleable<*>
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
companion object {
......@@ -59,11 +63,12 @@ class ChatAdapter(var context: Context, private var mList: ArrayList<ChatItemBea
holder.view.setOnClickListener {
//点击去私聊
if (TextUtils.equals(mList[position].toUid.toString(), "4108805")) {
SessionHelper.startP2PSession(context, -1, "4108805", null,
P2PCustomActionHandlerImpl("4108805", "课程小助手-壹壹", "4108805"))
}else {
// IMUtil.startChat(context as AppCompatActivity, mList[position].toUid.toString(), 0, 0, null, 0, true)
IMChatUtil.startChat(context as AppCompatActivity, mList[position])
SessionHelper.startP2PSession(
context, -1, "4108805", null,
P2PCustomActionHandlerImpl("4108805", "课程小助手-壹壹", "4108805")
)
} else {
IMChatUtil.startCms(context as AppCompatActivity, 1, null)
}
}
......@@ -83,7 +88,8 @@ class ChatAdapter(var context: Context, private var mList: ArrayList<ChatItemBea
name.add("标记为已读")
}
val builder = ListNoCancelDialog.Builder(context, name, 0)
builder.SetOnItemClickLister(object : ListNoCancelDialog.Builder.OnItemClickLister {
builder.SetOnItemClickLister(object :
ListNoCancelDialog.Builder.OnItemClickLister {
override fun onItemClick(dialog: Dialog, view: View, position1: Int) {
val tag = name[position1]
when (tag) {
......@@ -117,7 +123,8 @@ class ChatAdapter(var context: Context, private var mList: ArrayList<ChatItemBea
is ChatTimeItemHolder -> {
holder.view.initData(mList[position])
}
else -> {}
else -> {
}
}
}
......@@ -139,43 +146,48 @@ class ChatAdapter(var context: Context, private var mList: ArrayList<ChatItemBea
private fun delete(bean: ChatItemBean) {
LogHelper.getInstance().writeLogSync("删除聊天:uid = " + bean.toUid)
var dis = ImHttpImpl.getInstance().rmHistory(
var dis = ImHttpImpl.getInstance().rmHistory(
RmHistoryParam(
bean.toUid.toString(),
1
)
)
.compose(RxUtils.applySchedulers(lifecycleable))
.compose(RxUtils.resultData())
.subscribe({ o ->
LogHelper.getInstance().writeLogSync("删除聊天成功:uid = " + bean.toUid)
NIMClient.getService(MsgService::class.java).clearChattingHistory(bean.toUid.toString(), SessionTypeEnum.P2P)
deleteItem(bean)
}, {t ->
ToastHelper.show(t.message.toString())
LogHelper.getInstance().writeLogSync("删除聊天失败:uid = " + bean.toUid)
})
.compose(RxUtils.applySchedulers(lifecycleable))
.compose(RxUtils.resultData())
.subscribe({ o ->
LogHelper.getInstance().writeLogSync("删除聊天成功:uid = " + bean.toUid)
NIMClient.getService(MsgService::class.java)
.clearChattingHistory(bean.toUid.toString(), SessionTypeEnum.P2P)
deleteItem(bean)
}, { t ->
ToastHelper.show(t.message.toString())
LogHelper.getInstance().writeLogSync("删除聊天失败:uid = " + bean.toUid)
})
}
private fun deleteItem(bean: ChatItemBean) {
var dis = ImHttpImpl.getInstance().rmTalk(RmTalkParam(bean.toUid.toString()))
.compose(RxUtils.applySchedulers(lifecycleable))
.compose(RxUtils.resultData())
.subscribe({ o ->
NIMClient.getService(MsgService::class.java).clearUnreadCount(bean.toUid.toString(), SessionTypeEnum.P2P)
NIMClient.getService(MsgService::class.java).clearUnreadCount(bean.toUid.toString(), SessionTypeEnum.Team)
MsgReceiveHelper.updateNum(bean.toUid.toString(), 0)
EventBus.getDefault().post(UpdateTabUnreadNumEvent())
}, {t ->
ToastHelper.show(t.message.toString())
})
.compose(RxUtils.applySchedulers(lifecycleable))
.compose(RxUtils.resultData())
.subscribe({ o ->
NIMClient.getService(MsgService::class.java)
.clearUnreadCount(bean.toUid.toString(), SessionTypeEnum.P2P)
NIMClient.getService(MsgService::class.java)
.clearUnreadCount(bean.toUid.toString(), SessionTypeEnum.Team)
MsgReceiveHelper.updateNum(bean.toUid.toString(), 0)
EventBus.getDefault().post(UpdateTabUnreadNumEvent())
}, { t ->
ToastHelper.show(t.message.toString())
})
}
private fun toTop(bean: ChatItemBean, istop: Int) {
LogHelper.getInstance().writeLogSync("置顶聊天:uid = " + bean.toUid.toString() +
"取消置顶 = " + (istop == 0))
LogHelper.getInstance().writeLogSync(
"置顶聊天:uid = " + bean.toUid.toString() +
"取消置顶 = " + (istop == 0)
)
var dis = ImHttpImpl.getInstance().topMessage(
TopMessageParam(
bean.toUid.toString(),
......@@ -183,22 +195,27 @@ class ChatAdapter(var context: Context, private var mList: ArrayList<ChatItemBea
istop
)
)
.compose(RxUtils.applySchedulers(lifecycleable))
.compose(RxUtils.resultData())
.subscribe({ o ->
LogHelper.getInstance().writeLogSync("置顶聊天成功:uid = " + bean.toUid.toString() +
"取消置顶 = " + (istop == 0))
mListener?.onRefresh()
}, {t ->
LogHelper.getInstance().writeLogSync("置顶聊天失败:uid = " + bean.toUid.toString() +
"取消置顶 = " + (istop == 0))
ToastHelper.show("操作失败")
})
.compose(RxUtils.applySchedulers(lifecycleable))
.compose(RxUtils.resultData())
.subscribe({ o ->
LogHelper.getInstance().writeLogSync(
"置顶聊天成功:uid = " + bean.toUid.toString() +
"取消置顶 = " + (istop == 0)
)
mListener?.onRefresh()
}, { t ->
LogHelper.getInstance().writeLogSync(
"置顶聊天失败:uid = " + bean.toUid.toString() +
"取消置顶 = " + (istop == 0)
)
ToastHelper.show("操作失败")
})
}
private fun mark(bean: ChatItemBean) {
LogHelper.getInstance().writeLogSync("标记为已读:uid = " + bean.toUid.toString())
NIMClient.getService(MsgService::class.java).clearUnreadCount(bean.toUid.toString(), SessionTypeEnum.P2P)
NIMClient.getService(MsgService::class.java)
.clearUnreadCount(bean.toUid.toString(), SessionTypeEnum.P2P)
MsgReceiveHelper.updateNum(bean.toUid.toString(), 0)
mListener?.onRefresh()
EventBus.getDefault().post(UpdateTabUnreadNumEvent())
......@@ -217,11 +234,11 @@ class ChatAdapter(var context: Context, private var mList: ArrayList<ChatItemBea
/**
* 互动列表正常item的holder
*/
inner class ChatItemHolder(val view: ChatItemView): RecyclerView.ViewHolder(view)
inner class ChatItemHolder(val view: ChatItemView) : RecyclerView.ViewHolder(view)
/**
* 互动列表正常item的holder
*/
inner class ChatTimeItemHolder(val view: ChatTimeItemView): RecyclerView.ViewHolder(view)
inner class ChatTimeItemHolder(val view: ChatTimeItemView) : RecyclerView.ViewHolder(view)
}
\ No newline at end of file
......@@ -52,9 +52,8 @@ class ChatUnusualView constructor(private val mContext: Context, attrs: Attribut
}
// 没有私聊数据(全部)
TYPE_CHAT_ALL_NO_DATA -> {
unusual_txt.text = "主动私聊更容易遇到懂你的咨询师哦!"
unusual_btn.text = "去咨询"
unusual_btn.visibility = View.VISIBLE
unusual_txt.text = "您当前还未有咨询消息哦~"
unusual_btn.visibility = View.GONE
unusual_img.setImageResource(R.mipmap.im_default_siliao_none)
}
// 没有私聊数据(服务中)
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="96dp"
android:background="@color/white"
android:elevation="0dp"
android:gravity="bottom"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="56dp"
android:ellipsize="end"
android:gravity="center"
android:maxEms="10"
android:maxLines="1"
android:text="私聊"
android:textColor="#10233a"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/iv_back"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:paddingStart="16dp"
android:paddingEnd="20dp"
android:src="@drawable/platform_common_back" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
<RelativeLayout
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:layout_constraintVertical_weight="1">
<com.jcodecraeer.xrecyclerview.XRecyclerView
android:id="@+id/chat_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/im_white"></com.jcodecraeer.xrecyclerview.XRecyclerView>
<com.yidianling.im.ui.page.widget.ChatUnusualView
android:id="@+id/ll_chat_unusual_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/im_white"
android:visibility="gone" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
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