浏览代码

1.优化语音合成数据库内容加载功能

王鹏鹏 1 年之前
父节点
当前提交
7e2e4d1069

+ 7 - 0
baselib/src/main/java/com/yingyangfly/baselib/base/BaseActivity.kt

@@ -29,6 +29,7 @@ import com.yingyangfly.baselib.db.AppDataBase
 import com.yingyangfly.baselib.db.DoctorDao
 import com.yingyangfly.baselib.db.GameSoundDao
 import com.yingyangfly.baselib.db.QuestionsDao
+import com.yingyangfly.baselib.db.VoicePlayerDao
 import com.yingyangfly.baselib.dialog.LoadingDialog
 import com.yingyangfly.baselib.dialog.MessageDialog
 import com.yingyangfly.baselib.dialog.TaskFragment
@@ -91,6 +92,11 @@ abstract class BaseActivity<DB : ViewDataBinding> : AppCompatActivity(), OnRefre
      */
     var gameSoundDao: GameSoundDao? = null
 
+    /**
+     * 语音合成
+     */
+    var voicePlayerDao: VoicePlayerDao? = null
+
     @SuppressLint("SourceLockedOrientationActivity")
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -114,6 +120,7 @@ abstract class BaseActivity<DB : ViewDataBinding> : AppCompatActivity(), OnRefre
             questionsDao = db?.getQuestionsDao()
             doctorDao = db?.getDoctorsDao()
             gameSoundDao = db?.getGameSoundDao()
+            voicePlayerDao = db?.getVoicePlayerDao()
         }
         initProducer()
         initMVVM()

+ 10 - 18
game/src/main/java/com/yingyangfly/game/introduction/GameIntroductionActivity.kt

@@ -292,18 +292,13 @@ class GameIntroductionActivity :
      * 语音合成
      */
     private fun speak() {
-        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) {
+        if (voicePlayerDao != null) {
+            val voicePlayerBean = voicePlayerDao?.getVoicePlayerBean(desn)
+            if (voicePlayerBean != null) {
+                if (voicePlayer != null) {
+                    voicePlayer?.play(voicePlayerBean.url) {
 
-                        }
                     }
-                } else {
-                    getVoiceUrl(desn)
                 }
             } else {
                 getVoiceUrl(desn)
@@ -319,15 +314,12 @@ class GameIntroductionActivity :
     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 (voicePlayerDao != null) {
+                    val voicePlayerBean = VoicePlayerBean().apply {
+                        url = it
+                        words = taskDesn
                     }
+                    voicePlayerDao?.insert(voicePlayerBean)
                 }
                 if (voicePlayer != null) {
                     if (isTopActivity(this)) {

+ 13 - 21
game/src/main/java/com/yingyangfly/game/play/PlayGameActivity.kt

@@ -572,21 +572,16 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
      * 语音合成
      */
     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) {
-                        if (isTopActivity(this)) {
-                            voicePlayer?.play(voicePlayerBean.url) {
-                                binding.tvIntroduce.text = gameShortDesn
-                                callPlayBgMusic()
-                            }
+        if (voicePlayerDao != null) {
+            val voicePlayerBean = voicePlayerDao?.getVoicePlayerBean(desn)
+            if (voicePlayerBean != null) {
+                if (voicePlayer != null) {
+                    if (isTopActivity(this)) {
+                        voicePlayer?.play(voicePlayerBean.url) {
+                            binding.tvIntroduce.text = gameShortDesn
+                            callPlayBgMusic()
                         }
                     }
-                } else {
-                    getVoiceUrl(desn)
                 }
             } else {
                 getVoiceUrl(desn)
@@ -603,15 +598,12 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
     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 (voicePlayerDao != null) {
+                    val voicePlayerBean = VoicePlayerBean().apply {
+                        url = it
+                        words = taskDesn
                     }
+                    voicePlayerDao?.insert(voicePlayerBean)
                 }
                 if (voicePlayer != null) {
                     if (isTopActivity(this)) {

+ 11 - 21
home/src/main/java/com/yingyangfly/home/activity/HomeActivity.kt

@@ -12,14 +12,12 @@ import com.alibaba.android.arouter.launcher.ARouter
 import com.bumptech.glide.Glide
 import com.tencent.imsdk.v2.*
 import com.tencent.qcloud.tuikit.tuichat.bean.message.PatientStartConsultationBean
-import com.yingyang.home.BuildConfig
 import com.yingyang.home.R
 import com.yingyang.home.databinding.ActivityHomeBinding
 import com.yingyangfly.baselib.bean.MessageBean
 import com.yingyangfly.baselib.bean.PurchaseConsultationEvent
 import com.yingyangfly.baselib.bean.Record
 import com.yingyangfly.baselib.db.VoicePlayerBean
-import com.yingyangfly.baselib.dialog.MessageDialog
 import com.yingyangfly.baselib.dialog.TipsDialog
 import com.yingyangfly.baselib.ext.getEndAnimation
 import com.yingyangfly.baselib.ext.getScaleAnimation
@@ -594,18 +592,13 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(), Vie
      * 语音合成
      */
     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) {
-                            LiveEventBusUtil.send(RxBusCodes.STARTMUSIC, "")
-                        }
+        if (voicePlayerDao != null) {
+            val voicePlayerBean = voicePlayerDao?.getVoicePlayerBean(desn)
+            if (voicePlayerBean != null) {
+                if (voicePlayer != null) {
+                    voicePlayer?.play(voicePlayerBean.url) {
+                        LiveEventBusUtil.send(RxBusCodes.STARTMUSIC, "")
                     }
-                } else {
-                    getVoiceUrl(desn)
                 }
             } else {
                 getVoiceUrl(desn)
@@ -621,15 +614,12 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(), Vie
     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 (voicePlayerDao != null) {
+                    val voicePlayerBean = VoicePlayerBean().apply {
+                        url = it
+                        words = taskDesn
                     }
+                    voicePlayerDao?.insert(voicePlayerBean)
                 }
                 if (voicePlayer != null) {
                     voicePlayer?.play(it) {

+ 3 - 4
home/src/main/java/com/yingyangfly/home/evaluation/EvaluationActivity.kt

@@ -44,9 +44,8 @@ class EvaluationActivity : BaseMVVMActivity<ActivityEvaluationBinding, Evaluatio
     }
 
     private fun loadData(type: String) {
-        if (db != null) {
-            val dao = db?.getQuestionsDao()
-            dao?.deleteAll()
+        if (questionsDao != null) {
+            questionsDao?.deleteAll()
             val questionsList = mutableListOf<QuestionsBean>()
             viewModel.getQuestions(type, fail = {
                 it.toast()
@@ -56,7 +55,7 @@ class EvaluationActivity : BaseMVVMActivity<ActivityEvaluationBinding, Evaluatio
                     questionsList.forEach {
                         it.reviewTaskId = taskId
                     }
-                    dao?.insertAll(questionsList)
+                    questionsDao?.insertAll(questionsList)
                 }
                 if (TextUtils.equals("MMSE", type)) {
                     JumpUtil.jumpActivity(RouterUrlCommon.mmseEvaluation, mContext)