Merge branch 'feature-issues2065' into 'dev'
fix: 【光环助手V5.15.0】新增 猜你喜欢-发现页(1031测试:1,2,4,10,12) https://git.shanqu.cc/pm/halo/halo-app-issues/-/issues/2065 See merge request halo/android/assistant-android!394
This commit is contained in:
@ -1,9 +1,13 @@
|
||||
package com.gh.gamecenter.discovery
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.util.SparseArray
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Space
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.common.databind.BindingAdapters
|
||||
import com.gh.common.exposure.ExposureEvent
|
||||
@ -33,6 +37,7 @@ import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus
|
||||
import com.gh.gamecenter.eventbus.EBSkip
|
||||
import com.gh.gamecenter.fragment.MainWrapperFragment
|
||||
import com.gh.gamecenter.fragment.MainWrapperRepository
|
||||
import com.lightgame.download.DownloadEntity
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
@ -146,7 +151,7 @@ class DiscoveryAdapter(
|
||||
)
|
||||
}
|
||||
holder.itemView.setOnLongClickListener {
|
||||
discoveryFeedback(gameEntity)
|
||||
discoveryFeedback(position, gameEntity)
|
||||
true
|
||||
}
|
||||
DownloadItemUtils.setOnClickListener(
|
||||
@ -160,7 +165,7 @@ class DiscoveryAdapter(
|
||||
event
|
||||
)
|
||||
|
||||
DownloadItemUtils.updateItem(mContext, gameEntity, holder, true)
|
||||
DownloadItemUtils.updateItem(mContext, gameEntity, holder, true, "star&brief")
|
||||
}
|
||||
is RecommendInterestViewHolder -> {
|
||||
holder.binding.root.setBackgroundColor(R.color.background_white.toColor(mContext))
|
||||
@ -200,7 +205,8 @@ class DiscoveryAdapter(
|
||||
is DirectGameBlockViewHolder -> {
|
||||
holder.binding.root.setBackgroundColor(R.color.background_white.toColor(mContext))
|
||||
holder.binding.root.setOnClickListener {
|
||||
if (mContext is DiscoveryActivity) {
|
||||
val navBar = MainWrapperRepository.getInstance().getNavBarLiveData().value
|
||||
if (navBar == null || mContext is DiscoveryActivity) {
|
||||
val blockData = HomeBottomBarHelper.getDefaultGameBarData()
|
||||
mContext.startActivity(BlockActivity.getIntent(mContext, blockData, mEntrance))
|
||||
} else {
|
||||
@ -233,7 +239,7 @@ class DiscoveryAdapter(
|
||||
return if (mEntityList == null || mEntityList.isEmpty()) return 0 else mEntityList.size + 2
|
||||
}
|
||||
|
||||
private fun discoveryFeedback(gameEntity: GameEntity) {
|
||||
private fun discoveryFeedback(position: Int, gameEntity: GameEntity) {
|
||||
DialogUtils.showReportReasonDialog(
|
||||
mContext,
|
||||
Constants.FEEDBACK_REASON_LIST.toList() as ArrayList<String>,
|
||||
@ -241,7 +247,9 @@ class DiscoveryAdapter(
|
||||
) { reason, _ ->
|
||||
mViewModel.discoveryFeedback(gameEntity.id, reason, gameEntity.type ?: "") {
|
||||
NewFlatLogUtils.logDiscoverPageNotInterest(gameEntity.id, gameEntity.name ?: "")
|
||||
mViewModel.refreshLiveData.postValue(true)
|
||||
mViewModel.forceRefresh = true
|
||||
mEntityList.removeAt(position)
|
||||
notifyItemRemoved(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -332,7 +340,9 @@ class DiscoveryAdapter(
|
||||
R.color.theme.toColor(binding.root.context)
|
||||
}
|
||||
)
|
||||
gameDes.text = gameEntity.decoratedDes
|
||||
gameDes.goneIf(gameEntity.recommendTag.isEmpty()) {
|
||||
gameDes.text = "根据 “${gameEntity.recommendTag}” 兴趣推荐"
|
||||
}
|
||||
//type: recommend 专题游戏 | ad 广告游戏 | filter 算法游戏
|
||||
adLabelTv.goneIf(!(gameEntity.type == "ad" && gameEntity.adIconActive))
|
||||
if (gameEntity.type == "ad" && gameEntity.adIconActive) {
|
||||
@ -360,6 +370,45 @@ class DiscoveryAdapter(
|
||||
recommendReasonTv.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
initGameSubtitle(gameEntity, gameSubtitleTv, gameDesSpace)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initGameSubtitle(
|
||||
entity: GameEntity,
|
||||
gameSubtitleTv: TextView,
|
||||
gameDesSpace: Space,
|
||||
) {
|
||||
gameSubtitleTv.visibility = View.GONE
|
||||
if ((entity.serverLabel == null && entity.subtitle.isNotEmpty() && !entity.advanceDownload) || (entity.subtitle.isNotEmpty())) {
|
||||
gameSubtitleTv.run {
|
||||
visibility = View.VISIBLE
|
||||
text = entity.subtitle
|
||||
if (entity.subtitleStyle != null) {
|
||||
setTextColor(Color.parseColor("#${entity.subtitleStyle?.color}"))
|
||||
background = GradientDrawable().apply {
|
||||
cornerRadius = 2F.dip2px().toFloat()
|
||||
if (entity.subtitleStyle?.style == "border") {
|
||||
setColor(Color.TRANSPARENT)
|
||||
setStroke(0.5F.dip2px(), Color.parseColor("#${entity.subtitleStyle?.background}"))
|
||||
} else {
|
||||
shape = GradientDrawable.RECTANGLE
|
||||
setColor(Color.parseColor("#${entity.subtitleStyle?.background}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
gameDesSpace.post {
|
||||
gameSubtitleTv.maxWidth = gameDesSpace.width
|
||||
}
|
||||
}
|
||||
if (entity.advanceDownload) {
|
||||
gameSubtitleTv.apply {
|
||||
visibility = View.VISIBLE
|
||||
text = "预下载"
|
||||
setTextColor(R.color.text_subtitle.toColor(context))
|
||||
background = R.drawable.bg_advance_download_game_subtitle.toDrawable(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,11 +74,6 @@ class DiscoveryFragment : LazyListFragment<DiscoveryItemData, DiscoveryViewModel
|
||||
load(R.layout.fragment_discovery_skeleton)
|
||||
}
|
||||
.show()
|
||||
|
||||
mListViewModel.refreshLiveData.observe(this.viewLifecycleOwner) {
|
||||
mListViewModel.forceRefresh = true
|
||||
onLoadRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFragmentFirstVisible() {
|
||||
|
||||
@ -2,7 +2,7 @@ package com.gh.gamecenter.discovery
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.gh.common.util.PackageUtils
|
||||
import com.gh.download.DownloadManager
|
||||
import com.gh.gamecenter.common.baselist.ListViewModel
|
||||
import com.gh.gamecenter.common.baselist.LoadStatus
|
||||
@ -17,6 +17,7 @@ import com.gh.gamecenter.core.utils.ToastUtils
|
||||
import com.gh.gamecenter.entity.DiscoveryGameCardLabel
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.halo.assistant.HaloApp
|
||||
import io.reactivex.Observable
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.HttpException
|
||||
@ -24,7 +25,6 @@ import retrofit2.HttpException
|
||||
class DiscoveryViewModel(application: Application) : ListViewModel<GameEntity, DiscoveryItemData>(application) {
|
||||
|
||||
val positionAndPackageMap = HashMap<String, Int>()
|
||||
val refreshLiveData: MutableLiveData<Boolean> = MutableLiveData()
|
||||
var forceRefresh = false
|
||||
private val mApi = RetrofitManager.getInstance().api
|
||||
private var mGameTags: ArrayList<LinkEntity>? = null
|
||||
@ -37,58 +37,76 @@ class DiscoveryViewModel(application: Application) : ListViewModel<GameEntity, D
|
||||
|
||||
override fun mergeResultLiveData() {
|
||||
mResultLiveData.addSource(mListLiveData) {
|
||||
val itemDataList = arrayListOf<DiscoveryItemData>()
|
||||
var insertCount = 0
|
||||
it.forEachIndexed { index, gameEntity ->
|
||||
itemDataList.add(DiscoveryItemData(gameEntity))
|
||||
//第6、12、18、24个游戏后面固定插入兴趣推荐卡片
|
||||
when (index) {
|
||||
5 -> {
|
||||
itemDataList.add(
|
||||
DiscoveryItemData(
|
||||
cardPosition = 1,
|
||||
interestCardLabels = mDiscoveryGameCardLabelMap["卡片一"]
|
||||
)
|
||||
)
|
||||
insertCount++
|
||||
}
|
||||
11 -> {
|
||||
itemDataList.add(
|
||||
DiscoveryItemData(
|
||||
cardPosition = 2,
|
||||
interestImageCardLabel = mDiscoveryGameCardLabelMap["卡片二"]?.get(0)
|
||||
)
|
||||
)
|
||||
insertCount++
|
||||
}
|
||||
17 -> {
|
||||
itemDataList.add(
|
||||
DiscoveryItemData(
|
||||
cardPosition = 3,
|
||||
interestCardLabels = mDiscoveryGameCardLabelMap["卡片三"]
|
||||
)
|
||||
)
|
||||
insertCount++
|
||||
}
|
||||
23 -> {
|
||||
itemDataList.add(
|
||||
DiscoveryItemData(
|
||||
cardPosition = 4,
|
||||
interestCardLabels = mDiscoveryGameCardLabelMap["卡片四"]
|
||||
)
|
||||
)
|
||||
insertCount++
|
||||
}
|
||||
else -> {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
addGamePositionAndPackage(index + insertCount, gameEntity)
|
||||
}
|
||||
mResultLiveData.postValue(itemDataList)
|
||||
mergeResultItemData(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun mergeResultItemData(games: MutableList<GameEntity>) {
|
||||
val itemDataList = arrayListOf<DiscoveryItemData>()
|
||||
var insertCount = 0
|
||||
var i = 0
|
||||
while (i < games.size) {
|
||||
val gameEntity = games[i]
|
||||
//删除已安装的游戏
|
||||
if (gameEntity.getApk().isNotEmpty() && PackageUtils.isInstalled(
|
||||
HaloApp.getInstance().application,
|
||||
gameEntity.getApk()[0].packageName
|
||||
)
|
||||
) {
|
||||
games.removeAt(i)
|
||||
i--
|
||||
}
|
||||
i++
|
||||
}
|
||||
games.forEachIndexed { index, gameEntity ->
|
||||
itemDataList.add(DiscoveryItemData(gameEntity))
|
||||
//第6、12、18、24个游戏后面固定插入兴趣推荐卡片
|
||||
when (index) {
|
||||
5 -> {
|
||||
itemDataList.add(
|
||||
DiscoveryItemData(
|
||||
cardPosition = 1,
|
||||
interestCardLabels = mDiscoveryGameCardLabelMap["卡片一"]
|
||||
)
|
||||
)
|
||||
insertCount++
|
||||
}
|
||||
11 -> {
|
||||
itemDataList.add(
|
||||
DiscoveryItemData(
|
||||
cardPosition = 2,
|
||||
interestImageCardLabel = mDiscoveryGameCardLabelMap["卡片二"]?.get(0)
|
||||
)
|
||||
)
|
||||
insertCount++
|
||||
}
|
||||
17 -> {
|
||||
itemDataList.add(
|
||||
DiscoveryItemData(
|
||||
cardPosition = 3,
|
||||
interestCardLabels = mDiscoveryGameCardLabelMap["卡片三"]
|
||||
)
|
||||
)
|
||||
insertCount++
|
||||
}
|
||||
23 -> {
|
||||
itemDataList.add(
|
||||
DiscoveryItemData(
|
||||
cardPosition = 4,
|
||||
interestCardLabels = mDiscoveryGameCardLabelMap["卡片四"]
|
||||
)
|
||||
)
|
||||
insertCount++
|
||||
}
|
||||
else -> {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
addGamePositionAndPackage(index + insertCount, gameEntity)
|
||||
}
|
||||
mResultLiveData.postValue(itemDataList)
|
||||
}
|
||||
|
||||
override fun provideDataObservable(page: Int): Observable<MutableList<GameEntity>>? {
|
||||
val paramsMap = if (forceRefresh) {
|
||||
mapOf("refresh" to "true")
|
||||
|
||||
@ -20,7 +20,6 @@ import com.lightgame.download.DownloadEntity
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
@Parcelize
|
||||
data class GameEntity(
|
||||
@ -295,6 +294,8 @@ data class GameEntity(
|
||||
var columnRank: ColumnRank? = null,//榜单详情
|
||||
@SerializedName("ad_icon_active")
|
||||
var adIconActive: Boolean = false,// 游戏广告 true显示,false隐藏。只有当type=ad时才会返回该字段
|
||||
@SerializedName("recommend_tag")
|
||||
var recommendTag: String = "",
|
||||
|
||||
// 专题id,用于曝光使用
|
||||
var subjectId: String? = null,
|
||||
|
||||
@ -66,11 +66,32 @@
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintHorizontal_chainStyle="packed"
|
||||
app:layout_constraintLeft_toLeftOf="@+id/gameDescContainer"
|
||||
app:layout_constraintRight_toLeftOf="@+id/recent_played_tag"
|
||||
app:layout_constraintRight_toLeftOf="@+id/gameSubtitleTv"
|
||||
app:layout_constraintTop_toTopOf="@+id/gameIconView"
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
tools:text="地海争霸:巫妖王再怒" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gameSubtitleTv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="14dp"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:background="@drawable/bg_advance_download_game_subtitle"
|
||||
android:paddingStart="2dp"
|
||||
android:paddingEnd="2dp"
|
||||
android:singleLine="true"
|
||||
android:textColor="@color/text_subtitle"
|
||||
android:textSize="@dimen/tag_text_size"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/game_name"
|
||||
app:layout_constraintEnd_toStartOf="@+id/recent_played_tag"
|
||||
app:layout_constraintStart_toEndOf="@+id/game_name"
|
||||
app:layout_constraintTop_toTopOf="@+id/game_name"
|
||||
app:layout_goneMarginStart="0dp"
|
||||
tools:text="副标题"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recent_played_tag"
|
||||
android:layout_width="44dp"
|
||||
@ -83,7 +104,7 @@
|
||||
android:textSize="9sp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/game_name"
|
||||
app:layout_constraintLeft_toRightOf="@+id/game_name"
|
||||
app:layout_constraintLeft_toRightOf="@+id/gameSubtitleTv"
|
||||
app:layout_constraintRight_toLeftOf="@+id/game_kaifu_type"
|
||||
app:layout_constraintTop_toTopOf="@+id/game_name" />
|
||||
|
||||
@ -106,6 +127,16 @@
|
||||
app:layout_constraintRight_toLeftOf="@+id/adLabelTv"
|
||||
app:layout_constraintTop_toTopOf="@+id/game_name" />
|
||||
|
||||
<Space
|
||||
android:id="@+id/gameDesSpace"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:background="@color/black"
|
||||
app:layout_constraintBottom_toTopOf="@+id/recommendReasonTv"
|
||||
app:layout_constraintLeft_toRightOf="@+id/gameIconView"
|
||||
app:layout_constraintRight_toLeftOf="@+id/download_btn"
|
||||
app:layout_constraintTop_toBottomOf="@+id/game_name" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/adLabelTv"
|
||||
android:layout_width="21dp"
|
||||
@ -120,7 +151,8 @@
|
||||
app:layout_constraintBottom_toBottomOf="@+id/game_name"
|
||||
app:layout_constraintLeft_toRightOf="@+id/game_kaifu_type"
|
||||
app:layout_constraintRight_toRightOf="@+id/gameDescContainer"
|
||||
app:layout_constraintTop_toTopOf="@+id/game_name" />
|
||||
app:layout_constraintTop_toTopOf="@+id/game_name"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/gameDescContainer"
|
||||
@ -143,13 +175,14 @@
|
||||
app:layout_constraintHorizontal_chainStyle="packed"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toLeftOf="@+id/game_des"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/game_des"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_toRightOf="@id/game_rating"
|
||||
android:ellipsize="end"
|
||||
android:includeFontPadding="false"
|
||||
|
||||
Reference in New Issue
Block a user