From 7bed3f6090b14391d7dad4ca4bd632fb28d847c0 Mon Sep 17 00:00:00 2001
From: 罗明文 <125975490@qq.com>
Date: 星期三, 21 五月 2025 15:34:19 +0800
Subject: [PATCH] save

---
 app/src/main/java/com/dollearn/student/ui/home/MatchFragment.kt |   68 ++++++++++++++++++++++++++++++++++
 1 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/app/src/main/java/com/dollearn/student/ui/home/MatchFragment.kt b/app/src/main/java/com/dollearn/student/ui/home/MatchFragment.kt
index b670568..280bf8a 100644
--- a/app/src/main/java/com/dollearn/student/ui/home/MatchFragment.kt
+++ b/app/src/main/java/com/dollearn/student/ui/home/MatchFragment.kt
@@ -15,8 +15,46 @@
 import com.dollearn.student.R
 import com.dollearn.student.utils.AudioUtils
 import com.dollearn.student.utils.Const
+import com.dollearn.student.utils.event.EmptyEvent
 import com.dollearn.student.utils.extention.clickDelay
+import kotlinx.android.synthetic.main.fragment_choose_voice.*
 import kotlinx.android.synthetic.main.fragment_match.*
+import kotlinx.android.synthetic.main.fragment_match.cl_1
+import kotlinx.android.synthetic.main.fragment_match.cl_2
+import kotlinx.android.synthetic.main.fragment_match.cl_3
+import kotlinx.android.synthetic.main.fragment_match.cl_4
+import kotlinx.android.synthetic.main.fragment_match.cl_voice_end_1
+import kotlinx.android.synthetic.main.fragment_match.cl_voice_end_2
+import kotlinx.android.synthetic.main.fragment_match.cl_voice_end_3
+import kotlinx.android.synthetic.main.fragment_match.cl_voice_end_4
+import kotlinx.android.synthetic.main.fragment_match.iv1_1
+import kotlinx.android.synthetic.main.fragment_match.iv1_1_end
+import kotlinx.android.synthetic.main.fragment_match.iv1_2
+import kotlinx.android.synthetic.main.fragment_match.iv1_2_end
+import kotlinx.android.synthetic.main.fragment_match.iv1_3
+import kotlinx.android.synthetic.main.fragment_match.iv1_3_end
+import kotlinx.android.synthetic.main.fragment_match.iv1_4_end
+import kotlinx.android.synthetic.main.fragment_match.iv2_1
+import kotlinx.android.synthetic.main.fragment_match.iv2_1_end
+import kotlinx.android.synthetic.main.fragment_match.iv2_2
+import kotlinx.android.synthetic.main.fragment_match.iv2_2_end
+import kotlinx.android.synthetic.main.fragment_match.iv2_3
+import kotlinx.android.synthetic.main.fragment_match.iv2_3_end
+import kotlinx.android.synthetic.main.fragment_match.iv2_4_end
+import kotlinx.android.synthetic.main.fragment_match.iv_1
+import kotlinx.android.synthetic.main.fragment_match.iv_2
+import kotlinx.android.synthetic.main.fragment_match.iv_3
+import kotlinx.android.synthetic.main.fragment_match.iv_4
+import kotlinx.android.synthetic.main.fragment_match.iv_playing_1
+import kotlinx.android.synthetic.main.fragment_match.iv_playing_1_end
+import kotlinx.android.synthetic.main.fragment_match.iv_playing_2
+import kotlinx.android.synthetic.main.fragment_match.iv_playing_2_end
+import kotlinx.android.synthetic.main.fragment_match.iv_playing_3
+import kotlinx.android.synthetic.main.fragment_match.iv_playing_3_end
+import kotlinx.android.synthetic.main.fragment_match.iv_playing_4_end
+import kotlinx.android.synthetic.main.fragment_match.motion
+import org.greenrobot.eventbus.EventBus
+import org.greenrobot.eventbus.Subscribe
 import org.jetbrains.anko.imageResource
 
 
@@ -56,9 +94,16 @@
 
     private val completedVoice = arrayListOf<String>() //已经选了的音频 飞到图片上了
 
+    var right = true //true进入下一题为全对,false 一旦答错过就置为false,此时进入下一题,本题算做错误
+    var isAutoPlaying = false
+
+
+
     override fun onFirstVisibleToUser() {
         player.setOnAudioStatusUpdateListener(this)
         player.stopPlayMusic()
+        EventBus.getDefault().register(this)
+
         handler = object : Handler(Looper.getMainLooper()){
             override fun handleMessage(msg: Message) {
                 super.handleMessage(msg)
@@ -182,6 +227,7 @@
                 motion.transitionToEnd()
                 handler?.sendEmptyMessage(PLAY_RIGHT)
             }else{
+                right = false
                 result_1.imageResource = R.mipmap.zhifushibai
                 handler?.sendEmptyMessage(PLAY_ERROR)
             }
@@ -467,11 +513,22 @@
         })
     }
 
+    @Subscribe
+    fun onEvent(e: EmptyEvent){
+        if (e.code == Const.EventCode.RECOVERD){
+//            if (act.fragments[act.vp.currentItem] == this){ //自动播放
+//                isAutoPlaying = true
+//                cl_voice_1.callOnClick()
+//            }
+        }
+    }
+
     /**
      * 回到上一题,恢复状态
      */
     fun recover(){
         Log.e(TAG,"回到上一题,恢复答题前的状态")
+        right = true
         motion.progress = 0f
         data!!.subjectList[group].forEach {
             it.completed = false
@@ -486,6 +543,10 @@
         cl_voice_end_2.gone()
         cl_voice_end_3.gone()
         cl_voice_end_4.gone()
+        if (act.fragments[act.vp.currentItem] == this&&act.recoverd) { //自动播放
+//            isAutoPlaying = true
+//            cl_voice_1.callOnClick()
+        }
     }
 
     companion object{
@@ -644,4 +705,11 @@
         super.onPause()
         player.stopPlayMusic()
     }
+
+    override fun onDestroy() {
+        super.onDestroy()
+        handler?.removeCallbacksAndMessages(null)
+        EventBus.getDefault().unregister(this)
+
+    }
 }
\ No newline at end of file

--
Gitblit v1.7.1