Browse Source

1、完善聊天弹窗;

yzs 4 years ago
parent
commit
a5483216a2

+ 1 - 1
uchat_im/src/main/java/com/shanp/youqi/im/adapter/ConversationOnlyTextAdapter.java

@@ -157,7 +157,7 @@ public class ConversationOnlyTextAdapter extends BaseQuickAdapter<ConversationIt
         if (TextUtils.isEmpty(content)) content = "未知消息";
         helper.setText(R.id.tv_txt_content, content);
         TextView tv = helper.getView(R.id.tv_txt_content);
-        tv.setSelected(true);
+        tv.setTextIsSelectable(true);
     }
 
 

+ 18 - 8
uchat_im/src/main/java/com/shanp/youqi/im/fragment/MessageListOnlyUserFragment.kt

@@ -6,6 +6,7 @@ import androidx.recyclerview.widget.RecyclerView
 import com.chad.library.adapter.base.BaseQuickAdapter
 import com.shanp.youqi.base.rx.EventSubscriber
 import com.shanp.youqi.base.rx.RxBus
+import com.shanp.youqi.common.R2
 import com.shanp.youqi.common.base.UChatFragment
 import com.shanp.youqi.common.vo.im.ConversationListVo
 import com.shanp.youqi.common.widget.EmptyView
@@ -39,7 +40,6 @@ class MessageListOnlyUserFragment : UChatFragment() {
 
     private var adapter = MessageListOnlyUserAdapter(null)
     private val messageListDialog: MessageListDialog by lazy { parentFragment as MessageListDialog }
-    private lateinit var emptyView: EmptyView
 
     override fun getLayoutId(): Int = R.layout.im_fragment_message_list_only_user
 
@@ -53,11 +53,15 @@ class MessageListOnlyUserFragment : UChatFragment() {
     }
 
     private fun initRecyclerView() {
-        emptyView = EmptyView(mContext)
+        binding.emptyView
                 .setColorStyle(true)
                 .setNoDataTitle("暂无聊天联系人")
                 .setNoDataIconIds(R.drawable.empty_box_bright)
                 .setLayoutType(EmptyView.LayoutType.TYPE_LAYOUT_NO_DATA)
+
+        binding.emptyView.pageRootLayout.setBackgroundResource(R.drawable.bg_white_radius_top_13)
+
+        binding.emptyView.visibility = View.GONE
         val manager = LinearLayoutManager(mContext, RecyclerView.VERTICAL, false)
         binding.rcv.itemAnimator = null
         binding.rcv.layoutManager = manager
@@ -127,6 +131,7 @@ class MessageListOnlyUserFragment : UChatFragment() {
                         adapter.remove(oldDataIndex)
                     }
                     adapter.addData(0, ConversationListVo(it))
+                    binding.emptyView.visibility = View.GONE
                 }
             }
 
@@ -159,26 +164,31 @@ class MessageListOnlyUserFragment : UChatFragment() {
                 }
 
                 if (tempData.size > 0) {
-                    adapter.isUseEmpty(false)
                     adapter.addData(tempData)
                 }
                 timeStamp = adapter.data.last().conversation.sentTime
                 binding.srl.setEnableLoadMore(data.size >= count)
                 binding.srl.finishLoadMore()
             } else {
-                if (adapter.itemCount <= 0) {
-                    adapter.isUseEmpty(true)
-                    adapter.emptyView = emptyView
-                    adapter.notifyDataSetChanged()
-                }
                 binding.srl.setEnableLoadMore(false)
                 binding.srl.setNoMoreData(true)
                 binding.srl.finishLoadMore()
             }
+
+            if (adapter.itemCount <= 0) {
+                binding.emptyView.visibility = View.VISIBLE
+            } else {
+                binding.emptyView.visibility = View.GONE
+            }
         }
 
         override fun onError(error: RongIMClient.ErrorCode?) {
             binding.srl.finishLoadMore()
+            if (adapter.itemCount <= 0) {
+                binding.emptyView.visibility = View.VISIBLE
+            } else {
+                binding.emptyView.visibility = View.GONE
+            }
         }
 
     }

