罗明文
2024-06-19 481723ce3c05d74fec53b8567b9c79d77bdcc155
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.dollearn.student.ui.mine
 
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.fragment.BaseFragment
import cn.sinata.xldutils.utils.SPUtils
import com.dollearn.student.MainActivity
import com.dollearn.student.R
import com.dollearn.student.WeparkApplication
import com.dollearn.student.dialog.TipDialog
import com.dollearn.student.network.entity.Commodity
import com.dollearn.student.network.entity.UserBean
import com.dollearn.student.network.entity.WelfareHomeData
import com.dollearn.student.ui.course.WelfareActivity
import com.dollearn.student.ui.home.JoinVipActivity
import com.dollearn.student.ui.login.LoginActivity
import com.dollearn.student.ui.welfare.*
import com.dollearn.student.ui.welfare.adapter.WelfareGoodsAdapter
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_mine.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.jetbrains.anko.support.v4.startActivity
 
class MineFragment : BaseFragment() {
    override fun contentViewId() = R.layout.fragment_mine
 
    private var homeData: UserBean? = null
 
    override fun onFirstVisibleToUser() {
        EventBus.getDefault().register(this)
        iv_avatar.clickDelay { startActivity<UserInfoActivity>() }
        tv_name.clickDelay { startActivity<UserInfoActivity>() }
//        tv_coin.clickDelay { startActivityForResult<RechargeRecordActivity>(1) }
        tv_record.clickDelay { startActivity<CoinRecordActivity>() }
        showInfo()
        tv_logout.setOnClickListener {
            val tipDialog = TipDialog()
            tipDialog.arguments = bundleOf("msg" to "确认退出当前账户吗?")
            tipDialog.setCallback(object :TipDialog.OnClickCallback{
                override fun onOk() {
                    SPUtils.instance().put(Const.User.TOKEN,"").apply()
                    requireActivity().finish()
                    startActivity<LoginActivity>()
                }
 
                override fun onCancel() {
                }
            })
            tipDialog.show(childFragmentManager,"out")
        }
 
        tv_learn_record.setOnClickListener {
            startActivity<LearnRecordActivity>()
        }
 
        tv_score_record.setOnClickListener {
            startActivity<ScoreRecordActivity>()
        }
 
        tv_exchange_record.setOnClickListener {
            startActivity<ExchangeRecordActivity>()
        }
 
        tv_address.setOnClickListener {
            startActivity<AddressManageActivity>()
        }
    }
 
    @Subscribe
    fun refreshUser(e:EmptyEvent){
        if (e.code == Const.EventCode.REFRESH_USER_INFO){
            showInfo()
        }
    }
 
    private fun showInfo(){
        homeData = (requireActivity() as MainActivity).homeData
        homeData?.apply {
            iv_avatar.setImageURI(user.headImg)
            tv_name.text = user.name
            tv_record.text = "剩余积分:%d|学习进度:周目%d|学习总时长:%d小时".format(user.integral,userStudy.week,userStudy.totalStudy)
        }
    }
 
    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }
}