【光环助手V5.5.0】首页顶部tab-游戏单广场 https://git.ghzs.com/pm/halo-app-issues/-/issues/1599

This commit is contained in:
leafwai
2021-11-18 18:26:40 +08:00
parent 020c8d4456
commit e2140f501f
10 changed files with 106 additions and 35 deletions

View File

@ -39,6 +39,7 @@ import com.gh.gamecenter.gamedetail.GameDetailFragment
import com.gh.gamecenter.gamedetail.fuli.kaifu.ServersCalendarActivity
import com.gh.gamecenter.gamedetail.history.HistoryApkListActivity
import com.gh.gamecenter.gamedetail.rating.RatingReplyActivity
import com.gh.gamecenter.gamecollection.square.GameCollectionSquareActivity
import com.gh.gamecenter.manager.UserManager
import com.gh.gamecenter.mygame.PlayedGameActivity
import com.gh.gamecenter.personalhome.UserHomeActivity
@ -1643,4 +1644,18 @@ object DirectUtils {
bundle.putString(KEY_COLLECTION_ID, collectionId)
jumpActivity(context, bundle)
}
/**
* 跳转至游戏单广场
*/
@JvmStatic
fun directToGameCollectionSquare(context: Context, entrance: String = "", forumName: String = "", gameCollectionTitle: String = "", gameCollectionId: String = "") {
val bundle = Bundle()
bundle.putString(KEY_TO, GameCollectionSquareActivity::class.java.name)
bundle.putString(KEY_ENTRANCE, entrance)
bundle.putString(KEY_FORUM_NAME, forumName)
bundle.putString(KEY_GAME_COLLECTION_TITLE, gameCollectionTitle)
bundle.putString(KEY_GAME_COLLECTION_ID, gameCollectionId)
jumpActivity(context, bundle)
}
}

View File

