From 718f31c92e2029d05260810435a2c70cef6e6ce5 Mon Sep 17 00:00:00 2001 From: lmw <125975490@qq.com> Date: 星期四, 24 四月 2025 10:45:55 +0800 Subject: [PATCH] save --- app/src/main/java/com/sinata/xqmuse/ui/mine/MineGridFragment.kt | 62 ++++++++++++++++++++++--------- 1 files changed, 44 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/sinata/xqmuse/ui/mine/MineGridFragment.kt b/app/src/main/java/com/sinata/xqmuse/ui/mine/MineGridFragment.kt index a7d448f..9f7d938 100644 --- a/app/src/main/java/com/sinata/xqmuse/ui/mine/MineGridFragment.kt +++ b/app/src/main/java/com/sinata/xqmuse/ui/mine/MineGridFragment.kt @@ -1,5 +1,7 @@ package com.sinata.xqmuse.ui.mine +import android.app.Activity +import android.content.Intent import androidx.core.os.bundleOf import androidx.recyclerview.widget.GridLayoutManager import cn.sinata.xldutils.fragment.BaseFragment @@ -9,10 +11,11 @@ import com.sinata.xqmuse.network.HttpManager import com.sinata.xqmuse.network.entity.CourseBean import com.sinata.xqmuse.network.requestByF +import com.sinata.xqmuse.ui.course.BuyCourseActivity import com.sinata.xqmuse.ui.course.adapter.CourseGridAdapter -import com.sinata.xqmuse.ui.home.VoiceDetailActivity +import com.sinata.xqmuse.ui.home.BuyVoiceActivity import kotlinx.android.synthetic.main.layout_common_list.* -import org.jetbrains.anko.support.v4.startActivity +import org.jetbrains.anko.support.v4.startActivityForResult class MineGridFragment : BaseFragment() { override fun contentViewId() = R.layout.layout_common_list @@ -27,7 +30,10 @@ override fun onFirstVisibleToUser() { pType = when(type){ COLLECTED_COURSE, COLLECTED_SAVE->WatchHisActivity.COLLECTED - HAS_BUY_VOICE, HAS_BUY_COURSE->WatchHisActivity.HAS_BUY + HAS_BUY_VOICE, HAS_BUY_COURSE->{ + adapter.isOrder = true + WatchHisActivity.HAS_BUY + } else->WatchHisActivity.WATCH_HIS } state = when(type){ @@ -46,21 +52,35 @@ getData() } refreshLayout.autoRefresh() - adapter.setOnItemClickListener { view, position -> - when(type){ - WATCH_HIS_SAVE, COLLECTED_SAVE->{ - startActivity<VoiceDetailActivity>("id" to list[position].id) - } - WATCH_HIS_COURSE, COLLECTED_COURSE->{ - showDialog() - HttpManager.getPayCourseInfoById(list[position].id).requestByF(this,success = {_,data-> - dismissDialog() - data?.goDetail(requireContext()) - }){_,_-> - dismissDialog() + adapter.setOnItemClickListener { _, position -> + val courseBean = list[position] + if (adapter.isOrder&&courseBean.paymentStatus == 1) { + HttpManager.payOrder(courseBean.id).requestByF(this){_,data-> + if (type == HAS_BUY_COURSE) + startActivityForResult<BuyCourseActivity>(1,"isSend" to false,"fromDetail" to false,"data" to data) + else + startActivityForResult<BuyVoiceActivity>(1,"fromDetail" to false,"data" to data) + } + }else when(type){ + WATCH_HIS_SAVE, COLLECTED_SAVE, HAS_BUY_VOICE->{ + showDialog() + HttpManager.getMeditationDetails(courseBean.businessId?:"").requestByF(this,success = {_,data-> + dismissDialog() + data?.goDetail(requireContext()) + }){_,_-> + dismissDialog() + } + } + WATCH_HIS_COURSE, COLLECTED_COURSE, HAS_BUY_COURSE->{ + showDialog() + HttpManager.getPayCourseInfoById(courseBean.businessId?:"").requestByF(this,success = { _, data-> + dismissDialog() + data?.goDetail(requireContext()) + }){_,_-> + dismissDialog() + } } } - } } } @@ -68,13 +88,13 @@ HttpManager.lookHistory(pType,page,state).requestByF(this,success = { _, data-> if (page == 1) list.clear() - list.addAll(data?.list?: arrayListOf()) + list.addAll(data?: arrayListOf()) adapter.notifyDataSetChanged() tv_empty.gone() if (list.isEmpty()){ refreshLayout.finishRefreshWithNoMoreData() tv_empty.visible() - } else if (data?.list.isNullOrEmpty()) + } else if (data.isNullOrEmpty()) refreshLayout.finishLoadMoreWithNoMoreData() else if (page == 1) refreshLayout.finishRefresh() @@ -88,6 +108,12 @@ } } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (resultCode == Activity.RESULT_OK) + refreshLayout.autoRefresh() + } + companion object{ const val WATCH_HIS_SAVE = 1 //疗愈观看历史 const val WATCH_HIS_COURSE = 2 //课程观看历史 -- Gitblit v1.7.1