diff --git a/app/src/main/java/com/gh/common/util/DirectUtils.kt b/app/src/main/java/com/gh/common/util/DirectUtils.kt index c90bfd057b..c18247d085 100644 --- a/app/src/main/java/com/gh/common/util/DirectUtils.kt +++ b/app/src/main/java/com/gh/common/util/DirectUtils.kt @@ -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) + } } \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/util/EntranceUtils.java b/app/src/main/java/com/gh/common/util/EntranceUtils.java index b14e8c2c90..a22498e824 100644 --- a/app/src/main/java/com/gh/common/util/EntranceUtils.java +++ b/app/src/main/java/com/gh/common/util/EntranceUtils.java @@ -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); diff --git a/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionAmwayAdapter.kt b/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionAmwayAdapter.kt index dd8ec0761b..0a5d504f94 100644 --- a/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionAmwayAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionAmwayAdapter.kt @@ -10,9 +10,9 @@ import com.lightgame.adapter.BaseRecyclerAdapter class GameCollectionAmwayAdapter(context: Context) : BaseRecyclerAdapter(context) { - private var mAmwayList = ArrayList() + private var mAmwayList = listOf() - fun setAmwayList(amwayList: ArrayList) { + fun setAmwayList(amwayList: List) { 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) { diff --git a/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionAmwayViewHolder.kt b/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionAmwayViewHolder.kt index 479a51ad92..60e7326ee9 100644 --- a/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionAmwayViewHolder.kt +++ b/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionAmwayViewHolder.kt @@ -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 = 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) { + 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 + } } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionSquareAdapter.kt b/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionSquareAdapter.kt index e1c7f447b3..b09f8ee67b 100644 --- a/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionSquareAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionSquareAdapter.kt @@ -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(context), IExposable { + private var mAmwayList = listOf() + + fun setAmwayList(amwayList: List) { + 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? { diff --git a/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionSquareFragment.kt b/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionSquareFragment.kt index e2ca7dd304..f623c1df81 100644 --- a/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionSquareFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/gamecollection/square/GameCollectionSquareFragment.kt @@ -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(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> = RetrofitManager.getInstance(getApplication()) - .api.getGameCollectionSquareList(view, tagId, page) + val mAmwayCommentList = MutableLiveData>() + + init { + getAmwayCommentList() + } + + override fun provideDataSingle(page: Int): Single> = + 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>? = null + + @SuppressLint("CheckResult") + fun getAmwayCommentList() { + RetrofitManager.getInstance(getApplication()).api + .getAmwayCommentList(1, 10) + .subscribeOn(Schedulers.io()) + .subscribe(object : BiResponse>() { + override fun onSuccess(data: List) { + mAmwayCommentList.postValue(data) + } + }) + } } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java index b5e4a5b990..184ee5ae1c 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java @@ -3354,4 +3354,10 @@ public interface ApiService { */ @POST("game_lists/{game_list_id}:unvote") Single unVoteGameCollection(@Path("game_list_id") String id); + + /** + * 获取首页tab游戏单广场列表 + */ + @GET("game_lists?view=hot") + Single> getHomeGameCollectionSquareList(@Query("random") String id, @Query("page") int page); } \ No newline at end of file diff --git a/app/src/main/res/layout/game_collection_amway_content_item.xml b/app/src/main/res/layout/game_collection_amway_content_item.xml index 68fbd48317..64f2975c85 100644 --- a/app/src/main/res/layout/game_collection_amway_content_item.xml +++ b/app/src/main/res/layout/game_collection_amway_content_item.xml @@ -1,5 +1,6 @@ @@ -16,10 +17,11 @@ android:orientation="horizontal"> + android:layout_height="16dp" + app:gameIconCornerRadius="4dp" /> diff --git a/app/src/main/res/layout/game_collection_square_item.xml b/app/src/main/res/layout/game_collection_square_item.xml index dac3cae5b9..b9d01c3e24 100644 --- a/app/src/main/res/layout/game_collection_square_item.xml +++ b/app/src/main/res/layout/game_collection_square_item.xml @@ -204,6 +204,7 @@ @@ -255,7 +256,8 @@ style="@style/Widget.AppCompat.ProgressBar.Horizontal" android:layout_width="100dp" android:layout_height="10dp" - android:max="100" + android:max="@{entity.count.game}" + android:progress="@{entity.count.playedGame}" android:progressDrawable="@drawable/progressbar_game_collection" />