罗明文
昨天 442124baa483f8d1c4aaca7ff81e15dd3f122363
app/src/main/java/com/dollearn/student/ui/home/ResultActivity.kt
@@ -1,12 +1,16 @@
package com.dollearn.student.ui.home
import android.content.Context
import cn.sinata.xldutils.gone
import cn.sinata.xldutils.invisible
import cn.sinata.xldutils.visible
import com.dollearn.student.MainActivity
import com.dollearn.student.R
import com.dollearn.student.network.HttpManager
import com.dollearn.student.network.request
import com.dollearn.student.ui.TransparentStatusBarActivity
import com.dollearn.student.utils.Const
import com.dollearn.student.utils.event.EmptyEvent
import com.dollearn.student.utils.event.IntEvent
import com.dollearn.student.utils.extention.clickDelay
import kotlinx.android.synthetic.main.activity_result.*
@@ -17,6 +21,7 @@
    override fun setContentView() = R.layout.activity_result
    private val id by lazy { intent.getStringExtra("id") }
    private val time by lazy { intent.getIntExtra("time",0) }
    private val type by lazy { intent.getIntExtra("type",0) }
    private val day by lazy { intent.getIntExtra("day",0) }
    private val week by lazy { intent.getIntExtra("week",0) }
@@ -25,11 +30,16 @@
    private val total by lazy { intent.getIntExtra("total",0) }
    private val right by lazy { intent.getIntExtra("right",0) }
    private val score by lazy { intent.getIntExtra("score",0) }
    private val time by lazy { intent.getIntExtra("time",0) }
    private val difficulty by lazy { intent.getIntExtra("difficulty",0) } //游戏难度
    override fun initClick() {
        tv_last.setOnClickListener {
            startActivity<MainActivity>()
            finish()
        }
        tv_back.setOnClickListener {
            finish()
        }
        tv_exit.clickDelay {
@@ -39,20 +49,72 @@
    }
    override fun initView() {
        tv_score.text = "恭喜你,已完成全部答题!获得${score}积分!"
        tv_count.text = "${total}次"
        tv_right.text = "${right}次"
        tv_fault.text = "${total-right}次"
        val rate = (right * 100) / total
        val rate = if(total == 0) 0 else (right * 100) / total
        tv_rate.text = "正确率:$rate%"
        when(type){
            6->{
                title = "超级听力"
                tv_back.visible()
                tv_last.invisible()
                tv_exit.invisible()
                HttpManager.gameAchievement(rate,difficulty,id?:"","超级听力",time).request(this){_,data->
                    tv_score.text = "恭喜你,已完成全部答题!获得${data?:0}积分!"
        HttpManager.completeLearning(rate,time,day,week,season,type,id?:"").request(this){_,data->
                }
            }
            7->{
                title = "自主游戏2-超级记忆"
                tv_score.text = "恭喜你,已完成游戏!获得${score}积分!"
                tv_back.visible()
                tv_last.invisible()
                tv_exit.invisible()
                tv_1.text = "总题目:"
                tv_2.text = "正确题目:"
                tv_3.text = "错误题目:"
                tv_count.text = "$total"
                tv_right.text = "$right"
                tv_fault.text = "${total-right}"
                HttpManager.gameAchievement(rate,difficulty,id?:"","超级记忆",time).request(this){_,data->
                    tv_score.text = "恭喜你,已完成游戏!获得${data?:0}积分!"
                }
            }
            8->{
                title = "自主学故事1-看图配音"
                tv_back.visible()
                tv_last.invisible()
                tv_exit.invisible()
                HttpManager.completeStory(rate,1,id?:"",time).request(this){_,data->
                    tv_score.text = "恭喜你,已完成全部答题!获得${data?:0}积分!"
                }
            }
            else->{
                when(type){
                    1-> title = "自主学习1-听音选图"
                    2-> title = "自主学习2-看图选音"
                    3-> title = "自主学习3-归纳排除"
                    4-> title = "自主学习4-有问有答"
                }
                if (type == 5){
                    title = "自主学习5-音图相配"
                    tv_back.visible()
                    tv_last.invisible()
                    tv_exit.invisible()
                }
                HttpManager.completeLearning(rate,time,day,week,season,type,id?:"").request(this){_,data->
                    tv_score.text = "恭喜你,已完成全部答题!获得${data?:0}积分!"
                }
            }
        }
    }
    companion object{
        fun startResult(context:Context,day:Int,week:Int,season:Int,type:Int,total:Int,right:Int,score:Int,time:Int,id:String){
            context.startActivity<ResultActivity>("day" to day,"week" to week,"season" to season,"type" to type,"total" to total,"right" to right,"score" to score,"time" to time,"id" to id)
        fun startResult(context:Context,day:Int,week:Int,season:Int,type:Int,total:Int,right:Int,score:Int,time:Int,id:String,difficulty:Int? = null){
            context.startActivity<ResultActivity>("day" to day,"week" to week,"season" to season,"type" to type,"total" to total,"right" to right,"score" to score,
                "time" to time,"id" to id,"difficulty" to difficulty)
        }
    }
}