Merge branch 'dev_4.0.2' of gitlab.ghzs.com:halo/assistant-android into dev_4.0.2
This commit is contained in:
@ -28,11 +28,12 @@ data class ExposureEvent(
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun createEvent(gameEntity: GameEntity?, source: List<ExposureSource>, eTrace: List<ExposureEvent>? = null, event: ExposureType = ExposureType.EXPOSURE): ExposureEvent {
|
||||
if (!gameEntity?.getApk().isNullOrEmpty() && gameEntity?.getApk()?.size == 1) {
|
||||
if (gameEntity?.getApk()?.size == 1) {
|
||||
gameEntity.gameVersion = gameEntity.getApk().elementAtOrNull(0)?.version ?: ""
|
||||
}
|
||||
return ExposureEvent(
|
||||
payload = ExposureEntity(gameId = gameEntity?.id?.getFirstElementDividedByDivider(Constants.GAME_ID_DIVIDER),
|
||||
payload = ExposureEntity(
|
||||
gameId = gameEntity?.id?.getFirstElementDividedByDivider(Constants.GAME_ID_DIVIDER),
|
||||
gameName = gameEntity?.name?.removeSuffix(Constants.GAME_NAME_DECORATOR),
|
||||
gameVersion = gameEntity?.gameVersion,
|
||||
sequence = gameEntity?.sequence,
|
||||
|
||||
@ -1,19 +1,27 @@
|
||||
package com.gh.common.util
|
||||
|
||||
import android.content.Context
|
||||
import android.annotation.SuppressLint
|
||||
import android.text.TextUtils
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.entity.SubjectEntity
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.retrofit.BiResponse
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.lightgame.utils.Utils
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
/**
|
||||
* 首页补充游戏库辅助类
|
||||
*/
|
||||
object GameRepositoryHelper {
|
||||
object GameSubstituteRepositoryHelper {
|
||||
|
||||
private const val KEY_GAME_REPOSITORY = "game_repository"
|
||||
private const val KEY_GAME_REPOSITORY = "game_substitute_repository"
|
||||
|
||||
private var mSubstitutableGameIdSet = hashSetOf<String>()
|
||||
private var mApi = RetrofitManager.getInstance(HaloApp.getInstance().application).api
|
||||
private var mApplicationContext = HaloApp.getInstance().application
|
||||
|
||||
var gameCollectionList: List<SubjectEntity> = arrayListOf()
|
||||
|
||||
@ -25,11 +33,8 @@ object GameRepositoryHelper {
|
||||
* 获取游戏补充库
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getGameRepository(context: Context) {
|
||||
|
||||
RetrofitManager.getInstance(context)
|
||||
.api
|
||||
.reserveColumns
|
||||
fun updateGameSubstituteRepository() {
|
||||
mApi.reserveColumns
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(object : Response<List<SubjectEntity>>() {
|
||||
override fun onResponse(response: List<SubjectEntity>?) {
|
||||
@ -39,26 +44,43 @@ object GameRepositoryHelper {
|
||||
}
|
||||
})
|
||||
|
||||
updateSubstitutableGames()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@SuppressLint("CheckResult")
|
||||
fun updateSubstitutableGames() {
|
||||
val single = if (UserManager.getInstance().isLoggedIn) {
|
||||
Utils.log("获取登录后的可替换游戏")
|
||||
mApi.getIdListOfPlayedGames(UserManager.getInstance().userId, Utils.getTime(mApplicationContext))
|
||||
} else {
|
||||
Utils.log("获取未登录 ${HaloApp.getInstance().gid} 时的可替换游戏")
|
||||
mApi.getIdListOfDownloadedGames(HaloApp.getInstance().gid, Utils.getTime(mApplicationContext))
|
||||
}
|
||||
single.subscribeOn(Schedulers.io()).subscribe(object : BiResponse<List<String>>() {
|
||||
override fun onSuccess(data: List<String>) {
|
||||
mSubstitutableGameIdSet = data.toHashSet()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新内存中的游戏库(即从 SP 中再读一次)
|
||||
*/
|
||||
@JvmStatic
|
||||
fun refreshGameRepository() = loadSavedRepository()
|
||||
fun refreshRepositoryFromLocal() = loadSavedRepository()
|
||||
|
||||
private fun loadSavedRepository() {
|
||||
gameCollectionList = SPUtils.getString(KEY_GAME_REPOSITORY).toObject() ?: arrayListOf()
|
||||
}
|
||||
|
||||
fun updateGameRepository(subjects: List<SubjectEntity>?) {
|
||||
private fun updateGameRepository(subjects: List<SubjectEntity>?) {
|
||||
|
||||
if (subjects == null) return
|
||||
|
||||
SPUtils.setString(KEY_GAME_REPOSITORY, subjects.toJson())
|
||||
|
||||
gameCollectionList = subjects
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,7 +88,7 @@ object GameRepositoryHelper {
|
||||
* @param collectionId 补充游戏库相应专题 ID
|
||||
* @param gameIdList 该专题里已经包含的游戏 ID 列表
|
||||
*/
|
||||
fun getOneUniqueGame(collectionId: String?, gameIdList: HashSet<String>): GameEntity? {
|
||||
private fun getOneUniqueGame(collectionId: String?, gameIdList: HashSet<String>): GameEntity? {
|
||||
collectionId?.let {
|
||||
val collection = gameCollectionList.find { it.id == collectionId }
|
||||
collection?.let {
|
||||
@ -82,10 +104,13 @@ object GameRepositoryHelper {
|
||||
return null
|
||||
}
|
||||
|
||||
fun replaceInstalledApp(gameList: MutableList<GameEntity>,
|
||||
alreadyDisplayedGameIdSet: HashSet<String>,
|
||||
relatedCollectionId: String,
|
||||
shouldLogReplaceEvent: Boolean) {
|
||||
/**
|
||||
* 替换游戏,包括 已安装,历史下载,历史已安装等类型
|
||||
*/
|
||||
fun replaceGames(gameList: MutableList<GameEntity>,
|
||||
alreadyDisplayedGameIdSet: HashSet<String>,
|
||||
relatedCollectionId: String,
|
||||
shouldLogReplaceEvent: Boolean) {
|
||||
val positionOfTheGameToReplaceList = arrayListOf<Int>()
|
||||
|
||||
// 标记需要替换的已安装游戏
|
||||
@ -96,23 +121,32 @@ object GameRepositoryHelper {
|
||||
continue
|
||||
}
|
||||
|
||||
var isThisPositionAdded = false
|
||||
var isThisPositionLabeled = false
|
||||
|
||||
// 从 游戏ID 判断当前游戏是否需要被替换
|
||||
if (mSubstitutableGameIdSet.contains(game.id)) {
|
||||
positionOfTheGameToReplaceList.add(index)
|
||||
isThisPositionLabeled = true
|
||||
}
|
||||
|
||||
// 检查是否已安装该游戏里同包名的 APK
|
||||
for (apk in game.getApk()) {
|
||||
if (PackageHelper.validLocalPackageNameSet.contains(apk.packageName)) {
|
||||
// 将该位置的游戏标记为需要替换
|
||||
positionOfTheGameToReplaceList.add(index)
|
||||
isThisPositionAdded = true
|
||||
break
|
||||
if (!isThisPositionLabeled) {
|
||||
for (apk in game.getApk()) {
|
||||
if (PackageHelper.validLocalPackageNameSet.contains(apk.packageName)) {
|
||||
// 将该位置的游戏标记为需要替换
|
||||
positionOfTheGameToReplaceList.add(index)
|
||||
isThisPositionLabeled = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 若此游戏所包含的 apk 没有已安装,那么再检查是否已安装有预设相关包名
|
||||
if (!isThisPositionAdded) {
|
||||
if (!isThisPositionLabeled) {
|
||||
var relatedPackageList = arrayListOf<String>()
|
||||
for (entity in PackageHelper.relatedPackageList) {
|
||||
if (entity.gameId == game.id) {
|
||||
relatedPackageList = ArrayList(entity.packages)
|
||||
relatedPackageList = ArrayList(entity.packages!!)
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -139,14 +173,17 @@ object GameRepositoryHelper {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun isThisGameUnique(game: GameEntity, gameIdList: HashSet<String>): Boolean {
|
||||
// 若该补充游戏已经存在关联关系,判定为非唯一
|
||||
// 判断该游戏是否出现在已安装列表
|
||||
if (mSubstitutableGameIdSet.contains(game.id)) return false
|
||||
|
||||
// 该补充游戏是否已经存在关联关系
|
||||
for (relatedId in game.relatedGameIds!!) {
|
||||
if (gameIdList.contains(relatedId)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for (apk in game.getApk()) {
|
||||
// 检查本地是否已安装该游戏,已过滤那部分框架服务的包名
|
||||
if (PackageHelper.validLocalPackageNameSet.contains(apk.packageName)) {
|
||||
@ -25,7 +25,7 @@ import com.gh.common.util.DeviceTokenUtils;
|
||||
import com.gh.common.util.DeviceUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.EmptyCallback;
|
||||
import com.gh.common.util.GameRepositoryHelper;
|
||||
import com.gh.common.util.GameSubstituteRepositoryHelper;
|
||||
import com.gh.common.util.GdtHelper;
|
||||
import com.gh.common.util.GsonUtils;
|
||||
import com.gh.common.util.MtaHelper;
|
||||
@ -141,7 +141,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
getFilterDetailTags();
|
||||
getAuthDialog();
|
||||
UsageStatsHelper.checkAndPostUsageStats();
|
||||
GameRepositoryHelper.getGameRepository(this);
|
||||
GameSubstituteRepositoryHelper.updateGameSubstituteRepository();
|
||||
|
||||
// 第一次启动,把package.txt文件内容加载进数据库
|
||||
FilterManager filterManager = new FilterManager(getApplicationContext());
|
||||
|
||||
@ -72,7 +72,7 @@ class GameViewModel(application: Application, var blockData: SubjectRecommendEnt
|
||||
getSlideData(true)
|
||||
|
||||
// 触发列表刷新行为时亦刷新内存中的备用游戏库列表
|
||||
GameRepositoryHelper.refreshGameRepository()
|
||||
GameSubstituteRepositoryHelper.refreshRepositoryFromLocal()
|
||||
}
|
||||
|
||||
fun getSlideData(initData: Boolean) {
|
||||
@ -416,7 +416,7 @@ class GameViewModel(application: Application, var blockData: SubjectRecommendEnt
|
||||
}
|
||||
|
||||
subjectEntity.relatedColumnId?.let {
|
||||
GameRepositoryHelper.replaceInstalledApp(data, mSubjectGameIdList, it, false)
|
||||
GameSubstituteRepositoryHelper.replaceGames(data, mSubjectGameIdList, it, false)
|
||||
}
|
||||
|
||||
if (!data[0].image.isNullOrEmpty() && subjectEntity.type != "column_collection") {
|
||||
|
||||
@ -8,7 +8,7 @@ import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.MediatorLiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.gh.common.util.ApkActiveUtils
|
||||
import com.gh.common.util.GameRepositoryHelper
|
||||
import com.gh.common.util.GameSubstituteRepositoryHelper
|
||||
import com.gh.common.util.GameUtils
|
||||
import com.gh.common.util.RandomUtils
|
||||
import com.gh.download.DownloadManager
|
||||
@ -67,7 +67,7 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
|
||||
mSubjectGameIdList = hashSetOf()
|
||||
|
||||
// 触发列表刷新行为时亦刷新内存中的备用游戏库列表
|
||||
GameRepositoryHelper.refreshGameRepository()
|
||||
GameSubstituteRepositoryHelper.refreshRepositoryFromLocal()
|
||||
|
||||
getHomeSlides()
|
||||
getSmartColumn()
|
||||
@ -335,7 +335,7 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
||||
|
||||
subjectEntity.relatedColumnId?.let {
|
||||
GameRepositoryHelper.replaceInstalledApp(data, mSubjectGameIdList, it, mShouldLogReplaceEvent)
|
||||
GameSubstituteRepositoryHelper.replaceGames(data, mSubjectGameIdList, it, mShouldLogReplaceEvent)
|
||||
mShouldLogReplaceEvent = false
|
||||
}
|
||||
}
|
||||
|
||||
@ -2115,6 +2115,18 @@ public interface ApiService {
|
||||
*/
|
||||
@GET("users/{user_id}/played_games")
|
||||
Single<List<GameEntity>> getPlayedGames(@Path("user_id") String userId, @Query("page") int page, @Query("timestamp") long timestamp);
|
||||
|
||||
/**
|
||||
* 获取用户玩过的游戏列表(仅游戏ID)
|
||||
*/
|
||||
@GET("users/{user_id}/played_game_ids")
|
||||
Single<List<String>> getIdListOfPlayedGames(@Path("user_id") String userId, @Query("timestamp") long timestamp);
|
||||
|
||||
/**
|
||||
* 获取用户设备下载过的游戏列表(仅游戏ID)
|
||||
*/
|
||||
@GET("devices/{device_id}/downloaded_game_ids")
|
||||
Single<List<String>> getIdListOfDownloadedGames(@Path("device_id") String deviceId, @Query("timestamp") long timestamp);
|
||||
|
||||
/**
|
||||
* 获取开服过滤标签
|
||||
|
||||
@ -6,15 +6,13 @@ import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MediatorLiveData;
|
||||
|
||||
import com.gh.common.PushManager;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.im.ImManager;
|
||||
import com.gh.common.repository.ReservationRepository;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DeviceUtils;
|
||||
import com.gh.common.util.GameSubstituteRepositoryHelper;
|
||||
import com.gh.common.util.GsonUtils;
|
||||
import com.gh.common.util.LoginHelper;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
@ -44,6 +42,8 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MediatorLiveData;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
@ -146,9 +146,10 @@ public class UserRepository {
|
||||
SPUtils.setString(mPreferences, Constants.LOGIN_TOKEN_ID, null);
|
||||
LoginHelper.logoutWithQQ();
|
||||
|
||||
PushManager.deleteAlias();
|
||||
ImManager.detachIm();
|
||||
PushManager.deleteAlias();
|
||||
ReservationRepository.clearReservations();
|
||||
GameSubstituteRepositoryHelper.updateSubstitutableGames();
|
||||
|
||||
// 通知页面更新
|
||||
EventBus.getDefault().post(new EBReuse(PersonalFragment.LOGOUT_TAG));
|
||||
@ -240,6 +241,7 @@ public class UserRepository {
|
||||
userTokenHandle(response, loginTag);
|
||||
|
||||
PushManager.getAndSetAlias();
|
||||
GameSubstituteRepositoryHelper.updateSubstitutableGames();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user