+ 8 - 12
uchat_im/src/main/java/com/shanp/youqi/im/fragment/UChatConversationOnlyTextFragment.kt

@@ -2,7 +2,6 @@ package com.shanp.youqi.im.fragment
 
 import android.graphics.Rect
 import android.text.TextUtils
-import android.view.MotionEvent
 import android.view.View
 import android.view.inputmethod.EditorInfo
 import android.widget.TextView.OnEditorActionListener
@@ -11,7 +10,6 @@ import androidx.recyclerview.widget.RecyclerView
 import com.blankj.utilcode.util.ClickUtils
 import com.blankj.utilcode.util.KeyboardUtils
 import com.blankj.utilcode.util.ToastUtils
-import com.blankj.utilcode.util.TouchUtils
 import com.shanp.youqi.base.rx.EventSubscriber
 import com.shanp.youqi.base.rx.RxBus
 import com.shanp.youqi.base.util.LogUtil
@@ -99,11 +97,6 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
             }
         })
 
-        //监听加载,而不是监听 刷新
-//        binding.srl.setOnLoadMoreListener {
-//            loadConversationMessage()
-//        }
-        adapter.isUpFetchEnable = true
         adapter.setUpFetchListener {
             adapter.isUpFetching = true
             LogUtil.d("加载数据")
@@ -206,16 +199,18 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
         RongIMClient.getInstance().getHistoryMessages(Conversation.ConversationType.PRIVATE,
                 targetId, mOldestMessageId, Constant.conversation.LOAD_HISTORY_MESSAGE_COUNT, object : RongIMClient.ResultCallback<List<Message?>?>() {
             override fun onSuccess(messages: List<Message?>?) {
-//                binding.srl.finishLoadMore()
                 adapter.isUpFetching = false
-                messages?.let {
-                    disposeHistoryMessage(isInit, it)
+                if (messages != null) {
+                    disposeHistoryMessage(isInit, messages)
+                } else {
+                    adapter.isUpFetchEnable = false
                 }
             }
 
             override fun onError(errorCode: RongIMClient.ErrorCode) {
 //                binding.srl.finishLoadMore()
                 adapter.isUpFetching = false
+                adapter.isUpFetchEnable = false
             }
         })
     }
@@ -239,8 +234,9 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
             if (isInit) {
                 binding.rcv.postDelayed(Runnable { if (binding.rcv != null) binding.rcv.scrollToPosition(adapter.data.lastIndex) }, 100)
             }
-//            binding.srl.setEnableLoadMore(!notHasHistoryMessage)
             if (notHasHistoryMessage) adapter.isUpFetchEnable = false
+        } else {
+            adapter.isUpFetchEnable = false
         }
     }
 
@@ -288,7 +284,7 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
 
 
     private fun sendMessageSuccess(message: Message, position: Int) {
-        val data: List<ConversationItemVo> = adapter.getData()
+        val data: List<ConversationItemVo> = adapter.data
         val vo = data[position]
         vo.message = message
         adapter.notifyItemChanged(position)

+ 8 - 2
uchat_im/src/main/res/layout/im_fragment_message_list_only_user.xml

@@ -2,9 +2,9 @@
 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/clRootLayout"
-    android:background="@drawable/bg_white_radius_top_13"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="match_parent"
+    android:background="@drawable/bg_white_radius_top_13">
 
     <com.scwang.smartrefresh.layout.SmartRefreshLayout
         android:id="@+id/srl"
@@ -17,4 +17,10 @@
             android:layout_width="match_parent"
             android:layout_height="match_parent" />
     </com.scwang.smartrefresh.layout.SmartRefreshLayout>
+
+    <com.shanp.youqi.common.widget.EmptyView
+        android:id="@+id/emptyView"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:visibility="gone" />
 </androidx.constraintlayout.widget.ConstraintLayout>