瀏覽代碼

1.添加语音播报功能

王鹏鹏 2 年之前
父節點
當前提交
a6bd142f9d

+ 13 - 0
baselib/src/main/java/com/yingyangfly/baselib/dialog/TaskFragment.kt

@@ -15,6 +15,7 @@ import com.gyf.immersionbar.ktx.immersionBar
 import com.yingyangfly.baselib.R
 import com.yingyangfly.baselib.ext.setOnSingleClickListener
 import com.yingyangfly.baselib.utils.ViewTool
+import com.yingyangfly.baselib.voice.PlayVoice
 
 /**
  * 任务提醒
@@ -27,6 +28,8 @@ class TaskFragment : DialogFragment(), View.OnTouchListener {
     private var confirmBtan: AppCompatButton? = null
     private var animationDrawable: AnimationDrawable? = null
     private var id = ""
+    private var playVoice: PlayVoice? = null
+
     var onDialogClickListener: ((bean: String) -> Unit)? = null
 
     fun setTaskDesn(taskDesn: String, id: String) {
@@ -61,6 +64,8 @@ class TaskFragment : DialogFragment(), View.OnTouchListener {
         val rootView = ViewTool.inflateFragmentPixels(
             activity, R.layout.fragment_task, container, 1194, 834
         )
+        playVoice = PlayVoice()
+        playVoice?.setContext(requireActivity())
         findId(rootView)
         init()
         return rootView
@@ -87,6 +92,7 @@ class TaskFragment : DialogFragment(), View.OnTouchListener {
         animationDrawable = fishImage?.drawable as AnimationDrawable?
         animationDrawable?.start()
         tvContent?.text = taskDesn
+        playVoice?.speak(taskDesn)
     }
 
     override fun onTouch(v: View?, event: MotionEvent?): Boolean {
@@ -96,4 +102,11 @@ class TaskFragment : DialogFragment(), View.OnTouchListener {
         }
         return false
     }
+
+    override fun dismiss() {
+        if (playVoice != null) {
+            playVoice?.stop()
+        }
+        super.dismiss()
+    }
 }

+ 7 - 1
home/src/main/java/com/yingyangfly/home/activity/HomeActivity.kt

@@ -171,7 +171,6 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>() {
         getCountTrain()
         //获取未读消息数量
         getCountMyMsg()
-
     }
 
     /**
@@ -509,4 +508,11 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>() {
         guide.show(this)
     }
 
+    override fun onDestroy() {
+        if (playVoice != null) {
+            playVoice?.stop()
+        }
+        super.onDestroy()
+    }
+
 }

+ 1 - 1
home/src/main/java/com/yingyangfly/home/activity/HomeViewModel.kt

@@ -73,7 +73,7 @@ class HomeViewModel : BaseViewModel() {
         versionCode: Int,
         fail: ((msg: String) -> Unit)? = null,
         success: ((success: UpdateBean?) -> Unit)? = null,
-    ) = launchFlow(true) {
+    ) = launchFlow(false) {
         HOME_API.selectNewVersion(versionCode)
     }.runUI(
         success,