| | |
| | | package com.dollearn.student |
| | | |
| | | import android.annotation.SuppressLint |
| | | import android.os.Handler |
| | | import android.os.Looper |
| | | import android.os.Message |
| | | import android.util.Log |
| | | import androidx.fragment.app.Fragment |
| | | import androidx.fragment.app.FragmentPagerAdapter |
| | | import cn.sinata.xldutils.gone |
| | | import cn.sinata.xldutils.utils.showAllowingStateLoss |
| | | import cn.sinata.xldutils.utils.SPUtils |
| | | import com.flyco.tablayout.listener.CustomTabEntity |
| | | import com.flyco.tablayout.listener.OnTabSelectListener |
| | | import com.github.zackratos.ultimatebar.UltimateBar |
| | | import com.dollearn.student.dialog.CompetitionTipDialog |
| | | import com.dollearn.student.network.HttpManager |
| | | import com.dollearn.student.network.entity.UserBean |
| | | import com.dollearn.student.network.request |
| | |
| | | import com.dollearn.student.utils.Const |
| | | import com.dollearn.student.utils.event.EmptyEvent |
| | | import kotlinx.android.synthetic.main.activity_main.* |
| | | import kotlinx.android.synthetic.main.fragment_shop.* |
| | | import org.greenrobot.eventbus.EventBus |
| | | import org.greenrobot.eventbus.Subscribe |
| | | |
| | |
| | | private val fragments = arrayListOf<Fragment>() |
| | | var homeData: UserBean? = null //个人信息 |
| | | var score = 0 |
| | | private var handler: Handler? = null |
| | | var mins = 0 |
| | | |
| | | override fun initClick() { |
| | | } |
| | |
| | | initTab() |
| | | EventBus.getDefault().register(this) |
| | | getData() |
| | | getVoiceUrl() |
| | | getScoreConfig() |
| | | getIsText2() |
| | | } |
| | | |
| | | private fun getIsText2() { |
| | | HttpManager.getIsOpen().request(this){_,data-> |
| | | SPUtils.instance().put(Const.IS_SHOW_TEXT,data?:true).apply() |
| | | } |
| | | } |
| | | |
| | | private fun getScoreConfig() { |
| | | HttpManager.onlineDuration().request(this,false) { _, data -> |
| | | SPUtils.instance().put(Const.SCORE_DURATION, (data ?: "0").toInt()).apply() |
| | | } |
| | | } |
| | | |
| | | private fun startTimer() { |
| | | val duration = SPUtils.instance().getInt(Const.SCORE_DURATION,30)//单位分钟 |
| | | if (handler == null) |
| | | handler = object :Handler(Looper.myLooper()!!){ |
| | | override fun handleMessage(msg: Message) { |
| | | super.handleMessage(msg) |
| | | if (msg.what == 0){ |
| | | mins++ |
| | | Log.e("mmp","当前已听${mins}分钟") |
| | | if (mins >= duration){ |
| | | HttpManager.giveIntegral().request(this@MainActivity,false,{_,_-> |
| | | mins = 0 |
| | | handler?.sendEmptyMessageDelayed(0,1000*60) |
| | | }){_,_-> |
| | | handler?.sendEmptyMessageDelayed(0,1000*60) |
| | | } |
| | | }else |
| | | handler?.sendEmptyMessageDelayed(0,1000*60) |
| | | } |
| | | } |
| | | } |
| | | if (handler?.hasMessages(0) == false){ |
| | | mins = 0 |
| | | handler?.sendEmptyMessageDelayed(0,1000*60) |
| | | } |
| | | } |
| | | |
| | | private fun getVoiceUrl() { |
| | | HttpManager.promptVoice().request(this,false){_,data-> |
| | | if (!data?.correct.isNullOrEmpty()) |
| | | SPUtils.instance().put(Const.RV,data?.correct?:"").apply() |
| | | if (!data?.error.isNullOrEmpty()) |
| | | SPUtils.instance().put(Const.EV,data?.error?:"").apply() |
| | | } |
| | | } |
| | | |
| | | private fun initTab() { |
| | |
| | | |
| | | @Subscribe |
| | | fun onSwitch(e:EmptyEvent){ |
| | | if (e.code == Const.EventCode.SWITCH_HOME){ |
| | | switchHome() |
| | | }else if(e.code == Const.EventCode.CHANGE_WELFARE){ |
| | | tab_bar.currentTab = 2 |
| | | onTabSelect(2) |
| | | }else if(e.code == Const.EventCode.CHANGE_EXPLORE){ |
| | | tab_bar.currentTab = 3 |
| | | onTabSelect(3) |
| | | when (e.code) { |
| | | Const.EventCode.CLICK_GAME_ITEM -> { |
| | | switchHome() |
| | | } |
| | | Const.EventCode.REFRESH_USER -> getData() |
| | | Const.EventCode.SCORE_CHANGED -> getScore() |
| | | Const.EventCode.START_TIMER ->{ |
| | | Log.e("mmp","开始学习") |
| | | startTimer() |
| | | } |
| | | Const.EventCode.STOP_TIMER ->{ |
| | | Log.e("mmp","结束学习") |
| | | handler?.removeMessages(0) |
| | | mins = 0 |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Subscribe |
| | | fun refreshUser(e:EmptyEvent){ |
| | | if (e.code == Const.EventCode.REFRESH_USER) |
| | | getData() |
| | | if (e.code == Const.EventCode.SCORE_CHANGED) |
| | | getScore() |
| | | } |
| | | |
| | | private fun getData() { |
| | |
| | | override fun onDestroy() { |
| | | super.onDestroy() |
| | | EventBus.getDefault().unregister(this) |
| | | WeparkApplication.storeId = "" |
| | | handler?.removeCallbacksAndMessages(null) |
| | | handler = null |
| | | } |
| | | } |