Bladeren bron

修改游戏半屏的功能

Gogs 1 maand geleden
bovenliggende
commit
20d918d9df

+ 9 - 13
baselibrary/src/main/java/com/yc/baselibrary/view/webview/RoomWebViewClient.java

@@ -45,22 +45,18 @@ public class RoomWebViewClient extends WebViewClient {
                 mTouristCallBack.showTourist();
                 return true;
             }
-//            Intent intent = WebUtil.url2Intent(url, context);
-//            if (intent == null) {
-//                return startNew(view, url);
-//            } else {
-//                context.startActivity(intent);
-//                return true;
-//            }
+            return startNew(view, url);
         }
-        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
-        if (intent.resolveActivity(context.getPackageManager()) == null) {
-            //要跳转的第三方app不存在
-
-        } else {
+        try {
+            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+            if (intent.resolveActivity(context.getPackageManager()) == null) {
+                return startNew(view, url);
+            }
             context.startActivity(intent);
+            return true;
+        } catch (Exception e) {
+            return startNew(view, url);
         }
-        return true;
     }
 
     @Override

+ 24 - 3
module_live/src/main/java/com/yc/module_live/view/dialog/RoomGameBottomDialog.kt

@@ -1,6 +1,7 @@
 package com.yc.module_live.view.dialog
 
 import android.annotation.SuppressLint
+import android.net.Uri
 import androidx.fragment.app.FragmentActivity
 import com.hunliji.hlj_dialog.xpopup.core.BottomPopupView
 import com.xueyu.kotlinextlibrary.deviceHeight
@@ -13,6 +14,7 @@ import com.yc.baselibrary.net.exception.checkError
 import com.yc.baselibrary.view.webview.JsInjection
 import com.yc.baselibrary.view.webview.RoomWebViewClient
 import com.yc.baselibrary.view.webview.WebUtil
+import com.yc.module_base.LiveSession
 import com.yc.module_live.R
 import kotlinx.android.synthetic.main.module_room_game_dialog.view.webView
 
@@ -42,9 +44,28 @@ class RoomGameBottomDialog(
             retrofit.getH5Token().checkError()
         }) {
             success {
-                val gameUrl = url + "?token=${it}&width=${deviceWidth}&height=${deviceHeight * 2 / 3}"
-                startGame(gameUrl)
+                val rawUrl = url?.trim()?.trim('`')?.trim().orEmpty()
+                if (rawUrl.isEmpty()) {
+                    dismiss()
+                    return@success
+                }
+                val normalizedUrl = if (rawUrl.startsWith("http://") || rawUrl.startsWith("https://")) {
+                    rawUrl
+                } else {
+                    "https://$rawUrl"
+                }
+                val uri = Uri.parse(normalizedUrl)
+                val builder = uri.buildUpon()
 
+                val gtoken = LiveSession.getUserToken()
+                builder.appendQueryParameter("gtoken", gtoken)
+                if (uri.getQueryParameter("token").isNullOrEmpty()) {
+                    builder.appendQueryParameter("token", it)
+                }
+                builder.appendQueryParameter("width", deviceWidth.toString())
+                builder.appendQueryParameter("height", (deviceHeight * 2 / 3).toString())
+                val gameUrl = builder.build().toString()
+                startGame(gameUrl)
             }
 
         }
@@ -65,4 +86,4 @@ class RoomGameBottomDialog(
         webView.loadUrl("about:blank")// 清空当前加载
     }
 
-}
+}

+ 41 - 24
module_live/src/main/java/com/yc/module_live/view/live/livepopup/TopLivePopupFragment.kt

@@ -3,6 +3,7 @@ package com.yc.module_live.view.live.livepopup
 //import com.yc.module_live.view.live.beauty.BeautyViewDialog
 import android.content.Intent
 import android.net.Uri
+import android.util.Log
 import android.view.View
 import android.view.ViewGroup
 import com.hunliji.hlj_dialog.showDialogBottom
@@ -324,33 +325,49 @@ abstract class TopLivePopupFragment<T : BaseRoomVm> : TopLiveBaseFragment<T>(),
     }
 
     fun openGameWebView(game: Game) {
-        when (game.openType) {
-            GameOpenType.APP_H5.type -> {
-                launchActivity<WebViewActivity> {
-                    putExtra(WebViewVm.H5_URL, game.url)
-                    putExtra(WebViewVm.H5_TITLE, game.name)
-                }
-            }
 
-            GameOpenType.BROWSER.type -> {
-                val intent = Intent(Intent.ACTION_VIEW, Uri.parse(game.url))
-                startActivity(intent)
-            }
+        val token = LiveSession.getUserToken()
+        val baseUrl = game.url?.trim()?.trim('`')?.trim() ?: return
+        val gameUrl = Uri.parse(baseUrl).buildUpon()
+            .appendQueryParameter("gtoken", token)
+            .build()
+            .toString()
+        Log.d("openType", "openType=${game.openType}")
+        Log.d("openGameWebView", "openGameWebView: $gameUrl")
 
-            GameOpenType.APP_ALL.type -> {
-                launchActivity<WebViewJsActivity> {
-                    putExtra(WebViewVm.H5_URL, game.url)
-                    putExtra(WebViewVm.H5_TITLE, game.name)
-                }
-            }
+        val roomGameBottomDialog = RoomGameBottomDialog(requireActivity(), game.url)
+        requireContext().showDialogBottom(roomGameBottomDialog, init = {
+            showBehind(false)
+        })
 
-            GameOpenType.APP_HALF.type -> {
-                val roomGameBottomDialog = RoomGameBottomDialog(requireActivity(), game.url)
-                requireContext().showDialogBottom(roomGameBottomDialog, init = {
-                    showBehind(false)
-                })
-            }
-        }
+
+        // when (game.openType) {
+        //     GameOpenType.APP_H5.type -> {
+        //         launchActivity<WebViewActivity> {
+        //             putExtra(WebViewVm.H5_URL, game.url)
+        //             putExtra(WebViewVm.H5_TITLE, game.name)
+        //         }
+        //     }
+
+        //     GameOpenType.BROWSER.type -> {
+        //         val intent = Intent(Intent.ACTION_VIEW, Uri.parse(game.url))
+        //         startActivity(intent)
+        //     }
+
+        //     GameOpenType.APP_ALL.type -> {
+        //         launchActivity<WebViewJsActivity> {
+        //             putExtra(WebViewVm.H5_URL, game.url)
+        //             putExtra(WebViewVm.H5_TITLE, game.name)
+        //         }
+        //     }
+
+        //     GameOpenType.APP_HALF.type -> {
+        //         val roomGameBottomDialog = RoomGameBottomDialog(requireActivity(), game.url)
+        //         requireContext().showDialogBottom(roomGameBottomDialog, init = {
+        //             showBehind(false)
+        //         })
+        //     }
+        // }
     }
 
     //用户列表