添加简单首页列表项占位

This commit is contained in:
juntao
2022-05-31 20:44:41 +08:00
parent 477ffa0c33
commit 83afd7448f
6 changed files with 48 additions and 28 deletions

View File

@ -66,7 +66,6 @@ public class DownloadManagerActivity extends ToolBarActivity {
return true;
}
@Override
protected void onNightModeChange() {
super.onNightModeChange();

View File

@ -273,7 +273,6 @@ class HomeFragment : LazyFragment() {
@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(status: EBDownloadStatus) {
if ("delete" == status.status) {
// TODO 看看能不能避免粗暴地更新列表
mViewModel.refreshRecentVGameIfNeeded()
mListAdapter.notifyItemAndRemoveDownload(status)
}

View File

@ -9,10 +9,8 @@ import androidx.recyclerview.widget.RecyclerView
import com.gh.common.exposure.ExposureEvent
import com.gh.common.exposure.ExposureSource
import com.gh.common.exposure.IExposable
import com.gh.gamecenter.core.runOnIoThread
import com.gh.common.util.*
import com.gh.common.util.NewLogUtils
import com.gh.common.util.DirectUtils
import com.gh.common.util.NewLogUtils
import com.gh.gamecenter.AboutActivity
import com.gh.gamecenter.GameDetailActivity
import com.gh.gamecenter.R
@ -21,7 +19,6 @@ import com.gh.gamecenter.adapter.viewholder.ReuseViewHolder
import com.gh.gamecenter.baselist.DiffUtilAdapter
import com.gh.gamecenter.baselist.LoadStatus
import com.gh.gamecenter.common.constant.ItemViewType
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.core.runOnIoThread
import com.gh.gamecenter.core.utils.MtaHelper
@ -37,6 +34,7 @@ import com.gh.gamecenter.home.gamecollection.HomeGameCollectionViewHolder
import com.gh.gamecenter.home.slide.HomeSlideListAdapter
import com.gh.gamecenter.home.slide.HomeSlideListViewHolder
import com.gh.gamecenter.video.detail.VideoDetailContainerViewModel
import com.gh.vspace.HomeRecentVGameAdapter
import com.gh.vspace.HomeRecentVGameViewHolder
import com.halo.assistant.fragment.game.GamePluginAdapter
import com.lightgame.download.DownloadEntity
@ -387,10 +385,11 @@ class HomeFragmentAdapter(
val entryMap = gameAndPosition.entity.getEntryMap()
entryMap[download.platform] = download
}
if (getItemViewType(gameAndPosition.position) == ItemViewType.VERTICAL_SLIDE_ITEM ||
getItemViewType(gameAndPosition.position) == ItemViewType.GAME_PLUGIN ||
getItemViewType(gameAndPosition.position) == SLIDE_ITEM ||
getItemViewType(gameAndPosition.position) == ItemViewType.RANK_COLLECTION
if (getItemViewType(gameAndPosition.position) == ItemViewType.VERTICAL_SLIDE_ITEM
|| getItemViewType(gameAndPosition.position) == ItemViewType.GAME_PLUGIN
|| getItemViewType(gameAndPosition.position) == SLIDE_ITEM
|| getItemViewType(gameAndPosition.position) == ItemViewType.RANK_COLLECTION
|| getItemViewType(gameAndPosition.position) == RECENT_V_GAME
) {
val view = layoutManager.findViewByPosition(gameAndPosition.position)
val recyclerView = view?.findViewById<RecyclerView>(R.id.recycler_view)
@ -399,6 +398,7 @@ class HomeFragmentAdapter(
is GamePluginAdapter -> adapter.notifyItemByDownload(download)
is HomeSlideListAdapter -> adapter.notifyItemByDownload(download)
is RankCollectionAdapter -> adapter.notifyItemByDownload(download)
is HomeRecentVGameAdapter -> adapter.notifyItemByDownload(download)
}
} else {
notifyItemChanged(gameAndPosition.position)

View File

@ -307,7 +307,7 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
}
fun transformationItemData() {
runOnIoThread {
runOnIoThread(true) {
mSnapshotItemList.clear()
// 是否使用带特别高的带分割线的 item

View File

@ -4,37 +4,52 @@ import android.content.Context
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.gh.download.DownloadManager
import com.gh.gamecenter.baselist.DiffUtilAdapter
import com.gh.gamecenter.common.utils.toBinding
import com.gh.gamecenter.core.runOnIoThread
import com.gh.gamecenter.databinding.ItemHomeRecentVgameBinding
import com.gh.gamecenter.databinding.ItemHomeVgameBinding
import com.gh.gamecenter.entity.GameEntity
import com.lightgame.download.DownloadEntity
class HomeRecentVGameViewHolder(var binding: ItemHomeRecentVgameBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bindView(gameList: ArrayList<GameEntity>) {
if (binding.recyclerview.adapter == null) {
binding.recyclerview.layoutManager = LinearLayoutManager(binding.root.context)
binding.recyclerview.adapter = HomeRecentVGameAdapter(binding.root.context)
if (binding.recyclerView.adapter == null) {
binding.recyclerView.layoutManager = LinearLayoutManager(binding.root.context)
binding.recyclerView.adapter = HomeRecentVGameAdapter(binding.root.context)
}
(binding.recyclerview.adapter as? HomeRecentVGameAdapter)?.submitList(gameList)
(binding.recyclerView.adapter as? HomeRecentVGameAdapter)?.submitList(gameList)
}
}
class HomeRecentVGameAdapter(context: Context) : DiffUtilAdapter<GameEntity>(context) {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): HomeRecentVGameItemViewHolder {
return HomeRecentVGameItemViewHolder(parent.toBinding())
}
class HomeRecentVGameAdapter(context: Context) : DiffUtilAdapter<GameEntity>(context) {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): HomeRecentVGameItemViewHolder {
return HomeRecentVGameItemViewHolder(parent.toBinding())
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
(holder as HomeRecentVGameItemViewHolder).bindView(mDataList[position])
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
(holder as HomeRecentVGameItemViewHolder).bindView(mDataList[position])
}
override fun getItemCount() = mDataList.size
override fun getItemCount() = mDataList.size
fun notifyItemByDownload(downloadEntity: DownloadEntity?) {
if (downloadEntity == null) {
notifyDataSetChanged()
} else {
for (position in mDataList.indices) {
if (downloadEntity.name == mDataList[position].name) {
notifyItemChanged(position)
}
}
}
}
class HomeRecentVGameItemViewHolder(private var mBinding: ItemHomeVgameBinding) :
@ -42,11 +57,18 @@ class HomeRecentVGameViewHolder(var binding: ItemHomeRecentVgameBinding) :
fun bindView(gameEntity: GameEntity) {
mBinding.gameIconIv.displayGameIcon(gameEntity)
runOnIoThread(true) {
DownloadManager.getInstance().allVDownloadTask.find {
it.gameId == gameEntity.id
}
// TODO 添加 item 下载更新逻辑
}
mBinding.root.setOnClickListener {
VHelper.launch(mBinding.root.context, gameEntity.getUniquePackageName() ?: "")
}
}
}
}