ソースを参照

1、优化聊天弹窗交互效果;

yzs 4 年 前
コミット
3caf6c5c69

+ 2 - 1
uchat_common/src/main/res/anim/dialog_enter_r_l.xml

@@ -1,7 +1,8 @@
 <?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="100%p"
         android:toXDelta="0" />
+
 </set>

+ 7 - 6
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.dialogstyle)
+        setAnimStyle(R.style.dialog_style_left_right)
         setGravity(DialogGravity.BOTTOM)
         setDimAmount(0.0f)
         setWidthFull(true)
@@ -71,9 +71,6 @@ class ConversationDialog : BaseDialogFragment() {
             this.dismiss()
             return
         }
-        holder.setOnClickListener(R.id.rl_layout) {
-            this.dismiss()
-        }
         upHeight = AutoSizeUtils.dp2px(mContext, 317.5f)
         downHeight = AutoSizeUtils.dp2px(mContext, 402f)
         currentHeight = downHeight
@@ -85,14 +82,14 @@ class ConversationDialog : BaseDialogFragment() {
                 if (height > 0) {
                     if (currentHeight != upHeight) {
                         currentHeight = upHeight
-                        ViewHideShowUtils.performAnim(flContainer, downHeight, upHeight, 430) {
+                        ViewHideShowUtils.performAnim(flContainer, downHeight, upHeight, 300) {
                             fragment?.rcvToBottom()
                         }
                     }
                 } else {
                     if (currentHeight != downHeight) {
                         currentHeight = downHeight
-                        ViewHideShowUtils.performAnim(flContainer, upHeight, downHeight, 430) {
+                        ViewHideShowUtils.performAnim(flContainer, upHeight, downHeight, 300) {
                             fragment?.rcvToBottom()
                         }
                     }
@@ -103,6 +100,10 @@ class ConversationDialog : BaseDialogFragment() {
 
     override fun getLayoutId(): Int = R.layout.im_dialog_conversation_layout
 
+    fun back() {
+        this.dismiss()
+    }
+
     fun close() {
         if (parentFragment != null) {
             val messageListFragment = parentFragment as MessageListOnlyUserFragment

+ 25 - 29
uchat_im/src/main/java/com/shanp/youqi/im/fragment/UChatConversationOnlyTextFragment.kt

@@ -2,6 +2,7 @@ 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
@@ -10,6 +11,7 @@ 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
@@ -68,16 +70,8 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
         initTitleBar(view)?.apply {
             setTitle(targetName)
             backView.setOnClickListener {
-                if (activity != null) {
-                    if (KeyboardUtils.isSoftInputVisible(activity!!)) {
-                        KeyboardUtils.hideSoftInput(binding.etContent)
-                        return@setOnClickListener
-                    }
-                }
-
                 val dialog = parentFragment as ConversationDialog
-                dialog.dismiss()
-
+                dialog.back()
             }
         }
         val mine = AppManager.get().userMine
@@ -146,7 +140,7 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
             }
         })
 
-        //底部布局弹出,聊天列表上滑
+//        //底部布局弹出,聊天列表上滑
 //        binding.rcv.addOnLayoutChangeListener { _, _, _, _, bottom, _, _, _, oldBottom ->
 //            if (bottom < oldBottom) {
 //                binding.rcv.post {
@@ -157,24 +151,24 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
 //            }
 //        }
 
-//        TouchUtils.setOnTouchListener(binding.rcv, object : TouchUtils.OnTouchUtilsListener() {
-//            override fun onDown(view: View?, x: Int, y: Int, event: MotionEvent?): Boolean {
-//                return if (KeyboardUtils.isSoftInputVisible(mContext)) {
-//                    KeyboardUtils.hideSoftInput(binding.etContent)
-//                    true
-//                } else {
-//                    false
-//                }
-//            }
-//
-//            override fun onMove(view: View?, direction: Int, x: Int, y: Int, dx: Int, dy: Int, totalX: Int, totalY: Int, event: MotionEvent?): Boolean {
-//                return false
-//            }
-//
-//            override fun onStop(view: View?, direction: Int, x: Int, y: Int, totalX: Int, totalY: Int, vx: Int, vy: Int, event: MotionEvent?): Boolean {
-//                return false
-//            }
-//        })
+        TouchUtils.setOnTouchListener(binding.rcv, object : TouchUtils.OnTouchUtilsListener() {
+            override fun onDown(view: View?, x: Int, y: Int, event: MotionEvent?): Boolean {
+                return if (KeyboardUtils.isSoftInputVisible(mContext)) {
+                    KeyboardUtils.hideSoftInput(binding.etContent)
+                    true
+                } else {
+                    false
+                }
+            }
+
+            override fun onMove(view: View?, direction: Int, x: Int, y: Int, dx: Int, dy: Int, totalX: Int, totalY: Int, event: MotionEvent?): Boolean {
+                return false
+            }
+
+            override fun onStop(view: View?, direction: Int, x: Int, y: Int, totalX: Int, totalY: Int, vx: Int, vy: Int, event: MotionEvent?): Boolean {
+                return false
+            }
+        })
     }
 
     private fun initRecyclerView() {
@@ -311,7 +305,9 @@ class UChatConversationOnlyTextFragment : UChatFragment() {
 
     fun rcvToBottom() {
         if (adapter.itemCount > 0) {
-//            binding.rcv.smoothScrollToPosition(adapter.data.lastIndex)
+            binding.rcv.postDelayed({
+                binding.rcv?.smoothScrollToPosition(adapter.data.lastIndex)
+            }, 100)
 //            binding.rcv.scrollToPosition(adapter.data.lastIndex)
         }
     }

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

@@ -4,6 +4,7 @@
     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:orientation="vertical">