|
|
@@ -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
|
|
|
-// }
|
|
|
}
|