Browse Source

1、修改聊天列表弹窗进入会话界面的方案,使用fragment add的方式;2、优化交互体验;

yzs 4 years ago
parent
commit
e084f8c1f9

+ 18 - 0
build.gradle

@@ -70,6 +70,24 @@ allprojects {
         }
 //        // 私有仓库地址
 //        maven { url "http://lib.gcssloop.com/repository/gcssloop-central/" }
+
+//        maven {
+//            url 'https://maven.aliyun.com/repository/public'
+//        }
+//        maven {
+//            credentials {
+//                username '5f5ee8532d5925c55bec6983'
+//                password '8_]3dGOKe4zx'
+//            }
+//            url 'https://packages.aliyun.com/maven/repository/2033452-release-Tv7qvH/'
+//        }
+//        maven {
+//            credentials {
+//                username '5f5ee8532d5925c55bec6983'
+//                password '8_]3dGOKe4zx'
+//            }
+//            url 'https://packages.aliyun.com/maven/repository/2033452-snapshot-ELyiH0/'
+//        }
     }
 
     // 组件缓存更新时间设置(默认每次build都更新)

+ 1 - 0
gradle.properties

@@ -29,6 +29,7 @@ android.useAndroidX=true
 android.enableJetifier=true
 
 MAVEN_PUBLIC_URL=http://192.168.2.10:8081/repository/maven-releases
+#MAVEN_PUBLIC_URL=https://packages.aliyun.com/maven/repository/2033452-snapshot-ELyiH0
 
 MAVEN_USERNAME=shanp
 MAVEN_PASSWORD=admin123

+ 1 - 1
uchat_common/src/main/res/anim/dialog_exit_l_r.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"
-    android:duration="200">
+    android:duration="300">
     <translate
         android:fromXDelta="0"
         android:toXDelta="100%p" />

+ 1 - 1
uchat_im/src/main/java/com/shanp/youqi/im/activity/UChatConversationOnlyTextActivity.kt

@@ -31,7 +31,7 @@ class UChatConversationOnlyTextActivity : UChatActivity() {
         val targetId = intent.getStringExtra("targetId")
         val targetUserName = intent.getStringExtra("targetUserName")
         val targetHeadImg = intent.getStringExtra("targetHeadImg")
-        fragment.setParam(targetId, targetUserName, targetHeadImg)
+        fragment.setParam(targetId, targetUserName, targetHeadImg,true)
         FragmentUtils.add(supportFragmentManager, fragment, R.id.fl_container_chat)
 
     }

+ 7 - 2
uchat_im/src/main/java/com/shanp/youqi/im/dialog/ConversationDialog.kt

