新增资源位相关逻辑
This commit is contained in:
@@ -6,10 +6,9 @@ import com.yizhuan.erban.base.BaseViewModel
|
||||
import com.yizhuan.xchat_android_core.bean.response.ListResult
|
||||
import com.yizhuan.xchat_android_core.home.bean.*
|
||||
import com.yizhuan.xchat_android_core.home.model.HomeModel
|
||||
import com.yizhuan.xchat_android_library.utils.SingleToastUtil
|
||||
import com.yizhuan.xchat_android_core.utils.toast
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class HomeViewModel : BaseViewModel() {
|
||||
|
||||
@@ -22,8 +21,10 @@ class HomeViewModel : BaseViewModel() {
|
||||
private val _concernsLiveData = MutableLiveData<List<HomeConcernsInfo>>()
|
||||
val concernsLiveData: LiveData<List<HomeConcernsInfo>> = _concernsLiveData
|
||||
|
||||
private val _collectLiveData = MutableLiveData<ListResult<CollectionRoomInfo.FansRoomListBean>>()
|
||||
val collectLiveData: LiveData<ListResult<CollectionRoomInfo.FansRoomListBean>> = _collectLiveData
|
||||
private val _collectLiveData =
|
||||
MutableLiveData<ListResult<CollectionRoomInfo.FansRoomListBean>>()
|
||||
val collectLiveData: LiveData<ListResult<CollectionRoomInfo.FansRoomListBean>> =
|
||||
_collectLiveData
|
||||
|
||||
|
||||
private val _tagLiveData = MutableLiveData<List<HomeTagInfo>>()
|
||||
@@ -35,6 +36,12 @@ class HomeViewModel : BaseViewModel() {
|
||||
private val _emptyLiveData = MutableLiveData<Boolean>()
|
||||
val emptyLiveData: LiveData<Boolean> = _emptyLiveData
|
||||
|
||||
private val _resourceLiveData = MutableLiveData<List<ResourceInfo>>()
|
||||
val resourceLiveData: LiveData<List<ResourceInfo>> = _resourceLiveData
|
||||
|
||||
private val _resourceJumpLiveData = MutableLiveData<List<ResourceInfo>>()
|
||||
val resourceJumpLiveData: LiveData<List<ResourceInfo>> = _resourceJumpLiveData
|
||||
|
||||
fun getBannerInfo() {
|
||||
safeLaunch {
|
||||
_bannerLiveData.value = HomeModel.getHomeBanner("9")
|
||||
@@ -47,6 +54,25 @@ class HomeViewModel : BaseViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getHomeResource() {
|
||||
safeLaunch {
|
||||
_resourceLiveData.value = HomeModel.getHomeResource()
|
||||
}
|
||||
}
|
||||
|
||||
fun getResourceJumpInfo(id: Int) {
|
||||
safeLaunch(
|
||||
onError = {
|
||||
_resourceJumpLiveData.value = null
|
||||
it.message.toast()
|
||||
},
|
||||
block = {
|
||||
_resourceJumpLiveData.value = HomeModel.getResourceJumpInfo(id)
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
fun getHotRoom(pageNum: Int, pageSize: Int) {
|
||||
safeLaunch(
|
||||
onError = {
|
||||
@@ -87,7 +113,8 @@ class HomeViewModel : BaseViewModel() {
|
||||
HomeModel.getCollectRoom(pageNum, pageSize)
|
||||
}
|
||||
_concernsLiveData.value = concernsRooms.await()
|
||||
_collectLiveData.value = ListResult.success(collectRooms.await()?.fansRoomList, pageNum)
|
||||
_collectLiveData.value =
|
||||
ListResult.success(collectRooms.await()?.fansRoomList, pageNum)
|
||||
_emptyLiveData.value = concernsRooms.await().isNullOrEmpty() &&
|
||||
collectRooms.await()?.fansRoomList.isNullOrEmpty()
|
||||
} else {
|
||||
|
@@ -2,9 +2,9 @@ package com.yizhuan.erban.home.fragment
|
||||
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isGone
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
@@ -16,6 +16,7 @@ import com.yizhuan.erban.databinding.FragmentRecommendBinding
|
||||
import com.yizhuan.erban.home.HomeViewModel
|
||||
import com.yizhuan.erban.home.adapter.MainMagicIndicatorAdapter
|
||||
import com.yizhuan.erban.home.helper.BannerHelper
|
||||
import com.yizhuan.erban.ui.utils.load
|
||||
import com.yizhuan.erban.ui.widget.magicindicator.ViewPagerHelper
|
||||
import com.yizhuan.erban.ui.widget.magicindicator.buildins.commonnavigator.CommonNavigator
|
||||
import com.yizhuan.xchat_android_core.home.event.RefreshHomeDataEvent
|
||||
@@ -30,7 +31,7 @@ import java.util.*
|
||||
/**
|
||||
* 音游首页
|
||||
*/
|
||||
class RecommendFragment : BaseFragment(), View.OnClickListener,
|
||||
class RecommendFragment : BaseFragment(),
|
||||
MainMagicIndicatorAdapter.OnItemSelectListener {
|
||||
private lateinit var mBinding: FragmentRecommendBinding
|
||||
private var mFragmentsBottom: MutableList<Fragment> = ArrayList()
|
||||
@@ -46,30 +47,19 @@ class RecommendFragment : BaseFragment(), View.OnClickListener,
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
EventBus.getDefault().unregister(this)
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
|
||||
}
|
||||
|
||||
override fun getRootLayoutId(): Int {
|
||||
return R.layout.fragment_recommend
|
||||
}
|
||||
|
||||
|
||||
override fun onFindViews() {
|
||||
mBinding = DataBindingUtil.bind(mView)!!
|
||||
}
|
||||
|
||||
override fun onSetListener() {
|
||||
mBinding.click = this
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
homeViewModel.getBannerInfo()
|
||||
homeViewModel.getHomeResource()
|
||||
}
|
||||
|
||||
override fun initiate() {
|
||||
@@ -80,10 +70,37 @@ class RecommendFragment : BaseFragment(), View.OnClickListener,
|
||||
.replace(R.id.fg_recommend_room, HomeTabHomeFragment.newInstance(0))
|
||||
.commitAllowingStateLoss()
|
||||
|
||||
homeViewModel.getBannerInfo()
|
||||
homeViewModel.bannerLiveData.observe(this) {
|
||||
BannerHelper.setBanner(mBinding.rollView, it)
|
||||
}
|
||||
|
||||
homeViewModel.resourceLiveData.observe(this) {
|
||||
if (it.isNullOrEmpty() || it.size != 3) {
|
||||
mBinding.llResource.isGone = true
|
||||
return@observe
|
||||
}
|
||||
mBinding.llResource.isGone = false
|
||||
val resourceViews = arrayOf(
|
||||
mBinding.ivResource0,
|
||||
mBinding.ivResource1,
|
||||
mBinding.ivResource2
|
||||
)
|
||||
for (i in resourceViews.indices) {
|
||||
resourceViews[i].load(it[i].icon)
|
||||
resourceViews[i].setOnClickListener { _ ->
|
||||
dialogManager.showProgressDialog(mContext)
|
||||
homeViewModel.getResourceJumpInfo(it[i].id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
homeViewModel.resourceJumpLiveData.observe(this){
|
||||
dialogManager.dismissDialog()
|
||||
it?.let {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mBinding.tvMore.setOnClickListener {
|
||||
(parentFragment as HomeFragment).onItemSelect(1, null)
|
||||
}
|
||||
@@ -104,14 +121,6 @@ class RecommendFragment : BaseFragment(), View.OnClickListener,
|
||||
mBinding.refreshHeader.progressView.setImageDrawable(progressDrawable)
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onRefreshHomeDataEvent(event: RefreshHomeDataEvent?) {
|
||||
homeViewModel.getBannerInfo()
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化动态和聊天交友tab
|
||||
*/
|
||||
private fun initTitleTab() {
|
||||
val tagList = InitialModel.get().cacheInitInfo?.homeTabList.let {
|
||||
if (it?.size == 2) it else arrayListOf("组队开黑", "热门房间")
|
||||
@@ -146,4 +155,22 @@ class RecommendFragment : BaseFragment(), View.OnClickListener,
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onRefreshHomeDataEvent(event: RefreshHomeDataEvent?) {
|
||||
homeViewModel.getBannerInfo()
|
||||
homeViewModel.getHomeResource()
|
||||
}
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
EventBus.getDefault().unregister(this)
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -69,6 +69,7 @@
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_resource"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
|
@@ -0,0 +1,10 @@
|
||||
package com.yizhuan.xchat_android_core.home.bean
|
||||
|
||||
data class ResourceInfo(
|
||||
val icon: String? = null,
|
||||
val id: Int = 0,
|
||||
val posSeq: Int? = null,
|
||||
val resourceContent: String? = null,
|
||||
val resourceType: Int? = null,
|
||||
val strategySeq: Int? = null
|
||||
)
|
@@ -99,6 +99,16 @@ object HomeModel : BaseModel() {
|
||||
api.getHotRoom()
|
||||
}
|
||||
|
||||
suspend fun getHomeResource(): List<ResourceInfo>? =
|
||||
launchRequest {
|
||||
api.getHomeResource()
|
||||
}
|
||||
|
||||
suspend fun getResourceJumpInfo(id: Int): List<ResourceInfo>? =
|
||||
launchRequest {
|
||||
api.getResourceJumpInfo(id)
|
||||
}
|
||||
|
||||
suspend fun getCommonRoom(tabId: Int, pageNum: Int, pageSize: Int): List<HomeRoomInfo>? =
|
||||
launchRequest {
|
||||
api.getCommonRoom(tabId, pageNum, pageSize)
|
||||
@@ -186,6 +196,22 @@ object HomeModel : BaseModel() {
|
||||
@GET("/home/hotRoom")
|
||||
suspend fun getHotRoom(): ServiceResult<List<HomeRoomInfo>>
|
||||
|
||||
/**
|
||||
* 首页资源位
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET("/home/currentResource")
|
||||
suspend fun getHomeResource(): ServiceResult<List<ResourceInfo>>
|
||||
|
||||
/**
|
||||
* 首页资源位跳转
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET("/home/pickResource")
|
||||
suspend fun getResourceJumpInfo(@Query("id") id: Int): ServiceResult<List<ResourceInfo>>
|
||||
|
||||
/**
|
||||
* 首页热门房间
|
||||
*
|
||||
|
Reference in New Issue
Block a user