Jelajahi Sumber

玩游戏时可以聊天

admin 1 tahun lalu
induk
melakukan
3ab867aa9c

+ 38 - 33
room/src/main/java/com/swago/room/base/BaseComFragment.kt

@@ -322,12 +322,12 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
         }
     }
 
-    var listener = KeyboardUtils.OnSoftInputChangedListener {
-        if (it == 0) {
-            setChatRvPop(false, it)
-        } else {
-            setChatRvPop(true, it)
-        }
+    private var isPopUp = false
+    private var keyboardHeight = 0
+    private var listener = KeyboardUtils.OnSoftInputChangedListener {
+        isPopUp = it != 0
+        keyboardHeight = it
+        setChatRvPop()
     }
 
     private fun setHeaderViewPosition() {
@@ -638,37 +638,32 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
     }
 
 
-    private var keyboardUpRvLayoutParams: ViewGroup.LayoutParams? = null
-    private var keyboardCloseRvLayoutParams: ViewGroup.LayoutParams? = null
-    private fun setChatRvPop(isPopUp: Boolean, height: Int) {
-        if (isPopUp) {
-            if (keyboardUpRvLayoutParams == null) {
-                keyboardUpRvLayoutParams =
-                    ConstraintLayout.LayoutParams(0, DpPxUtil.dip2px(170f)).apply {
-                        bottomToBottom = R.id.cl
-                        startToStart = R.id.cl
-                        endToEnd = R.id.cl
-                        marginStart = DpPxUtil.dip2px(10f)
-                        marginEnd = DpPxUtil.dip2px(10f)
-                        bottomMargin = height + DpPxUtil.dip2px(55f)
-                    }
-            }
+    private val keyboardUpRvLayoutParams by lazy {
+        ConstraintLayout.LayoutParams(0, DpPxUtil.dip2px(170f)).apply {
+            bottomToBottom = R.id.cl
+            startToStart = R.id.cl
+            endToEnd = R.id.cl
+            marginStart = DpPxUtil.dip2px(10f)
+            marginEnd = DpPxUtil.dip2px(10f)
+            bottomMargin = DpPxUtil.dip2px(290f) + DpPxUtil.dip2px(55f)
+        }
+    }
+    private val keyboardCloseRvLayoutParams by lazy {
+        ConstraintLayout.LayoutParams(0, DpPxUtil.dip2px(170f)).apply {
+            bottomToBottom = R.id.cl
+            startToStart = R.id.cl
+            endToEnd = R.id.cl
+            marginStart = DpPxUtil.dip2px(10f)
+            marginEnd = DpPxUtil.dip2px(10f)
+            bottomMargin = DpPxUtil.dip2px(70f)
+        }
+    }
+    private fun setChatRvPop() {
+        if (isPopUp || gameIsOpen) {
             binding.rv.layoutParams = keyboardUpRvLayoutParams
         } else {
-            if (keyboardCloseRvLayoutParams == null) {
-                keyboardCloseRvLayoutParams =
-                    ConstraintLayout.LayoutParams(0, DpPxUtil.dip2px(170f)).apply {
-                        bottomToBottom = R.id.cl
-                        startToStart = R.id.cl
-                        endToEnd = R.id.cl
-                        marginStart = DpPxUtil.dip2px(10f)
-                        marginEnd = DpPxUtil.dip2px(10f)
-                        bottomMargin = DpPxUtil.dip2px(70f)
-                    }
-            }
             binding.rv.layoutParams = keyboardCloseRvLayoutParams
         }
-
     }
 
 
@@ -698,8 +693,10 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
         msgListDialog?.show(childFragmentManager, "MessageListDialog")
     }
 
+    private var gameIsOpen = false
     fun openGameDialog() {
         SwagoRoomManager.iRoomInfo?.let {
+            gameIsOpen = true
             val download = checkGameVersion(
                 it.getGameType().toString(),
                 it.getGameDownLoadUrl(),
@@ -711,7 +708,15 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
             } else {
                 gameDialog = GamePlayDialog.newInstance(it.getGameUrl(),it.getIsFullGame())
             }
+            gameDialog?.dialogDisFun = {
+                gameIsOpen = false
+                setChatRvPop()
+            }
+            gameDialog?.openMessageFun = {
+                openSendMessageDialog()
+            }
             gameDialog?.show(childFragmentManager, "GamePlayDialog")
+            setChatRvPop()
         }
     }
 

+ 14 - 19
room/src/main/java/com/swago/room/game/GamePlayDialog.kt

@@ -56,6 +56,8 @@ class GamePlayDialog : BaseXDFragment<DialogGamePlayBinding>(), IRoomActiveListe
 
     private var isFullScreen = false
 
+    var dialogDisFun: (() -> Unit)? = null
+    var openMessageFun:(()->Unit)? = null
     companion object {
         private const val URL = "url"
         private const val FULL_GAME = "fullGame"
@@ -88,11 +90,19 @@ class GamePlayDialog : BaseXDFragment<DialogGamePlayBinding>(), IRoomActiveListe
 
                 webView = WebView(activity)
 
+                val imageViewLayoutParams = ConstraintLayout.LayoutParams(DpPxUtil.dip2px(40f),DpPxUtil.dip2px(40f))
+                imageViewLayoutParams.bottomToBottom = R.id.cl
+                imageViewLayoutParams.startToStart = R.id.cl
+                imageViewLayoutParams.marginStart = DpPxUtil.dip2px(10f)
+                imageViewLayoutParams.bottomMargin = DpPxUtil.dip2px(310f)
                 val imageView = ImageView(activity)
-                imageView.setImageResource(R.mipmap.icon_game_close)
+                imageView.setBackgroundResource(R.drawable.shape_80000000_20)
+                imageView.setImageResource(R.mipmap.live_chat)
+                imageView.layoutParams = imageViewLayoutParams
+
                 imageView.setOnClickListener(object:NoDoubleClickListener(){
                     override fun onClick() {
-                        dismissAllowingStateLoss()
+                        openMessageFun?.invoke()
                     }
                 })
 
@@ -148,36 +158,20 @@ class GamePlayDialog : BaseXDFragment<DialogGamePlayBinding>(), IRoomActiveListe
                     params.width = DpPxUtil.getScreenWidth()
                     params.bottomToBottom = R.id.cl
 
-
-
                     if (isFullScreen){
                         params.height = DpPxUtil.getScreenHeight()
-                        val gameCloseParams = ConstraintLayout.LayoutParams(WRAP_CONTENT,WRAP_CONTENT)
-                        gameCloseParams.endToEnd = R.id.cl
-                        gameCloseParams.topToTop = R.id.cl
-                        gameCloseParams.marginEnd = DpPxUtil.dip2px(8f)
-                        gameCloseParams.topMargin = DpPxUtil.dip2px(45f)
-                        imageView.layoutParams = gameCloseParams
                     }else{
                         params.height = (params.width * 276 / 360f).toInt()
-
-                        val gameCloseParams = ConstraintLayout.LayoutParams(WRAP_CONTENT,WRAP_CONTENT)
-                        gameCloseParams.endToEnd = R.id.cl
-                        gameCloseParams.bottomToBottom = R.id.cl
-                        gameCloseParams.marginEnd = DpPxUtil.dip2px(8f)
-                        gameCloseParams.bottomMargin = params.height + DpPxUtil.dip2px(8f)
-                        imageView.layoutParams = gameCloseParams
                     }
                     this.layoutParams = params
                     binding.cl.addView(this)
-//                    binding.cl.addView(imageView)
+                    binding.cl.addView(imageView)
                 }
 
                 webView?.loadUrl(url)
             }
         }
 
-
         imGroupNewMsgListener.handleMsgType<CusNewMsgBean<GameData>>(
             ImConstant.fruit_game
         ) {
@@ -333,6 +327,7 @@ class GamePlayDialog : BaseXDFragment<DialogGamePlayBinding>(), IRoomActiveListe
         } catch (e: Exception) {
             e.printStackTrace()
         }
+        dialogDisFun?.invoke()
         super.onDestroyView()
     }