Browse Source

1.添加获取首页轮播图接口

王鹏鹏 2 năm trước cách đây
mục cha
commit
51a69d2bb3

+ 0 - 105
baselib/src/main/java/com/yingyangfly/baselib/utils/RxBusCodes.kt

@@ -2,82 +2,12 @@ package com.yingyangfly.baselib.utils
 
 object RxBusCodes {
 
-    //关闭webview页面
-    const val FINISHWEBVIEW = "finishWebview"
-
-    //播放语音
-    const val PLAYVOICE = "playVoice"
-
-    //获取数据监控
-    const val GetDataMonitor = 9001
-
-    //获取训练内容
-    const val GetTrainContent = 9002
-
     //结束答题
     const val EndMMSEQuestion = 9003
 
     //结束答题
     const val EndMOCAQuestion = 9004
 
-    //脑能力值
-    const val BrainAbility = 9008
-
-    //获取理疗报告
-    const val GetTrainReport = 9005
-
-    //购买成功
-    const val SuccessfulPurchase = "SuccessfulPurchase"
-
-    //评价医生
-    const val EVALUATE_ORDER = 9007
-
-    //退出游戏
-    const val CALLQUITGAME = "callQuitGame"
-
-    //退出游戏
-    const val QUITGAME = "quitGame"
-
-    /**
-     * 游戏计时
-     */
-    const val SETTIME = "setTime"
-
-    /**
-     * 游戏分数
-     */
-    const val SETSCORE = "setScore"
-
-    /**
-     * 游戏关卡
-     */
-    const val SETLEVEL = "setLevel"
-
-    /**
-     * 保存游戏进度
-     */
-    const val SAVEDATA = "saveData"
-
-    /**
-     * 游戏加载完成
-     */
-    const val LOADINGOVER = "loading:over"
-
-    /**
-     * 游戏超时退出
-     */
-    const val GAMEOVERTIME = "gameOvertime"
-
-    /**
-     * 结束游戏
-     */
-    const val FINISHGAME = "finishGame"
-
-    /**
-     * 游戏倒计时弹框消失
-     */
-    const val COUNTDOWNSUCCESS = "countdownSuccess"
-
     /**
      * 语音合成
      */
@@ -87,39 +17,4 @@ object RxBusCodes {
      * 结束语音播放
      */
     const val STOPVOICE = "stopVoice"
-
-    /**
-     * 开始播放音乐
-     */
-    const val STARTMUSIC = "startMusic"
-
-    /**
-     * 展示首页弹窗
-     */
-    const val SHOWTASKDIALOG = "showTaskDialog"
-
-    /**
-     * 退出登录
-     */
-    const val LOGINOUT = "LoginOut"
-
-    /**
-     * 医生开始接诊
-     */
-    const val doctorReception = 9006
-
-    /**
-     * 已预约直播
-     */
-    const val APPOINTMENTLIVE = "appointmentLive"
-
-    /**
-     * 购买问诊服务成功
-     */
-    const val purchaseConsultationEvent = 9009
-
-    /**
-     * IM被踢下线
-     */
-    const val ONKICKEDOFFLINE = "onKickedOffline"
 }

+ 74 - 0
evaluation/src/main/java/com/yingyangfly/evaluation/hospital/HospitalActivity.kt

@@ -8,6 +8,7 @@ import android.view.View
 import com.alibaba.android.arouter.facade.annotation.Route
 import com.yingyangfly.baselib.bean.def.PermissionList
 import com.yingyangfly.baselib.db.QuestionsBean
+import com.yingyangfly.baselib.db.VoicePlayerBean
 import com.yingyangfly.baselib.dialog.BindingPhoneDialog
 import com.yingyangfly.baselib.ext.check
 import com.yingyangfly.baselib.ext.getEndAnimation
@@ -15,8 +16,11 @@ import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.show
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.baselib.mvvm.BaseTvMVVMActivity
+import com.yingyangfly.baselib.player.VoicePlayer
 import com.yingyangfly.baselib.router.RouterUrlCommon
 import com.yingyangfly.baselib.utils.JumpUtil
+import com.yingyangfly.baselib.utils.LiveEventBusUtil
+import com.yingyangfly.baselib.utils.RxBusCodes
 import com.yingyangfly.baselib.utils.User
 import com.yingyangfly.evaluation.R
 import com.yingyangfly.evaluation.databinding.ActivityHospitalBinding
@@ -36,8 +40,14 @@ class HospitalActivity : BaseTvMVVMActivity<ActivityHospitalBinding, HospitalVie
     private var reviewTaskId = ""
     private var taskId = ""
 
+    /**
+     * 语音合成
+     */
+    private var voicePlayer: VoicePlayer? = null
+
     @SuppressLint("SetTextI18n")
     override fun initViews() {
+        voicePlayer = VoicePlayer.getInstance(mContext)
         initPermission()
         adapterGuide = GuidePageAdapter(imageList, mContext)
         binding.guide.addBannerLifecycleObserver(this)?.setAdapter(adapterGuide)?.indicator =
@@ -70,7 +80,71 @@ class HospitalActivity : BaseTvMVVMActivity<ActivityHospitalBinding, HospitalVie
     }
 
     override fun initData() {
+        initLiveData()
+    }
+
+    private fun initLiveData() {
+        //语音合成
+        LiveEventBusUtil.observer<String>(this, RxBusCodes.SPEECHSYNTHESIS) {
+            if (TextUtils.isEmpty(it).not()) {
+                speak(it)
+            }
+        }
+
+        //结束语音播放
+        LiveEventBusUtil.observer<String>(this, RxBusCodes.STOPVOICE) {
+            if (voicePlayer != null) {
+                if (voicePlayer!!.isPlaying) {
+                    voicePlayer?.stop()
+                }
+            }
+        }
+    }
 
+    /**
+     * 语音合成
+     */
+    private fun speak(desn: String) {
+        if (db != null) {
+            val voicePlayerDao = db?.getVoicePlayerDao()
+            if (voicePlayerDao != null) {
+                val voicePlayerBean = voicePlayerDao.getVoicePlayerBean(desn)
+                if (voicePlayerBean != null) {
+                    if (voicePlayer != null) {
+                        voicePlayer?.play(voicePlayerBean.url) {}
+                    }
+                } else {
+                    getVoiceUrl(desn)
+                }
+            } else {
+                getVoiceUrl(desn)
+            }
+        } else {
+            getVoiceUrl(desn)
+        }
+    }
+
+    /**
+     * 获取声音url
+     */
+    private fun getVoiceUrl(taskDesn: String) {
+        viewModel.getVoiceUrl(taskDesn, fail = {}, success = {
+            if (TextUtils.isEmpty(it).not()) {
+                if (db != null) {
+                    val voicePlayerDao = db?.getVoicePlayerDao()
+                    if (voicePlayerDao != null) {
+                        val voicePlayerBean = VoicePlayerBean().apply {
+                            url = it
+                            words = taskDesn
+                        }
+                        voicePlayerDao.insert(voicePlayerBean)
+                    }
+                }
+                if (voicePlayer != null) {
+                    voicePlayer?.play(it) {}
+                }
+            }
+        })
     }
 
     @SuppressLint("ClickableViewAccessibility")

+ 14 - 0
evaluation/src/main/java/com/yingyangfly/evaluation/hospital/HospitalViewModel.kt

@@ -83,4 +83,18 @@ class HospitalViewModel : BaseViewModel() {
     }.runUI(
         success, fail
     )
+
+    /**
+     * 获取声音url
+     */
+    fun getVoiceUrl(
+        msg: String,
+        fail: ((msg: String) -> Unit)? = null,
+        success: ((success: String?) -> Unit)? = null,
+    ) = launchFlow(false) {
+        EVALUATION_API.getVoiceUrl(msg)
+    }.runUI(
+        success,
+        fail
+    )
 }

+ 8 - 0
evaluation/src/main/java/com/yingyangfly/evaluation/net/EvaluationApiService.kt

@@ -91,4 +91,12 @@ interface EvaluationApiService {
      */
     @POST("questionRecord/selectAnswerRecordDetail")
     suspend fun selectAnswerRecordDetail(@Body requestBody: RequestBody): BaseResp<SelectAnswerRecordDetailBean>
+
+    /**
+     * 获取声音url
+     */
+    @POST("app/video/getVoiceUrl")
+    suspend fun getVoiceUrl(
+        @Query("voiceMsg") voiceMsg: String
+    ): BaseResp<String>
 }