From ec282d9bf134fbda578ff901e4a620222a851d3f Mon Sep 17 00:00:00 2001 From: lmw <125975490@qq.com> Date: 星期三, 20 十一月 2024 10:14:46 +0800 Subject: [PATCH] fix bug --- app/src/main/java/com/sinata/xqmuse/ui/home/HomeFragment.kt | 95 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 84 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/sinata/xqmuse/ui/home/HomeFragment.kt b/app/src/main/java/com/sinata/xqmuse/ui/home/HomeFragment.kt index 98a243d..2b09161 100644 --- a/app/src/main/java/com/sinata/xqmuse/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/sinata/xqmuse/ui/home/HomeFragment.kt @@ -3,11 +3,14 @@ import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import cn.sinata.xldutils.fragment.BaseFragment +import cn.sinata.xldutils.gone +import cn.sinata.xldutils.utils.SPUtils +import cn.sinata.xldutils.utils.ellipsize +import cn.sinata.xldutils.visible +import com.sinata.xqmuse.MainActivity import com.sinata.xqmuse.R -import com.sinata.xqmuse.dialog.LoginRuleDialog import com.sinata.xqmuse.network.HttpManager import com.sinata.xqmuse.network.entity.* -import com.sinata.xqmuse.network.request import com.sinata.xqmuse.network.requestByF import com.sinata.xqmuse.ui.BGMSettingActivity import com.sinata.xqmuse.ui.H5Activity @@ -15,9 +18,14 @@ import com.sinata.xqmuse.ui.home.adapter.HomeAdapter import com.sinata.xqmuse.ui.home.adapter.HomeBannerAdapter import com.sinata.xqmuse.ui.home.adapter.TopMenuAdapter +import com.sinata.xqmuse.ui.login.LoginActivity +import com.sinata.xqmuse.utils.Const +import com.sinata.xqmuse.utils.event.EmptyEvent +import com.sinata.xqmuse.utils.interfaces.StringCallback import kotlinx.android.synthetic.main.fragment_home.* -import org.jetbrains.anko.startActivityForResult +import org.greenrobot.eventbus.EventBus import org.jetbrains.anko.support.v4.startActivity +import org.jetbrains.anko.support.v4.toast class HomeFragment : BaseFragment() { override fun contentViewId() = R.layout.fragment_home @@ -37,12 +45,30 @@ banner_privacy.adapter = privacyAdapter rv_list.layoutManager = LinearLayoutManager(requireContext()) rv_list.adapter = adapter + adapter.callback = object :StringCallback{ + override fun onResult(rst: String) { + showDialog() + HttpManager.getMeditationDetails(rst).requestByF(this@HomeFragment,success = {_,data-> + dismissDialog() + data?.goDetail(requireContext()) + }){_,_-> + dismissDialog() + } + } + } getTopMenu() getToday() getPrivacy() getList() getBottomMenu() initClick() + changeBg() + } + + fun refreshData(){ + getToday() + getPrivacy() + getList() } private fun initClick() { @@ -53,11 +79,14 @@ startActivity<GuideActivity>() } iv_guide.setOnClickListener { - HttpManager.getH5(LoginRuleDialog.TYPE_PRIVACY).requestByF(this){ _, data-> + HttpManager.getH5(4).requestByF(this){ _, data-> data?.let { startActivity<H5Activity>("title" to "新手冥想指南","url" to it.content) } } + } + iv_daily_empty.setOnClickListener { + toast("平台暂未设置今日疗愈") } iv_voice.setOnClickListener { startActivity<BGMSettingActivity>() @@ -67,9 +96,42 @@ } iv_today.setOnClickListener { if (today!=null){ - startActivity<VoiceDetailActivity>("id" to today!!.id) + if (MainActivity.voice?.id == today?.meditationId){ + EventBus.getDefault().post(EmptyEvent(Const.EventCode.PAUSE_OR_RESUME_THINK)) + if (MainActivity.playing) //播放中 + iv_play_today.setImageResource(R.mipmap.player_pause) + else + iv_play_today.setImageResource(R.mipmap.play) + }else{ + showDialog() + HttpManager.getMeditationDetails(today!!.meditationId).requestByF(this,success = {_,data-> + dismissDialog() + if (MainActivity.playing) + EventBus.getDefault().post(EmptyEvent(Const.EventCode.FINISH_THINK)) + MainActivity.voice = data + EventBus.getDefault().post(EmptyEvent(Const.EventCode.START_THINK)) + }){_,_-> + dismissDialog() + } + } } } + banner_privacy.setOnBannerListener { data, position -> + showDialog() + HttpManager.getMeditationDetails(privacy[position].id).requestByF(this,success = {_,data-> + dismissDialog() + data?.goDetail(requireContext()) + }){_,_-> + dismissDialog() + } + } + iv_pri_empty.setOnClickListener { startActivity<LoginActivity>() } + } + + fun changeBg(){ + val bg = SPUtils.instance().getString(Const.User.BG) + if (!bg.isNullOrEmpty()) + iv_home.setImageURI(bg) } private fun getTopMenu(){ @@ -91,16 +153,28 @@ } } - private fun getToday() { + fun getToday() { HttpManager.getTodayMeditation().requestByF(this){_,data-> today = data - iv_today.setImageURI(today?.clientMeditationVO?.backgroundUrl) - tv_length_today.text = "${today?.clientMeditationVO?.meditationTitle} | ${"00:00"}" - tv_today_count.text = "${today?.clientMeditationVO?.realLearnedNum}人已参加学习" + if (today?.clientMeditationVO?.backgroundUrl.isNullOrEmpty()){ + iv_daily_empty.visible() + }else{ + iv_daily_empty.gone() + iv_today.setImageURI(today?.imageUrl) + tv_length_today.text = "${today?.clientMeditationVO?.meditationTitle?.ellipsize(12)} | ${"%02d:%02d".format((data?.time?:0)/60,(data?.time?:0)%60)}" + tv_today_count.text = "${(today?.clientMeditationVO?.realLearnedNum?:0)+(today?.clientMeditationVO?.virtualLearnedNum?:0)}人已参加学习" + } } } - private fun getPrivacy() { + fun refreshTodayPlayingState(){ + if (MainActivity.voice?.id == today?.meditationId&&MainActivity.playing) + iv_play_today.setImageResource(R.mipmap.player_pause) + else + iv_play_today.setImageResource(R.mipmap.play) + } + + fun getPrivacy() { HttpManager.getPersonalityPlan().requestByF(this){_,data-> privacy.clear() privacy.addAll(data?: arrayListOf()) @@ -118,5 +192,4 @@ } } } - } \ No newline at end of file -- Gitblit v1.7.1