diff --git a/app/src/main/java/com/gh/common/util/DialogUtils.java b/app/src/main/java/com/gh/common/util/DialogUtils.java index 354b7ca21b..f19613d264 100644 --- a/app/src/main/java/com/gh/common/util/DialogUtils.java +++ b/app/src/main/java/com/gh/common/util/DialogUtils.java @@ -29,12 +29,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; -import androidx.core.content.ContextCompat; -import androidx.databinding.DataBindingUtil; -import androidx.recyclerview.widget.RecyclerView; - import com.facebook.drawee.generic.GenericDraweeHierarchy; import com.gh.common.AppExecutor; import com.gh.common.constant.Config; @@ -63,6 +57,12 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.core.content.ContextCompat; +import androidx.databinding.DataBindingUtil; +import androidx.recyclerview.widget.RecyclerView; + public class DialogUtils { public static Dialog showWaitDialog(Context context, String msg) { @@ -1305,6 +1305,28 @@ public class DialogUtils { content.addView(view); } + public static void showKaifuRemindDialog(Context context, String content) { + context = checkDialogContext(context); + + final Dialog dialog = new Dialog(context, R.style.GhAlertDialog); + + View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_kaifu_remind, null); + + TextView contentTv = contentView.findViewById(R.id.contentTv); + contentTv.setText(Html.fromHtml(content)); + TextView ok = contentView.findViewById(R.id.dialog_ok); + ok.setOnClickListener(v -> dialog.dismiss()); + + Window window = dialog.getWindow(); + if (window != null) { + window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + } + + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.setContentView(contentView); + dialog.show(); + } + /** * @param context may be is application context * @return activity context diff --git a/app/src/main/java/com/gh/common/view/MaxHeightNestedScrollView.kt b/app/src/main/java/com/gh/common/view/MaxHeightNestedScrollView.kt new file mode 100644 index 0000000000..39148051a0 --- /dev/null +++ b/app/src/main/java/com/gh/common/view/MaxHeightNestedScrollView.kt @@ -0,0 +1,29 @@ +package com.gh.common.view + +import android.content.Context +import android.util.AttributeSet +import androidx.core.widget.NestedScrollView +import com.gh.gamecenter.R + + +class MaxHeightNestedScrollView(context: Context, attrs: AttributeSet? = null) : NestedScrollView(context, attrs) { + + var maxHeight = 0F + + init { + val typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaxHeightNestedScrollView) + maxHeight = typedArray.getDimension(R.styleable.MaxHeightNestedScrollView_mMaxHeight, 0f) + typedArray.recycle() + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + var newHeightMeasureSpec = 0 + try { + newHeightMeasureSpec = MeasureSpec.makeMeasureSpec(maxHeight.toInt(), MeasureSpec.AT_MOST) + } catch (e: Exception) { + e.printStackTrace() + } + //重新计算控件高、宽 + super.onMeasure(widthMeasureSpec, newHeightMeasureSpec) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailViewModel.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailViewModel.kt index 9374dcc5f5..f2df84f764 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailViewModel.kt @@ -53,7 +53,6 @@ class GameDetailViewModel(application: Application, filterGameTags() gameLiveData.value = Resource.success(game) -// getUnifiedGameDetail() getGameDetailNew() } gameId != null -> getGameDigest() @@ -75,7 +74,6 @@ class GameDetailViewModel(application: Application, game = response filterGameTags() gameLiveData.postValue(Resource.success(game)) -// getUnifiedGameDetail() getGameDetailNew() } @@ -101,51 +99,6 @@ class GameDetailViewModel(application: Application, } } - // 获取游戏详情 (包括了包括 游戏文章,游戏工具箱,游戏礼包 等游戏相关内容但不包含用户([MeEntity])相关内容) - /*@SuppressLint("CheckResult") - private fun getUnifiedGameDetail() { - mApi.getUnifiedGameDetail(game?.id) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(object : BiResponse() { - override fun onSuccess(data: UnifiedGameDetailEntity) { - data.game.id = game?.id - - // 过滤过期公告 - if (!data.game.notice.isNullOrEmpty()) { - val l = System.currentTimeMillis() - var i = 0 - while (i < data.game.notice!!.size) { - if (l > data.game.notice!![i].overtime * 1000) { - data.game.notice!!.removeAt(i) - i-- - } - i++ - } - } - - // 4.4以下设备不显示顶部视频 - displayTopVideo = data.game.topVideo != null - && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT - - unifiedGameDetailLiveData.postValue(Resource.success(data)) - - if (CheckLoginUtils.isLogin()) { - getUserRelatedInfo(data) - } else { - // 初始化礼包按钮状态 - data.libao?.let { loadLiBaoStatus(data, it) } - } - } - - override fun onFailure(exception: Exception) { - if (exception is HttpException) { - unifiedGameDetailLiveData.postValue(Resource.error(exception)) - } - } - }) - }*/ - @SuppressLint("CheckResult") fun getGameDetailNew() { mApi.getGameDetailNew(game?.id) @@ -162,7 +115,6 @@ class GameDetailViewModel(application: Application, getUserRelatedInfo(data) } else { // 初始化礼包按钮状态 -// data.libao?.let { loadLiBaoStatus(data, it) } for (entity in data.detailEntity) { if (entity.type == "libao") { if (entity.libao != null) { @@ -188,26 +140,6 @@ class GameDetailViewModel(application: Application, */ @SuppressLint("CheckResult") private fun getUserRelatedInfo(newGameDetailEntity: NewGameDetailEntity) { - /*val toolkitIdList = arrayListOf() - unifiedGameDetailEntity.toolkits?.let { - for (toolkit in it) { - toolkitIdList.add(toolkit.id ?: "") - } - } - - val libaoIdList = arrayListOf() - unifiedGameDetailEntity.libao?.let { - for (libao in it) { - libaoIdList.add(libao.id ?: "") - } - } - - val answerIdList = arrayListOf() - unifiedGameDetailEntity.communityColumnContents?.let { - for (answer in it) { - answerIdList.add(answer.id ?: "") - } - }*/ val libaoIdList = arrayListOf() val toolkitIdList = arrayListOf() val answerIdList = arrayListOf() diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescAdapter.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescAdapter.kt index 455505c6df..b087056424 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescAdapter.kt @@ -9,9 +9,11 @@ import android.widget.LinearLayout import android.widget.TextView import androidx.core.content.ContextCompat import androidx.databinding.DataBindingUtil +import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.gh.base.OnListClickListener import com.gh.common.util.* import com.gh.common.view.GridSpacingItemColorDecoration import com.gh.common.view.HorizontalItemDecoration @@ -22,11 +24,10 @@ import com.gh.gamecenter.SuggestionActivity import com.gh.gamecenter.adapter.viewholder.FooterViewHolder import com.gh.gamecenter.adapter.viewholder.GameDetailIntroViewHolder import com.gh.gamecenter.adapter.viewholder.GameDetailPluginViewHolder -import com.gh.gamecenter.adapter.viewholder.ReuseViewHolder import com.gh.gamecenter.databinding.* import com.gh.gamecenter.entity.* import com.gh.gamecenter.eventbus.EBReuse -import com.gh.gamecenter.game.horizontal.GameHorizontalListViewHolder +import com.gh.gamecenter.game.horizontal.GameHorizontalAdapter import com.gh.gamecenter.gamedetail.GameDetailFragment import com.gh.gamecenter.gamedetail.entity.DetailEntity import com.gh.gamecenter.gamedetail.entity.GameInfo @@ -38,7 +39,8 @@ import org.greenrobot.eventbus.EventBus class DescAdapter(context: Context, private val mEntrance: String, - private val mViewModel: DescViewModel) + private val mViewModel: DescViewModel, + private val mListListener: OnListClickListener?) : BaseRecyclerAdapter(context) { var gameName: String? = mViewModel.game?.name ?: "unknown" @@ -56,44 +58,11 @@ class DescAdapter(context: Context, fun updateDescItemList(descItemList: ArrayList) { this.descItemList = descItemList - gameList.clear() - /*for (descItem in this.descItemList) { - if (descItem.recommendedGames != null && descItem.recommendedGames?.data != null) { - for (game in descItem.recommendedGames!!.data!!) { - gameList.add(game) - } - } - }*/ notifyDataSetChanged() } override fun getItemViewType(position: Int): Int { val descItemData = descItemList[position] - /* return if (descItemData.intro != null) { - INTRO - } else if (descItemData.recommendedGames != null) { - RECOMMENDED_GAMES - } else if (descItemData.relatedVersion != null) { - RELATED_VERSION - } else if (descItemData.customColumn != null) { - CUSTOM_COLUMN - } else if (!TextUtils.isEmpty(descItemData.header)) { - HEADER - } else if (descItemData.recommendedImage != null) { - IMAGE - } else if (descItemData.comments != null) { - COMMENTS - } else if (descItemData.videos != null) { - VIDEOS - } else if (descItemData.gallery != null) { - IMAGE_GALLERY - } else if (descItemData.updateContent != null) { - UPDATE_CONTENT - } else if (descItemData.server != null) { - LATEST_SERVICE - } else { - FOOTER - }*/ return when (descItemData.type) { "gallery" -> IMAGE_GALLERY "video" -> VIDEOS @@ -105,6 +74,7 @@ class DescAdapter(context: Context, "image_recommend" -> IMAGE "libao" -> LIBAO "article" -> INFO_RAIDERS + "related_game" -> RECOMMENDED_GAMES else -> FOOTER } } @@ -115,14 +85,6 @@ class DescAdapter(context: Context, val view = mLayoutInflater.inflate(R.layout.gamedetail_item_intro, parent, false) GameDetailIntroViewHolder(view) } - HEADER -> { - val view = mLayoutInflater.inflate(R.layout.gamedetail_item_header, parent, false) - GameDetailHeaderViewHolder(view) - } - RECOMMENDED_GAMES -> { - val binding = GameHorizontalListBinding.bind(mLayoutInflater.inflate(R.layout.game_horizontal_list, parent, false)) - GameHorizontalListViewHolder(binding) - } COMMENTS -> { GameDetailCommentsViewHolder(DataBindingUtil.inflate(mLayoutInflater, R.layout.gamedetail_item_comments, parent, false)) } @@ -159,6 +121,9 @@ class DescAdapter(context: Context, GAME_DETAIL -> { GameDetailInfoViewHolder(DataBindingUtil.inflate(mLayoutInflater, R.layout.game_detail_info, parent, false)) } + RECOMMENDED_GAMES -> { + GamesRecommendedGalleryViewHolder(DataBindingUtil.inflate(mLayoutInflater, R.layout.game_gallery_list, parent, false)) + } FOOTER -> { val view = mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false) FooterViewHolder(view) @@ -173,19 +138,17 @@ class DescAdapter(context: Context, override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { when (holder) { // is GameDetailIntroViewHolder -> initIntroViewHolder(holder, descItemList[position]) -// -// is GameHorizontalListViewHolder -> bindGameHorizontalListView(holder, position) -// - is GameDetailRecommendImageViewHolder -> bindImageViewHolder(holder, descItemList[position].imageRecommend) -// - is GameDetailCommentsViewHolder -> bindCommentsViewHolder(holder, descItemList[position].comment) -// + // is GameDetailCustomColumnViewHolder -> bindCustomColumnViewHolder(holder, descItemList[position]) -// -// is GameDetailHeaderViewHolder -> holder.bindView(descItemList[position].header!!) -// + + is GamesRecommendedGalleryViewHolder -> bindGamesRecommendedGalleryViewHolder(holder, position) + + is GameDetailRecommendImageViewHolder -> bindImageViewHolder(holder, descItemList[position].imageRecommend) + + is GameDetailCommentsViewHolder -> bindCommentsViewHolder(holder, descItemList[position].comment) + is GameDetailRelatedVersionViewHolder -> bindRelatedVersion(holder, descItemList[position].relatedVersion) -// + is GameVideoGalleryViewHolder -> bindVideosViewHolder(holder, descItemList[position].video) is GameImageGalleryViewHolder -> bindImageGalleryViewHolder(holder, descItemList[position].gallery) @@ -301,14 +264,6 @@ class DescAdapter(context: Context, } } - - private fun bindGameHorizontalListView(holder: GameHorizontalListViewHolder, position: Int) { -// val subjectEntity = descItemList[position].recommendedGames -// val subjectAdapter = holder.bindHorizontalList(subjectEntity!!) -// subjectAdapter.gameName = gameName!! -// subjectAdapter.entrance = mEntrance - } - private fun initIntroViewHolder(viewHolder: GameDetailIntroViewHolder, descItemData: DescItemData) { viewHolder.introGallery.isNestedScrollingEnabled = false if (viewHolder.introGallery.adapter == null) { @@ -378,6 +333,27 @@ class DescAdapter(context: Context, } } + + //绑定大家都在玩 + private fun bindGamesRecommendedGalleryViewHolder(viewHolder: GamesRecommendedGalleryViewHolder, position: Int) { + viewHolder.binding.galleryRv.isNestedScrollingEnabled = false + val subjectEntity = descItemList[position].recommendedGames + if (subjectEntity != null) { + var subjectAdapter = viewHolder.binding.galleryRv.adapter + if (subjectAdapter == null) { + viewHolder.binding.galleryRv.layoutManager = GridLayoutManager(mContext, 4) + subjectAdapter = GameHorizontalAdapter(mContext, subjectEntity, true) + (viewHolder.binding.galleryRv.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false + viewHolder.binding.galleryRv.adapter = subjectAdapter + } else { + (subjectAdapter as GameHorizontalAdapter).checkResetData(subjectEntity) + } + } + + viewHolder.binding.titleTv.text = "大家都在玩" + viewHolder.binding.moreTv.visibility = View.GONE + } + //绑定评论 private fun bindCommentsViewHolder(viewHolder: GameDetailCommentsViewHolder, comments: ArrayList?) { if (viewHolder.binding.recyclerview.adapter == null) { @@ -402,10 +378,6 @@ class DescAdapter(context: Context, //绑定其他相关版本 private fun bindRelatedVersion(viewHolder: GameDetailRelatedVersionViewHolder, relatedVersion: ArrayList?) { -// holder.binding.relatedVersion = descItemData.relatedVersion -// holder.binding.root.setOnClickListener { -// DirectUtils.directToGameDetail(mContext, descItemData.relatedVersion!!.gameId, mEntrance) -// } viewHolder.binding.galleryRv.isNestedScrollingEnabled = false if (viewHolder.binding.galleryRv.adapter == null) { viewHolder.binding.galleryRv.apply { @@ -483,18 +455,34 @@ class DescAdapter(context: Context, //绑定最近开服 private fun bindLatestServiceViewHolder(viewHolder: GameLatestServiceViewHolder, server: GameDetailServer?) { viewHolder.binding.serviceRv.isNestedScrollingEnabled = false - if (viewHolder.binding.serviceRv.adapter == null) { - viewHolder.binding.serviceRv.apply { - layoutManager = LinearLayoutManager(mContext) - val serviceAdapter = GameLatestServiceAdapter(mContext, server?.calendar!!) - adapter = serviceAdapter - addItemDecoration(VerticalItemDecoration(mContext, 12F, false, R.color.white)) + + if (!server!!.calendar.isNullOrEmpty()) { + viewHolder.binding.serviceRv.visibility = View.VISIBLE + if (viewHolder.binding.serviceRv.adapter == null) { + viewHolder.binding.serviceRv.apply { + layoutManager = LinearLayoutManager(mContext) + val serviceAdapter = GameLatestServiceAdapter(mContext, server.calendar!!) + adapter = serviceAdapter + val itemDecoration = HorizontalDividerItemDecoration.Builder(mContext) + .size(DisplayUtils.dip2px(12f)) + .color(ContextCompat.getColor(mContext, R.color.white)).build() + addItemDecoration(itemDecoration) + } } + } else {//当天没有、未来没有、历史30天之前有 + viewHolder.binding.moreTv.visibility = View.GONE + viewHolder.binding.tipsTv.visibleIf(server.total > 0) } - viewHolder.binding.moreTv.visibleIf(server?.calendar?.size ?: 0 > 10) viewHolder.binding.moreTv.setOnClickListener { } + if (server.showDes && server.des.isNotEmpty()) { + viewHolder.binding.tipsIv.visibility = View.VISIBLE + viewHolder.binding.tipsIv.setOnClickListener { + DialogUtils.showKaifuRemindDialog(mContext, server.des) + } + } + } //绑定攻略文章 @@ -515,12 +503,12 @@ class DescAdapter(context: Context, //绑定礼包 private fun bindLibaoViewHolder(viewHolder: GameLibaoGalleryViewHolder, libao: ArrayList?) { viewHolder.binding.galleryRv.isNestedScrollingEnabled = false - if (viewHolder.binding.galleryRv.adapter == null) { - viewHolder.binding.galleryRv.apply { - background = ContextCompat.getDrawable(mContext, R.drawable.bg_shape_f8_radius_5) - layoutManager = LinearLayoutManager(mContext) - val libaoAdapter = GameLibaoAdapter(mContext, libao!!) - adapter = libaoAdapter + viewHolder.binding.galleryRv.apply { + background = ContextCompat.getDrawable(mContext, R.drawable.bg_shape_f8_radius_5) + layoutManager = LinearLayoutManager(mContext) + val libaoAdapter = GameLibaoAdapter(mContext, libao!!, mListListener) + adapter = libaoAdapter + if (itemDecorationCount == 0) { val itemDecoration = HorizontalDividerItemDecoration.Builder(mContext) .size(DisplayUtils.dip2px(1f)) .color(ContextCompat.getColor(mContext, R.color.text_eeeeee)).build() @@ -534,6 +522,7 @@ class DescAdapter(context: Context, //绑定游戏信息 private fun bindGameDetailInfoViewHolder(viewHolder: GameDetailInfoViewHolder, info: GameInfo?) { if (!info!!.topTags.isNullOrEmpty()) { + viewHolder.binding.labelsLl.visibility = View.VISIBLE viewHolder.binding.labelsLl.removeAllViews() info.topTags.forEach { viewHolder.binding.labelsLl.addView(createGameInfoLabel(it.name)) @@ -565,10 +554,10 @@ class DescAdapter(context: Context, companion object { const val INTRO = 4 const val HEADER = 6 - const val COMMENTS = 8//评论 const val CUSTOM_COLUMN = 64 - const val RELATED_VERSION = 128 + const val RELATED_VERSION = 128//其他相关版本 + const val COMMENTS = 8//评论 const val IMAGE = 3//图片推荐 const val RECOMMENDED_GAMES = 100//大家都在玩 const val VIDEOS = 129//视频 @@ -581,12 +570,6 @@ class DescAdapter(context: Context, const val FOOTER = 101 } - class GameDetailHeaderViewHolder(var view: View) : ReuseViewHolder(view) { - fun bindView(title: String) { - view.findViewById(R.id.title_tv).text = title - } - } - class GameDetailRecommendImageViewHolder(var binding: GamedetailItemImageBinding) : RecyclerView.ViewHolder(binding.root) class GameDetailCommentsViewHolder(var binding: GamedetailItemCommentsBinding) : RecyclerView.ViewHolder(binding.root) @@ -608,4 +591,6 @@ class DescAdapter(context: Context, class GameLibaoGalleryViewHolder(var binding: GameGalleryListBinding) : RecyclerView.ViewHolder(binding.root) class GameDetailInfoViewHolder(var binding: GameDetailInfoBinding) : RecyclerView.ViewHolder(binding.root) + + class GamesRecommendedGalleryViewHolder(var binding: GameGalleryListBinding) : RecyclerView.ViewHolder(binding.root) } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescFragment.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescFragment.kt index 0398115fbf..1fb38d4393 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescFragment.kt @@ -11,8 +11,10 @@ import androidx.recyclerview.widget.RecyclerView import butterknife.BindView import com.gh.base.fragment.BaseFragment import com.gh.common.util.* +import com.gh.gamecenter.LibaoDetailActivity import com.gh.gamecenter.R import com.gh.gamecenter.entity.GameEntity +import com.gh.gamecenter.entity.LibaoEntity import com.gh.gamecenter.entity.RatingComment import com.gh.gamecenter.eventbus.EBReuse import com.gh.gamecenter.gamedetail.GameDetailFragment.Companion.OPEN_APPBAR @@ -43,25 +45,29 @@ class DescFragment : BaseFragment() { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) - if (DescCommentsAdapter.RATING_REPLY_REQUEST == requestCode && resultCode == Activity.RESULT_OK) { - var commentPosition = 0 - SyncDataBetweenPageHelper.resultHandle(data, object : OnSyncCallBack { - override fun onData(dataPosition: Int): RatingComment? { - val descItemList = mAdapter.descItemList - for (i in 0 until descItemList.size) { - val comments = descItemList[i].comment - if (comments != null) { - commentPosition = i - return comments[dataPosition] + if (resultCode == Activity.RESULT_OK) { + if (DescCommentsAdapter.RATING_REPLY_REQUEST == requestCode) { + var commentPosition = 0 + SyncDataBetweenPageHelper.resultHandle(data, object : OnSyncCallBack { + override fun onData(dataPosition: Int): RatingComment? { + val descItemList = mAdapter.descItemList + for (i in 0 until descItemList.size) { + val comments = descItemList[i].comment + if (comments != null) { + commentPosition = i + return comments[dataPosition] + } } + return null } - return null - } - override fun onNotify(dataPosition: Int) { - mAdapter.notifyItemChanged(commentPosition) - } - }) + override fun onNotify(dataPosition: Int) { + mAdapter.notifyItemChanged(commentPosition) + } + }) + } else if (requestCode == 100) { + mAdapter.notifyDataSetChanged() + } } } @@ -72,34 +78,30 @@ class DescFragment : BaseFragment() { val gameDetailFactory = GameDetailViewModel.Factory(HaloApp.getInstance().application, mGameEntity?.id, mGameEntity) val gameDetailViewModel: GameDetailViewModel = viewModelProviderFromParent(gameDetailFactory) -// mDetailEntity = gameDetailViewModel.unifiedGameDetailLiveData.value?.data?.game mNewDetailEntity = gameDetailViewModel.gameDetailLiveData.value?.data val factory = DescViewModel.Factory(HaloApp.getInstance().application, mGameEntity) mViewModel = viewModelProvider(factory) -// gameDetailViewModel.unifiedGameDetailLiveData.observeNonNull(this) { -// mViewModel.constructList(it.data!!.game) -// } gameDetailViewModel.gameDetailLiveData.observeNonNull(this) { mAdapter.updateDescItemList(it.data!!.detailEntity) + if (openVideoStreaming) { + it.data.detailEntity.forEach { entity -> + if (entity.video != null && !RunningUtils.isEqualsTop(context, VideoDetailActivity::class.java.name)) { + DirectUtils.directToVideoDetail(requireContext(), entity.video!![0].videoId + , entity.video!![0].videoId, path = "游戏详情-介绍视频") + return@forEach + } + } + } } gameDetailViewModel.unifiedGameDetailWithUserRelatedInfoForChildLiveData.observeNonNull(this) { mAdapter.updateDescItemList(it.detailEntity) + mViewModel.generateRecommendedGamesItem(it.detailEntity) } - mViewModel.list.observe(this, Observer { descItemDataList -> - descItemDataList?.let { - //mAdapter.updateDescItemList(it) - } - descItemDataList.forEach { - if (openVideoStreaming && it.intro?.video != null && !RunningUtils.isEqualsTop(context, VideoDetailActivity::class.java.name)) { - DirectUtils.directToVideoDetail(requireContext(), it.intro?.video?.videoId - ?: "", it.intro?.video?.videoId ?: "", path = "游戏详情-介绍视频") - return@forEach - } - } + mViewModel.list.observe(this, Observer { + mAdapter.updateDescItemList(it) }) - mViewModel.generateRecommendedGamesItem() super.onCreate(savedInstanceState) } @@ -112,7 +114,7 @@ class DescFragment : BaseFragment() { super.initView(view) loadingView.visibility = View.GONE - mAdapter = DescAdapter(requireContext(), mEntrance, mViewModel) + mAdapter = DescAdapter(requireContext(), mEntrance, mViewModel, this) (mRecyclerView.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false layoutManager = LinearLayoutManager(context) mRecyclerView.layoutManager = layoutManager @@ -136,4 +138,16 @@ class DescFragment : BaseFragment() { } } + override fun onListClick(view: View?, position: Int, data: LIST) { + when (view?.id) { + R.id.receiveTv -> { + val liBao = data as LibaoEntity + val intent = LibaoDetailActivity.getIntent(context, liBao, "$mEntrance[$position]") + DataUtils.onMtaEvent(context, "游戏详情_新", "游戏礼包", mViewModel.game?.name + "->" + liBao.name) + startActivityForResult(intent, 100) + } + } + } + + } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescViewModel.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescViewModel.kt index b8b02c7b0d..a5ae33d459 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescViewModel.kt @@ -2,7 +2,6 @@ package com.gh.gamecenter.gamedetail.desc import android.annotation.SuppressLint import android.app.Application -import android.os.Build import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel @@ -12,7 +11,10 @@ import com.gh.common.util.ApkActiveUtils import com.gh.common.util.ErrorHelper import com.gh.common.util.RandomUtils import com.gh.common.util.toObject -import com.gh.gamecenter.entity.* +import com.gh.gamecenter.entity.ErrorEntity +import com.gh.gamecenter.entity.GameEntity +import com.gh.gamecenter.entity.SubjectEntity +import com.gh.gamecenter.gamedetail.entity.DetailEntity import com.gh.gamecenter.retrofit.Response import com.gh.gamecenter.retrofit.RetrofitManager import io.reactivex.Observable @@ -24,124 +26,26 @@ import retrofit2.HttpException class DescViewModel(application: Application, var game: GameEntity?) : AndroidViewModel(application) { - private var mDataList = arrayListOf() + private var mDataList = arrayListOf() private var mRelatedGameList = arrayListOf() - private var mGameDetail: GameDetailEntity? = null - var list = MutableLiveData>() + var list = MutableLiveData>() var gameId = game?.id - fun constructList(gameDetailEntity: GameDetailEntity) { - - mGameDetail = gameDetailEntity - // 构建列表 - mGameDetail?.let { - - // 这里的高、低优先级是指相对于游戏介绍区域的位置,高在上面低在下面 - val highPriorityCustomColumnList = arrayListOf() - val lowPriorityCustomColumnList = arrayListOf() - - for (customColumn in it.customColumns) { - if (customColumn.order > 0) { - highPriorityCustomColumnList.add(customColumn) - } else { - lowPriorityCustomColumnList.add(customColumn) - } - } - - // 插件 (3.6.6 起不再显示 https://gitlab.ghzs.com/pm/halo-app-issues/issues/599 第5点) - - // 高优先级自定义栏目 - for (customColumn in highPriorityCustomColumnList) { - mDataList.add(DescItemData(customColumn = customColumn)) - } - - // 游戏介绍 - if (it.gallery != null && it.gallery?.size != 0) { - // 低于 4.4 设备不显示视频 - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - it.introVideo = null - } - - mDataList.add(DescItemData( - intro = DescItemData.Intro( - video = it.introVideo, - gallery = it.gallery, - description = it.des, - gameTag = ArrayList(it.tagStyle), - name = game?.name))) - } - - // 低优先级自定义栏目 - for (customColumn in lowPriorityCustomColumnList) { - mDataList.add(DescItemData(customColumn = customColumn)) - } - - // 其它版本 - /*if (it.relatedVersion.size > 0) { - mDataList.add(DescItemData(header = "其它相关版本")) - for ((index, relatedVersion) in it.relatedVersion.withIndex()) { - if (index == 0) { - // 第一个 - relatedVersion.first = true - } else if (index == it.relatedVersion.size - 1) { - // 最后一个 - relatedVersion.last = true - } - relatedVersion.index = index + 1 - mDataList.add(DescItemData(relatedVersion = relatedVersion)) - } - }*/ - - // 图片推荐 - if (it.imageRecommend != null) { - mDataList.add(DescItemData(recommendedImage = it.imageRecommend)) - } - - //Todo:测试数据 - if (it.gallery != null) { - mDataList.add(DescItemData(gallery = it.gallery)) - } - if (it.introVideo != null) { - mDataList.add(DescItemData(videos = arrayListOf(it.introVideo!!, it.introVideo!!, it.introVideo!!))) - } - mDataList.add(DescItemData(updateContent = "1、功能标签只显示标签名字在第一行,游戏没有填写功能标签就不显示" + - "2、详细信息板块有多少内容显示多少内容,即各个数据的位置不是固定的" + - "3、做设备上是否安装QQ应用的判断,如有安装则直接跳转,未安装则点击是复制并toast“已复制”")) - if (it.serverEntity != null) { - mDataList.add(DescItemData(server = it.serverEntity)) - } - - if (it.relatedVersion.size > 0) { - val list= arrayListOf() - list.addAll(it.relatedVersion) - list.addAll(it.relatedVersion) - list.addAll(it.relatedVersion) - list.addAll(it.relatedVersion) - mDataList.add(DescItemData(relatedVersion = list)) - } - - list.postValue(mDataList) - - if (mGameDetail?.showComment == true) { - retrieveComment() - } - } - } - /** * 构建大家都在玩的item */ - fun generateRecommendedGamesItem() { + fun generateRecommendedGamesItem(mDataList: ArrayList) { + this.mDataList = mDataList + val detailEntity = mDataList.find { it.relatedGames != null } // 看游戏详情有没有相关游戏,没有就拿 3个 热门卡牌 - if (mGameDetail == null - || mGameDetail!!.relatedGames == null - || mGameDetail!!.relatedGames!!.isEmpty()) { + if (detailEntity?.relatedGames == null + || detailEntity.relatedGames!!.isEmpty()) { assembleListWithRecommendedGames() return } - val relatedGames = mGameDetail!!.relatedGames + val relatedGames = detailEntity.relatedGames val idList = ArrayList() for (relatedGame in relatedGames!!) { val size = relatedGame.game!!.size @@ -245,13 +149,17 @@ class DescViewModel(application: Application, SubjectEntity(data = recommendedGameList) } - mDataList.add(DescItemData(header = "大家都在玩")) - mDataList.add(DescItemData(recommendedGames = recommendedGames)) + for (data in mDataList) { + if (data.relatedGames != null) { + data.recommendedGames = recommendedGames + break + } + } list.postValue(mDataList) }, { e -> e.printStackTrace() }) } - private fun retrieveComment() { + /*private fun retrieveComment() { RetrofitManager.getInstance(getApplication()) .api .getGameCommentsForDesc(game!!.id, 1) @@ -289,7 +197,7 @@ class DescViewModel(application: Application, } } }) - } + }*/ class Factory(private val mApplication: Application, private val game: GameEntity?) : ViewModelProvider.NewInstanceFactory() { diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameLatestServiceAdapter.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameLatestServiceAdapter.kt index fc58585cac..3608fa1268 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameLatestServiceAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameLatestServiceAdapter.kt @@ -17,9 +17,9 @@ class GameLatestServiceAdapter(val context: Context, val datas: MutableList 10) 10 else datas.size override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { - if (holder is GameLatestServiceViewHolder){ - holder.binding.timeTv.text=datas[position].getFormatTime("MM-dd HH:mm") - holder.binding.serviceNameTv.text=datas[position].getNote() + if (holder is GameLatestServiceViewHolder) { + holder.binding.timeTv.text = datas[position].getFormatTime("MM-dd HH:mm") + holder.binding.serviceNameTv.text = "${datas[position].getNote()} ${datas[position].remark}" } } diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameLibaoAdapter.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameLibaoAdapter.kt index 8f6a555484..abc68e3a25 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameLibaoAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameLibaoAdapter.kt @@ -6,11 +6,14 @@ import android.view.View import android.view.ViewGroup import androidx.databinding.DataBindingUtil import androidx.recyclerview.widget.RecyclerView +import com.gh.base.OnListClickListener +import com.gh.common.util.LibaoUtils import com.gh.gamecenter.R import com.gh.gamecenter.databinding.ItemGameLibaoBinding import com.gh.gamecenter.entity.LibaoEntity +import java.util.* -class GameLibaoAdapter(val context: Context, val libaos: ArrayList) : RecyclerView.Adapter() { +class GameLibaoAdapter(val context: Context, val libaos: ArrayList, val listListener: OnListClickListener?) : RecyclerView.Adapter() { var isExpand = false private val mShowItemCount: Int = 3//最多展示多少个礼包 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { @@ -43,11 +46,14 @@ class GameLibaoAdapter(val context: Context, val libaos: ArrayList) holder.binding.libaoNameTv.text = libaoEntity.name holder.binding.contentTv.text = libaoEntity.content val total = libaoEntity.total - val repeat = libaoEntity.repeat - holder.binding.libaoSchedulePb.progress = ((total - repeat) / total) * 100 - holder.binding.remainingTv.text = "剩余${((repeat) / total) * 100}%" + val available = libaoEntity.available + if (total != 0) { + holder.binding.libaoSchedulePb.progress = (((total - available) / total.toFloat()) * 100).toInt() + holder.binding.remainingTv.text = String.format(Locale.CHINA, "剩余%.2f", ((available) / total.toFloat()) * 100) + "%" + } + LibaoUtils.setLiBaoBtnStatus(holder.binding.receiveTv, libaoEntity.status, context) holder.binding.receiveTv.setOnClickListener { - + listListener?.onListClick(it, position, libaoEntity) } } is MoreViewHolder -> { diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/entity/DetailEntity.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/entity/DetailEntity.kt index 329b3a147b..dcdd59e4fe 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/entity/DetailEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/entity/DetailEntity.kt @@ -7,7 +7,7 @@ import com.google.gson.annotations.SerializedName @Keep data class DetailEntity( var type: String = "", - var notice: NoticeEntity? = null, + var notice: ArrayList? = null, var des: String? = null,// 介绍文案 var gallery: ArrayList? = null, var video: ArrayList? = null, @@ -22,6 +22,7 @@ data class DetailEntity( var imageRecommend: LinkEntity? = null, @SerializedName("related_game") var relatedGames: ArrayList? = null, + var recommendedGames: SubjectEntity? = null, var article: ArrayList? = null ) diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/entity/ZoneEntity.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/entity/ZoneEntity.kt index 69b3f6d576..621a9ba83d 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/entity/ZoneEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/entity/ZoneEntity.kt @@ -15,7 +15,7 @@ data class ZoneEntity( data class ZoneContentEntity( var type: String = "", - var notice: NoticeEntity? = null, + var notice: ArrayList? = null, var article: ArrayList? = null, var toolkit: List? = null, @SerializedName("community_column_content") diff --git a/app/src/main/res/drawable-xxhdpi/ic_game_detail_kaifu_tips.png b/app/src/main/res/drawable-xxhdpi/ic_game_detail_kaifu_tips.png new file mode 100644 index 0000000000..bd252c4fa6 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_game_detail_kaifu_tips.png differ diff --git a/app/src/main/res/drawable/bg_shape_f5_radius_3.xml b/app/src/main/res/drawable/bg_shape_f5_radius_3.xml new file mode 100644 index 0000000000..c50dabef23 --- /dev/null +++ b/app/src/main/res/drawable/bg_shape_f5_radius_3.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_kaifu_remind.xml b/app/src/main/res/layout/dialog_kaifu_remind.xml new file mode 100644 index 0000000000..9f19a2409e --- /dev/null +++ b/app/src/main/res/layout/dialog_kaifu_remind.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/game_detail_info.xml b/app/src/main/res/layout/game_detail_info.xml index 0e8a4b5884..e0087dcb3e 100644 --- a/app/src/main/res/layout/game_detail_info.xml +++ b/app/src/main/res/layout/game_detail_info.xml @@ -41,24 +41,15 @@ android:id="@+id/labelsLl" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> - - + android:visibility="gone" + android:layout_marginBottom="16dp" + android:orientation="horizontal"/> - + android:layout_height="wrap_content"/> \ No newline at end of file diff --git a/app/src/main/res/layout/game_latest_service_list.xml b/app/src/main/res/layout/game_latest_service_list.xml index a2034b3a10..5a436bddea 100644 --- a/app/src/main/res/layout/game_latest_service_list.xml +++ b/app/src/main/res/layout/game_latest_service_list.xml @@ -24,6 +24,17 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + + app:layout_constraintTop_toTopOf="@+id/titleTv"/> - + app:layout_constraintTop_toBottomOf="@+id/serviceRv" />--> + app:layout_constraintTop_toBottomOf="@+id/serviceRv" /> \ No newline at end of file diff --git a/app/src/main/res/layout/item_game_detail_more.xml b/app/src/main/res/layout/item_game_detail_more.xml index 3873e09ab9..1f4f138310 100644 --- a/app/src/main/res/layout/item_game_detail_more.xml +++ b/app/src/main/res/layout/item_game_detail_more.xml @@ -11,5 +11,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" + android:paddingTop="16dp" + android:paddingBottom="16dp" android:src="@drawable/ic_game_detail_arrow_down"/> \ No newline at end of file diff --git a/app/src/main/res/layout/item_game_libao.xml b/app/src/main/res/layout/item_game_libao.xml index 75aa8a4cec..bfdc2c3198 100644 --- a/app/src/main/res/layout/item_game_libao.xml +++ b/app/src/main/res/layout/item_game_libao.xml @@ -43,7 +43,7 @@ app:layout_constraintBottom_toBottomOf="@+id/libaoSchedulePb" app:layout_constraintStart_toEndOf="@+id/libaoSchedulePb" app:layout_constraintTop_toTopOf="@+id/libaoSchedulePb" - tools:text="剩余0%" /> + android:text="剩余0%"/> @@ -41,7 +41,7 @@ android:id="@+id/line" android:layout_width="match_parent" android:layout_height="1dp" - android:layout_marginTop="16dp" + android:layout_marginTop="14dp" android:background="@color/text_eeeeee" app:layout_constraintRight_toRightOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -51,7 +51,7 @@ android:id="@+id/timeTv" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="12dp" + android:layout_marginTop="10dp" android:textColor="@color/text_999999" android:textSize="11sp" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 5b7b058384..fc75e17e20 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -106,4 +106,8 @@ + + + + \ No newline at end of file