瀏覽代碼

feat: 转盘webview setting

tongmengxiao 3 月之前
父節點
當前提交
13499c7ea3

+ 25 - 4
baseswago/src/main/java/com/swago/baseswago/dialog/TodayTrafficDialog.kt

@@ -1,10 +1,12 @@
 package com.swago.baseswago.dialog
 
 import android.content.Intent
+import android.graphics.Color
 import android.os.Bundle
 import android.view.Gravity
 import android.view.View
 import android.view.View.OnClickListener
+import android.webkit.JavascriptInterface
 import android.webkit.WebViewClient
 import com.alibaba.android.arouter.launcher.ARouter
 import com.swago.baseswago.constant.ARouteConstant
@@ -16,7 +18,9 @@ import com.swago.baseswago.util.SpUtil
 import com.swago.baseswago.util.UserInfo
 
 class TodayTrafficDialog : BaseXDFragment<DialogTodayTrafficBinding>() {
-
+    private val jsLoad by lazy {
+        JSLoad()
+    }
     init {
         setGravity(Gravity.CENTER)
         setDimAmount(0.5f)
@@ -33,12 +37,29 @@ class TodayTrafficDialog : BaseXDFragment<DialogTodayTrafficBinding>() {
     }
 
     override fun initOther() {
-        binding.webview.settings.javaScriptEnabled = true
-        binding.webview.webViewClient = WebViewClient()
-        binding.webview.loadUrl("https://www.baidu.com")
+        binding.webview.apply {
+            settings.javaScriptEnabled = true
+            addJavascriptInterface(jsLoad, "jsLoad")
+            settings.allowFileAccess = true
+            settings.useWideViewPort = true
+            settings.loadWithOverviewMode = true
+            settings.javaScriptCanOpenWindowsAutomatically = true//设置允许JS弹窗
+            settings.domStorageEnabled = true
+            isHorizontalScrollBarEnabled = true
+            isVerticalScrollBarEnabled = true
+            setBackgroundColor(Color.TRANSPARENT)
+            webViewClient = WebViewClient()
+            loadUrl("https://www.baidu.com")
+        }
     }
 
     override fun initLiveData() {
 
     }
+    inner class JSLoad {
+        @JavascriptInterface
+        fun closeDialog() {
+            dismissAllowingStateLoss()
+        }
+    }
 }

+ 7 - 0
room/src/main/java/com/swago/room/reward/RewardView.kt

@@ -30,6 +30,7 @@ class RewardView : FrameLayout, IRoomActiveListener, RoomTimer.TimeTickListener
     private var coins: Int = 0
     private var nextCoins: Int = 0
     private var nextTime: Int = 0
+    private var showChangeRoom = false
     private var rewardsModel: OnlineRewardsModel? = null
     private var scaleXAnimator: ObjectAnimator? = null
     private var scaleYAnimator: ObjectAnimator? = null
@@ -94,6 +95,9 @@ class RewardView : FrameLayout, IRoomActiveListener, RoomTimer.TimeTickListener
     }
 
     override fun joinedRoom(iRoomInfo: IRoomInfo) {
+        if (showChangeRoom){
+            visibility = View.VISIBLE
+        }
     }
 
     override fun endRoom(iRoomInfo: IRoomInfo?) {
@@ -119,6 +123,7 @@ class RewardView : FrameLayout, IRoomActiveListener, RoomTimer.TimeTickListener
     }
 
     fun checkOnlineTime(model: OnlineRewardsModel?) {
+        showChangeRoom = true
         if (model == null) {
             rewardsModel = null
             binding?.tvTime?.setBackgroundResource(R.mipmap.bg_get_reward)
@@ -166,6 +171,7 @@ class RewardView : FrameLayout, IRoomActiveListener, RoomTimer.TimeTickListener
                     totalTime = totalTime.coerceAtLeast(1800)
                     rewardsModel?.thirty = true
                     visibility = View.GONE
+                    showChangeRoom = false
                 }
             }
         }
@@ -232,6 +238,7 @@ class RewardView : FrameLayout, IRoomActiveListener, RoomTimer.TimeTickListener
                 }
             } else {
                 visibility =View.GONE
+                showChangeRoom = false
             }
 
         }

+ 1 - 0
room/src/main/res/layout/view_rewards.xml

@@ -3,6 +3,7 @@
     android:layout_width="52dp"
     android:layout_height="52dp"
     android:id="@+id/clReward"
+    android:layout_marginEnd="2dp"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools">