分离新首页的旧首页部分
This commit is contained in:
@ -135,6 +135,8 @@ object DirectUtils {
|
||||
context.startActivity(GameServersActivity.getIntent(context, entrance, path))
|
||||
}
|
||||
|
||||
"top_game_comment" -> directToAmway(context, null, entrance, path)
|
||||
|
||||
else -> DialogUtils.showLowVersionDialog(context)
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ object TextHelper {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getCommentLabelSpannableStringBuilder(comment: CharSequence): SpannableStringBuilder {
|
||||
fun getCommentLabelSpannableStringBuilder(comment: CharSequence, lineFeed: String = "\n"): SpannableStringBuilder {
|
||||
val contents = SpannableStringBuilder()
|
||||
var count = 0
|
||||
val splits = comment.split("<tag>")
|
||||
@ -166,7 +166,7 @@ object TextHelper {
|
||||
val label = matcher.group(1)
|
||||
val content = matcher.group(2)
|
||||
val newLabel = " $label "
|
||||
val newContent = if (index != splits.size - 1) "$content\n" else content
|
||||
val newContent = if (index != splits.size - 1) "$content$lineFeed" else content
|
||||
contents.append(newLabel)
|
||||
contents.setSpan(RelativeSizeSpan(0.8f), count, count + newLabel.length - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
contents.setSpan(RoundStrokeBackgroundColorSpan(Color.parseColor("#FFDAA2"), Color.parseColor("#FF9B06"), 2), count, count + newLabel.length - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
|
||||
@ -669,5 +669,6 @@ class GameFragmentAdapter(context: Context,
|
||||
return mItemDataList[pos].exposureEventList
|
||||
}
|
||||
|
||||
data class GameAndPosition(val entity: GameEntity?, val position: Int, val index: Int = 0)
|
||||
}
|
||||
|
||||
data class GameAndPosition(val entity: GameEntity?, val position: Int, val index: Int = 0)
|
||||
|
||||
@ -26,7 +26,7 @@ import com.gh.gamecenter.databinding.RatingCommentItemBinding
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.RatingComment
|
||||
import com.gh.gamecenter.gamedetail.rating.edit.RatingEditActivity
|
||||
import com.gh.gamecenter.gamedetail.rating.edit.RatingEditActivity.Companion.labelRegex
|
||||
import com.gh.gamecenter.gamedetail.rating.edit.RatingEditActivity.Companion.LABEL_REGEX
|
||||
import com.gh.gamecenter.gamedetail.rating.logs.CommentLogsActivity
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import java.util.regex.Pattern
|
||||
@ -35,7 +35,7 @@ class RatingCommentItemViewHolder(val binding: RatingCommentItemBinding) : BaseR
|
||||
fun setContent(commentData: RatingComment, game: GameEntity?, dataPosition: Int, entrance: String, path: String) {
|
||||
binding.run {
|
||||
val context = itemView.context
|
||||
val p = Pattern.compile(labelRegex)
|
||||
val p = Pattern.compile(LABEL_REGEX)
|
||||
val m = p.matcher(commentData.content)
|
||||
if (m.find()) {
|
||||
val contents = TextHelper.getCommentLabelSpannableStringBuilder(commentData.content)
|
||||
|
||||
@ -138,7 +138,7 @@ class RatingEditActivity : ToolBarActivity() {
|
||||
mBinding.deviceBox.isChecked = mComment!!.getDevice().isNotEmpty()
|
||||
|
||||
val content = mComment!!.content
|
||||
val p = Pattern.compile(labelRegex)
|
||||
val p = Pattern.compile(LABEL_REGEX)
|
||||
val matcher = p.matcher(content)
|
||||
if (matcher.find()) {
|
||||
mBinding.content.visibility = View.GONE
|
||||
@ -201,7 +201,7 @@ class RatingEditActivity : ToolBarActivity() {
|
||||
splits.forEachIndexed { index, s ->
|
||||
if (index != 0) {
|
||||
val item = "<tag>$s"
|
||||
val p = Pattern.compile(labelRegex)
|
||||
val p = Pattern.compile(LABEL_REGEX)
|
||||
val matcher = p.matcher(item)
|
||||
if (matcher.find()) {
|
||||
val entity = CommentItemEntity(matcher.group(1), matcher.group(2))
|
||||
@ -315,7 +315,8 @@ class RatingEditActivity : ToolBarActivity() {
|
||||
|
||||
companion object {
|
||||
|
||||
const val labelRegex = "<tag>(\\S+)</tag>(\\S+)"
|
||||
const val LABEL_PREFIX = "<tag>"
|
||||
const val LABEL_REGEX = "<tag>(\\S+)</tag>(\\S+)"
|
||||
|
||||
const val RATING_CONTENT_LIMIT = 5000
|
||||
|
||||
|
||||
@ -102,7 +102,6 @@ class HomeFragment : BaseFragment<Any>() {
|
||||
MtaHelper.onEvent("首页_新", "刷新")
|
||||
mViewModel.initData()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
||||
@ -3,40 +3,29 @@ package com.gh.gamecenter.home
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.common.constant.ItemViewType
|
||||
import com.gh.common.util.*
|
||||
import com.gh.common.util.MtaHelper
|
||||
import com.gh.common.view.DownloadProgressBar
|
||||
import com.gh.gamecenter.GameDetailActivity
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
|
||||
import com.gh.gamecenter.adapter.viewholder.GameHeadViewHolder
|
||||
import com.gh.gamecenter.adapter.viewholder.GameImageViewHolder
|
||||
import com.gh.gamecenter.adapter.viewholder.GameViewHolder
|
||||
import com.gh.gamecenter.baselist.DiffUtilAdapter
|
||||
import com.gh.gamecenter.baselist.LoadStatus
|
||||
import com.gh.gamecenter.databinding.*
|
||||
import com.gh.gamecenter.databinding.HomeAmwayListBinding
|
||||
import com.gh.gamecenter.databinding.HomeGameItemBinding
|
||||
import com.gh.gamecenter.databinding.HomeRecommendItemBinding
|
||||
import com.gh.gamecenter.databinding.HomeSlideListBinding
|
||||
import com.gh.gamecenter.entity.AmwayCommentEntity
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.LinkEntity
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus
|
||||
import com.gh.gamecenter.game.GameFragmentAdapter
|
||||
import com.gh.gamecenter.game.GameItemViewHolder
|
||||
import com.gh.gamecenter.game.columncollection.GameColumnCollectionViewHolder
|
||||
import com.gh.gamecenter.game.horizontal.GameHorizontalListViewHolder
|
||||
import com.gh.gamecenter.game.imageslide.GameImageSlideViewHolder
|
||||
import com.gh.gamecenter.game.GameAndPosition
|
||||
import com.gh.gamecenter.game.vertical.GameVerticalAdapter
|
||||
import com.gh.gamecenter.game.vertical.GameVerticalSlideViewHolder
|
||||
import com.gh.gamecenter.gamedetail.rating.RatingReplyActivity
|
||||
import com.gh.gamecenter.home.amway.HomeAmwayListViewHolder
|
||||
import com.gh.gamecenter.home.slide.HomeSlideListAdapter
|
||||
import com.gh.gamecenter.home.slide.HomeSlideListViewHolder
|
||||
import com.gh.gamecenter.subject.SubjectActivity
|
||||
import com.halo.assistant.fragment.game.GamePluginAdapter
|
||||
import com.halo.assistant.fragment.game.GamePluginViewHolder
|
||||
import com.lightgame.download.DownloadEntity
|
||||
import java.util.*
|
||||
|
||||
@ -45,7 +34,7 @@ class HomeFragmentAdapter(context: Context,
|
||||
val layoutManager: LinearLayoutManager) : DiffUtilAdapter<HomeItemData>(context) {
|
||||
|
||||
private var mLoadStatus: LoadStatus? = null
|
||||
private var mIsOpenPluginList: Boolean = false
|
||||
private val mLegacyHomeFragmentAdapterAssistant by lazy { LegacyHomeFragmentAdapterAssistant(mContext, this, mLayoutInflater) }
|
||||
|
||||
fun setLoadStatus(status: LoadStatus) {
|
||||
this.mLoadStatus = status
|
||||
@ -61,16 +50,7 @@ class HomeFragmentAdapter(context: Context,
|
||||
if (itemData.attachGame != null) return GAME_ITEM
|
||||
if (itemData.amway != null) return AMWAY_ITEM
|
||||
|
||||
// 原游戏板块样式
|
||||
if (itemData.pluginList != null) return ItemViewType.GAME_PLUGIN
|
||||
if (itemData.columnHead != null) return ItemViewType.COLUMN_HEADER
|
||||
if (itemData.game != null) return ItemViewType.GAME_NORMAL
|
||||
if (itemData.image != null) return ItemViewType.GAME_IMAGE
|
||||
if (itemData.horizontalColumn != null || itemData.horizontalSlide != null) return ItemViewType.GAME_SUBJECT
|
||||
if (itemData.imageSlide != null) return ItemViewType.IMAGE_SLIDE_ITEM
|
||||
if (itemData.verticalSlide != null) return ItemViewType.VERTICAL_SLIDE_ITEM
|
||||
if (itemData.columnCollection != null) return ItemViewType.COLUMN_COLLECTION
|
||||
return super.getItemViewType(position)
|
||||
return mLegacyHomeFragmentAdapterAssistant.getLegacyItemType(itemData)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
@ -98,35 +78,7 @@ class HomeFragmentAdapter(context: Context,
|
||||
}
|
||||
|
||||
// 原游戏板块样式
|
||||
ItemViewType.LOADING -> {
|
||||
FooterViewHolder(mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false))
|
||||
}
|
||||
ItemViewType.GAME_SUBJECT -> {
|
||||
val binding = GameHorizontalListBinding.bind(mLayoutInflater.inflate(R.layout.game_horizontal_list, parent, false))
|
||||
GameHorizontalListViewHolder(binding)
|
||||
}
|
||||
ItemViewType.GAME_NORMAL -> {
|
||||
GameItemViewHolder(GameItemBinding.bind(mLayoutInflater.inflate(R.layout.game_item, parent, false)))
|
||||
}
|
||||
ItemViewType.GAME_IMAGE -> {
|
||||
GameImageViewHolder(GameImageItemBinding.bind(mLayoutInflater.inflate(R.layout.game_image_item, parent, false)))
|
||||
}
|
||||
ItemViewType.COLUMN_HEADER -> {
|
||||
GameHeadViewHolder(GameHeadItemBinding.bind(mLayoutInflater.inflate(R.layout.game_head_item, parent, false)))
|
||||
}
|
||||
ItemViewType.GAME_PLUGIN -> {
|
||||
GamePluginViewHolder(mLayoutInflater.inflate(R.layout.game_plugin_item, parent, false))
|
||||
}
|
||||
ItemViewType.IMAGE_SLIDE_ITEM -> {
|
||||
GameImageSlideViewHolder(GameImageSlideItemBinding.bind(mLayoutInflater.inflate(R.layout.game_image_slide_item, parent, false)))
|
||||
}
|
||||
ItemViewType.VERTICAL_SLIDE_ITEM -> {
|
||||
GameVerticalSlideViewHolder(GameVerticalSlideItemBinding.bind(mLayoutInflater.inflate(R.layout.game_vertical_slide_item, parent, false)))
|
||||
}
|
||||
ItemViewType.COLUMN_COLLECTION -> {
|
||||
GameColumnCollectionViewHolder(GameColumnCollectionListBinding.bind(mLayoutInflater.inflate(R.layout.game_column_collection_list, parent, false)))
|
||||
}
|
||||
else -> throw NullPointerException()
|
||||
else -> return mLegacyHomeFragmentAdapterAssistant.createLegacyViewHolder(parent, viewType)
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,16 +93,9 @@ class HomeFragmentAdapter(context: Context,
|
||||
is HomeAmwayListViewHolder -> bindAmway(holder, position)
|
||||
is HomeGameItemViewHolder -> bindAttachGame(holder, position)
|
||||
|
||||
// 原游戏板块样式
|
||||
is GameHeadViewHolder -> bindHeadView(holder, position)
|
||||
is GamePluginViewHolder -> bindPluginView(holder, position)
|
||||
is GameItemViewHolder -> bindGameItemView(holder, position)
|
||||
is FooterViewHolder -> bindFooterView(holder)
|
||||
is GameImageViewHolder -> bindGameImageView(holder, position)
|
||||
is GameHorizontalListViewHolder -> bindGameHorizontalListView(holder, position)
|
||||
is GameImageSlideViewHolder -> bindGameImageSlide(holder, position)
|
||||
is GameVerticalSlideViewHolder -> bindVerticalSlide(holder, position)
|
||||
is GameColumnCollectionViewHolder -> bindColumnCollection(holder, position)
|
||||
|
||||
else -> mLegacyHomeFragmentAdapterAssistant.bindLegacyViewHolder(holder, mDataList[position], position)
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,7 +114,6 @@ class HomeFragmentAdapter(context: Context,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
holder.bindAmwayList(amwayList, clickClosure)
|
||||
}
|
||||
|
||||
@ -187,107 +131,10 @@ class HomeFragmentAdapter(context: Context,
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindColumnCollection(holder: GameColumnCollectionViewHolder, position: Int) {
|
||||
val homeItemData = mDataList[position]
|
||||
val columnCollection = homeItemData.columnCollection!!
|
||||
|
||||
val clickClosure: (position: Int, gameEntity: GameEntity) -> Unit = { prefixedPosition, gameEntity ->
|
||||
MtaHelper.onEvent("游戏专题合集", "首页合集图片", columnCollection.name)
|
||||
// 类型为排行榜时点击处理不一样
|
||||
if (columnCollection.style == "top") {
|
||||
DirectUtils.directToColumnCollection(mContext, columnCollection.id
|
||||
?: "", prefixedPosition, "(首页游戏)")
|
||||
} else {
|
||||
DirectUtils.directToLinkPage(mContext, LinkEntity(link = gameEntity.link, type = gameEntity.type), "(首页游戏)", "游戏-专题")
|
||||
}
|
||||
}
|
||||
|
||||
holder.bindColumnCollection(columnCollection, clickClosure)
|
||||
|
||||
val dataList = columnCollection.data!!
|
||||
if (dataList.size == 1) {
|
||||
val data = dataList[0]
|
||||
holder.binding.columnCollectionImage.setOnClickListener {
|
||||
MtaHelper.onEvent("游戏专题合集", "首页合集图片", columnCollection.name)
|
||||
DirectUtils.directToLinkPage(mContext, LinkEntity(link = data.link, type = data.type), "(首页游戏)", "游戏-专题")
|
||||
}
|
||||
} else {
|
||||
holder.binding.columnCollectionList.doOnScrolledSpecificDistance(distanceX = DisplayUtils.dip2px(24f), singleTimeEvent = true) {
|
||||
MtaHelper.onEvent("游戏专题", "新首页合辑滑动", "内容" + homeItemData.blockPosition + "_" + columnCollection.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindVerticalSlide(holder: GameVerticalSlideViewHolder, position: Int) {
|
||||
val verticalSlide = mDataList[position].verticalSlide!!
|
||||
val clickClosure: (GameEntity) -> Unit = { gameEntity ->
|
||||
val subjectData = gameEntity.subjectData
|
||||
DataCollectionUtils.uploadClick(mContext, subjectData?.name + "-列表", "游戏-专题", gameEntity.name)
|
||||
GameDetailActivity.startGameDetailActivity(mContext, gameEntity,
|
||||
StringUtils.buildString("(首页-专题:", subjectData?.name, "-列表[", (subjectData?.position).toString(), "])"))
|
||||
}
|
||||
|
||||
holder.bindVerticalSlide(verticalSlide, clickClosure)
|
||||
|
||||
}
|
||||
|
||||
private fun bindGameImageSlide(holder: GameImageSlideViewHolder, position: Int) {
|
||||
val binding = holder.binding
|
||||
binding.gameImageLine.visibility = View.GONE
|
||||
val homeItemData = mDataList[position]
|
||||
val entity = homeItemData.imageSlide
|
||||
|
||||
if (binding.columnList.adapter == null) {
|
||||
binding.columnList.doOnScrolledSpecificDistance(distanceX = DisplayUtils.dip2px(24f), singleTimeEvent = true) {
|
||||
MtaHelper.onEvent("游戏专题", "新首页专题滑动", "内容" + homeItemData.blockPosition + "_" + entity?.name)
|
||||
}
|
||||
}
|
||||
|
||||
val imageClickListener = View.OnClickListener {
|
||||
DataCollectionUtils.uploadClick(mContext, entity?.name + "-大图", "游戏-专题")
|
||||
MtaHelper.onEvent("游戏专题", "底部图片", entity?.name)
|
||||
val linkEntity = LinkEntity()
|
||||
linkEntity.link = entity?.link
|
||||
linkEntity.type = entity?.type
|
||||
DirectUtils.directToLinkPage(mContext, linkEntity, "(游戏-专题:" + entity?.name + "-大图)", "首页游戏")
|
||||
}
|
||||
|
||||
holder.bindImageSlide(entity!!, imageClickListener, "游戏-专题")
|
||||
}
|
||||
|
||||
private fun bindGameHorizontalListView(holder: GameHorizontalListViewHolder, position: Int) {
|
||||
val homeItemData = mDataList[position]
|
||||
val subjectEntity = homeItemData.horizontalColumn ?: homeItemData.horizontalSlide
|
||||
holder.bindHorizontalList(subjectEntity!!)
|
||||
|
||||
if (subjectEntity.type != "game_horizontal") {
|
||||
holder.binding.horizontalRv.doOnScrolledSpecificDistance(distanceX = DisplayUtils.dip2px(24f), singleTimeEvent = true) {
|
||||
MtaHelper.onEvent("游戏专题", "新首页专题滑动", "内容" + homeItemData.blockPosition + "_" + subjectEntity.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindGameImageView(holder: GameImageViewHolder, position: Int) {
|
||||
val entity = mDataList[position].image
|
||||
holder.bindImage(entity!!)
|
||||
|
||||
val name = entity.subjectData?.name
|
||||
val link = entity.link
|
||||
|
||||
holder.binding.gameImageIcon.setOnClickListener {
|
||||
DataCollectionUtils.uploadClick(mContext, "$name-大图", "游戏-专题")
|
||||
MtaHelper.onEvent("游戏专题", "大图", name + ":" + entity.name)
|
||||
val linkEntity = LinkEntity()
|
||||
linkEntity.link = link
|
||||
linkEntity.type = entity.type
|
||||
DirectUtils.directToLinkPage(mContext, linkEntity, "(游戏-专题:$name-大图)", "首页游戏")
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindFooterView(holder: FooterViewHolder) {
|
||||
holder.initFooterViewHolder(mLoadStatus == LoadStatus.LIST_LOADING
|
||||
, mLoadStatus == LoadStatus.LIST_FAILED
|
||||
, mLoadStatus == LoadStatus.LIST_OVER) {
|
||||
holder.initFooterViewHolder(mLoadStatus == LoadStatus.LIST_LOADING,
|
||||
mLoadStatus == LoadStatus.LIST_FAILED,
|
||||
mLoadStatus == LoadStatus.LIST_OVER) {
|
||||
if (mLoadStatus == LoadStatus.LIST_FAILED) {
|
||||
viewModel.getHomeContent(false)
|
||||
notifyItemChanged(itemCount - 1)
|
||||
@ -295,113 +142,6 @@ class HomeFragmentAdapter(context: Context,
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindGameItemView(holder: GameItemViewHolder, position: Int) {
|
||||
val itemData = mDataList[position]
|
||||
val gameEntity = itemData.game
|
||||
val subjectData = gameEntity?.subjectData!!
|
||||
|
||||
if (mDataList.size == position + 1 || mDataList[position + 1].game == null) {
|
||||
holder.itemView.setPadding(
|
||||
DisplayUtils.dip2px(16F), DisplayUtils.dip2px(4F),
|
||||
DisplayUtils.dip2px(20F), DisplayUtils.dip2px(12F))
|
||||
} else {
|
||||
holder.itemView.setPadding(
|
||||
DisplayUtils.dip2px(16F), DisplayUtils.dip2px(4F),
|
||||
DisplayUtils.dip2px(20F), DisplayUtils.dip2px(4F))
|
||||
}
|
||||
|
||||
holder.binding.game = gameEntity
|
||||
holder.binding.subjectTag = subjectData?.tag
|
||||
holder.initServerType(gameEntity!!)
|
||||
holder.binding.executePendingBindings()
|
||||
|
||||
|
||||
DownloadItemUtils.setOnClickListener(mContext, holder.binding.downloadBtn, gameEntity, position,
|
||||
this@HomeFragmentAdapter,
|
||||
StringUtils.buildString("(游戏-专题:", subjectData.name, "-列表[", (position + 1).toString(), "])"),
|
||||
StringUtils.buildString("游戏-专题-", subjectData.name, ":", gameEntity.name), null,
|
||||
object : EmptyCallback {
|
||||
override fun onCallback() {
|
||||
MtaHelper.onEvent("首页_新", "点击",
|
||||
"内容" + itemData.blockPosition + "_序号" + subjectData.position + "_" + gameEntity.name + "_" + holder.binding.downloadBtn.text.toString())
|
||||
}
|
||||
})
|
||||
DownloadItemUtils.updateItem(mContext, gameEntity, GameViewHolder(holder.binding), !gameEntity.isPluggable)
|
||||
|
||||
holder.itemView.setOnClickListener {
|
||||
MtaHelper.onEvent("游戏专题", "新首页专题点击", "内容" + itemData.blockPosition + "_序号" + subjectData.position + "_" + gameEntity.name)
|
||||
DataCollectionUtils.uploadClick(mContext, subjectData.name + "-列表", "游戏-专题", gameEntity.name)
|
||||
|
||||
if (gameEntity.isPluggable) {
|
||||
GameDetailActivity.startGameDetailActivity(mContext, gameEntity.id,
|
||||
StringUtils.buildString("(游戏-专题:插件化-列表[", (subjectData.position).toString(), "])"))
|
||||
} else {
|
||||
GameDetailActivity.startGameDetailActivity(mContext, gameEntity,
|
||||
StringUtils.buildString("(游戏-专题:", subjectData.name, "-列表[", (subjectData.position).toString(), "])"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindHeadView(holder: GameHeadViewHolder, position: Int) {
|
||||
val homeItemData = mDataList[position]
|
||||
val column = homeItemData.columnHead
|
||||
holder.bindHead(column!!)
|
||||
|
||||
holder.binding.headLineTop.visibility = View.GONE
|
||||
holder.binding.headMore.setOnClickListener {
|
||||
if ("change" == column.home) {
|
||||
MtaHelper.onEvent("游戏专题", "新首页专题点击", "内容" + homeItemData.blockPosition + "_换一批")
|
||||
holder.binding.headPb.visibility = View.VISIBLE
|
||||
viewModel.changeSubjectGame(column.id!!)
|
||||
} else {
|
||||
if (column.type == "column_collection") {
|
||||
MtaHelper.onEvent("游戏专题", "游戏专题合集", "内容" + homeItemData.blockPosition + "_全部")
|
||||
DirectUtils.directToColumnCollection(mContext, column.id!!, -1, "(游戏-专题:" + column.name + "-全部)")
|
||||
} else {
|
||||
MtaHelper.onEvent("游戏专题", "新首页专题点击", "内容" + homeItemData.blockPosition + "_全部")
|
||||
SubjectActivity.startSubjectActivity(mContext, column.id, column.getFilterName(), column.isOrder, "(游戏-专题:" + column.name + "-全部)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindPluginView(holder: GamePluginViewHolder, position: Int) {
|
||||
val pluginList = mDataList[position].pluginList
|
||||
var adapter = holder.mPluginRv.adapter
|
||||
|
||||
val layoutParams = holder.mPluginHead.layoutParams as LinearLayout.LayoutParams
|
||||
if (mIsOpenPluginList) {
|
||||
holder.mHeadOpen.setImageResource(R.drawable.gamedetail_colse_icon)
|
||||
layoutParams.setMargins(0, DisplayUtils.dip2px(4F), 0, 0)
|
||||
} else {
|
||||
holder.mHeadOpen.setImageResource(R.drawable.gamedetail_open_icon)
|
||||
layoutParams.setMargins(0, DisplayUtils.dip2px(4F), 0, DisplayUtils.dip2px(4F))
|
||||
}
|
||||
|
||||
if (adapter == null) {
|
||||
adapter = GamePluginAdapter(mContext, pluginList)
|
||||
adapter.openList(mIsOpenPluginList)
|
||||
(holder.mPluginRv.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false
|
||||
holder.mPluginRv.layoutManager = LinearLayoutManager(mContext)
|
||||
holder.mPluginRv.adapter = adapter
|
||||
} else {
|
||||
(adapter as GamePluginAdapter).openList(mIsOpenPluginList)
|
||||
adapter.checkResetData(pluginList)
|
||||
}
|
||||
|
||||
holder.mHeadTitle.text = String.format(Locale.getDefault(), "你有%d个游戏可以升级插件版", pluginList?.size)
|
||||
holder.mPluginHead.setOnClickListener {
|
||||
if (mIsOpenPluginList) {
|
||||
mIsOpenPluginList = false
|
||||
MtaHelper.onEvent("首页_点击", "插件化区域", "收起")
|
||||
} else {
|
||||
mIsOpenPluginList = true
|
||||
MtaHelper.onEvent("首页_点击", "插件化区域", "展开")
|
||||
}
|
||||
notifyItemChanged(holder.adapterPosition)
|
||||
}
|
||||
}
|
||||
|
||||
fun notifyItemByDownload(download: DownloadEntity) {
|
||||
val data = getGameEntityByPackage(download.packageName)
|
||||
for (gameAndPosition in data) {
|
||||
@ -447,8 +187,8 @@ class HomeFragmentAdapter(context: Context,
|
||||
}
|
||||
}
|
||||
|
||||
fun getGameEntityByPackage(packageName: String): List<GameFragmentAdapter.GameAndPosition> {
|
||||
val positionList = ArrayList<GameFragmentAdapter.GameAndPosition>()
|
||||
fun getGameEntityByPackage(packageName: String): List<GameAndPosition> {
|
||||
val positionList = ArrayList<GameAndPosition>()
|
||||
val positionMap = viewModel.positionAndPackageMap
|
||||
for (key in positionMap.keys) {
|
||||
if (key.contains(packageName)) {
|
||||
@ -464,7 +204,7 @@ class HomeFragmentAdapter(context: Context,
|
||||
if (linkGame != null) {
|
||||
for (apkEntity in linkGame.getApk()) {
|
||||
if (apkEntity.packageName == packageName) {
|
||||
positionList.add(GameFragmentAdapter.GameAndPosition(linkGame, position))
|
||||
positionList.add(GameAndPosition(linkGame, position))
|
||||
break@main
|
||||
}
|
||||
}
|
||||
@ -475,48 +215,12 @@ class HomeFragmentAdapter(context: Context,
|
||||
|
||||
val attachGame = itemData.attachGame
|
||||
if (attachGame != null) {
|
||||
positionList.add(GameFragmentAdapter.GameAndPosition(attachGame, position))
|
||||
positionList.add(GameAndPosition(attachGame, position))
|
||||
continue
|
||||
}
|
||||
|
||||
// 原游戏板块样式
|
||||
val plugins = itemData.pluginList
|
||||
if (plugins != null) {
|
||||
for (entity in plugins) {
|
||||
for (apkEntity in entity.getApk()) {
|
||||
if (apkEntity.packageName == packageName) positionList.add(GameFragmentAdapter.GameAndPosition(entity, position))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val game = itemData.game
|
||||
if (game != null) {
|
||||
positionList.add(GameFragmentAdapter.GameAndPosition(game, position))
|
||||
continue
|
||||
}
|
||||
|
||||
val horizontalColumn = itemData.horizontalColumn
|
||||
if (horizontalColumn != null) {
|
||||
positionList.add(GameFragmentAdapter.GameAndPosition(null, position))
|
||||
continue
|
||||
}
|
||||
|
||||
val verticalSlide = itemData.verticalSlide
|
||||
if (verticalSlide != null) {
|
||||
for (i in verticalSlide.data!!.indices) {
|
||||
val entity = verticalSlide.data!![i]
|
||||
if (!entity.image.isNullOrEmpty()) continue
|
||||
for (apkEntity in entity.getApk()) {
|
||||
if (apkEntity.packageName == packageName) {
|
||||
positionList.add(GameFragmentAdapter.GameAndPosition(entity, position))
|
||||
}
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
val image = itemData.image
|
||||
if (image != null) positionList.add(GameFragmentAdapter.GameAndPosition(image, position))
|
||||
mLegacyHomeFragmentAdapterAssistant.getLegacyGameEntityByPackage(positionList, itemData, packageName, position)
|
||||
}
|
||||
}
|
||||
return positionList
|
||||
@ -534,7 +238,6 @@ class HomeFragmentAdapter(context: Context,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
const val SLIDE_ITEM: Int = 100
|
||||
const val RECOMMENDS_ITEM: Int = 101
|
||||
|
||||
@ -1,20 +1,11 @@
|
||||
package com.gh.gamecenter.home
|
||||
|
||||
import com.gh.gamecenter.entity.*
|
||||
import com.gh.gamecenter.entity.AmwayCommentEntity
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.HomeRecommend
|
||||
import com.gh.gamecenter.entity.HomeSlide
|
||||
|
||||
data class HomeItemData(var slides: List<HomeSlide>? = null,
|
||||
var recommends: List<HomeRecommend>? = null,
|
||||
var amway: List<AmwayCommentEntity>? = null,
|
||||
var attachGame: GameEntity? = null,
|
||||
var blockPosition: Int = -1, // 统计会用到块的位置(相当于一个专题就是1)
|
||||
// 原游戏板块样式
|
||||
var game: GameEntity? = null,
|
||||
var columnHead: SubjectEntity? = null,
|
||||
var horizontalColumn: SubjectEntity? = null,
|
||||
var subjectRecommend: List<SubjectRecommendEntity>? = null,
|
||||
var image: GameEntity? = null,
|
||||
var pluginList: List<GameEntity>? = null,
|
||||
var verticalSlide: SubjectEntity? = null,
|
||||
var horizontalSlide: SubjectEntity? = null,
|
||||
var imageSlide: GameEntity? = null,
|
||||
var columnCollection: SubjectEntity? = null)
|
||||
var attachGame: GameEntity? = null) : LegacyHomeItemData()
|
||||
@ -12,9 +12,13 @@ class HomeRecommendItemViewHolder(val binding: HomeRecommendItemBinding) : BaseR
|
||||
fun bindRecommend(recommends: List<HomeRecommend>) {
|
||||
binding.list = recommends
|
||||
binding.clickListener = OnViewClickListener<Int> { v, position ->
|
||||
MtaHelper.onEvent("首页_新", "推荐入口_点击",(position +1).toString() )
|
||||
MtaHelper.onEvent("首页_新", "推荐入口_点击", (position + 1).toString())
|
||||
val recommend = recommends[position]
|
||||
DirectUtils.directToLinkPage(binding.root.context,recommend.transformLinkEntity(),"", "首页-推荐入口")
|
||||
|
||||
if (recommend.linkType == "top_game_comment") {
|
||||
MtaHelper.onEvent("安利墙", "首页推荐入口")
|
||||
}
|
||||
DirectUtils.directToLinkPage(binding.root.context, recommend.transformLinkEntity(), "", "首页-推荐入口")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
package com.gh.gamecenter.home
|
||||
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.SubjectEntity
|
||||
import com.gh.gamecenter.game.data.GameSubjectData
|
||||
|
||||
object HomeSubjectTransformer {
|
||||
|
||||
fun transform(
|
||||
itemList: ArrayList<LegacyHomeItemData>,
|
||||
subjectEntity: SubjectEntity?,
|
||||
blockPosition: Int,
|
||||
newItemInstance: () -> LegacyHomeItemData,
|
||||
addGamePositionAndPackage: (gameEntity: GameEntity) -> Unit) {
|
||||
val data = subjectEntity?.data
|
||||
if (data == null || data.isEmpty()) return
|
||||
|
||||
if (!data[0].image.isNullOrEmpty() && subjectEntity.type != "column_collection") {
|
||||
val itemDataImage = newItemInstance()
|
||||
itemDataImage.blockPosition = blockPosition + 1
|
||||
|
||||
val gameEntity = data[0]
|
||||
if (gameEntity.id.isEmpty()) gameEntity.id = gameEntity.link ?: ""
|
||||
|
||||
if (data[0].type == "column") {
|
||||
itemDataImage.imageSlide = gameEntity
|
||||
itemList.add(itemDataImage)
|
||||
} else {
|
||||
itemDataImage.image = gameEntity
|
||||
itemDataImage.image?.subjectData = GameSubjectData(name = subjectEntity.name, isOrder = false)
|
||||
itemList.add(itemDataImage)
|
||||
if (gameEntity.type == "game") addGamePositionAndPackage(gameEntity)
|
||||
}
|
||||
if (subjectEntity.type == "image" || subjectEntity.type == "image_slide") return
|
||||
}
|
||||
|
||||
val itemDataHead = newItemInstance()
|
||||
itemDataHead.blockPosition = blockPosition + 1
|
||||
itemDataHead.columnHead = subjectEntity
|
||||
itemList.add(itemDataHead)
|
||||
|
||||
if (subjectEntity.type == "game_vertical_slide") {
|
||||
val itemVerticalSlide = newItemInstance()
|
||||
itemVerticalSlide.blockPosition = blockPosition + 1
|
||||
itemVerticalSlide.verticalSlide = subjectEntity
|
||||
itemList.add(itemVerticalSlide)
|
||||
|
||||
for (i in 0 until data.size) {
|
||||
val game = data[i]
|
||||
if (!game.image.isNullOrEmpty()) continue
|
||||
game.subjectData = GameSubjectData(
|
||||
name = subjectEntity.name,
|
||||
tag = subjectEntity.tag,
|
||||
position = i + if (data[0].image.isNullOrEmpty()) 1 else 0,
|
||||
isOrder = subjectEntity.isOrder)
|
||||
|
||||
addGamePositionAndPackage(game)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (subjectEntity.type == "game_horizontal_slide") {
|
||||
val itemHorizontalSlide = newItemInstance()
|
||||
itemHorizontalSlide.blockPosition = blockPosition + 1
|
||||
itemHorizontalSlide.horizontalSlide = subjectEntity
|
||||
itemList.add(itemHorizontalSlide)
|
||||
return
|
||||
}
|
||||
|
||||
if (subjectEntity.type == "game_horizontal") {
|
||||
val itemDataSubject = newItemInstance()
|
||||
itemDataSubject.blockPosition = blockPosition + 1
|
||||
itemDataSubject.horizontalColumn = subjectEntity
|
||||
itemList.add(itemDataSubject)
|
||||
return
|
||||
}
|
||||
|
||||
if (subjectEntity.type == "column_collection") {
|
||||
val itemColumnCollection = newItemInstance()
|
||||
itemColumnCollection.blockPosition = blockPosition + 1
|
||||
itemColumnCollection.columnCollection = subjectEntity
|
||||
itemList.add(itemColumnCollection)
|
||||
return
|
||||
}
|
||||
|
||||
for (i in 0 until data.size) {
|
||||
val game = data[i]
|
||||
if (!game.image.isNullOrEmpty()) continue
|
||||
|
||||
game.subjectData = GameSubjectData(
|
||||
name = subjectEntity.name,
|
||||
tag = subjectEntity.tag,
|
||||
position = i + if (data[0].image.isNullOrEmpty()) 1 else 0,
|
||||
isOrder = subjectEntity.isOrder)
|
||||
val itemDataGame = newItemInstance()
|
||||
itemDataGame.blockPosition = blockPosition + 1
|
||||
game.sequence = i
|
||||
itemDataGame.game = game
|
||||
itemList.add(itemDataGame)
|
||||
addGamePositionAndPackage(game)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -13,7 +13,6 @@ import com.gh.common.util.RandomUtils
|
||||
import com.gh.download.DownloadManager
|
||||
import com.gh.gamecenter.baselist.LoadStatus
|
||||
import com.gh.gamecenter.entity.*
|
||||
import com.gh.gamecenter.game.data.GameSubjectData
|
||||
import com.gh.gamecenter.packagehelper.PackageRepository
|
||||
import com.gh.gamecenter.retrofit.BiResponse
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
@ -22,7 +21,7 @@ import com.lightgame.utils.Utils
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import retrofit2.HttpException
|
||||
import java.util.HashMap
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.set
|
||||
|
||||
@ -307,103 +306,19 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
|
||||
} else if (linkType == "column"
|
||||
|| linkType == "column_collection"
|
||||
|| linkType == "smart_subject") {
|
||||
transformationSubject(homeContent.linkColumn, i)
|
||||
|
||||
HomeSubjectTransformer.transform(
|
||||
mSnapshotItemList as ArrayList<LegacyHomeItemData>,
|
||||
homeContent.linkColumn,
|
||||
i,
|
||||
{ HomeItemData() },
|
||||
{ addGamePositionAndPackage(it) }
|
||||
)
|
||||
}
|
||||
}
|
||||
itemDataList.postValue(mSnapshotItemList)
|
||||
}
|
||||
|
||||
// 原游戏板块样式
|
||||
private fun transformationSubject(subjectEntity: SubjectEntity?, blockPosition: Int) {
|
||||
val data = subjectEntity?.data
|
||||
if (data == null || data.isEmpty()) return
|
||||
|
||||
if (!data[0].image.isNullOrEmpty() && subjectEntity.type != "column_collection") {
|
||||
val itemDataImage = HomeItemData()
|
||||
itemDataImage.blockPosition = blockPosition + 1
|
||||
|
||||
val gameEntity = data[0]
|
||||
if (gameEntity.id.isNullOrEmpty()) gameEntity.id = gameEntity.link ?: ""
|
||||
|
||||
if (data[0].type == "column") {
|
||||
itemDataImage.imageSlide = gameEntity
|
||||
mSnapshotItemList.add(itemDataImage)
|
||||
} else {
|
||||
itemDataImage.image = gameEntity
|
||||
itemDataImage.image?.subjectData = GameSubjectData(name = subjectEntity.name, isOrder = false)
|
||||
mSnapshotItemList.add(itemDataImage)
|
||||
if (gameEntity.type == "game") addGamePositionAndPackage(gameEntity)
|
||||
}
|
||||
if (subjectEntity.type == "image" || subjectEntity.type == "image_slide") return
|
||||
}
|
||||
|
||||
val itemDataHead = HomeItemData()
|
||||
itemDataHead.blockPosition = blockPosition + 1
|
||||
itemDataHead.columnHead = subjectEntity
|
||||
mSnapshotItemList.add(itemDataHead)
|
||||
|
||||
if (subjectEntity.type == "game_vertical_slide") {
|
||||
val itemVerticalSlide = HomeItemData()
|
||||
itemVerticalSlide.blockPosition = blockPosition + 1
|
||||
itemVerticalSlide.verticalSlide = subjectEntity
|
||||
mSnapshotItemList.add(itemVerticalSlide)
|
||||
|
||||
for (i in 0 until data.size) {
|
||||
val game = data[i]
|
||||
if (!game.image.isNullOrEmpty()) continue
|
||||
game.subjectData = GameSubjectData(
|
||||
name = subjectEntity.name,
|
||||
tag = subjectEntity.tag,
|
||||
position = i + if (data[0].image.isNullOrEmpty()) 1 else 0,
|
||||
isOrder = subjectEntity.isOrder)
|
||||
|
||||
addGamePositionAndPackage(game)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (subjectEntity.type == "game_horizontal_slide") {
|
||||
val itemHorizontalSlide = HomeItemData()
|
||||
itemHorizontalSlide.blockPosition = blockPosition + 1
|
||||
itemHorizontalSlide.horizontalSlide = subjectEntity
|
||||
mSnapshotItemList.add(itemHorizontalSlide)
|
||||
return
|
||||
}
|
||||
|
||||
if (subjectEntity.type == "game_horizontal") {
|
||||
val itemDataSubject = HomeItemData()
|
||||
itemDataSubject.blockPosition = blockPosition + 1
|
||||
itemDataSubject.horizontalColumn = subjectEntity
|
||||
mSnapshotItemList.add(itemDataSubject)
|
||||
return
|
||||
}
|
||||
|
||||
if (subjectEntity.type == "column_collection") {
|
||||
val itemColumnCollection = HomeItemData()
|
||||
itemColumnCollection.blockPosition = blockPosition + 1
|
||||
itemColumnCollection.columnCollection = subjectEntity
|
||||
mSnapshotItemList.add(itemColumnCollection)
|
||||
return
|
||||
}
|
||||
|
||||
for (i in 0 until data.size) {
|
||||
val game = data[i]
|
||||
if (!game.image.isNullOrEmpty()) continue
|
||||
|
||||
game.subjectData = GameSubjectData(
|
||||
name = subjectEntity.name,
|
||||
tag = subjectEntity.tag,
|
||||
position = i + if (data[0].image.isNullOrEmpty()) 1 else 0,
|
||||
isOrder = subjectEntity.isOrder)
|
||||
val itemDataGame = HomeItemData()
|
||||
itemDataGame.blockPosition = blockPosition + 1
|
||||
game.sequence = i
|
||||
itemDataGame.game = game
|
||||
mSnapshotItemList.add(itemDataGame)
|
||||
addGamePositionAndPackage(game)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun addGamePositionAndPackage(game: GameEntity) {
|
||||
var packages = ""
|
||||
|
||||
@ -0,0 +1,397 @@
|
||||
package com.gh.gamecenter.home
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.common.constant.ItemViewType
|
||||
import com.gh.common.util.*
|
||||
import com.gh.gamecenter.GameDetailActivity
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.adapter.viewholder.GameHeadViewHolder
|
||||
import com.gh.gamecenter.adapter.viewholder.GameImageViewHolder
|
||||
import com.gh.gamecenter.adapter.viewholder.GameViewHolder
|
||||
import com.gh.gamecenter.databinding.*
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.LinkEntity
|
||||
import com.gh.gamecenter.game.GameAndPosition
|
||||
import com.gh.gamecenter.game.GameItemViewHolder
|
||||
import com.gh.gamecenter.game.columncollection.GameColumnCollectionViewHolder
|
||||
import com.gh.gamecenter.game.horizontal.GameHorizontalListViewHolder
|
||||
import com.gh.gamecenter.game.imageslide.GameImageSlideViewHolder
|
||||
import com.gh.gamecenter.game.vertical.GameVerticalSlideViewHolder
|
||||
import com.gh.gamecenter.subject.SubjectActivity
|
||||
import com.halo.assistant.fragment.game.GamePluginAdapter
|
||||
import com.halo.assistant.fragment.game.GamePluginViewHolder
|
||||
import java.util.*
|
||||
|
||||
// 产品没定义的数据统计会用[首页]作为默认值,不管了 bite me
|
||||
class LegacyHomeFragmentAdapterAssistant(private var mContext: Context,
|
||||
private var mAdapter: RecyclerView.Adapter<RecyclerView.ViewHolder>,
|
||||
private var mLayoutInflater: LayoutInflater,
|
||||
private var mMakeItemBackgroundTransparent: Boolean = false,
|
||||
private var mOuterType: OuterType = OuterType.NEW_HOME) {
|
||||
|
||||
private var mIsOpenPluginList: Boolean = false
|
||||
|
||||
fun getLegacyItemType(itemData: LegacyHomeItemData): Int {
|
||||
|
||||
// 原游戏板块样式
|
||||
if (itemData.pluginList != null) return ItemViewType.GAME_PLUGIN
|
||||
if (itemData.columnHead != null) return ItemViewType.COLUMN_HEADER
|
||||
if (itemData.game != null) return ItemViewType.GAME_NORMAL
|
||||
if (itemData.image != null) return ItemViewType.GAME_IMAGE
|
||||
if (itemData.horizontalColumn != null || itemData.horizontalSlide != null) return ItemViewType.GAME_SUBJECT
|
||||
if (itemData.imageSlide != null) return ItemViewType.IMAGE_SLIDE_ITEM
|
||||
if (itemData.verticalSlide != null) return ItemViewType.VERTICAL_SLIDE_ITEM
|
||||
if (itemData.columnCollection != null) return ItemViewType.COLUMN_COLLECTION
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
fun createLegacyViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
return when (viewType) {
|
||||
ItemViewType.GAME_SUBJECT -> {
|
||||
val binding = GameHorizontalListBinding.bind(mLayoutInflater.inflate(R.layout.game_horizontal_list, parent, false))
|
||||
GameHorizontalListViewHolder(binding)
|
||||
}
|
||||
ItemViewType.GAME_NORMAL -> {
|
||||
GameItemViewHolder(GameItemBinding.bind(mLayoutInflater.inflate(R.layout.game_item, parent, false)))
|
||||
}
|
||||
ItemViewType.GAME_IMAGE -> {
|
||||
GameImageViewHolder(GameImageItemBinding.bind(mLayoutInflater.inflate(R.layout.game_image_item, parent, false)))
|
||||
}
|
||||
ItemViewType.COLUMN_HEADER -> {
|
||||
GameHeadViewHolder(GameHeadItemBinding.bind(mLayoutInflater.inflate(R.layout.game_head_item, parent, false)))
|
||||
}
|
||||
ItemViewType.GAME_PLUGIN -> {
|
||||
GamePluginViewHolder(mLayoutInflater.inflate(R.layout.game_plugin_item, parent, false))
|
||||
}
|
||||
ItemViewType.IMAGE_SLIDE_ITEM -> {
|
||||
GameImageSlideViewHolder(GameImageSlideItemBinding.bind(mLayoutInflater.inflate(R.layout.game_image_slide_item, parent, false)))
|
||||
}
|
||||
ItemViewType.VERTICAL_SLIDE_ITEM -> {
|
||||
GameVerticalSlideViewHolder(GameVerticalSlideItemBinding.bind(mLayoutInflater.inflate(R.layout.game_vertical_slide_item, parent, false)))
|
||||
}
|
||||
ItemViewType.COLUMN_COLLECTION -> {
|
||||
GameColumnCollectionViewHolder(GameColumnCollectionListBinding.bind(mLayoutInflater.inflate(R.layout.game_column_collection_list, parent, false)))
|
||||
}
|
||||
else -> throw NullPointerException()
|
||||
}
|
||||
}
|
||||
|
||||
fun bindLegacyViewHolder(holder: RecyclerView.ViewHolder,
|
||||
item: LegacyHomeItemData,
|
||||
position: Int) {
|
||||
when (holder) {
|
||||
is GameHeadViewHolder -> bindHeadView(holder, item)
|
||||
is GamePluginViewHolder -> bindPluginView(holder, item)
|
||||
is GameItemViewHolder -> bindGameItemView(holder, item, position)
|
||||
is GameImageViewHolder -> bindGameImageView(holder, item)
|
||||
is GameHorizontalListViewHolder -> bindGameHorizontalListView(holder, item)
|
||||
is GameImageSlideViewHolder -> bindGameImageSlide(holder, item)
|
||||
is GameVerticalSlideViewHolder -> bindVerticalSlide(holder, item)
|
||||
is GameColumnCollectionViewHolder -> bindColumnCollection(holder, item)
|
||||
}
|
||||
}
|
||||
|
||||
fun getLegacyGameEntityByPackage(positionList: ArrayList<GameAndPosition>,
|
||||
itemData: LegacyHomeItemData,
|
||||
packageName: String,
|
||||
position: Int) {
|
||||
// 原游戏板块样式
|
||||
val plugins = itemData.pluginList
|
||||
if (plugins != null) {
|
||||
for (entity in plugins) {
|
||||
for (apkEntity in entity.getApk()) {
|
||||
if (apkEntity.packageName == packageName) positionList.add(GameAndPosition(entity, position))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val game = itemData.game
|
||||
if (game != null) {
|
||||
positionList.add(GameAndPosition(game, position))
|
||||
return
|
||||
}
|
||||
|
||||
val horizontalColumn = itemData.horizontalColumn
|
||||
if (horizontalColumn != null) {
|
||||
positionList.add(GameAndPosition(null, position))
|
||||
return
|
||||
}
|
||||
|
||||
val verticalSlide = itemData.verticalSlide
|
||||
if (verticalSlide != null) {
|
||||
for (i in verticalSlide.data!!.indices) {
|
||||
val entity = verticalSlide.data!![i]
|
||||
if (!entity.image.isNullOrEmpty()) continue
|
||||
for (apkEntity in entity.getApk()) {
|
||||
if (apkEntity.packageName == packageName) {
|
||||
positionList.add(GameAndPosition(entity, position))
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
val image = itemData.image
|
||||
if (image != null) positionList.add(GameAndPosition(image, position))
|
||||
}
|
||||
|
||||
private fun bindColumnCollection(holder: GameColumnCollectionViewHolder, item: LegacyHomeItemData) {
|
||||
if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.transparent))
|
||||
|
||||
val columnCollection = item.columnCollection!!
|
||||
|
||||
val clickClosure: (position: Int, gameEntity: GameEntity) -> Unit = { prefixedPosition, gameEntity ->
|
||||
MtaHelper.onEvent("游戏专题合集", "首页合集图片", columnCollection.name)
|
||||
// 类型为排行榜时点击处理不一样
|
||||
if (columnCollection.style == "top") {
|
||||
DirectUtils.directToColumnCollection(mContext, columnCollection.id
|
||||
?: "", prefixedPosition, "(首页游戏)")
|
||||
} else {
|
||||
DirectUtils.directToLinkPage(mContext, LinkEntity(link = gameEntity.link, type = gameEntity.type), "(首页游戏)", "游戏-专题")
|
||||
}
|
||||
}
|
||||
|
||||
holder.bindColumnCollection(columnCollection, clickClosure)
|
||||
|
||||
val dataList = columnCollection.data!!
|
||||
if (dataList.size == 1) {
|
||||
val data = dataList[0]
|
||||
holder.binding.columnCollectionImage.setOnClickListener {
|
||||
if (mOuterType == OuterType.NEW_HOME) {
|
||||
MtaHelper.onEvent("游戏专题合集", "首页合集图片", columnCollection.name)
|
||||
} else {
|
||||
MtaHelper.onEvent("游戏专题合集", "安利墙合集图片", columnCollection.name)
|
||||
}
|
||||
DirectUtils.directToLinkPage(mContext, LinkEntity(link = data.link, type = data.type), "(首页游戏)", "游戏-专题")
|
||||
}
|
||||
} else {
|
||||
holder.binding.columnCollectionList.doOnScrolledSpecificDistance(distanceX = DisplayUtils.dip2px(24f), singleTimeEvent = true) {
|
||||
if (mOuterType == OuterType.NEW_HOME) {
|
||||
MtaHelper.onEvent("游戏专题", "新首页合辑滑动", "内容" + item.blockPosition + "_" + columnCollection.name)
|
||||
} else {
|
||||
MtaHelper.onEvent("游戏专题", "安利墙合辑滑动", "专题" + item.blockPosition + "_" + columnCollection.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindVerticalSlide(holder: GameVerticalSlideViewHolder, item: LegacyHomeItemData) {
|
||||
if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.transparent))
|
||||
|
||||
val verticalSlide = item.verticalSlide!!
|
||||
val clickClosure: (GameEntity) -> Unit = { gameEntity ->
|
||||
val subjectData = gameEntity.subjectData
|
||||
DataCollectionUtils.uploadClick(mContext, subjectData?.name + "-列表", "游戏-专题", gameEntity.name)
|
||||
GameDetailActivity.startGameDetailActivity(mContext, gameEntity,
|
||||
StringUtils.buildString("(首页-专题:", subjectData?.name, "-列表[", (subjectData?.position).toString(), "])"))
|
||||
}
|
||||
|
||||
holder.bindVerticalSlide(verticalSlide, clickClosure)
|
||||
}
|
||||
|
||||
private fun bindGameImageSlide(holder: GameImageSlideViewHolder, item: LegacyHomeItemData) {
|
||||
val binding = holder.binding
|
||||
binding.gameImageLine.visibility = View.GONE
|
||||
val entity = item.imageSlide
|
||||
|
||||
if (binding.columnList.adapter == null) {
|
||||
binding.columnList.doOnScrolledSpecificDistance(distanceX = DisplayUtils.dip2px(24f), singleTimeEvent = true) {
|
||||
if (mOuterType == OuterType.NEW_HOME) {
|
||||
MtaHelper.onEvent("游戏专题", "新首页专题滑动", "内容" + item.blockPosition + "_" + entity?.name)
|
||||
} else {
|
||||
MtaHelper.onEvent("游戏专题", "安利墙专题滑动", "专题" + item.blockPosition + "_" + entity?.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val imageClickListener = View.OnClickListener {
|
||||
DataCollectionUtils.uploadClick(mContext, entity?.name + "-大图", "游戏-专题")
|
||||
MtaHelper.onEvent("游戏专题", "底部图片", entity?.name)
|
||||
val linkEntity = LinkEntity()
|
||||
linkEntity.link = entity?.link
|
||||
linkEntity.type = entity?.type
|
||||
DirectUtils.directToLinkPage(mContext, linkEntity, "(游戏-专题:" + entity?.name + "-大图)", "首页游戏")
|
||||
}
|
||||
|
||||
holder.bindImageSlide(entity!!, imageClickListener, "游戏-专题")
|
||||
}
|
||||
|
||||
private fun bindGameHorizontalListView(holder: GameHorizontalListViewHolder, item: LegacyHomeItemData) {
|
||||
if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.transparent))
|
||||
|
||||
val subjectEntity = item.horizontalColumn ?: item.horizontalSlide
|
||||
holder.bindHorizontalList(subjectEntity!!)
|
||||
|
||||
if (subjectEntity.type != "game_horizontal") {
|
||||
holder.binding.horizontalRv.doOnScrolledSpecificDistance(distanceX = DisplayUtils.dip2px(24f), singleTimeEvent = true) {
|
||||
if (mOuterType == OuterType.NEW_HOME) {
|
||||
MtaHelper.onEvent("游戏专题", "新首页专题滑动", "内容" + item.blockPosition + "_" + subjectEntity.name)
|
||||
} else {
|
||||
MtaHelper.onEvent("游戏专题", "安利墙专题滑动", "专题" + item.blockPosition + "_" + subjectEntity.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindGameImageView(holder: GameImageViewHolder, item: LegacyHomeItemData) {
|
||||
if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.transparent))
|
||||
|
||||
val entity = item.image
|
||||
holder.bindImage(entity!!)
|
||||
|
||||
val name = entity.subjectData?.name
|
||||
val link = entity.link
|
||||
|
||||
holder.binding.gameImageIcon.setOnClickListener {
|
||||
DataCollectionUtils.uploadClick(mContext, "$name-大图", "游戏-专题")
|
||||
MtaHelper.onEvent("游戏专题", "大图", name + ":" + entity.name)
|
||||
val linkEntity = LinkEntity()
|
||||
linkEntity.link = link
|
||||
linkEntity.type = entity.type
|
||||
DirectUtils.directToLinkPage(mContext, linkEntity, "(游戏-专题:$name-大图)", "首页游戏")
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindGameItemView(holder: GameItemViewHolder, item: LegacyHomeItemData, position: Int) {
|
||||
if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.transparent))
|
||||
|
||||
val gameEntity = item.game
|
||||
val subjectData = gameEntity?.subjectData!!
|
||||
|
||||
// TODO check if this logic works
|
||||
if (mAdapter.itemCount - 1 == position + 1) {
|
||||
holder.itemView.setPadding(
|
||||
DisplayUtils.dip2px(16F), DisplayUtils.dip2px(4F),
|
||||
DisplayUtils.dip2px(20F), DisplayUtils.dip2px(12F))
|
||||
} else {
|
||||
holder.itemView.setPadding(
|
||||
DisplayUtils.dip2px(16F), DisplayUtils.dip2px(4F),
|
||||
DisplayUtils.dip2px(20F), DisplayUtils.dip2px(4F))
|
||||
}
|
||||
|
||||
holder.binding.game = gameEntity
|
||||
holder.binding.subjectTag = subjectData.tag
|
||||
holder.initServerType(gameEntity)
|
||||
holder.binding.executePendingBindings()
|
||||
|
||||
DownloadItemUtils.setOnClickListener(mContext, holder.binding.downloadBtn, gameEntity, position,
|
||||
mAdapter,
|
||||
StringUtils.buildString("(游戏-专题:", subjectData.name, "-列表[", (position + 1).toString(), "])"),
|
||||
StringUtils.buildString("游戏-专题-", subjectData.name, ":", gameEntity.name), null,
|
||||
object : EmptyCallback {
|
||||
override fun onCallback() {
|
||||
if (mOuterType == OuterType.NEW_HOME) {
|
||||
MtaHelper.onEvent("首页_新", "点击",
|
||||
"内容" + item.blockPosition + "_序号" + subjectData.position + "_" + gameEntity.name + "_" + holder.binding.downloadBtn.text.toString())
|
||||
} else {
|
||||
MtaHelper.onEvent("安利墙", "点击",
|
||||
"专题" + item.blockPosition + "_序号" + subjectData.position + "_" + gameEntity.name + "_" + holder.binding.downloadBtn.text.toString())
|
||||
}
|
||||
}
|
||||
})
|
||||
DownloadItemUtils.updateItem(mContext, gameEntity, GameViewHolder(holder.binding), !gameEntity.isPluggable)
|
||||
|
||||
holder.itemView.setOnClickListener {
|
||||
if (mOuterType == OuterType.NEW_HOME) {
|
||||
MtaHelper.onEvent("游戏专题", "新首页专题点击", "内容" + item.blockPosition + "_序号" + subjectData.position + "_" + gameEntity.name)
|
||||
} else {
|
||||
MtaHelper.onEvent("游戏专题", "安利墙专题点击", "专题" + item.blockPosition + "_序号" + subjectData.position + "_" + gameEntity.name)
|
||||
}
|
||||
DataCollectionUtils.uploadClick(mContext, subjectData.name + "-列表", "游戏-专题", gameEntity.name)
|
||||
|
||||
if (gameEntity.isPluggable) {
|
||||
GameDetailActivity.startGameDetailActivity(mContext, gameEntity.id,
|
||||
StringUtils.buildString("(游戏-专题:插件化-列表[", (subjectData.position).toString(), "])"))
|
||||
} else {
|
||||
GameDetailActivity.startGameDetailActivity(mContext, gameEntity,
|
||||
StringUtils.buildString("(游戏-专题:", subjectData.name, "-列表[", (subjectData.position).toString(), "])"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindHeadView(holder: GameHeadViewHolder, item: LegacyHomeItemData) {
|
||||
if (mMakeItemBackgroundTransparent) holder.binding.root.setBackgroundColor(ContextCompat.getColor(mContext, R.color.transparent))
|
||||
|
||||
val column = item.columnHead
|
||||
holder.bindHead(column!!)
|
||||
|
||||
holder.binding.headLineTop.visibility = View.GONE
|
||||
holder.binding.headMore.setOnClickListener {
|
||||
if ("change" == column.home) {
|
||||
MtaHelper.onEvent("游戏专题", "新首页专题点击", "内容" + item.blockPosition + "_换一批")
|
||||
holder.binding.headPb.visibility = View.VISIBLE
|
||||
|
||||
// 草,需要使用"换一个"功能的上层类自己加方法
|
||||
if (mAdapter is HomeFragmentAdapter) {
|
||||
(mAdapter as HomeFragmentAdapter).viewModel.changeSubjectGame(column.id!!)
|
||||
}
|
||||
} else {
|
||||
if (column.type == "column_collection") {
|
||||
MtaHelper.onEvent("游戏专题", "游戏专题合集", "内容" + item.blockPosition + "_全部")
|
||||
DirectUtils.directToColumnCollection(mContext, column.id!!, -1, "(游戏-专题:" + column.name + "-全部)")
|
||||
} else if (column.type == "top_game_comment") {
|
||||
MtaHelper.onEvent("安利墙", "进入", "首页查看全部")
|
||||
DirectUtils.directToAmway(mContext, null, "(游戏-专题:" + column.name + "-全部)", "")
|
||||
} else {
|
||||
MtaHelper.onEvent("游戏专题", "新首页专题点击", "内容" + item.blockPosition + "_全部")
|
||||
SubjectActivity.startSubjectActivity(mContext, column.id, column.getFilterName(), column.isOrder, "(游戏-专题:" + column.name + "-全部)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindPluginView(holder: GamePluginViewHolder, item: LegacyHomeItemData) {
|
||||
if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.transparent))
|
||||
|
||||
val pluginList = item.pluginList
|
||||
var adapter = holder.mPluginRv.adapter
|
||||
|
||||
val layoutParams = holder.mPluginHead.layoutParams as LinearLayout.LayoutParams
|
||||
if (mIsOpenPluginList) {
|
||||
holder.mHeadOpen.setImageResource(R.drawable.gamedetail_colse_icon)
|
||||
layoutParams.setMargins(0, DisplayUtils.dip2px(4F), 0, 0)
|
||||
} else {
|
||||
holder.mHeadOpen.setImageResource(R.drawable.gamedetail_open_icon)
|
||||
layoutParams.setMargins(0, DisplayUtils.dip2px(4F), 0, DisplayUtils.dip2px(4F))
|
||||
}
|
||||
|
||||
if (adapter == null) {
|
||||
adapter = GamePluginAdapter(mContext, pluginList)
|
||||
adapter.openList(mIsOpenPluginList)
|
||||
(holder.mPluginRv.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false
|
||||
holder.mPluginRv.layoutManager = LinearLayoutManager(mContext)
|
||||
holder.mPluginRv.adapter = adapter
|
||||
} else {
|
||||
(adapter as GamePluginAdapter).openList(mIsOpenPluginList)
|
||||
adapter.checkResetData(pluginList)
|
||||
}
|
||||
|
||||
holder.mHeadTitle.text = String.format(Locale.getDefault(), "你有%d个游戏可以升级插件版", pluginList?.size)
|
||||
holder.mPluginHead.setOnClickListener {
|
||||
if (mIsOpenPluginList) {
|
||||
mIsOpenPluginList = false
|
||||
MtaHelper.onEvent("首页_点击", "插件化区域", "收起")
|
||||
} else {
|
||||
mIsOpenPluginList = true
|
||||
MtaHelper.onEvent("首页_点击", "插件化区域", "展开")
|
||||
}
|
||||
mAdapter.notifyItemChanged(holder.adapterPosition)
|
||||
}
|
||||
}
|
||||
|
||||
enum class OuterType(val value: String) {
|
||||
NEW_HOME("首页_新"),
|
||||
|
||||
AMWAY("安利墙")
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package com.gh.gamecenter.home
|
||||
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.SubjectEntity
|
||||
import com.gh.gamecenter.entity.SubjectRecommendEntity
|
||||
|
||||
// 原游戏板块样式
|
||||
open class LegacyHomeItemData(
|
||||
// 非实体
|
||||
var blockPosition: Int = -1, // 统计会用到块的位置(相当于一个专题就是1)
|
||||
|
||||
// 实体
|
||||
var game: GameEntity? = null,
|
||||
var columnHead: SubjectEntity? = null,
|
||||
var horizontalColumn: SubjectEntity? = null,
|
||||
var subjectRecommend: List<SubjectRecommendEntity>? = null,
|
||||
var image: GameEntity? = null,
|
||||
var pluginList: List<GameEntity>? = null,
|
||||
var verticalSlide: SubjectEntity? = null,
|
||||
var horizontalSlide: SubjectEntity? = null,
|
||||
var imageSlide: GameEntity? = null,
|
||||
var columnCollection: SubjectEntity? = null)
|
||||
@ -111,7 +111,7 @@ class UserHistoryAdapter(context: Context,
|
||||
private fun bindRatingItem(holder: PersonalHomeRatingViewHolder) {
|
||||
val historyEntity = mEntityList[holder.adapterPosition]
|
||||
holder.binding.entity = historyEntity
|
||||
val m = Pattern.compile(RatingEditActivity.labelRegex).matcher(historyEntity.comment.content)
|
||||
val m = Pattern.compile(RatingEditActivity.LABEL_REGEX).matcher(historyEntity.comment.content)
|
||||
if (m.find()) {
|
||||
val contents = TextHelper.getCommentLabelSpannableStringBuilder(historyEntity.comment.content)
|
||||
holder.binding.content.setTextWithHighlightedTextWrappedInsideWrapper(text = contents, copyClickedText = true)
|
||||
|
||||
@ -6,7 +6,10 @@ import io.reactivex.functions.BiConsumer
|
||||
abstract class BiResponse<T> : BiConsumer<T, Throwable> {
|
||||
|
||||
override fun accept(t: T?, throwable: Throwable?) {
|
||||
if (t != null) onSuccess(t)
|
||||
if (t != null) {
|
||||
onSuccess(t)
|
||||
return
|
||||
}
|
||||
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace()
|
||||
|
||||
@ -9,7 +9,10 @@ import io.reactivex.functions.BiConsumer
|
||||
class EmptyResponse<T> : BiConsumer<T, Throwable> {
|
||||
|
||||
override fun accept(t: T?, throwable: Throwable?) {
|
||||
if (t != null) Utils.log(t)
|
||||
if (t != null) {
|
||||
Utils.log(t)
|
||||
return
|
||||
}
|
||||
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace()
|
||||
|
||||
Reference in New Issue
Block a user