Browse Source

1.优化查看理疗报告打不开bug

王鹏鹏 2 years ago
parent
commit
19fed05772

+ 5 - 89
webview/src/main/java/com/yingyangfly/webview/BridgeWebActivity.kt

@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
 import android.content.pm.ActivityInfo
 import android.os.Build
 import android.os.Bundle
-import android.text.TextUtils
 import android.view.ViewGroup
 import android.webkit.WebResourceRequest
 import android.webkit.WebSettings
@@ -15,19 +14,10 @@ import androidx.databinding.DataBindingUtil
 import com.alibaba.android.arouter.facade.annotation.Route
 import com.gyf.immersionbar.BarHide
 import com.gyf.immersionbar.ktx.immersionBar
-import com.yingyangfly.baselib.db.AppDataBase
-import com.yingyangfly.baselib.db.VoicePlayerBean
-import com.yingyangfly.baselib.db.VoicePlayerDao
-import com.yingyangfly.baselib.ext.toast
-import com.yingyangfly.baselib.net.BaseObserver
-import com.yingyangfly.baselib.net.MyRxScheduler
-import com.yingyangfly.baselib.player.VoicePlayer
+import com.yingyangfly.baselib.ext.click
 import com.yingyangfly.baselib.router.RouterUrlCommon
-import com.yingyangfly.baselib.utils.LiveEventBusUtil
-import com.yingyangfly.baselib.utils.RxBusCodes
+import com.yingyangfly.baselib.utils.ViewTool
 import com.yingyangfly.webview.databinding.ActivityBridgeWebBinding
-import com.yingyangfly.webview.net.WebViewServiceFactory
-import io.reactivex.schedulers.Schedulers
 
 /**
  * BridgeWebview
@@ -38,24 +28,16 @@ class BridgeWebActivity : AppCompatActivity() {
     private lateinit var binding: ActivityBridgeWebBinding
     private lateinit var webSettings: WebSettings
     private var url: String = ""
-    private var db: AppDataBase? = null
-    private var dao: VoicePlayerDao? = null
-    private var voicePlayer: VoicePlayer? = null
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         immersionBar {
             hideBar(BarHide.FLAG_HIDE_BAR)
-            navigationBarColor(com.yingyangfly.baselib.R.color.transparent)
+            navigationBarColor(R.color.transparent)
         }
-        db = AppDataBase.getInstance(this.applicationContext)
-        if (db != null) {
-            dao = db?.getVoicePlayerDao()
-        }
-        voicePlayer = VoicePlayer.getInstance(this)
         url = intent.getStringExtra("url") ?: ""
         binding = DataBindingUtil.setContentView(this, R.layout.activity_bridge_web)
-        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+        ViewTool.inflateLayoutPixels(this, binding.root, 1194, 834)
         initWebView()
         initView()
     }
@@ -118,72 +100,13 @@ class BridgeWebActivity : AppCompatActivity() {
     }
 
     private fun initView() {
-        //结束页面
-        LiveEventBusUtil.observer<String>(this, RxBusCodes.FINISHWEBVIEW) {
+        binding.layoutHead.click {
             finish()
         }
-        //播放语音
-        LiveEventBusUtil.observer<String>(this, RxBusCodes.PLAYVOICE) {
-            if (it.isNullOrEmpty().not()) {
-                val msg = it.split("voice:")
-                if (msg.isNullOrEmpty().not()) {
-                    if (msg[1].isNullOrEmpty().not()) {
-                        if (dao != null) {
-                            val voicePlayerBean = dao?.getVoicePlayerBean(msg[1])
-                            if (voicePlayerBean != null && TextUtils.isEmpty(voicePlayerBean.url)
-                                    .not()
-                            ) {
-                                voicePlayer?.play(voicePlayerBean.url) {
-
-                                }
-                            } else {
-                                getWordsUrl(msg[1])
-                            }
-                        }
-                    }
-                }
-            }
-
-        }
-    }
-
-    /**
-     * 获取声音 url
-     */
-    private fun getWordsUrl(word: String) {
-        WebViewServiceFactory.getService()
-            .getVoiceUrl(word)
-            .subscribeOn(Schedulers.io())
-            .compose(MyRxScheduler.ioMain(this, false))
-            .subscribe(object : BaseObserver<String>() {
-                override fun onSuccess(t: String?) {
-                    t?.let {
-                        if (dao != null) {
-                            val voicePlayerBean = VoicePlayerBean().apply {
-                                words = word
-                                url = it
-                            }
-                            dao?.insert(voicePlayerBean)
-                        }
-                        voicePlayer?.play(it) {
-
-                        }
-                    }
-                }
-
-                override fun onFail(msg: String) {
-                    msg.toast()
-                }
-            })
     }
 
     override fun onDestroy() {
         destoryWebView()
-        if (voicePlayer != null) {
-            if (voicePlayer!!.isPlaying) {
-                voicePlayer?.stop()
-            }
-        }
         super.onDestroy()
     }
 
@@ -210,11 +133,4 @@ class BridgeWebActivity : AppCompatActivity() {
         }
         super.onResume()
     }
-
-//    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
-//        if (keyCode == KeyEvent.KEYCODE_BACK) {
-//            return true;
-//        }
-//        return false
-//    }
 }

+ 15 - 9
webview/src/main/res/layout/activity_bridge_web.xml

@@ -1,10 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <layout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     tools:ignore="ResourceName">
 
-    <androidx.constraintlayout.widget.ConstraintLayout
+    <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent">
 
@@ -12,13 +11,20 @@
         <com.github.lzyzsd.jsbridge.BridgeWebView
             android:id="@+id/webView"
             android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:background="@android:color/white"
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintTop_toTopOf="parent" />
+            android:layout_height="match_parent" />
 
-    </androidx.constraintlayout.widget.ConstraintLayout>
+        <LinearLayout
+            android:id="@+id/layoutHead"
+            style="@style/back_layout"
+            tools:ignore="MissingConstraints">
+
+            <androidx.appcompat.widget.AppCompatImageView style="@style/back_image" />
+
+            <androidx.appcompat.widget.AppCompatTextView
+                style="@style/back_text"
+                android:textColor="@color/color_FF333333" />
+        </LinearLayout>
+
+    </FrameLayout>
 
 </layout>

+ 1 - 1
workbenches/src/main/java/com/yingyang/workbenches/trainreport/TrainReportFragment.kt

@@ -40,7 +40,7 @@ class TrainReportFragment : BaseMVVMFragment<FragmentTrainReportBinding, TrainRe
                 val trainingDailyUrl = url +
                         "?userId=" + User.getUserId() + "&time=" + it + "&userToken=" + User.getToken()
                 JumpUtil.jumpActivityWithUrl(
-                    RouterUrlCommon.load_web_view,
+                    RouterUrlCommon.WEB_VIEW_INTERACTION_JS,
                     trainingDailyUrl,
                     mContext
                 )