New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project version="4"> |
| | | <component name="RunConfigurationProducerService"> |
| | | <option name="ignoredProducers"> |
| | | <set> |
| | | <option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" /> |
| | | </set> |
| | | </option> |
| | | </component> |
| | | </project> |
| | |
| | | data class MemoryData( |
| | | val answerCount: Int, |
| | | val answerIntegral: Int, |
| | | val answerRate: String, |
| | | val answerRate: String?, |
| | | val answerTime: Int, |
| | | val count: Int, |
| | | val createBy: String, |
| | | val createTime: String, |
| | | val disabled: Boolean, |
| | | val id: Int, |
| | | val id: String, |
| | | val integral: String, |
| | | val rate: String, |
| | | val rate: String?, |
| | | val studyId: Int, |
| | | val time: String, |
| | | val updateBy: String, |
| | |
| | | package com.dollearn.student.ui.home |
| | | |
| | | import android.os.CountDownTimer |
| | | import android.os.Handler |
| | | import androidx.core.os.bundleOf |
| | | import androidx.recyclerview.widget.GridLayoutManager |
| | | import cn.sinata.xldutils.utils.showAllowingStateLoss |
| | | import com.dollearn.student.R |
| | | import com.dollearn.student.dialog.TipDialog |
| | | import com.dollearn.student.network.entity.Card |
| | |
| | | } |
| | | private val list = arrayListOf<Card>() |
| | | private val adapter = CardAdapter(list) |
| | | private val TIME = 600*1000L |
| | | private var timer:CountDownTimer? = null |
| | | |
| | | private var lastTime = 600 //剩余秒 |
| | | |
| | | private var totalCount = 0 |
| | | private var rightCount = 0 |
| | | |
| | | private var handler: Handler? = null |
| | | var time = 0 //学习秒数 |
| | | |
| | | |
| | | private val PLAY_VOICE = 1 |
| | | private val STUDY_TIME = 2 |
| | | |
| | | private val player by lazy { com.dollearn.student.utils.AudioUtils() } |
| | | |
| | | private var index = 0 |
| | | |
| | | |
| | | override fun initClick() { |
| | | |
| | | tv_exit.setOnClickListener { |
| | | if (tv_exit.text == "提交"){ |
| | | //todo 分数问题 |
| | | ResultActivity.startResult(this,0,0,0,7,totalCount,rightCount,100,time,data!!.data.id) |
| | | finish() |
| | | }else |
| | | finish() |
| | | } |
| | | } |
| | | |
| | | override fun initView() { |
| | | handler = object : Handler(android.os.Looper.getMainLooper()){ |
| | | override fun handleMessage(msg: android.os.Message) { |
| | | super.handleMessage(msg) |
| | | when(msg.what){ |
| | | STUDY_TIME->{ |
| | | time++ |
| | | lastTime -- |
| | | tv_timer.text = "${lastTime}S" |
| | | if (lastTime == 0){ |
| | | val tipDialog = TipDialog() |
| | | tipDialog.arguments = bundleOf("msg" to "答题时间已结束,停止作答!","isAlert" to true,"ok" to "查看成绩") |
| | | tipDialog.setDismissCallback(object :TipDialog.OnDismiss{ |
| | | override fun onDismiss() { |
| | | ResultActivity.startResult(this@MemoryActivity,0,0,0,7,totalCount,rightCount |
| | | ,100,time,data!!.data.id) |
| | | } |
| | | }) |
| | | tipDialog.showAllowingStateLoss(supportFragmentManager,"finish") |
| | | }else |
| | | sendEmptyMessageDelayed(STUDY_TIME,1000) |
| | | } |
| | | PLAY_VOICE->{ |
| | | player.startPlayMusic(this@MemoryActivity,list[index].url) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | handler?.sendEmptyMessageDelayed(STUDY_TIME,1000) |
| | | |
| | | rv_list.layoutManager = GridLayoutManager(this,5) |
| | | rv_list.adapter = adapter |
| | | list.addAll(data.photoList.map { Card(it.id,1,it.photo) }) |
| | | list.addAll(data.voiceList.map { Card(it.id,2,it.voice) }) |
| | | list.shuffle() |
| | | adapter.notifyDataSetChanged() |
| | | } |
| | | |
| | | timer = object :CountDownTimer(TIME,1000){ |
| | | override fun onTick(millisUntilFinished: Long) { |
| | | /** |
| | | * 翻开卡片 |
| | | */ |
| | | fun flyover(position:Int){ |
| | | val card = list[position] |
| | | if (card.type == 2){ |
| | | index = position |
| | | handler?.sendEmptyMessage(PLAY_VOICE) |
| | | } |
| | | |
| | | if (adapter.position1!=-1&&adapter.position2!=-1){ //已经翻开2张卡片,比较结果是否匹配 |
| | | totalCount++ |
| | | val card1 = list[adapter.position1] |
| | | val card2 = list[adapter.position2] |
| | | if (card1.type!=card2.type&&card1.id == card2.id){//匹配成功 |
| | | adapter.releaseHolder() |
| | | rightCount++ |
| | | tv_timer.postDelayed({ |
| | | if (list.filter { !it.isBack }.size == list.size){ //全部答对 |
| | | tv_exit.text = "提交" |
| | | handler?.removeMessages(STUDY_TIME) //停止计时 |
| | | } |
| | | },500) |
| | | }else{ |
| | | tv_timer.postDelayed({ |
| | | adapter.bothToBack() |
| | | },500) |
| | | } |
| | | |
| | | override fun onFinish() { |
| | | val tipDialog = TipDialog() |
| | | tipDialog.arguments = bundleOf("msg" to "答题时间已结束,停止作答!") |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | override fun onDestroy() { |
| | | super.onDestroy() |
| | | handler?.removeMessages(PLAY_VOICE) |
| | | handler?.removeMessages(STUDY_TIME) |
| | | handler = null |
| | | } |
| | | } |
| | |
| | | showVoiceUi() |
| | | |
| | | rl_check_1.clickDelay { |
| | | if (playing) |
| | | return@clickDelay |
| | | if (list[questionIndex].completed) //已作答 |
| | | return@clickDelay |
| | | act.totalCount++ |
| | |
| | | Log.e(TAG,"选择正确") |
| | | transAnimation(cl_answer_1,voiceViews[questionIndex]) |
| | | list[questionIndex].completed = true |
| | | cl_answer_1.callOnClick() |
| | | }else{ |
| | | dot_1.visible() |
| | | iv_error_1.visible() |
| | |
| | | } |
| | | } |
| | | rl_check_2.clickDelay { |
| | | if (playing) |
| | | return@clickDelay |
| | | if (list[questionIndex].completed) //已作答 |
| | | return@clickDelay |
| | | act.totalCount++ |
| | |
| | | Log.e(TAG,"选择正确") |
| | | transAnimation(cl_answer_2,voiceViews[questionIndex]) |
| | | list[questionIndex].completed = true |
| | | cl_answer_2.callOnClick() |
| | | }else{ |
| | | dot_2.visible() |
| | | iv_error_2.visible() |
| | |
| | | } |
| | | } |
| | | rl_check_3.clickDelay { |
| | | if (playing) |
| | | return@clickDelay |
| | | if (list[questionIndex].completed) //已作答 |
| | | return@clickDelay |
| | | act.totalCount++ |
| | |
| | | Log.e(TAG,"选择正确") |
| | | transAnimation(cl_answer_3,voiceViews[questionIndex]) |
| | | list[questionIndex].completed = true |
| | | cl_answer_3.callOnClick() |
| | | }else{ |
| | | dot_3.visible() |
| | | iv_error_3.visible() |
| | |
| | | cl_answer_1.visible() |
| | | cl_answer_2.visible() |
| | | cl_answer_3.visible() |
| | | answerList.clear() |
| | | answerList.add(list[position].correct) |
| | | answerList.addAll(list[position].error?.split(",")?: arrayListOf()) |
| | | answerList.shuffle() |
| | | cl_answer_1.setOnClickListener { |
| | | if (playing) |
| | | return@setOnClickListener |
| | | voiceIndex = 4 |
| | | handler?.sendEmptyMessage(PLAY_VOICE) |
| | | } |
| | | cl_answer_2.setOnClickListener { |
| | | if (playing) |
| | | return@setOnClickListener |
| | | voiceIndex = 5 |
| | | handler?.sendEmptyMessage(PLAY_VOICE) |
| | | } |
| | | cl_answer_3.setOnClickListener { |
| | | if (playing) |
| | | return@setOnClickListener |
| | | voiceIndex = 6 |
| | | handler?.sendEmptyMessage(PLAY_VOICE) |
| | | } |
| | |
| | | v1Views[voiceIndex].gone() |
| | | v2Views[voiceIndex].gone() |
| | | playingViews[voiceIndex].visible() |
| | | if (voiceIndex == 0&&!list[1].completed){ |
| | | if (voiceIndex == 0&&list[0].isQuestion == 1&&!list[1].completed){ |
| | | showAnswerView(1) |
| | | } |
| | | if (voiceIndex == 1&&!list[0].completed){ |
| | | if (voiceIndex == 1&&list[1].isQuestion == 1&&!list[0].completed){ |
| | | showAnswerView(0) |
| | | |
| | | } |
| | | if (voiceIndex == 2&&!list[3].completed){ |
| | | if (voiceIndex == 2&&list[2].isQuestion == 1&&!list[3].completed){ |
| | | showAnswerView(3) |
| | | } |
| | | if (voiceIndex == 3&&!list[2].completed){ |
| | | if (voiceIndex == 3&&list[3].isQuestion == 1&&!list[2].completed){ |
| | | showAnswerView(2) |
| | | } |
| | | } |
| | |
| | | v1Views[voiceIndex].visible() |
| | | v2Views[voiceIndex].visible() |
| | | playingViews[voiceIndex].gone() |
| | | if (list.filter { it.completed }.size == 2){ //全部作答,3秒后下一题 |
| | | handler?.sendEmptyMessageDelayed(TO_NEXT,3000) |
| | | } |
| | | } |
| | | } |
| | |
| | | HttpManager.gameAchievement(rate,difficulty,id?:"","超级听力",time).request(this){_,data-> |
| | | } |
| | | } |
| | | 7->{ |
| | | title = "超级记忆" |
| | | tv_back.visible() |
| | | tv_last.gone() |
| | | tv_exit.gone() |
| | | HttpManager.gameAchievement(rate,difficulty,id?:"","超级记忆",time).request(this){_,data-> |
| | | } |
| | | } |
| | | 8->{ |
| | | tv_back.visible() |
| | | tv_last.gone() |
| | |
| | | import cn.sinata.xldutils.visible |
| | | import com.dollearn.student.R |
| | | import com.dollearn.student.network.entity.Card |
| | | import com.dollearn.student.ui.home.MemoryActivity |
| | | import com.dollearn.student.utils.ViewAnimUtils |
| | | import com.dollearn.student.utils.extention.clickDelay |
| | | import com.facebook.drawee.view.SimpleDraweeView |
| | | import kotlinx.android.synthetic.main.fragment_q_a.* |
| | | import java.util.ArrayList |
| | | |
| | | class CardAdapter(list: ArrayList<Card>):HFRecyclerAdapter<Card>(list, R.layout.item_card) { |
| | | private val act by lazy { context as MemoryActivity } |
| | | |
| | | //第一次翻开的 |
| | | var position1 = -1 |
| | | private var p1View:View? = null |
| | | private var f1View:View? = null |
| | | private var b1View:View? = null |
| | | |
| | | //第2次翻开的 |
| | | var position2 = -1 |
| | | private var p2View:View? = null |
| | | private var f2View:View? = null |
| | | private var b2View:View? = null |
| | | |
| | | override fun onBind(holder: ViewHolder, position: Int, data: Card) { |
| | | val frame = holder.bind<View>(R.id.frame) |
| | | val back = holder.bind<View>(R.id.back) |
| | | val front = holder.bind<View>(R.id.front) |
| | | frame.setOnClickListener { |
| | | flip(position,frame,back, front) |
| | | val rlVoice = holder.bind<View>(R.id.rl_voice) |
| | | val ivImg = holder.bind<SimpleDraweeView>(R.id.iv_img) |
| | | |
| | | if(data.type == 1){ |
| | | rlVoice.gone() |
| | | ivImg.visible() |
| | | ivImg.setImageURI(data.url) |
| | | }else{ |
| | | rlVoice.visible() |
| | | ivImg.gone() |
| | | } |
| | | |
| | | frame.clickDelay { |
| | | if(data.isBack){ |
| | | if(position1 == -1) |
| | | position1 = position |
| | | else if(position2 == -1) |
| | | position2 = position |
| | | flip(position,frame,back, front) |
| | | act.flyover(position) |
| | | } |
| | | } |
| | | if (data.isBack){ |
| | | back.visible() |
| | |
| | | parent.postDelayed({ |
| | | mData[position].isBack = direction != -1 |
| | | switchViewVisibility(back, front) },300) |
| | | if(p1View == null){ |
| | | p1View = parent |
| | | b1View = back |
| | | f1View = front |
| | | }else if(p2View == null){ |
| | | p2View = parent |
| | | b2View = back |
| | | f2View = front |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 答案不匹配,2张卡片都翻回去 |
| | | */ |
| | | fun bothToBack(){ |
| | | if (p1View!=null&&b1View!=null&&f1View!=null) |
| | | flip(position1,p1View!!,b1View!!,f1View!!) |
| | | if (p2View!=null&&b2View!=null&&f2View!=null) |
| | | flip(position2,p2View!!,b2View!!,f2View!!) |
| | | releaseHolder() |
| | | } |
| | | |
| | | fun releaseHolder(){ |
| | | position1 = -1 |
| | | position2 = -1 |
| | | p1View = null |
| | | b1View = null |
| | | f1View = null |
| | | p2View = null |
| | | b2View = null |
| | | f2View = null |
| | | } |
| | | |
| | | private fun switchViewVisibility(back:View,front:View) { |
| | |
| | | android:layout_marginStart="40dp" |
| | | android:textSize="14sp" |
| | | android:textColor="@color/textColor" |
| | | app:layout_constraintTop_toTopOf="@id/timer" |
| | | app:layout_constraintBottom_toBottomOf="@id/timer" |
| | | app:layout_constraintTop_toTopOf="@id/tv_timer" |
| | | app:layout_constraintBottom_toBottomOf="@id/tv_timer" |
| | | android:textStyle="bold" |
| | | android:text="答题剩余时间:"/> |
| | | |
| | | <TextView |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:id="@+id/timer" |
| | | android:id="@+id/tv_timer" |
| | | app:layout_constraintStart_toEndOf="@id/tv_1" |
| | | android:textSize="36sp" |
| | | android:textColor="@color/colorRed" |