@@ -49,7 +49,7 @@ class ConversationDialog : BaseDialogFragment() {
     private var currentHeight = 0
 
     init {
-        setAnimStyle(R.style.dialog_style_left_right)
+        setAnimStyle(R.style.dialogstyle)
         setGravity(DialogGravity.BOTTOM)
         setDimAmount(0.0f)
         setWidthFull(true)
@@ -75,7 +75,7 @@ class ConversationDialog : BaseDialogFragment() {
         downHeight = AutoSizeUtils.dp2px(mContext, 402f)
         currentHeight = downHeight
         flContainer = holder.getView(R.id.fl_container_conversation)
-        fragment.setParam(targetId!!, targetUserName!!, targetHeadImg!!)
+        fragment.setParam(targetId!!, targetUserName!!, targetHeadImg!!, false)
         FragmentUtils.add(childFragmentManager, fragment, R.id.fl_container_conversation)
         activity?.window?.let {
             KeyboardUtils.registerSoftInputChangedListener(it) { height ->
@@ -113,4 +113,9 @@ class ConversationDialog : BaseDialogFragment() {
             this.dismiss()
         }
     }
+
+    override fun onStop() {
+        super.onStop()
+    }
+
 }

+ 37 - 14
uchat_im/src/main/java/com/shanp/youqi/im/dialog/MessageListDialog.kt

@@ -1,16 +1,17 @@
 package com.shanp.youqi.im.dialog
 
-import android.os.Bundle
-import android.view.View
 import android.widget.FrameLayout
 import com.alibaba.android.arouter.facade.annotation.Route
 import com.alibaba.android.arouter.launcher.ARouter
 import com.blankj.utilcode.util.FragmentUtils
+import com.blankj.utilcode.util.KeyboardUtils
 import com.shanp.youqi.common.app.Route.RouterUrl
 import com.shanp.youqi.common.base.BaseDialogFragment
 import com.shanp.youqi.common.base.BaseViewHolder
+import com.shanp.youqi.common.utils.ViewHideShowUtils
 import com.shanp.youqi.im.R
 import com.shanp.youqi.im.fragment.MessageListOnlyUserFragment
+import com.shanp.youqi.im.fragment.UChatConversationOnlyTextFragment
 import me.jessyan.autosize.utils.AutoSizeUtils
 
 /**
@@ -23,8 +24,10 @@ class MessageListDialog : BaseDialogFragment() {
 
     private var upHeight = 0
     private var downHeight = 0
+    private var currentHeight = 0
 
-    lateinit var flContainer: FrameLayout
+    private lateinit var flContainer: FrameLayout
+    private var conversationFragment: UChatConversationOnlyTextFragment? = null
 
     init {
         setAnimStyle(R.style.dialogstyle)
@@ -32,26 +35,46 @@ class MessageListDialog : BaseDialogFragment() {
         setDimAmount(0.0f)
         setWidthFull(true)
     }
-    
+
     override fun convert(holder: BaseViewHolder, dialog: BaseDialogFragment?) {
         ARouter.getInstance().inject(this)
         upHeight = AutoSizeUtils.dp2px(mContext, 317.5f)
         downHeight = AutoSizeUtils.dp2px(mContext, 402f)
+        currentHeight = downHeight
         flContainer = holder.getView(R.id.fl_container_message_list)
         FragmentUtils.add(childFragmentManager, MessageListOnlyUserFragment(), R.id.fl_container_message_list)
-    }
-
-    fun showHide(show: Boolean) {
-        if (show) {
-            flContainer.visibility = View.VISIBLE
-        } else {
-            flContainer.postDelayed({
-                if (flContainer != null) {
-                    flContainer.visibility = View.INVISIBLE
+        activity?.window?.let {
+            KeyboardUtils.registerSoftInputChangedListener(it) { height ->
+                conversationFragment?.let {
+                    if (height > 0) {
+                        if (currentHeight != upHeight) {
+                            currentHeight = upHeight
+                            ViewHideShowUtils.performAnim(flContainer, downHeight, upHeight, 300) {
+                                it?.rcvToBottom()
+                            }
+                        }
+                    } else {
+                        if (currentHeight != downHeight) {
+                            currentHeight = downHeight
+                            ViewHideShowUtils.performAnim(flContainer, upHeight, downHeight, 300) {
+                                it?.rcvToBottom()
+                            }
+                        }
+                    }
                 }
-            }, 310)
+            }
         }
     }
 
     override fun getLayoutId(): Int = R.layout.im_dialog_message_list_layout
+
+
+    fun addConversation(targetId: String, targetUserName: String, targetHeadImg: String) {
+        conversationFragment = UChatConversationOnlyTextFragment()
+        conversationFragment?.let {
+            it.setParam(targetId, targetUserName, targetHeadImg, true)
+            FragmentUtils.add(childFragmentManager, it, R.id.fl_container_message_list,true,
+                    R.anim.dialog_enter_r_l, R.anim.dialog_exit_l_r,  R.anim.dialog_enter_r_l, R.anim.dialog_exit_l_r)
+        }
+    }
 }

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

@@ -6,7 +6,6 @@ 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
@@ -16,7 +15,6 @@ import com.shanp.youqi.core.memory.AppManager
 import com.shanp.youqi.im.R
 import com.shanp.youqi.im.adapter.MessageListOnlyUserAdapter
 import com.shanp.youqi.im.databinding.ImFragmentMessageListOnlyUserBinding
-import com.shanp.youqi.im.dialog.ConversationDialog
 import com.shanp.youqi.im.dialog.MessageListDialog
 import io.rong.imlib.RongIMClient
 import io.rong.imlib.model.Conversation
@@ -46,7 +44,9 @@ class MessageListOnlyUserFragment : UChatFragment() {
 
     override fun initEventAndData(view: View) {
         binding = ImFragmentMessageListOnlyUserBinding.bind(view)
-
+        initTitleBar(view).apply {
+            titleView.textSize =  17f
+        }
         initRecyclerView()
         initListener()
         loadPrivateConversation()
@@ -101,19 +101,19 @@ class MessageListOnlyUserFragment : UChatFragment() {
                 it.unreadMessageCount = 0
                 adapter.notifyItemChanged(position, MessageListOnlyUserAdapter.REFRESH_UNREAD_COUNT)
                 clearMessagesUnreadStatus(it.conversationType, it.targetId)
-//                UChatConversationOnlyTextActivity.launch(mContext, it.targetId, it.senderUserName, it.portraitUrl)
-                val conversationDialog = ConversationDialog()
-                conversationDialog.targetId = it.targetId
-                conversationDialog.targetUserName = it.senderUserName
-                conversationDialog.targetHeadImg = it.portraitUrl
-                conversationDialog
-                        .setOnHiddenListener {
-                            messageListDialog.showHide(true)
-                        }
-                        .setOnShowListener {
-                            messageListDialog.showHide(false)
-                        }
-                        .show(childFragmentManager)
+                messageListDialog.addConversation(it.targetId,it.senderUserName,it.portraitUrl)
+//                val conversationDialog = ConversationDialog()
+//                conversationDialog.targetId = it.targetId
+//                conversationDialog.targetUserName = it.senderUserName
+//                conversationDialog.targetHeadImg = it.portraitUrl
+//                conversationDialog
+//                        .setOnHiddenListener {
+//                            messageListDialog.showHide(true)
+//                        }
+//                        .setOnShowListener {
+//                            messageListDialog.showHide(false)
+//                        }
+//                        .show(childFragmentManager)
             }
         }
     }

+ 19 - 6
uchat_im/src/main/java/com/shanp/youqi/im/fragment/UChatConversationOnlyTextFragment.kt

@@ -24,6 +24,7 @@ import com.shanp.youqi.im.R
 import com.shanp.youqi.im.adapter.ConversationOnlyTextAdapter
 import com.shanp.youqi.im.databinding.ImFragmentMessageListOnlyTextBinding
 import com.shanp.youqi.im.dialog.ConversationDialog
+import com.shanp.youqi.im.dialog.MessageListDialog
 import com.shanp.youqi.im.util.IMChatUtils
 import com.shanp.youqi.im.vo.ConversationItemVo
 import com.shanp.youqi.im.vo.MsgType
@@ -51,16 +52,19 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
 
     private var mOldestMessageId = -1   // 获取历史消息最老一条消息的 id
     private val word: String by lazy { AppManager.get().sensitiveWord }
+    private var isAddFragment = false
 
     private val adapter = ConversationOnlyTextAdapter(null)
     private val layoutManager: LinearLayoutManager by lazy { LinearLayoutManager(mContext, RecyclerView.VERTICAL, false) }
 
     fun setParam(targetId: String,
                  targetUserName: String,
-                 targetHeadImg: String) {
+                 targetHeadImg: String,
+                 isAddFragment: Boolean) {
         this.targetId = targetId
         this.targetName = targetUserName
         this.targetHeadImg = targetHeadImg
+        this.isAddFragment = isAddFragment
     }
 
     override fun getLayoutId(): Int = R.layout.im_fragment_message_list_only_text
@@ -69,9 +73,14 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
         binding = ImFragmentMessageListOnlyTextBinding.bind(view)
         initTitleBar(view)?.apply {
             setTitle(targetName)
+            titleView.textSize = 17f
             backView.setOnClickListener {
-                val dialog = parentFragment as ConversationDialog
-                dialog.back()
+                if (isAddFragment) {
+                    fragmentManager?.popBackStack()
+                } else {
+                    val dialog = parentFragment as ConversationDialog
+                    dialog.back()
+                }
             }
         }
         val mine = AppManager.get().userMine
@@ -86,8 +95,13 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
     private fun initListener() {
         binding.ivClose.setOnClickListener(object : ClickUtils.OnDebouncingClickListener() {
             override fun onDebouncingClick(v: View?) {
-                val dialog = parentFragment as ConversationDialog
-                dialog.close()
+                if (isAddFragment) {
+                    val dialog = parentFragment as MessageListDialog
+                    dialog.dismiss()
+                } else {
+                    val dialog = parentFragment as ConversationDialog
+                    dialog.close()
+                }
             }
         })
 
@@ -320,5 +334,4 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
         }
         super.onDestroyView()
     }
-
 }

+ 3 - 1
uchat_im/src/main/res/layout/im_fragment_message_list_only_text.xml

@@ -4,8 +4,9 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:gravity="bottom"
     android:background="@drawable/bg_white_radius_top_13"
+    android:clickable="true"
+    android:gravity="bottom"
     android:orientation="vertical">
 
     <RelativeLayout
@@ -46,6 +47,7 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="@color/color_F4F4F5"
+        android:clickable="true"
         android:orientation="vertical">
 
         <EditText