| | |
| | | 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.invisible |
| | | import cn.sinata.xldutils.utils.ellipsize |
| | | import cn.sinata.xldutils.visible |
| | | import com.google.android.exoplayer2.upstream.DataSpec |
| | | import com.google.android.exoplayer2.upstream.RawResourceDataSource |
| | | import com.sinata.xqmuse.MainActivity |
| | | import com.sinata.xqmuse.R |
| | | import com.sinata.xqmuse.network.HttpManager |
| | |
| | | import com.sinata.xqmuse.utils.interfaces.StringCallback |
| | | import kotlinx.android.synthetic.main.fragment_home.* |
| | | import org.greenrobot.eventbus.EventBus |
| | | import org.jetbrains.anko.startActivity |
| | | import org.jetbrains.anko.support.v4.startActivity |
| | | import org.jetbrains.anko.support.v4.toast |
| | | |
| | |
| | | getList() |
| | | getBottomMenu() |
| | | initClick() |
| | | changeBg() |
| | | } |
| | | |
| | | fun refreshData(){ |
| | | getToday() |
| | | getPrivacy() |
| | | getList() |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.CHANGE_BGM)) //BGM切换流程 |
| | | } |
| | | |
| | | private fun initClick() { |
| | |
| | | iv_privacy.setOnClickListener { |
| | | startActivity<GuideActivity>() |
| | | } |
| | | iv_guide.setOnClickListener { |
| | | tv_3.setOnClickListener { |
| | | HttpManager.getH5(4).requestByF(this){ _, data-> |
| | | data?.let { |
| | | startActivity<H5Activity>("title" to "新手冥想指南","url" to it.content) |
| | |
| | | } |
| | | iv_today.setOnClickListener { |
| | | if (today!=null){ |
| | | if (MainActivity.voice?.id == today?.meditationId){ |
| | | if (today?.isShow == 1){ //跳转播放微电影 |
| | | startActivity<MicroVideoActivity>("url" to today?.meditationVideo?.videoUrl,"title" to today?.meditationVideo?.title) |
| | | }else 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) |
| | |
| | | iv_pri_empty.setOnClickListener { startActivity<LoginActivity>() } |
| | | } |
| | | |
| | | fun changeBg(){ |
| | | val bg = SPUtils.instance().getString(Const.User.BG) |
| | | if (!bg.isNullOrEmpty()) |
| | | fun changeBg(bg:String,video:String){ |
| | | if (video.isNotEmpty()){ |
| | | iv_home.invisible() |
| | | player.visible() |
| | | player.release() |
| | | player.setUrl(video) |
| | | player.setLooping(true) |
| | | player.start() |
| | | } else if (bg.isNotEmpty()){ |
| | | iv_home.setImageURI(bg) |
| | | player.release() |
| | | player.gone() |
| | | iv_home.visible() |
| | | }else{ |
| | | iv_home.invisible() |
| | | player.visible() |
| | | player.release() |
| | | //ExoPlayer |
| | | val dataSpec = DataSpec(RawResourceDataSource.buildRawResourceUri(R.raw.default_bg)) |
| | | val rawResourceDataSource = RawResourceDataSource(requireContext()) |
| | | try { |
| | | rawResourceDataSource.open(dataSpec) |
| | | } catch (e: RawResourceDataSource.RawResourceDataSourceException) { |
| | | e.printStackTrace() |
| | | } |
| | | val url = rawResourceDataSource.uri.toString() |
| | | player.setUrl(url) |
| | | player.setLooping(true) |
| | | player.start() |
| | | } |
| | | } |
| | | |
| | | private fun getTopMenu(){ |
| | |
| | | fun getToday() { |
| | | HttpManager.getTodayMeditation().requestByF(this){_,data-> |
| | | today = data |
| | | if (today?.clientMeditationVO?.backgroundUrl.isNullOrEmpty()){ |
| | | iv_daily_empty.visible() |
| | | if (data?.isShow == 0){ |
| | | tv_1.text = "每日疗愈" |
| | | tv_sub_1.text = "Daily Meditation" |
| | | 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)}人已参加学习" |
| | | } |
| | | }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)}人已参加学习" |
| | | tv_1.text = "泉疗愈 微电影" |
| | | tv_sub_1.text = "Spring Healing Microfilm" |
| | | if (today?.meditationVideo?.videoUrl.isNullOrEmpty()){ |
| | | iv_daily_empty.visible() |
| | | }else{ |
| | | iv_daily_empty.gone() |
| | | iv_today.setImageURI(today?.meditationVideo?.imageUrl) |
| | | tv_length_today.text = "${today?.meditationVideo?.title?.ellipsize(18)} | ${"%02d:%02d".format((today?.meditationVideo?.videoSecond?:0)/60,(today?.meditationVideo?.videoSecond?:0)%60)}" |
| | | tv_today_count.text = "" |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | override fun onPause() { |
| | | super.onPause() |
| | | player?.pause() |
| | | } |
| | | |
| | | override fun onResume() { |
| | | super.onResume() |
| | | player?.resume() |
| | | } |
| | | |
| | | override fun onDestroy() { |
| | | super.onDestroy() |
| | | player?.release() |
| | | } |
| | | } |