@ -253,6 +253,9 @@ public class EntranceUtils {
public static final String KEY_BLOCK_NAME = "block_name";
public static final String KEY_INSERT_GAME_COLLECTION = "insert_game_collection";
public static final String KEY_IS_FROM_SQUARE = "is_from_square";
public static final String KEY_FORUM_NAME = "forum_name";//版块名称
public static final String KEY_GAME_COLLECTION_TITLE = "game_collection_title";//游戏单标题
public static final String KEY_GAME_COLLECTION_ID = "game_collection_id";//游戏单ID
public static void jumpActivity(Context context, Bundle bundle) {
bundle.putBoolean(KEY_REQUIRE_REDIRECT, true);

View File

@ -10,9 +10,9 @@ import com.lightgame.adapter.BaseRecyclerAdapter
class GameCollectionAmwayAdapter(context: Context) :
BaseRecyclerAdapter<RecyclerView.ViewHolder>(context) {
private var mAmwayList = ArrayList<AmwayCommentEntity>()
private var mAmwayList = listOf<AmwayCommentEntity>()
fun setAmwayList(amwayList: ArrayList<AmwayCommentEntity>) {
fun setAmwayList(amwayList: List<AmwayCommentEntity>) {
mAmwayList = amwayList
notifyDataSetChanged()
}
@ -20,7 +20,7 @@ class GameCollectionAmwayAdapter(context: Context) :
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
GameCollectionAmwayContentItemViewHolder(GameCollectionAmwayContentItemBinding.inflate(mLayoutInflater, parent, false))
override fun getItemCount(): Int = if (getRealCount() > 1) getRealCount() + INCREASE_COUNT else getRealCount()
override fun getItemCount() = if (getRealCount() > 1) getRealCount() + INCREASE_COUNT else getRealCount()
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is GameCollectionAmwayContentItemViewHolder) {

View File

@ -8,18 +8,11 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import com.gh.common.util.DirectUtils
import com.gh.gamecenter.databinding.GameCollectionSquareAmwayItemBinding
import com.gh.gamecenter.entity.AmwayCommentEntity
import java.lang.ref.WeakReference
class GameCollectionAmwayViewHolder(var binding: GameCollectionSquareAmwayItemBinding) : RecyclerView.ViewHolder(binding.root) {
val mAdapter = GameCollectionAmwayAdapter(binding.root.context).apply { registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onChanged() {
if (itemCount <= 1) {
stop()
} else {
start()
}
}
}) }
val mAdapter = GameCollectionAmwayAdapter(binding.root.context)
val mLoopTask = object : Runnable {
private val reference: WeakReference<ViewPager2> = WeakReference(binding.amwayVp)
override fun run() {
@ -29,13 +22,13 @@ class GameCollectionAmwayViewHolder(var binding: GameCollectionSquareAmwayItemBi
if (count == 0) return
val next = (vp.currentItem + 1) % count
vp.setCurrentItem(next, 1000)
vp.postDelayed(this, GameCollectionSquareAdapter.AMWAY_LOOP_TIME)
vp.postDelayed(this, AMWAY_LOOP_TIME)
}
}
}
fun bindAmway() {
fun bindAmway(amwayList: List<AmwayCommentEntity>) {
mAdapter.setAmwayList(amwayList)
binding.amwayVp.run {
if (adapter is GameCollectionAmwayAdapter) return
isUserInputEnabled = false
@ -69,14 +62,14 @@ class GameCollectionAmwayViewHolder(var binding: GameCollectionSquareAmwayItemBi
}
})
setCurrentItem(1, false)
postDelayed(mLoopTask, GameCollectionSquareAdapter.AMWAY_LOOP_TIME)
postDelayed(mLoopTask, AMWAY_LOOP_TIME)
}
binding.root.setOnClickListener { DirectUtils.directToAmway(binding.root.context) }
}
fun start() {
stop()
binding.amwayVp.postDelayed(mLoopTask, GameCollectionSquareAdapter.AMWAY_LOOP_TIME)
binding.amwayVp.postDelayed(mLoopTask, AMWAY_LOOP_TIME)
}
fun stop() {
@ -108,4 +101,9 @@ class GameCollectionAmwayViewHolder(var binding: GameCollectionSquareAmwayItemBi
animator.duration = duration
animator.start()
}
companion object {
// 安利墙卡片轮播时间
const val AMWAY_LOOP_TIME = 5000L
}
}

View File

@ -15,11 +15,13 @@ import com.gh.common.exposure.ExposureEvent
import com.gh.common.exposure.ExposureSource
import com.gh.common.exposure.IExposable
import com.gh.common.util.*
import com.gh.gamecenter.GameDetailActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
import com.gh.gamecenter.baselist.ListAdapter
import com.gh.gamecenter.databinding.GameCollectionSquareAmwayItemBinding
import com.gh.gamecenter.databinding.GameCollectionSquareItemBinding
import com.gh.gamecenter.entity.AmwayCommentEntity
import com.gh.gamecenter.entity.GamesCollectionEntity
import com.gh.gamecenter.gamecollection.detail.GameCollectionDetailActivity
@ -31,6 +33,15 @@ class GameCollectionSquareAdapter(
) :
ListAdapter<GamesCollectionEntity>(context), IExposable {
private var mAmwayList = listOf<AmwayCommentEntity>()
fun setAmwayList(amwayList: List<AmwayCommentEntity>) {
if (isHome) {
mAmwayList = amwayList
notifyItemChanged(0)
}
}
override fun getItemViewType(position: Int): Int {
return if (isHome && position == 0) ItemViewType.ITEM_HEADER else if (position == itemCount - 1) ItemViewType.ITEM_FOOTER else ItemViewType.ITEM_BODY
}
@ -84,7 +95,7 @@ class GameCollectionSquareAdapter(
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) {
is GameCollectionAmwayViewHolder -> {
holder.bindAmway()
holder.bindAmway(mAmwayList)
}
is GameCollectionSquareItemViewHolder -> {
val realPosition = if (isHome) position - 1 else position
@ -144,12 +155,6 @@ class GameCollectionSquareAdapter(
DirectUtils.directToGameDetail(context,
id, "游戏单广场")
} }
playedGameProgress.progress = gamesCollectionEntity.count?.game?.let {
gamesCollectionEntity.count?.playedGame?.div(
it
)
} ?: 0
playedGameTv.text = "玩过 ${gamesCollectionEntity.count?.playedGame} / ${gamesCollectionEntity.count?.game}"
userContainer.setOnClickListener { DirectUtils.directToHomeActivity(context, gamesCollectionEntity.user?.id, 0, "游戏单广场") }
root.setOnClickListener { context.startActivity(GameCollectionDetailActivity.getIntent(context, gamesCollectionEntity.id, true)) }
}
@ -158,9 +163,6 @@ class GameCollectionSquareAdapter(
companion object {
const val INVALID_VALUE = -1
// 安利墙卡片轮播时间
const val AMWAY_LOOP_TIME = 5000L
}
override fun getEventByPosition(pos: Int): ExposureEvent? {

View File

@ -1,5 +1,6 @@
package com.gh.gamecenter.gamecollection.square
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.os.Bundle
@ -39,9 +40,15 @@ class GameCollectionSquareFragment : LazyListFragment<GamesCollectionEntity, Gam
private var mAdapter: GameCollectionSquareAdapter? = null
private var mUseAlternativeLayout = false
private var mForumName = ""
private var mGameCollectionTitle = ""
private var mGameCollectionId = ""
override fun onCreate(savedInstanceState: Bundle?) {
mUseAlternativeLayout = arguments?.getBoolean(EntranceUtils.KEY_IS_HOME, false) ?: false
mForumName = arguments?.getString(EntranceUtils.KEY_FORUM_NAME, "") ?: ""
mGameCollectionTitle = arguments?.getString(EntranceUtils.KEY_GAME_COLLECTION_TITLE, "") ?: ""
mGameCollectionId = arguments?.getString(EntranceUtils.KEY_GAME_COLLECTION_ID, "") ?: ""
super.onCreate(savedInstanceState)
}
@ -54,6 +61,8 @@ class GameCollectionSquareFragment : LazyListFragment<GamesCollectionEntity, Gam
override fun onFragmentFirstVisible() {
super.onFragmentFirstVisible()
mViewModel.entrance = mEntrance
mViewModel.isHome = mUseAlternativeLayout
}
override fun onRealLayoutInflated(inflatedView: View) {
@ -186,6 +195,10 @@ class GameCollectionSquareFragment : LazyListFragment<GamesCollectionEntity, Gam
}
}
mViewModel.mAmwayCommentList.observe(this) {
mAdapter?.setAmwayList(it)
}
// mSkeletonScreen = Skeleton.bind(mAlternativeBinding?.skeletonPlaceholder).shimmer(false).load(
// R.layout.fragment_amway_skeleton_al).show()
}
@ -195,6 +208,7 @@ class GameCollectionSquareFragment : LazyListFragment<GamesCollectionEntity, Gam
// mElapsedHelper.pauseCounting()
}
@SuppressLint("NotifyDataSetChanged")
override fun onResume() {
if (isEverPause) mAdapter?.notifyDataSetChanged()
super.onResume()
@ -224,6 +238,7 @@ class GameCollectionSquareFragment : LazyListFragment<GamesCollectionEntity, Gam
override fun onLoadRefresh() {
super.onLoadRefresh()
if (!mUseAlternativeLayout) mDefaultBinding.tagFilterContainer.visibility = View.VISIBLE
mViewModel.getAmwayCommentList()
}
private fun scrollToTop() {

View File

@ -1,12 +1,17 @@
package com.gh.gamecenter.gamecollection.square
import android.annotation.SuppressLint
import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.gh.gamecenter.baselist.ListViewModel
import com.gh.gamecenter.entity.AmwayCommentEntity
import com.gh.gamecenter.entity.GamesCollectionEntity
import com.gh.gamecenter.retrofit.BiResponse
import com.gh.gamecenter.retrofit.RetrofitManager
import io.reactivex.Observable
import io.reactivex.Single
import java.util.HashMap
import io.reactivex.schedulers.Schedulers
import java.util.*
class GameCollectionSquareViewModel(application: Application) :
ListViewModel<GamesCollectionEntity, GamesCollectionEntity>(application) {
@ -14,13 +19,35 @@ class GameCollectionSquareViewModel(application: Application) :
var entrance: String? = null
var tagId = ""
var view = "hot"
var isHome = false
override fun provideDataSingle(page: Int): Single<MutableList<GamesCollectionEntity>> = RetrofitManager.getInstance(getApplication())
.api.getGameCollectionSquareList(view, tagId, page)
val mAmwayCommentList = MutableLiveData<List<AmwayCommentEntity>>()
init {
getAmwayCommentList()
}
override fun provideDataSingle(page: Int): Single<MutableList<GamesCollectionEntity>> =
if (isHome) RetrofitManager.getInstance(getApplication())
.api.getHomeGameCollectionSquareList(UUID.randomUUID().toString(), page)
else RetrofitManager.getInstance(getApplication())
.api.getGameCollectionSquareList(view, tagId, page)
override fun mergeResultLiveData() {
mResultLiveData.addSource(mListLiveData) { mResultLiveData.postValue(it) }
}
override fun provideDataObservable(page: Int): Observable<MutableList<GamesCollectionEntity>>? = null
@SuppressLint("CheckResult")
fun getAmwayCommentList() {
RetrofitManager.getInstance(getApplication()).api
.getAmwayCommentList(1, 10)
.subscribeOn(Schedulers.io())
.subscribe(object : BiResponse<List<AmwayCommentEntity>>() {
override fun onSuccess(data: List<AmwayCommentEntity>) {
mAmwayCommentList.postValue(data)
}
})
}
}

View File

@ -3354,4 +3354,10 @@ public interface ApiService {
*/
@POST("game_lists/{game_list_id}:unvote")
Single<ResponseBody> unVoteGameCollection(@Path("game_list_id") String id);
/**
* 获取首页tab游戏单广场列表
*/
@GET("game_lists?view=hot")
Single<List<GamesCollectionEntity>> getHomeGameCollectionSquareList(@Query("random") String id, @Query("page") int page);
}