Compare commits

..

10 Commits

Author SHA1 Message Date
04468c0627 build: suppress warning 2022-12-23 16:16:12 +08:00
e585d905ac fix: 处理一些细节问题 2022-11-08 17:56:55 +08:00
1f066e676f Merge branch 'feature-module_setting' into feature-module_setting_compose 2022-11-08 17:51:03 +08:00
a08f3aa9ac Merge branch 'dev-5.16.0' into feature-module_setting
# Conflicts:
#	app/src/main/res/values/strings.xml
2022-11-08 17:30:04 +08:00
f799096655 fix: 处理一些细节问题 2022-11-07 18:01:28 +08:00
431aa52e49 refactor:使用 Jetpack Compose 实现设置功能模块的 UI https://git.shanqu.cc/halo/android/assistant-android/-/issues/88 2022-11-04 11:36:25 +08:00
26d6e4086a fix: 处理合并分支后出现的冲突 2022-11-02 17:16:55 +08:00
7e999784b7 Merge branch 'feature-module_setting' into dev
# Conflicts:
#	app/build.gradle
#	app/src/main/java/com/gh/common/util/DownloadObserver.kt
#	app/src/main/java/com/gh/gamecenter/home/HomeFragmentAdapter.kt
#	app/src/main/java/com/gh/gamecenter/personal/HaloPersonalFragment.kt
#	app/src/main/java/com/gh/gamecenter/personal/PersonalFunctionAdapter.kt
#	module_core/src/main/java/com/gh/gamecenter/core/provider/IAppProvider.kt
#	module_setting/src/main/java/com/gh/gamecenter/setting/view/GameDownloadSettingActivity.kt
#	module_setting/src/main/java/com/gh/gamecenter/setting/view/GameDownloadSettingFragment.kt
#	module_setting/src/main/java/com/gh/gamecenter/setting/view/NetworkDiagnosisActivity.kt
#	module_setting/src/main/java/com/gh/gamecenter/setting/view/SettingsFragment.kt
#	module_setting/src/main/java/com/gh/gamecenter/setting/view/VideoSettingActivity.kt
#	module_setting/src/main/java/com/gh/gamecenter/setting/view/security/BindPhoneFragment.kt
#	module_setting/src/main/java/com/gh/gamecenter/setting/view/security/SecurityActivity.kt
#	module_setting/src/main/java/com/gh/gamecenter/setting/view/security/SecurityFragment.kt
2022-11-02 16:56:56 +08:00
f07bcc89e8 fix:修复无法跳转安装包清理的问题 2022-10-28 17:47:14 +08:00
22cff4ed72 refactor: 组件化设置功能 https://git.shanqu.cc/halo/android/assistant-android/-/issues/87 2022-10-18 11:57:27 +08:00
410 changed files with 8458 additions and 10200 deletions

3
.gitmodules vendored
View File

@ -8,6 +8,3 @@
[submodule "module_common/src/debug/assets/assistant-android-mock"]
path = module_common/src/debug/assets/assistant-android-mock
url = git@git.shanqu.cc:halo/android/assistant-android-mock.git
[submodule "ndownload"]
path = ndownload
url = git@git.shanqu.cc:android/ndownload.git

View File

@ -260,7 +260,6 @@ dependencies {
compileOnly "com.github.axen1314.lancet:lancet-base:${lancet_version}"
kapt "com.alibaba:arouter-compiler:$arouterVersion"
implementation project(':ndownload')
implementation project(':vspace-bridge:vspace')
implementation (project(':module_common')) {
@ -269,7 +268,7 @@ dependencies {
implementation(project(':module_login')) {
exclude group: 'androidx.swiperefreshlayout'
}
implementation(project(':module_setting')) {
implementation(project(':module_setting_compose')) {
exclude group: 'androidx.swiperefreshlayout'
}
// 默认不接入光能模块,提高编译速度

View File

@ -51,7 +51,27 @@
com.google.android.exoplayer2,
tv.danmaku.ijk.media.exo2,
pl.droidsonroids.gif,
com.lzf.easyfloat" />
com.lzf.easyfloat,
com.airbnb.lottie.compose,
androidx.compose.ui.platform,
androidx.compose.material.icons,
androidx.activity.compose,
androidx.compose.ui.tooling,
androidx.compose.ui.tooling.data,
androidx.compose.material.ripple,
androidx.compose.foundation,
androidx.compose.animation,
androidx.compose.foundation.layout,
androidx.compose.ui.text,
androidx.compose.ui.graphics,
androidx.compose.ui.unit,
androidx.compose.ui.util,
androidx.compose.ui.geometry,
androidx.compose.runtime.saveable,
androidx.compose.animation.core,
androidx.constraintlayout.compose,
androidx.compose.ui.test.manifest,
androidx.compose.ui.tooling.preview"/>
<!-- 去掉 SDK 一些流氓权限 -->
<uses-permission
@ -709,15 +729,6 @@
android:name=".discovery.DiscoveryActivity"
android:screenOrientation="portrait" />
<activity
android:name=".cloudarchive.CloudArchiveManagerActivity"
android:screenOrientation="portrait" />
<activity
android:name=".savegame.GameArchiveListActivity"
android:screenOrientation="portrait" />
<!-- <activity-->
<!-- android:name="${applicationId}.douyinapi.DouYinEntryActivity"-->
<!-- android:launchMode="singleTask"-->
@ -740,26 +751,6 @@
android:enabled="true"
android:exported="true" />
<provider
android:name="com.gh.vspace.VFileProvider"
android:authorities="${applicationId}.virtual_file_provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<service
android:name=".aidl.CommunicationService"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="com.gh.gamecenter.aidl.CommunicationService"/>
</intent-filter>
</service>
<!-- <provider-->
<!-- android:name="androidx.startup.InitializationProvider"-->
<!-- android:authorities="${applicationId}.androidx-startup"-->

View File

@ -1 +0,0 @@
{"v":"5.9.1","fr":60,"ip":0,"op":100,"w":64,"h":64,"nm":"多版本下载提示_dark","ddd":0,"assets":[{"id":"comp_0","nm":"arrow 合成_dark","fr":60,"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"arrow","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.333],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":0,"s":[0]},{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":24,"s":[100]},{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.667],"y":[0]},"t":76,"s":[100]},{"t":100,"s":[0]}],"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":1,"k":[{"i":{"x":0.333,"y":1},"o":{"x":0.364,"y":0},"t":0,"s":[28,-12,0],"to":[0,6.382,0],"ti":[0,-0.284,0]},{"i":{"x":0.667,"y":0.667},"o":{"x":0.333,"y":0.333},"t":24,"s":[28,28,0],"to":[0,0,0],"ti":[0,0,0]},{"i":{"x":0.667,"y":1},"o":{"x":0.667,"y":0},"t":76,"s":[28,28,0],"to":[0,6.667,0],"ti":[0,-6.667,0]},{"t":100,"s":[28,68,0]}],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[0,2],[0,-2]],"c":false},"ix":2},"nm":"路径 1","mn":"ADBE Vector Shape - Group","hd":false},{"ind":1,"ty":"sh","ix":2,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[-2,0],[0,2]],"c":false},"ix":2},"nm":"路径 2","mn":"ADBE Vector Shape - Group","hd":false},{"ind":2,"ty":"sh","ix":3,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[2,0],[0,2]],"c":false},"ix":2},"nm":"路径 3","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":1,"k":[{"i":{"x":[0.333,0.333],"y":[1,1]},"o":{"x":[0.333,0.333],"y":[0,0]},"t":0,"s":[80,120]},{"i":{"x":[0.667,0.667],"y":[1,1]},"o":{"x":[0.667,0.667],"y":[0,0]},"t":24,"s":[100,100]},{"i":{"x":[0.667,0.667],"y":[1,1]},"o":{"x":[0.667,0.667],"y":[0,0]},"t":76,"s":[100,100]},{"t":100,"s":[80,120]}],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"组 1","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"st","c":{"a":0,"k":[0.156862750649,0.533333361149,0.878431379795,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":1,"ix":5},"lc":2,"lj":2,"bm":0,"nm":"stroke","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[400,400],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"Vector 97","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":100,"st":0,"bm":0}]}],"layers":[{"ddd":0,"ind":1,"ty":0,"nm":"arrow 合成_dark","refId":"comp_0","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[32,32,0],"ix":2,"l":2},"a":{"a":0,"k":[28,28,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"w":56,"h":56,"ip":0,"op":100,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"base","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[32,32,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[15,15],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"椭圆路径 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"st","c":{"a":0,"k":[0.156862750649,0.533333361149,0.878431379795,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":1,"ix":5},"lc":1,"lj":1,"ml":4,"bm":0,"nm":"stroke","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"fl","c":{"a":0,"k":[0.137254908681,0.137254908681,0.137254908681,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"filling","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[400,400],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"Ellipse 44","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":100,"st":0,"bm":0}],"markers":[]}

View File

@ -1 +0,0 @@
{"v":"5.9.1","fr":60,"ip":0,"op":100,"w":64,"h":64,"nm":"多版本下载提示_light","ddd":0,"assets":[{"id":"comp_0","nm":"arrow 合成_light","fr":60,"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"arrow","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.333],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":0,"s":[0]},{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":24,"s":[100]},{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.667],"y":[0]},"t":76,"s":[100]},{"t":100,"s":[0]}],"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":1,"k":[{"i":{"x":0.333,"y":1},"o":{"x":0.364,"y":0},"t":0,"s":[28,-12,0],"to":[0,6.382,0],"ti":[0,-0.284,0]},{"i":{"x":0.667,"y":0.667},"o":{"x":0.333,"y":0.333},"t":24,"s":[28,28,0],"to":[0,0,0],"ti":[0,0,0]},{"i":{"x":0.667,"y":1},"o":{"x":0.667,"y":0},"t":76,"s":[28,28,0],"to":[0,6.667,0],"ti":[0,-6.667,0]},{"t":100,"s":[28,68,0]}],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[0,2],[0,-2]],"c":false},"ix":2},"nm":"路径 1","mn":"ADBE Vector Shape - Group","hd":false},{"ind":1,"ty":"sh","ix":2,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[-2,0],[0,2]],"c":false},"ix":2},"nm":"路径 2","mn":"ADBE Vector Shape - Group","hd":false},{"ind":2,"ty":"sh","ix":3,"ks":{"a":0,"k":{"i":[[0,0],[0,0]],"o":[[0,0],[0,0]],"v":[[2,0],[0,2]],"c":false},"ix":2},"nm":"路径 3","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":1,"k":[{"i":{"x":[0.333,0.333],"y":[1,1]},"o":{"x":[0.333,0.333],"y":[0,0]},"t":0,"s":[80,120]},{"i":{"x":[0.667,0.667],"y":[1,1]},"o":{"x":[0.667,0.667],"y":[0,0]},"t":24,"s":[100,100]},{"i":{"x":[0.667,0.667],"y":[1,1]},"o":{"x":[0.667,0.667],"y":[0,0]},"t":76,"s":[100,100]},{"t":100,"s":[80,120]}],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"组 1","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"st","c":{"a":0,"k":[0.141176477075,0.588235318661,1,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":1,"ix":5},"lc":2,"lj":2,"bm":0,"nm":"stroke","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[400,400],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"Vector 97","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":100,"st":0,"bm":0}]}],"layers":[{"ddd":0,"ind":1,"ty":0,"nm":"arrow 合成_light","refId":"comp_0","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[32,32,0],"ix":2,"l":2},"a":{"a":0,"k":[28,28,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"w":56,"h":56,"ip":0,"op":100,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"base","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[32,32,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[15,15],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"椭圆路径 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"st","c":{"a":0,"k":[0.141176477075,0.588235318661,1,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":1,"ix":5},"lc":1,"lj":1,"ml":4,"bm":0,"nm":"stroke","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"fl","c":{"a":0,"k":[1,1,1,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"filling","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[400,400],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"Ellipse 44","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":100,"st":0,"bm":0}],"markers":[]}

View File

@ -38,8 +38,8 @@ import com.gh.gamecenter.login.utils.LoginHelper
import com.gh.gamecenter.login.utils.QuickLoginHelper
import com.gh.gamecenter.login.view.LoginActivity
import com.gh.gamecenter.personalhome.border.AvatarBorderActivity
import com.gh.gamecenter.setting.view.AboutActivity
import com.gh.gamecenter.setting.view.security.BindPhoneActivity
import com.gh.gamecenter.setting.compose.activity.ComposeAboutActivity
import com.gh.gamecenter.setting.compose.activity.ComposeBindPhoneActivity
import com.halo.assistant.HaloApp
import com.lightgame.utils.Utils
import org.json.JSONObject
@ -270,7 +270,7 @@ class DefaultJsApi(var context: Context, val entrance: String = "") {
@JavascriptInterface
fun bindPhone(msg: Any) {
val intent = BindPhoneActivity.getNormalIntent(context, false)
val intent = ComposeBindPhoneActivity.getNormalIntent(context, false)
context.startActivity(intent)
}
@ -416,7 +416,7 @@ class DefaultJsApi(var context: Context, val entrance: String = "") {
@JavascriptInterface
fun checkUpdateGhzs(msg: Any) {
context.startActivity(AboutActivity.getIntent(context, true))
context.startActivity(ComposeAboutActivity.getIntent(context, true))
}
@JavascriptInterface

View File

@ -2,15 +2,14 @@ package com.gh.common
import com.gh.common.exposure.ExposureManager
import com.gh.common.filter.RegionSettingHelper
import com.gh.common.util.AdHelper
import com.gh.common.videolog.VideoRecordUtils
import com.gh.download.DownloadDataHelper
import com.gh.gamecenter.common.loghub.LoghubUtils
import com.gh.gamecenter.common.retrofit.Response
import com.gh.gamecenter.common.utils.doOnMainProcessOnly
import com.gh.gamecenter.common.utils.tryCatchInRelease
import com.gh.gamecenter.core.runOnUiThread
import com.gh.common.videolog.VideoRecordUtils
import com.gh.download.DownloadDataHelper
import com.gh.gamecenter.entity.TimeEntity
import com.gh.gamecenter.common.retrofit.Response
import com.gh.gamecenter.core.runOnUiThread
import com.gh.gamecenter.retrofit.RetrofitManager
import com.halo.assistant.HaloApp
import io.reactivex.schedulers.Schedulers
@ -26,7 +25,6 @@ object FixedRateJobHelper {
private const val DOWNLOAD_HEARTBEAT_PERIOD: Long = 60 * 1000L
private const val DOWNLOAD_HEARTBEAT_SHEET_PERIOD: Long = 15 * 1000L
private const val STARTUP_AD: Long = 30 * 60 * 1000L
private var mExecuteCount: Int = 0
@ -84,11 +82,6 @@ object FixedRateJobHelper {
VideoRecordUtils.commitVideoRecord()
}
// 获取启动广告
if ((mExecuteCount * CHECKER_PERIOD) % STARTUP_AD == 0L) {
AdHelper.getSettingAdCache()
}
// ExposureUtils.logADownloadCompleteExposureEvent(GameEntity(id = mExecuteCount.toString(), name = "测试曝光上传"), platform = "", trace = null, downloadType = ExposureUtils.DownloadType.DOWNLOAD)
mExecuteCount++
}

View File

@ -7,7 +7,7 @@ import com.gh.vspace.VHelper
class ValidateVSpaceHandler : ChainHandler() {
override fun handleRequest(context: Context, gameEntity: GameEntity) {
VHelper.validateVSpaceBeforeAction(context, gameEntity) {
VHelper.validateVSpaceBeforeAction(context, gameEntity, true) {
if (hasNext()) {
getNext()?.handleRequest(context, gameEntity)
} else {

View File

@ -1,33 +1,18 @@
package com.gh.common.chain
import android.content.Context
import com.gh.gamecenter.R
import com.gh.gamecenter.common.utils.DialogHelper
import com.gh.gamecenter.common.utils.toResString
import com.gh.common.util.DialogUtils
import com.gh.gamecenter.entity.GameEntity
class VersionNumberHandler : ChainHandler() {
override fun handleRequest(context: Context, gameEntity: GameEntity) {
val confirmCallback = {
DialogUtils.showVersionNumberDialog(context, gameEntity) {
if (hasNext()) {
getNext()?.handleRequest(context, gameEntity)
} else {
processEndCallback?.invoke(null)
}
}
if (!gameEntity.isShowVersionNumber()) {
confirmCallback.invoke()
} else {
DialogHelper.showGuideDialog(
context,
"温馨提示",
gameEntity.getVersionNumberString(),
"继续下载",
R.string.cancel.toResString(),
{ confirmCallback.invoke() },
extraConfig = DialogHelper.Config(titleIcon = R.drawable.ic_dialog_tips)
)
}
}
}

View File

@ -8,26 +8,24 @@ import android.text.TextUtils;
import androidx.annotation.Nullable;
import com.gh.common.util.AdHelper;
import com.gh.gamecenter.common.utils.DarkModeUtils;
import com.gh.gamecenter.common.utils.EnvHelper;
import com.gh.gamecenter.common.constant.Constants;
import com.gh.gamecenter.core.utils.GsonUtils;
import com.gh.common.util.PackageHelper;
import com.gh.common.util.PackageUtils;
import com.gh.gamecenter.BuildConfig;
import com.gh.gamecenter.SuggestionActivity;
import com.gh.gamecenter.common.constant.Constants;
import com.gh.gamecenter.common.eventbus.EBReuse;
import com.gh.gamecenter.common.retrofit.BiResponse;
import com.gh.gamecenter.common.retrofit.Response;
import com.gh.gamecenter.common.utils.DarkModeUtils;
import com.gh.gamecenter.common.utils.EnvHelper;
import com.gh.gamecenter.core.utils.GsonUtils;
import com.gh.gamecenter.core.utils.SPUtils;
import com.gh.gamecenter.entity.GameGuidePopupEntity;
import com.gh.gamecenter.entity.NewApiSettingsEntity;
import com.gh.gamecenter.entity.NewSettingsEntity;
import com.gh.gamecenter.entity.NewsEntity;
import com.gh.gamecenter.entity.SettingsEntity;
import com.gh.gamecenter.common.eventbus.EBReuse;
import com.gh.gamecenter.entity.SimulatorEntity;
import com.gh.gamecenter.entity.VSetting;
import com.gh.gamecenter.common.retrofit.BiResponse;
import com.gh.gamecenter.common.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.gh.vspace.VHelper;
import com.halo.assistant.HaloApp;
@ -66,9 +64,8 @@ public class Config {
private static SettingsEntity mSettingsEntity;
private static NewSettingsEntity mNewSettingsEntity;
private static NewApiSettingsEntity mNewApiSettingsEntity;
private static NewApiSettingsEntity.NightMode mNightModeSetting;
private static NewSettingsEntity.NightMode mNightModeSetting;
private static SimulatorEntity mNewSimulatorEntity;
private static VSetting mVSetting;
private static GameGuidePopupEntity mGameGuidePopupEntity;
@ -207,7 +204,7 @@ public class Config {
PackageHelper.initList();
// 初始化畅玩相关的东西
VHelper.init(HaloApp.getInstance(), false);
VHelper.init(HaloApp.getInstance());
}
@Nullable
@ -230,19 +227,19 @@ public class Config {
public static SimulatorEntity getNewSimulatorEntitySetting() {
if (mNewSimulatorEntity != null) {
return mNewSimulatorEntity;
} else if (mNewApiSettingsEntity != null && mNewApiSettingsEntity.getSimulator() != null) {
return mNewApiSettingsEntity.getSimulator();
} else if (mNewSettingsEntity != null && mNewSettingsEntity.getSimulator() != null) {
return mNewSettingsEntity.getSimulator();
} else {
return null;
}
}
@Nullable
public static NewApiSettingsEntity.NightMode getNightModeSetting() {
public static NewSettingsEntity.NightMode getNightModeSetting() {
if (mNightModeSetting != null) {
return mNightModeSetting;
} else if (mNewApiSettingsEntity != null && mNewApiSettingsEntity.getNightMode() != null) {
return mNewApiSettingsEntity.getNightMode();
} else if (mNewSettingsEntity != null && mNewSettingsEntity.getNightMode() != null) {
return mNewSettingsEntity.getNightMode();
} else {
return null;
}
@ -263,26 +260,6 @@ public class Config {
return mNewSettingsEntity;
}
@Nullable
public static NewApiSettingsEntity getNewApiSettingsEntity() {
if (mNewApiSettingsEntity == null) {
try {
String json = SPUtils.getString(Constants.SP_NEW_API_SETTINGS);
if (!TextUtils.isEmpty(json)) {
mNewApiSettingsEntity = GsonUtils.fromJson(json, NewApiSettingsEntity.class);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return mNewApiSettingsEntity;
}
public static void updateNewApiSettings(NewApiSettingsEntity settingsEntity) {
mNewApiSettingsEntity = settingsEntity;
SPUtils.setString(Constants.SP_NEW_API_SETTINGS, GsonUtils.toJson(settingsEntity));
}
@Nullable
public static VSetting getVSettingEntity() {
if (mVSetting == null) {
@ -367,6 +344,9 @@ public class Config {
@Override
public void onSuccess(NewSettingsEntity data) {
mNewSettingsEntity = data;
if (mNightModeSetting != null) {
mNewSettingsEntity.setNightMode(mNightModeSetting);
}
SPUtils.setString(Constants.SP_NEW_SETTINGS, GsonUtils.toJson(data));
}
});
@ -384,23 +364,27 @@ public class Config {
});
}
if (mNewApiSettingsEntity == null) {
if (mNightModeSetting == null && mNewSimulatorEntity == null) {
RetrofitManager.getInstance()
.getNewApi().getNewSettings(PackageUtils.getGhVersionName(), channel)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BiResponse<NewApiSettingsEntity>() {
.subscribe(new BiResponse<NewSettingsEntity>() {
@Override
public void onSuccess(NewApiSettingsEntity data) {
mNewApiSettingsEntity = data;
public void onSuccess(NewSettingsEntity data) {
mNightModeSetting = data.getNightMode();
mNewSimulatorEntity = data.getSimulator();
if (HaloApp.getInstance().isNewForThisVersion && mNightModeSetting != null && mNightModeSetting.getInstall()) {
DarkModeUtils.INSTANCE.updateFollowSystemDarkModeToSp(true);
DarkModeUtils.INSTANCE.updateAppDarkModeStatusToSp(true);
DarkModeUtils.INSTANCE.initDarkMode();
}
AdHelper.prefetchStartUpAd(mNewApiSettingsEntity);
SPUtils.setString(Constants.SP_NEW_API_SETTINGS, GsonUtils.toJson(data));
if (mNewSettingsEntity != null) {
mNewSettingsEntity.setSimulator(mNewSimulatorEntity);
mNewSettingsEntity.setNightMode(mNightModeSetting);
SPUtils.setString(Constants.SP_NEW_SETTINGS, GsonUtils.toJson(data));
}
}
});
}

View File

@ -850,11 +850,11 @@ public class BindingAdapters {
public static void setVideoData(TextView view, int count) {
if (count > 0) {
ExtensionsKt.setDrawableStart(view, ContextCompat.getDrawable(view.getContext(), R.drawable.ic_video_data_up), null, null);
view.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(view.getContext(), R.drawable.ic_video_data_up), null, null, null);
view.setTextColor(ContextCompat.getColor(view.getContext(), R.color.text_EA3333));
view.setText(count + "");
} else {
ExtensionsKt.removeDrawable(view);
view.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
view.setTextColor(ContextCompat.getColor(view.getContext(), R.color.text_subtitleDesc));
view.setText("-");
}

View File

@ -18,18 +18,18 @@ import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import com.facebook.drawee.view.SimpleDraweeView
import com.gh.gamecenter.common.constant.Constants
import com.gh.download.DownloadManager
import com.gh.gamecenter.R
import com.gh.gamecenter.core.utils.GsonUtils
import com.gh.gamecenter.core.utils.SPUtils
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.utils.ImageUtils
import com.gh.gamecenter.common.utils.countDownTimer
import com.gh.gamecenter.core.utils.DisplayUtils
import com.gh.gamecenter.common.utils.ImageUtils
import com.gh.gamecenter.core.utils.GsonUtils
import com.gh.gamecenter.core.utils.SPUtils
import com.gh.gamecenter.databinding.DialogDeviceRemindBinding
import com.gh.gamecenter.entity.DeviceDialogEntity
import com.gh.gamecenter.entity.GameEntity
import com.gh.gamecenter.setting.view.GameDownloadSettingFragment
import com.gh.gamecenter.setting.compose.activity.ComposeGameDownloadSettingActivity
import com.google.gson.reflect.TypeToken
import com.lightgame.download.DataWatcher
import com.lightgame.download.DownloadEntity
@ -53,7 +53,7 @@ class DeviceRemindDialog(context: Context, val entity: DeviceDialogEntity, val g
private val dataWatcher = object : DataWatcher() {
override fun onDataChanged(downloadEntity: DownloadEntity) {
if (downloadEntity.status == DownloadStatus.done && downloadEntity.name == gameEntity.name) {
val autoInstall = SPUtils.getBoolean(GameDownloadSettingFragment.AUTO_INSTALL_SP_KEY, true)
val autoInstall = SPUtils.getBoolean(ComposeGameDownloadSettingActivity.AUTO_INSTALL_SP_KEY, true)
if (autoInstall) {
dismiss()
}

View File

@ -13,11 +13,13 @@ import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentTransaction
import com.gh.common.util.DirectUtils
import com.gh.gamecenter.R
import com.gh.gamecenter.WebActivity
import com.gh.gamecenter.common.base.fragment.BaseDialogFragment
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.common.view.CustomLinkMovementMethod
import com.gh.gamecenter.databinding.DialogPrivacyProtocolNewBinding
import com.gh.gamecenter.entity.DialogEntity
import splitties.bundle.put
class NewPrivacyPolicyDialogFragment : BaseDialogFragment() {
@ -159,7 +161,7 @@ class NewPrivacyPolicyDialogFragment : BaseDialogFragment() {
}
}
privacyDialogFragment.arguments = Bundle().apply {
putParcelable(KEY_DATA, privacyPolicyEntity)
put(KEY_DATA, privacyPolicyEntity)
}
privacyDialogFragment.show(
activity.supportFragmentManager,

View File

@ -303,7 +303,7 @@ class PackageCheckDialogFragment : BaseDialogFragment() {
//安装、卸载事件
@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(busFour: EBPackage) {
if (busFour.isInstalledOrUninstalled()) {
if ("安装" == busFour.type || "卸载" == busFour.type) {
mAllInstalledPackages = PackageUtils.getInstalledPackages(HaloApp.getInstance().application, 0)
mAdapter?.notifyDataSetChanged()
}

View File

@ -23,6 +23,7 @@ import com.gh.gamecenter.core.utils.SPUtils
import com.gh.gamecenter.databinding.DialogPrivacyProtocolBinding
import com.gh.gamecenter.entity.DialogEntity
import com.lightgame.utils.AppManager
import splitties.bundle.put
class PrivacyPolicyDialogFragment : BaseDialogFragment() {
@ -183,7 +184,7 @@ class PrivacyPolicyDialogFragment : BaseDialogFragment() {
}
}
privacyDialogFragment.arguments = Bundle().apply {
putParcelable(KEY_DATA, privacyPolicyEntity)
put(KEY_DATA, privacyPolicyEntity)
}
privacyDialogFragment.show(
activity.supportFragmentManager,

View File

@ -29,7 +29,7 @@ data class ExposureEvent(
var timeInMillisecond: Long = System.currentTimeMillis(),
@PrimaryKey
var id: String = UUID.randomUUID().toString(),
) : Parcelable, Cloneable {
) : Parcelable {
@Transient
@IgnoredOnParcel
@ -45,9 +45,6 @@ data class ExposureEvent(
eTrace: List<ExposureEvent>? = null,
event: ExposureType = ExposureType.EXPOSURE
) {
if (gameEntity?.adIconActive == true) {
gameEntity.isAdData = true
}
this.payload = ExposureEntity(
gameId = gameEntity?.id?.getFirstElementDividedByDivider(DownloadEntity.GAME_ID_DIVIDER),
gameName = eTrace?.firstOrNull()?.payload?.gameName
@ -74,7 +71,7 @@ data class ExposureEvent(
?: eTrace?.firstOrNull()?.payload?.welcomeDialogId,
welcomeDialogLinkTitle = gameEntity?.welcomeDialogTitle
?: eTrace?.firstOrNull()?.payload?.welcomeDialogLinkTitle,
isAdData = gameEntity?.isAdData ?: eTrace?.firstOrNull()?.payload?.isAdData ?: false
isAdData = gameEntity?.adIconActive ?: eTrace?.firstOrNull()?.payload?.isAdData ?: false
)
this.id = UUID.randomUUID().toString()
this.timeInMillisecond = System.currentTimeMillis()
@ -127,10 +124,6 @@ data class ExposureEvent(
return flags == FLAG_IN_USE
}
fun deepCopy(): ExposureEvent {
return super.clone() as ExposureEvent
}
companion object {
private val sPoolSync = Any()
private var sPool: ExposureEvent? = null

View File

@ -6,13 +6,11 @@ object ExposureTraceUtils {
val traceList = arrayListOf<ExposureEvent>()
event?.let {
//这里使用deepCopy是为了防止循环引用调用hashCode方法触发StackOverflowError错误
val deepCopy = it.deepCopy()
if (deepCopy.eTrace == null) {
traceList.add(deepCopy)
if (event.eTrace == null) {
traceList.add(event)
} else {
traceList.addAll(deepCopy.eTrace!!)
traceList.add(flattenTrace(deepCopy))
traceList.addAll(event.eTrace!!)
traceList.add(flattenTrace(event))
}
}

View File

@ -18,7 +18,7 @@ import com.halo.assistant.HaloApp
@Database(
entities = [AnswerEntity::class, ArticleEntity::class, NewsEntity::class, HistoryGameEntity::class, MyVideoEntity::class, GamesCollectionEntity::class],
version = 12,
version = 11,
exportSchema = false
)
@TypeConverters(
@ -28,7 +28,6 @@ import com.halo.assistant.HaloApp
AnswerUserConverter::class,
ThumbnailConverter::class,
TagStyleListConverter::class,
TagStyleConverter::class,
StringArrayListConverter::class,
ListStringConverter::class,
CommunityVideoConverter::class,
@ -128,13 +127,6 @@ abstract class HistoryDatabase : RoomDatabase() {
}
}
val MIGRATION_11_12: Migration = object : Migration(11, 12) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("Alter TABLE HistoryGameEntity add subtitle TEXT NOT NULL DEFAULT ''")
database.execSQL("Alter TABLE HistoryGameEntity add subtitleStyle TEXT")
}
}
val instance by lazy {
Room.databaseBuilder(
HaloApp.getInstance().application,
@ -150,7 +142,6 @@ abstract class HistoryDatabase : RoomDatabase() {
.addMigrations(MIGRATION_8_9)
.addMigrations(MIGRATION_9_10)
.addMigrations(MIGRATION_10_11)
.addMigrations(MIGRATION_11_12)
.build()
}
}

View File

@ -71,8 +71,6 @@ object HistoryHelper {
historyGame.name = gameEntity.name
historyGame.tagStyle = gameEntity.tagStyle
historyGame.tag = gameEntity.getTag()
historyGame.subtitle = gameEntity.subtitle
historyGame.subtitleStyle = gameEntity.subtitleStyle
return historyGame
}

View File

@ -146,31 +146,21 @@ class SimulatorDownloadManager private constructor() {
PermissionHelper.checkGetInstalledAppsListBeforeAction(context, object : EmptyCallback {
override fun onCallback() {
val isInstalledNewSimulator =
SimulatorGameManager.isNewSimulatorInstalled(HaloApp.getInstance().application)
//当没有安装新版本模拟器时候 判断是否隐藏
if (simulator?.active == false && !isInstalledNewSimulator) {
//判断是否隐藏
if (simulator?.active == false) {
showNoneEmulatorDialog(context)
return
}
var isInstalled = PackageUtils.isInstalledFromAllPackage(
context,
simulator?.apk?.packageName
)
//模拟器管理界面还是用之前的逻辑
if (isInstalledNewSimulator && location != SimulatorLocation.SIMULATOR_MANAGE) {
isInstalled = isInstalledNewSimulator
}
val isInstalled = PackageUtils.isInstalledFromAllPackage(context, simulator?.apk?.packageName)
// val versionFromInstalledApp = PackageUtils.getVersionNameByPackageName(simulator?.apk?.packageName)
val shouldShowUpdate =
PackageUtils.isInstalledApkMatchedMd5(simulator?.apk?.packageName, simulator?.apk?.md5)
val shouldShowUpdate = PackageUtils.isInstalledApkMatchedMd5(simulator?.apk?.packageName, simulator?.apk?.md5)
val showAlertTag = SPUtils.getString(SimulatorGameManager.SIMULATOR_UPDATE_SHOW_ALERT_TAG, "") //当天是否弹过
val todayIsShow = showAlertTag == TimeUtils.getToday()
downloadType = if (shouldShowUpdate && isInstalled) "update" else "download"
if (downloadType == "update" && todayIsShow && location != SimulatorLocation.SIMULATOR_MANAGE) {
if (downloadType == "update" && todayIsShow && location != SimulatorLocation.SIMULATOR_MANAGE){
return
}
if (downloadType == "download" && isInstalled) {
if (downloadType == "download" && isInstalled){
return
}
val title = if (shouldShowUpdate && isInstalled) "更新模拟器" else "安装模拟器"

View File

@ -1,15 +1,15 @@
package com.gh.common.util
import android.annotation.SuppressLint
import androidx.lifecycle.MutableLiveData
import com.gh.common.constant.Config
import com.gh.gamecenter.common.retrofit.Response
import com.gh.gamecenter.common.utils.ImageUtils
import com.gh.gamecenter.common.utils.observableToMain
import com.gh.gamecenter.core.utils.DisplayUtils
import com.gh.gamecenter.entity.NewApiSettingsEntity
import com.gh.gamecenter.common.utils.NetworkUtils
import com.gh.gamecenter.entity.SettingsEntity
import com.gh.gamecenter.entity.StartupAdEntity
import com.gh.gamecenter.common.retrofit.BiResponse
import com.gh.gamecenter.retrofit.RetrofitManager
import com.halo.assistant.HaloApp
import io.reactivex.schedulers.Schedulers
object AdHelper {
@ -19,40 +19,24 @@ object AdHelper {
const val LOCATION_SUGGESTION_FUNCTION = "suggestion_function"
const val LOCATION_SIMULATOR_GAME = "simulator_game"
@JvmStatic
fun getStartUpAd(): StartupAdEntity? {
return Config.getNewApiSettingsEntity()?.startAd
}
@JvmField
var startupAd = MutableLiveData<StartupAdEntity>()
@JvmStatic
fun getStartUp(): StartupAdEntity? {
return Config.getNewApiSettingsEntity()?.startup
}
@JvmStatic
fun prefetchStartUpAd(settingsEntity: NewApiSettingsEntity) {
if (settingsEntity.startAd != null && !settingsEntity.startAd?.img.isNullOrEmpty()) {
val screenWidth = DisplayUtils.getScreenWidth()
val transformedUrl = ImageUtils.getTransformedUrl(settingsEntity.startAd?.img, screenWidth) ?: return
ImageUtils.prefetchToDiskCache(transformedUrl)
@SuppressLint("CheckResult")
fun getStartUpAd() {
if (!NetworkUtils.isNetworkConnected(HaloApp.getInstance())) {
startupAd.postValue(null)
return
}
}
fun getSettingAdCache() {
RetrofitManager.getInstance().newApi
.getSettingAdCache(HaloApp.getInstance().channel)
.compose(observableToMain())
.subscribe(object : Response<NewApiSettingsEntity>() {
override fun onResponse(response: NewApiSettingsEntity?) {
super.onResponse(response)
val settings = Config.getNewApiSettingsEntity()
if (settings != null) {
settings.startAd = response?.startAd
Config.updateNewApiSettings(settings)
if (response != null) {
prefetchStartUpAd(response)
}
}
RetrofitManager.getInstance()
.api
.getSplashAd(HaloApp.getInstance().channel)
.subscribeOn(Schedulers.io())
.subscribe(object : BiResponse<StartupAdEntity>() {
override fun onSuccess(data: StartupAdEntity) {
startupAd.postValue(data)
}
})
}

View File

@ -1,250 +0,0 @@
package com.gh.common.util
import android.app.Dialog
import android.content.Context
import android.view.View
import android.view.Window
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.gh.download.simple.AutoUnregisteredSimpleDownloadListener
import com.gh.download.simple.DownloadListener
import com.gh.gamecenter.R
import com.gh.gamecenter.common.eventbus.EBReuse
import com.gh.gamecenter.common.utils.DialogHelper
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.common.utils.roundTo
import com.gh.gamecenter.common.utils.toResString
import com.gh.gamecenter.core.utils.DisplayUtils
import com.gh.gamecenter.core.utils.ToastUtils
import com.gh.gamecenter.databinding.DialogArchiveLoadingBinding
import com.gh.gamecenter.entity.ArchiveEntity
import com.gh.gamecenter.retrofit.RetrofitManager
import com.gh.vspace.VArchiveHelper
import com.gh.vspace.VHelper
import com.lg.download.DownloadError
import com.lg.download.DownloadStatus
import io.reactivex.schedulers.Schedulers
import org.greenrobot.eventbus.EventBus
import splitties.systemservices.layoutInflater
/**
* 云存档下载按钮辅助类
*/
object ArchiveDownloadButtonHelper {
fun bindItem(
context: Context,
entrance: String,
fragment: Fragment,
packageName: String,
archiveEntity: ArchiveEntity,
downloadBtn: TextView,
downloadCompletedListener: (() -> Unit)? = null
) {
downloadBtn.text = if (VArchiveHelper.isArchiveDownloaded(archiveEntity.md5)) {
R.string.archive_apply.toResString()
} else {
R.string.archive_download.toResString()
}
downloadBtn.setOnClickListener {
when {
// 检查是否已安装畅玩助手
!VHelper.isVSpaceInstalled(context) -> showVspaceTipDialog(context)
// 检查是否已安装游戏
!VHelper.isInstalled(packageName) -> {
// 检查游戏是否在安装中
if (!VHelper.isInstalling(packageName)) {
showDownloadTipDialog(context)
} else {
ToastUtils.toast("游戏正在安装中,请稍候")
}
}
// 检查本地是否已下载存档
VArchiveHelper.isArchiveDownloaded(archiveEntity.md5) -> showApplyArchiveTipDialog(
context,
entrance,
packageName,
archiveEntity
)
// 检查完毕下载存档
else -> downloadArchive(
context,
entrance,
fragment,
packageName,
archiveEntity,
downloadBtn,
downloadCompletedListener
)
}
}
}
private fun showVspaceTipDialog(context: Context) {
NewFlatLogUtils.logCloudArchiveVSpaceDownloadDialogShow()
DialogHelper.showDialog(
context,
R.string.archive_dialog_title.toResString(),
R.string.archive_vspace_dialog_content.toResString(),
R.string.archive_vspace_dialog_confirm.toResString(),
R.string.cancel.toResString(),
{
NewFlatLogUtils.logCloudArchiveVSpaceDownloadDialogClick(R.string.archive_vspace_dialog_confirm.toResString())
VHelper.showVspaceDialog(context)
},
{
NewFlatLogUtils.logCloudArchiveVSpaceDownloadDialogClick(R.string.cancel.toResString())
},
extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true)
)
}
private fun showDownloadTipDialog(context: Context) {
NewFlatLogUtils.logCloudArchiveGameDownloadDialogShow()
DialogHelper.showDialog(
context,
R.string.archive_dialog_title.toResString(),
R.string.archive_download_dialog_content.toResString(),
R.string.archive_download_dialog_confirm.toResString(),
R.string.cancel.toResString(),
{
NewFlatLogUtils.logCloudArchiveGameDownloadDialogClick(R.string.archive_download_dialog_confirm.toResString())
VHelper.disableLaunchGameAfterInstallation()
EventBus.getDefault().post(EBReuse("download"))
},
{
NewFlatLogUtils.logCloudArchiveGameDownloadDialogClick(R.string.cancel.toResString())
},
extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true)
)
}
private fun applyArchive(
context: Context,
entrance: String,
packageName: String,
archiveEntity: ArchiveEntity
) {
VArchiveHelper.getArchiveFile(archiveEntity.md5)?.run {
RetrofitManager.getInstance().newApi
.postArchiveUsage(archiveEntity.gameId, archiveEntity.id)
.subscribeOn(Schedulers.io())
.subscribe()
VArchiveHelper.applyGameArchive(context, packageName, this) { packageName, isSuccess ->
if (isSuccess) {
VHelper.launch(context, packageName)
} else {
ToastUtils.toast(R.string.archive_apply_fail.toResString())
}
}
}
NewFlatLogUtils.logCloudArchiveDownloadOrApply(archiveEntity.name, entrance)
}
private fun downloadArchive(
context: Context,
entrance: String,
fragment: Fragment,
packageName: String,
archiveEntity: ArchiveEntity,
downloadBtn: TextView,
downloadCompletedListener: (() -> Unit)? = null
) {
// 执行下载
VArchiveHelper.downloadArchive(archiveEntity)
// 下载进度弹窗
val archiveLoadingDialog = Dialog(context, R.style.DialogWindowTransparent)
val archiveLoadingBinding = DialogArchiveLoadingBinding.inflate(context.layoutInflater)
showArchiveLoadingDialog(archiveLoadingDialog, archiveLoadingBinding.root)
// 下载进度监听
AutoUnregisteredSimpleDownloadListener(archiveEntity.id, fragment, object : DownloadListener {
override fun onError(error: DownloadError) {
dismissArchiveLoadingDialog(archiveLoadingDialog)
ToastUtils.toast(R.string.archive_download_fail.toResString())
}
override fun onProgress(progress: Float) {
archiveLoadingBinding.run {
progressTv.text = "${progress.roundTo(1)}%"
progressBar.progress = progress.toInt()
}
}
override fun onSizeReceived(fileSize: Long) {
// Do nothing
}
override fun onStatusChanged(status: DownloadStatus) {
when (status) {
DownloadStatus.COMPLETED -> {
dismissArchiveLoadingDialog(archiveLoadingDialog)
downloadBtn.text = R.string.archive_apply.toResString()
showApplyArchiveTipDialog(context, entrance, packageName, archiveEntity)
downloadCompletedListener?.invoke()
}
else -> {
// Do nothing
}
}
}
override fun onSpeedChanged(speed: Float) {
// Do nothing
}
})
NewFlatLogUtils.logCloudArchiveDownloadOrApply(archiveEntity.name, entrance)
}
private fun showArchiveLoadingDialog(
archiveLoadingDialog: Dialog,
contentView: View
) {
archiveLoadingDialog.run {
setCancelable(false)
setCanceledOnTouchOutside(false)
requestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(contentView)
show()
}
archiveLoadingDialog.window?.attributes?.apply {
width = DisplayUtils.getScreenWidth() - 120F.dip2px()
archiveLoadingDialog.window?.attributes = this
}
}
private fun showApplyArchiveTipDialog(
context: Context,
entrance: String,
packageName: String,
archiveEntity: ArchiveEntity
) {
DialogHelper.showDialog(
context,
R.string.archive_dialog_title.toResString(),
R.string.archive_apply_dialog_content.toResString(),
R.string.archive_apply.toResString(),
R.string.cancel.toResString(),
{
applyArchive(context, entrance, packageName, archiveEntity)
NewFlatLogUtils.logCloudArchiveApplyDialogRelated("cloud_save_overwrite_dialog_click", "使用")
},
{ NewFlatLogUtils.logCloudArchiveApplyDialogRelated("cloud_save_overwrite_dialog_click", "取消") },
extraConfig = DialogHelper.Config(centerTitle = true)
)
NewFlatLogUtils.logCloudArchiveApplyDialogRelated("cloud_save_overwrite_dialog_show")
}
private fun dismissArchiveLoadingDialog(archiveLoadingDialog: Dialog) {
if (archiveLoadingDialog.isShowing) {
archiveLoadingDialog.dismiss()
}
}
}

View File

@ -15,14 +15,12 @@ import com.gh.download.DownloadManager;
import com.gh.gamecenter.R;
import com.gh.gamecenter.adapter.viewholder.DetailViewHolder;
import com.gh.gamecenter.common.constant.Constants;
import com.gh.gamecenter.common.entity.LinkEntity;
import com.gh.gamecenter.common.utils.ExtensionsKt;
import com.gh.gamecenter.core.utils.SPUtils;
import com.gh.gamecenter.common.entity.LinkEntity;
import com.gh.gamecenter.entity.PluginLocation;
import com.gh.gamecenter.manager.PackagesManager;
import com.gh.vspace.VHelper;
import com.lightgame.download.DownloadEntity;
import com.lightgame.download.DownloadStatus;
/**
* Created by khy on 27/06/17.
@ -38,10 +36,6 @@ public class DetailDownloadUtils {
viewHolder.getOverlayTv().setVisibility(View.GONE);
}
if (viewHolder.mMultiVersionDownloadTv != null) {
viewHolder.mMultiVersionDownloadTv.setVisibility(View.GONE);
}
if (viewHolder.gameEntity != null
&& Config.isShowDownload(viewHolder.gameEntity.getId())
&& !"光环助手".equals(viewHolder.gameEntity.getName())) {
@ -177,34 +171,8 @@ public class DetailDownloadUtils {
}
viewHolder.mDownloadPb.setText(downloadText);
} else {
viewHolder.mMultiVersionDownloadTv.setText("选择下载你的版本" + (TextUtils.isEmpty(downloadAddWord) ? "" : "-" + downloadAddWord));
viewHolder.mMultiVersionDownloadTv.setVisibility(View.VISIBLE);
viewHolder.mDownloadPb.setText("");
viewHolder.mDownloadPb.setText("选择下载你的版本" + (TextUtils.isEmpty(downloadAddWord) ? "" : "-" + downloadAddWord) + " >");
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.NORMAL);
DownloadEntity downloadEntity = DownloadManager.getInstance().getDownloadEntitySnapshot(viewHolder.gameEntity);
if (downloadEntity != null) {
switch (downloadEntity.getStatus()) {
case downloading:
viewHolder.mDownloadTips.setVisibility(View.VISIBLE);
ExtensionsKt.setDownloadTipsAnimation(viewHolder.mDownloadTips, true);
break;
case done:
case pause:
case waiting:
case timeout:
case subscribe:
case neterror:
case overflow:
viewHolder.mDownloadTips.setVisibility(View.VISIBLE);
ExtensionsKt.setDownloadTipsAnimation(viewHolder.mDownloadTips, false);
break;
default:
viewHolder.mDownloadTips.setVisibility(View.GONE);
break;
}
} else {
viewHolder.mDownloadTips.setVisibility(View.GONE);
}
}
if (isCheck && viewHolder.gameEntity.getApk().size() == 1) {
@ -235,14 +203,10 @@ public class DetailDownloadUtils {
if (XapkUnzipStatus.UNZIPPING.name().equals(xapkStatus)) {
String percent = downloadEntity.getMeta().get(XapkInstaller.XAPK_UNZIP_PERCENT);
viewHolder.mDownloadPb.setText("游戏解压中 " + percent + "%");
viewHolder.mDownloadPb.setText("解压中" + percent + "%");
viewHolder.mDownloadPb.setProgress((int) (Float.valueOf(percent) * 10));
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.XAPK_UNZIPPING);
return;
} else if (XapkUnzipStatus.FAILURE.name().equals(xapkStatus)) {
viewHolder.mDownloadPb.setText(R.string.install);
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.XAPK_FAILURE);
return;
}
viewHolder.mDownloadPb.setProgress((int) (viewHolder.downloadEntity.getPercent() * 10));
@ -256,28 +220,29 @@ public class DetailDownloadUtils {
}
switch (downloadEntity.getStatus()) {
case timeout:
case neterror:
case subscribe:
case downloading:
case redirected:
case pause:
case overflow:
String downloadingText = "游戏加载中 " + downloadEntity.getPercent() + "%";
String resumeText = "继续加载 " + downloadEntity.getPercent() + "%";
viewHolder.mDownloadPb.setText((downloadEntity.getStatus() == DownloadStatus.downloading || downloadEntity.getStatus() == DownloadStatus.redirected) ? downloadingText : resumeText);
if (SPUtils.getBoolean(Constants.SP_USE_BROWSER_TO_INSTALL)) {
viewHolder.mDownloadPb.setText(R.string.browser_install_downloading);
} else {
viewHolder.mDownloadPb.setText(R.string.downloading);
}
if (downloadEntity.isPluggable() && PackagesManager.INSTANCE.isInstalled(downloadEntity.getPackageName())) {
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.DOWNLOADING_PLUGIN);
} else {
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.DOWNLOADING_NORMAL);
}
break;
case timeout:
case neterror:
case waiting:
case subscribe:
viewHolder.mDownloadPb.setText(R.string.waiting);
if (downloadEntity.isPluggable() && PackagesManager.INSTANCE.isInstalled(downloadEntity.getPackageName())) {
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.WAITING);
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.DOWNLOADING_PLUGIN);
} else {
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.WAITING);
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.DOWNLOADING_NORMAL);
}
break;
case done:
@ -339,19 +304,18 @@ public class DetailDownloadUtils {
private static void updateVStyleButton(DetailViewHolder viewHolder) {
switch (viewHolder.downloadEntity.getStatus()) {
case redirected:
case downloading:
case overflow:
viewHolder.mDownloadPb.setText("游戏加载中 " + viewHolder.downloadEntity.getPercent() + "%");
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.DOWNLOADING_NORMAL);
break;
case timeout:
case neterror:
case waiting:
case subscribe:
viewHolder.mDownloadPb.setText(R.string.waiting);
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.DOWNLOADING_NORMAL);
break;
case overflow:
case timeout:
case neterror:
case subscribe:
case pause:
viewHolder.mDownloadPb.setText("继续加载 " + viewHolder.downloadEntity.getPercent() + "%");
viewHolder.mDownloadPb.setButtonStyle(DownloadButton.ButtonStyle.DOWNLOADING_NORMAL);

View File

@ -8,6 +8,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.CountDownTimer;
import android.provider.Settings;
@ -92,8 +93,8 @@ import com.gh.gamecenter.entity.SettingsEntity;
import com.gh.gamecenter.entity.SimpleGameEntity;
import com.gh.gamecenter.entity.TrackableEntity;
import com.gh.gamecenter.login.entity.Badge;
import com.gh.gamecenter.setting.view.GameDownloadSettingFragment;
import com.gh.gamecenter.setting.view.security.BindPhoneActivity;
import com.gh.gamecenter.setting.compose.activity.ComposeBindPhoneActivity;
import com.gh.gamecenter.setting.compose.activity.ComposeGameDownloadSettingActivity;
import com.gh.gamecenter.suggest.SuggestType;
import com.lightgame.adapter.BaseRecyclerAdapter;
import com.lightgame.download.DownloadEntity;
@ -215,7 +216,7 @@ public class DialogUtils {
} else if (NetworkUtils.isWifiConnected(context)
|| filter4GorSize(context, size)) {
callBack.onResponse(false);
} else if (!SPUtils.getBoolean(GameDownloadSettingFragment.getTrafficDownloadHintKey(), true)) {
} else if (!SPUtils.getBoolean(ComposeGameDownloadSettingActivity.getTrafficDownloadHintKey(), true)) {
AppExecutor.getUiExecutor().executeWithDelay(() -> Utils.toast(context, "当前使用移动网络下载,请注意流量消耗"), 500);
callBack.onResponse(false);
} else {
@ -287,7 +288,7 @@ public class DialogUtils {
// MtaHelper.onEvent("移动网络下载", NetworkUtils.getMobileNetworkType(finalContext), "连上WiFi后自动下载");
});
allowAlways.setOnClickListener(v -> {
SPUtils.setBoolean(GameDownloadSettingFragment.getTrafficDownloadHintKey(), false);
SPUtils.setBoolean(ComposeGameDownloadSettingActivity.getTrafficDownloadHintKey(), false);
AppExecutor.getUiExecutor().executeWithDelay(() -> {
// 显示了弹窗以后,即便下面这个 toast 放在 listener.onConfirm 后调用也是显示 listener.onConfirm 里的 toast
// 喷了,延时包治疑难杂症
@ -1251,6 +1252,38 @@ public class DialogUtils {
dialog.show();
}
public static void showVersionNumberDialog(Context context, GameEntity gameEntity, @NonNull ConfirmListener listener) {
context = checkDialogContext(context);
if (!gameEntity.isShowVersionNumber()) {
listener.onConfirm();
} else {
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_version_number, null);
TextView contentTv = contentView.findViewById(R.id.contentTv);
TextView cancelTv = contentView.findViewById(R.id.cancelTv);
TextView continueTv = contentView.findViewById(R.id.continueTv);
contentTv.setText(gameEntity.getVersionNumberString());
cancelTv.setOnClickListener(v -> dialog.dismiss());
continueTv.setOnClickListener(v -> {
listener.onConfirm();
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();
}
}
// 海外下载地址弹窗
public static void showOverseaDownloadDialog(Context context, GameEntity gameEntity, @NonNull ConfirmListener listener) {
context = checkDialogContext(context);
@ -1585,7 +1618,7 @@ public class DialogUtils {
TextView commitTv = view.findViewById(R.id.commitTv);
Context finalContext = context;
//添加透明阴影,实现类似 clipPadding=false 效果
complaintCommentEt.setShadowLayer(complaintCommentEt.getExtendedPaddingBottom(), 0F, 0F, Color.TRANSPARENT);
complaintCommentEt.setShadowLayer(complaintCommentEt.getExtendedPaddingBottom(), 0f, 0f, Color.TRANSPARENT);
ExtensionsKt.setTextChangedListener(complaintCommentEt, (s, start, before, count) -> {
commitTv.setTextColor(ContextCompat.getColor(finalContext, s.toString().trim().isEmpty() ? R.color.text_subtitleDesc : R.color.theme_font));
@ -1595,7 +1628,7 @@ public class DialogUtils {
for (String option : options) {
TextView reportTv = new TextView(context);
reportTv.setText(option);
reportTv.setTextSize(16F);
reportTv.setTextSize(16f);
if (disabledOptions != null && disabledOptions.contains(option)) {
reportTv.setTextColor(ContextCompat.getColor(context, R.color.btn_gray));
} else {
@ -1604,10 +1637,12 @@ public class DialogUtils {
}
reportTv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
reportTv.setPadding(DisplayUtils.dip2px(context, 20F), DisplayUtils.dip2px(context, 17F),
DisplayUtils.dip2px(context, 20F), DisplayUtils.dip2px(context, 17F));
reportTv.setPadding(DisplayUtils.dip2px(context, 20f), DisplayUtils.dip2px(context, 17f),
DisplayUtils.dip2px(context, 20f), DisplayUtils.dip2px(context, 17f));
if (option.equals("其它")) {
ExtensionsKt.setDrawableEnd(reportTv, R.drawable.ic_complaint_arrow_right, DisplayUtils.dip2px(6F), DisplayUtils.dip2px(6F));
Drawable drawable = ContextCompat.getDrawable(context, R.drawable.ic_complaint_arrow_right);
drawable.setBounds(0, 0, DisplayUtils.dip2px(6f), DisplayUtils.dip2px(10f));
reportTv.setCompoundDrawables(null, null, drawable, null);
}
complaintContainer.addView(reportTv);
@ -2016,7 +2051,7 @@ public class DialogUtils {
binding.confirmTv.setText("我知道了");
binding.centerDivider.setVisibility(View.GONE);
binding.cancelTv.setVisibility(View.GONE);
ExtensionsKt.setDrawableStart(binding.titleTv, R.drawable.ic_reserve_success, null, null);
binding.titleTv.setCompoundDrawablesWithIntrinsicBounds(ExtensionsKt.toDrawable(R.drawable.ic_reserve_success), null, null, null);
binding.confirmTv.setOnClickListener(v -> dialog.dismiss());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(binding.getRoot());
@ -2045,7 +2080,7 @@ public class DialogUtils {
binding.bindPhoneBtn.setOnClickListener(v -> {
dialog.dismiss();
Intent intent = BindPhoneActivity.getNormalIntent(finalContext, false);
Intent intent = ComposeBindPhoneActivity.getNormalIntent(finalContext, false);
finalContext.startActivity(intent);
});

View File

@ -65,8 +65,8 @@ import com.gh.gamecenter.qa.video.detail.ForumVideoDetailActivity
import com.gh.gamecenter.retrofit.RetrofitManager
import com.gh.gamecenter.servers.GameServerTestActivity
import com.gh.gamecenter.servers.GameServersActivity
import com.gh.gamecenter.setting.view.security.BindPhoneActivity
import com.gh.gamecenter.setting.view.SettingActivity
import com.gh.gamecenter.setting.compose.activity.ComposeBindPhoneActivity
import com.gh.gamecenter.setting.compose.activity.ComposeSettingActivity
import com.gh.gamecenter.subject.SubjectActivity
import com.gh.gamecenter.suggest.SuggestType
import com.gh.gamecenter.tag.TagsActivity
@ -145,7 +145,6 @@ object DirectUtils {
directToLinkPage(context, linkEntity, entrance, path, null)
}
@JvmStatic
fun directToLinkPage(
context: Context,
linkEntity: LinkEntity,
@ -359,7 +358,7 @@ object DirectUtils {
"mobile_bind" -> {
CheckLoginUtils.checkLogin(context, entrance) {
context.startActivity(BindPhoneActivity.getNormalIntent(context, false))
context.startActivity(ComposeBindPhoneActivity.getNormalIntent(context, false))
}
}
@ -389,7 +388,7 @@ object DirectUtils {
"etiquette_exam" -> directToRegulationTestPage(context)
"setting" -> context.startActivity(SettingActivity.getIntent(context, false, entrance))
"setting" -> context.startActivity(ComposeSettingActivity.getIntent(context, false, entrance))
"index_page" -> directToHomeTab(context)
@ -773,36 +772,6 @@ object DirectUtils {
jumpActivity(context, bundle)
}
@JvmStatic
fun directToFeedbackCompat(
context: Context,
content: String? = null,
hintType: String? = null,
isQaFeedback: Boolean = false,
qaContentId: String? = "",
entrance: String? = null
) {
val bundle = Bundle()
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
bundle.putString(KEY_TO, SuggestionActivity::class.java.simpleName)
if (isQaFeedback) {
bundle.putBoolean(KEY_IS_QA_FEEDBACK, true)
bundle.putString(KEY_QA_CONTENT_ID, qaContentId)
bundle.putSerializable(KEY_SUGGESTTYPE, SuggestType.normal)
} else {
bundle.putString(KEY_CONTENT, content)
if (TextUtils.isEmpty(hintType)) {
bundle.putSerializable(KEY_SUGGESTTYPE, SuggestType.gameQuestion)
bundle.putString(KEY_SUGGEST_HINT_TYPE, KEY_PLUGIN)
} else {
bundle.putSerializable(KEY_SUGGESTTYPE, SuggestType.normal)
bundle.putString(KEY_SUGGEST_HINT_TYPE, hintType)
}
}
EntranceUtils.jumpActivityCompat(context, bundle)
}
@JvmStatic
fun directToDownloadManager(context: Context, entrance: String? = null) {
val bundle = Bundle()

View File

@ -19,25 +19,26 @@ import com.gh.common.simulator.SimulatorDownloadManager
import com.gh.common.simulator.SimulatorGameManager
import com.gh.common.view.DownloadButton
import com.gh.common.xapk.XapkInstaller
import com.gh.common.xapk.XapkInstaller.cancelUnzipTask
import com.gh.common.xapk.XapkUnzipStatus
import com.gh.download.DownloadManager
import com.gh.download.dialog.DownloadDialog
import com.gh.gamecenter.DownloadManagerActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.WebActivity
import com.gh.gamecenter.adapter.viewholder.GameViewHolder
import com.gh.gamecenter.common.callback.CancelListener
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.core.utils.*
import com.gh.gamecenter.energy.EnergyBridge
import com.gh.gamecenter.entity.GameEntity
import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.energy.EnergyBridge
import com.gh.gamecenter.entity.PluginLocation
import com.gh.gamecenter.gamedetail.dialog.GamePermissionDialogFragment
import com.gh.gamecenter.manager.PackagesManager
import com.gh.gamecenter.teenagermode.TeenagerModeActivity
import com.gh.vspace.VDownloadManagerActivity
import com.gh.vspace.VHelper
import com.lightgame.download.DownloadConfig
import com.lightgame.download.DownloadEntity
@ -125,7 +126,7 @@ object DownloadItemUtils {
holder.gameDownloadBtn.text = "已预约"
holder.gameDownloadBtn.visibility = View.VISIBLE
holder.gameDownloadBtn.buttonStyle = DownloadButton.ButtonStyle.RESERVED
updateItemViewStatus(holder, null, null)
updateItemViewStatus(holder, false, null, null)
}
}
@ -165,8 +166,7 @@ object DownloadItemUtils {
) {
// 显示预约
if (gameEntity.isReservable) {
holder.multiVersionDownloadTv?.visibility = View.GONE
updateItemViewStatus(holder, briefStyle, gameEntity.columnRecommend, isShowRecommendStar)
updateItemViewStatus(holder, false, briefStyle, gameEntity.columnRecommend, isShowRecommendStar)
updateDownloadButton(
context,
holder.gameDownloadBtn,
@ -177,16 +177,11 @@ object DownloadItemUtils {
return
}
if (gameEntity.getApk().isEmpty() || gameEntity.downloadOffStatus != null) {
holder.multiVersionDownloadTv?.visibility = View.GONE
holder.gameDownloadTips?.visibility = View.GONE
updateItemViewStatus(holder, briefStyle, gameEntity.columnRecommend, isShowRecommendStar)
updateItemViewStatus(holder, false, briefStyle, gameEntity.columnRecommend, isShowRecommendStar)
} else if (gameEntity.getApk().size == 1) {
holder.multiVersionDownloadTv?.visibility = View.GONE
holder.gameDownloadTips?.visibility = View.GONE
updateNormalItem(context, holder, gameEntity, briefStyle, isShowRecommendStar)
updateNormalItem(context, holder, gameEntity, isShowPlatform, briefStyle, isShowRecommendStar)
} else {
holder.multiVersionDownloadTv?.visibility = View.VISIBLE
updatePluginItem(context, holder, gameEntity, briefStyle, isShowRecommendStar)
updatePluginItem(context, holder, gameEntity, isShowPlatform, briefStyle, isShowRecommendStar)
}
updateDownloadButton(
context,
@ -267,56 +262,42 @@ object DownloadItemUtils {
downloadEntity = VHelper.getDownloadEntitySnapshot(gameEntity.id, gameEntity.getUniquePackageName())
}
if (downloadEntity == null) {
val entryMap: ArrayMap<String, DownloadEntity> = gameEntity.getEntryMap()
val apkEntity = gameEntity.getApk()[0]
if (entryMap.isNotEmpty()) {
downloadEntity = entryMap[apkEntity.getPlatform()]
}
}
if (downloadEntity != null) {
downloadBtn.apply {
when (downloadEntity.status) {
DownloadStatus.done -> {
if (downloadEntity.isSimulatorGame() && gameEntity.simulator != null) {
GameUtils.setDownloadBtnStatus(context, gameEntity, downloadBtn, pluginLocation)
} else if (downloadEntity.isVGame()) {
buttonStyle =
if (PackagesManager.isCanUpdate(
downloadEntity.gameId,
downloadEntity.packageName
)
) {
setText(R.string.update)
DownloadButton.ButtonStyle.NORMAL
} else {
setText(R.string.launch)
DownloadButton.ButtonStyle.LAUNCH_OR_OPEN
}
} else {
buttonStyle = DownloadButton.ButtonStyle.INSTALL_NORMAL
setText(R.string.install)
}
buttonStyle =
if (downloadEntity.isPluggable && PackagesManager.isInstalled(downloadEntity.packageName)) {
DownloadButton.ButtonStyle.PLUGIN
} else {
DownloadButton.ButtonStyle.NORMAL
}
}
DownloadStatus.pause,
DownloadStatus.timeout,
DownloadStatus.neterror,
DownloadStatus.subscribe,
DownloadStatus.overflow -> {
val status = downloadEntity.status
if (status == DownloadStatus.downloading) {
setText(R.string.downloading)
buttonStyle = DownloadButton.ButtonStyle.DOWNLOADING_NORMAL
} else if (status == DownloadStatus.waiting) {
setText(R.string.waiting)
buttonStyle = DownloadButton.ButtonStyle.WAITING
} else if (status == DownloadStatus.pause || status == DownloadStatus.timeout || status == DownloadStatus.neterror || status == DownloadStatus.subscribe || status == DownloadStatus.overflow) {
setText(R.string.downloading)
buttonStyle = DownloadButton.ButtonStyle.DOWNLOADING_NORMAL
} else if (status == DownloadStatus.done) {
val xapkStatus = downloadEntity.meta[XapkInstaller.XAPK_UNZIP_STATUS]
if (XapkUnzipStatus.UNZIPPING.name == xapkStatus) {
setText(R.string.unzipping)
buttonStyle = DownloadButton.ButtonStyle.NORMAL
setText(R.string.resume)
return
}
DownloadStatus.cancel -> {
if (downloadEntity.isSimulatorGame() && gameEntity.simulator != null) {
GameUtils.setDownloadBtnStatus(context, gameEntity, downloadBtn, pluginLocation)
} else if (downloadEntity.isVGame()) {
if (PackagesManager.isCanUpdate(downloadEntity.gameId, downloadEntity.packageName)) {
setText(R.string.update)
} else {
setText(R.string.launch)
}
} else {
setText(R.string.install)
}
else -> {}
buttonStyle =
if (downloadEntity.isPluggable && PackagesManager.isInstalled(downloadEntity.packageName)) {
DownloadButton.ButtonStyle.PLUGIN
} else {
DownloadButton.ButtonStyle.NORMAL
}
}
}
} else {
@ -329,10 +310,8 @@ object DownloadItemUtils {
// 更新正常的条目只有一个apk包
private fun updateNormalItem(
context: Context,
holder: GameViewHolder,
gameEntity: GameEntity,
briefStyle: String?,
context: Context, holder: GameViewHolder, gameEntity: GameEntity,
isShowPlatform: Boolean, briefStyle: String?,
isShowRecommendStar: Boolean = false
) {
val entryMap: ArrayMap<String, DownloadEntity> = gameEntity.getEntryMap()
@ -343,25 +322,23 @@ object DownloadItemUtils {
if (downloadEntity.isSimulatorGame()) {
if (downloadEntity.status != DownloadStatus.done) {
// 更改进度条和提示文本的状态
changeStatus(context, holder, downloadEntity)
changeStatus(context, holder, downloadEntity, isShowPlatform, true)
return
}
} else {
// 更改进度条和提示文本的状态
changeStatus(context, holder, downloadEntity)
changeStatus(context, holder, downloadEntity, isShowPlatform, true, isShowRecommendStar)
return
}
}
}
updateItemViewStatus(holder, briefStyle, gameEntity.columnRecommend, isShowRecommendStar)
updateItemViewStatus(holder, false, briefStyle, gameEntity.columnRecommend, isShowRecommendStar)
}
// 更新插件的条目有多个apk包
private fun updatePluginItem(
context: Context,
holder: GameViewHolder,
gameEntity: GameEntity,
briefStyle: String?,
context: Context, holder: GameViewHolder, gameEntity: GameEntity,
isShowPlatform: Boolean, briefStyle: String?,
isShowRecommendStar: Boolean = false
) {
val entryMap = gameEntity.getEntryMap()
@ -374,131 +351,151 @@ object DownloadItemUtils {
}
if (downloadEntity != null) {
// 更改进度条和提示文本的状态
changeStatus(context, holder, downloadEntity, gameEntity.getApk().size > 1)
changeStatus(context, holder, downloadEntity, isShowPlatform, false, isShowRecommendStar)
return
}
}
updateItemViewStatus(holder, briefStyle, gameEntity.columnRecommend, isShowRecommendStar)
updateItemViewStatus(holder, false, briefStyle, gameEntity.columnRecommend, isShowRecommendStar)
}
// 更改进度条和提示文本的状态
fun changeStatus(
context: Context,
holder: GameViewHolder,
downloadEntity: DownloadEntity,
isMultiVersion: Boolean = false
context: Context, holder: GameViewHolder, downloadEntity: DownloadEntity,
isShowPlatform: Boolean, isNormal: Boolean, isShowRecommendStar: Boolean = false
) {
when (downloadEntity.status) {
DownloadStatus.redirected,
DownloadStatus.downloading -> {
if (isMultiVersion) {
holder.gameDownloadBtn.buttonStyle = DownloadButton.ButtonStyle.NORMAL
val darkMode = (holder.gameDownloadTips?.getTag(R.string.is_dark_mode_on_id) as? Boolean) ?: false
val isDarkModeChanged = DarkModeUtils.isDarkModeOn(context) != darkMode
if (holder.gameDownloadTips?.visibility == View.GONE || holder.gameDownloadTips?.isAnimating == false || isDarkModeChanged) {
holder.gameDownloadTips?.visibility = View.VISIBLE
holder.gameDownloadTips?.setDownloadTipsAnimation(true)
}
holder.gameDownloadTips?.setTag(R.string.is_dark_mode_on_id, DarkModeUtils.isDarkModeOn(context))
val status = downloadEntity.status
// 畅玩游戏下载完成时不再需要显示进度条
val shouldShowDownload = !(downloadEntity.isVGame() && status == DownloadStatus.done)
val platform = PlatformUtils.getInstance(context).getPlatformName(downloadEntity.platform)
updateItemViewStatus(holder, shouldShowDownload, null, null, isShowRecommendStar)
holder.gameProgressbar.progressDrawable = R.drawable.progressbar_bg_style.toDrawable()
if (status == DownloadStatus.downloading) {
if (DownloadStatus.pause != DownloadManager.getInstance().getStatus(downloadEntity.url)) {
holder.gameProgressbar.progress = (downloadEntity.percent * 10).toInt()
if (isShowPlatform && platform != null) {
holder.gameDownloadSpeed.text = String.format(
"%s - %s(剩%s)", platform,
SpeedUtils.getSpeed(downloadEntity.speed),
SpeedUtils.getRemainTime(
downloadEntity.size,
downloadEntity.progress,
downloadEntity.speed * 1024
)
)
} else {
holder.gameDownloadTips?.visibility = View.GONE
holder.gameDownloadBtn.buttonStyle = DownloadButton.ButtonStyle.DOWNLOADING_NORMAL
holder.gameDownloadBtn.progress = (downloadEntity.percent * 10).toInt()
holder.gameDownloadBtn.text = downloadEntity.percent.toString() + "%"
holder.gameDownloadSpeed.text = String.format(
"%s(剩%s)", SpeedUtils.getSpeed(downloadEntity.speed),
SpeedUtils.getRemainTime(
downloadEntity.size,
downloadEntity.progress,
downloadEntity.speed * 1024
)
)
}
holder.gameDownloadPercentage.text = downloadEntity.percent.toString() + "%"
}
DownloadStatus.waiting -> {
if (isMultiVersion) {
holder.gameDownloadTips?.visibility = View.VISIBLE
holder.gameDownloadTips?.setDownloadTipsAnimation(false)
}
holder.gameDownloadBtn.buttonStyle = DownloadButton.ButtonStyle.WAITING
holder.gameDownloadBtn.text = context.getString(R.string.waiting)
} else if (status == DownloadStatus.waiting) {
holder.gameProgressbar.progress = (downloadEntity.percent * 10).toInt()
if (isShowPlatform && platform != null) {
holder.gameDownloadSpeed.text = String.format("%s - 等待", platform)
} else {
holder.gameDownloadSpeed.text = "等待"
}
DownloadStatus.pause,
DownloadStatus.timeout,
DownloadStatus.neterror,
DownloadStatus.subscribe,
DownloadStatus.overflow -> {
if (isMultiVersion) {
holder.gameDownloadTips?.visibility = View.VISIBLE
holder.gameDownloadTips?.setDownloadTipsAnimation(false)
}
holder.gameDownloadBtn.buttonStyle = DownloadButton.ButtonStyle.NORMAL
holder.gameDownloadBtn.text = context.getString(R.string.resume)
holder.gameDownloadPercentage.text = downloadEntity.percent.toString() + "%"
} else if (status == DownloadStatus.pause || status == DownloadStatus.timeout || status == DownloadStatus.neterror || status == DownloadStatus.subscribe || status == DownloadStatus.overflow) {
holder.gameProgressbar.progress = (downloadEntity.percent * 10).toInt()
if (isShowPlatform && platform != null) {
holder.gameDownloadSpeed.text = String.format("%s - 暂停", platform)
} else {
holder.gameDownloadSpeed.text = "暂停"
}
DownloadStatus.done -> {
if (isMultiVersion) {
holder.gameDownloadTips?.visibility = View.VISIBLE
holder.gameDownloadTips?.setDownloadTipsAnimation(false)
}
val xapkStatus = downloadEntity.meta[XapkInstaller.XAPK_UNZIP_STATUS]
if (XapkUnzipStatus.UNZIPPING.name == xapkStatus) {
val percent = downloadEntity.meta[XapkInstaller.XAPK_UNZIP_PERCENT]
holder.gameDownloadBtn.progress = (java.lang.Float.valueOf(percent) * 10).toInt()
holder.gameDownloadBtn.text = "$percent%"
return
} else if (XapkUnzipStatus.FAILURE.name == xapkStatus) {
holder.gameDownloadBtn.setText(R.string.install)
holder.gameDownloadBtn.buttonStyle = DownloadButton.ButtonStyle.INSTALL_NORMAL
return
}
holder.gameDownloadBtn.progress = 1000
holder.gameDownloadBtn.setText(R.string.hundred_percent)
holder.gameDownloadPercentage.text = downloadEntity.percent.toString() + "%"
} else if (status == DownloadStatus.done) {
val xapkStatus = downloadEntity.meta[XapkInstaller.XAPK_UNZIP_STATUS]
if (XapkUnzipStatus.UNZIPPING.name == xapkStatus) {
val percent = downloadEntity.meta[XapkInstaller.XAPK_UNZIP_PERCENT]
holder.gameProgressbar.progressDrawable =
context.resources.getDrawable(R.drawable.progressbar_xapk_style)
holder.gameDownloadSpeed.setText(R.string.unzipping)
holder.gameProgressbar.progress = (java.lang.Float.valueOf(percent) * 10).toInt()
holder.gameDownloadPercentage.text = "$percent%"
return
}
else -> {
holder.gameDownloadTips?.visibility = View.GONE
holder.gameProgressbar.progress = 1000
if (isShowPlatform && platform != null) {
holder.gameDownloadSpeed.text = String.format("%s - 下载完成", platform)
} else {
holder.gameDownloadSpeed.text = "下载完成"
}
holder.gameDownloadPercentage.setText(R.string.hundred_percent)
}
}
private fun updateItemViewStatus(
holder: GameViewHolder,
showDownload: Boolean,
briefStyle: String?,
recommendStyle: LinkEntity?,
isShowRecommendStar: Boolean = false
) {
holder.gameDownloadTips?.visibility = View.GONE
// 推荐指数优先,现暂时为游戏单详情列表游戏使用
if (isShowRecommendStar && holder.recommendStarInfo != null) {
holder.recommendStarInfo!!.visibility = View.VISIBLE
if (showDownload) {
if (holder.gameRating != null) holder.gameRating!!.visibility = View.GONE
holder.gameDes.visibility = View.GONE
return
}
// 推荐优先,有推荐内容时不执行下面的 star 和 brief 代码块
if (briefStyle != null && recommendStyle != null && briefStyle.contains("recommend")) {
if (holder.recommendContainer != null) {
holder.recommendContainer!!.visibility = View.VISIBLE
}
if (holder.gameRating != null) holder.gameRating!!.visibility = View.GONE
holder.gameDes.visibility = View.GONE
holder.recommendTv.text = recommendStyle.text
if (TextUtils.isEmpty(recommendStyle.icon)) {
holder.recommendIv.visibility = View.GONE
holder.recommendContainer?.setPadding(6F.dip2px(), 0, 8F.dip2px(), 0)
} else {
holder.recommendIv.visibility = View.VISIBLE
ImageUtils.display(holder.recommendIv, recommendStyle.icon)
}
return
} else {
holder.gameProgressbar.visibility = View.VISIBLE
holder.gameInfo.visibility = View.VISIBLE
if (holder.recommendContainer != null) {
holder.recommendContainer!!.visibility = View.GONE
}
}
if (briefStyle != null && briefStyle.contains("star")) {
if (holder.gameRating != null) holder.gameRating!!.visibility = View.VISIBLE
if (holder.recommendStarInfo != null) {
holder.recommendStarInfo!!.visibility = View.GONE
}
} else {
if (holder.gameRating != null) holder.gameRating!!.visibility = View.GONE
}
holder.gameProgressbar.visibility = View.GONE
holder.gameInfo.visibility = View.GONE
// 缺省情况下回落到游戏简介
if (TextUtils.isEmpty(briefStyle) || briefStyle!!.contains("brief") || briefStyle.contains("recommend")) {
holder.gameDes.visibility = View.VISIBLE
} else {
holder.gameDes.visibility = View.GONE
// 推荐指数优先,现暂时为游戏单详情列表游戏使用
if (isShowRecommendStar && holder.recommendStarInfo != null) {
holder.recommendStarInfo!!.visibility = View.VISIBLE
if (holder.gameRating != null) holder.gameRating!!.visibility = View.GONE
holder.gameDes.visibility = View.GONE
return
}
// 推荐优先,有推荐内容时不执行下面的 star 和 brief 代码块
if (briefStyle != null && recommendStyle != null && briefStyle.contains("recommend")) {
if (holder.recommendContainer != null) {
holder.recommendContainer!!.visibility = View.VISIBLE
}
if (holder.gameRating != null) holder.gameRating!!.visibility = View.GONE
holder.gameDes.visibility = View.GONE
holder.recommendTv.text = recommendStyle.text
if (TextUtils.isEmpty(recommendStyle.icon)) {
holder.recommendIv.visibility = View.GONE
holder.recommendContainer?.setPadding(6F.dip2px(), 0, 8F.dip2px(), 0)
} else {
holder.recommendIv.visibility = View.VISIBLE
ImageUtils.display(holder.recommendIv, recommendStyle.icon)
}
return
} else {
if (holder.recommendContainer != null) {
holder.recommendContainer!!.visibility = View.GONE
}
}
if (briefStyle != null && briefStyle.contains("star")) {
if (holder.gameRating != null) holder.gameRating!!.visibility = View.VISIBLE
} else {
if (holder.gameRating != null) holder.gameRating!!.visibility = View.GONE
}
// 缺省情况下回落到游戏简介
if (TextUtils.isEmpty(briefStyle) || briefStyle!!.contains("brief") || briefStyle.contains("recommend")) {
holder.gameDes.visibility = View.VISIBLE
} else {
holder.gameDes.visibility = View.GONE
}
}
}
@ -790,7 +787,6 @@ object DownloadItemUtils {
DataLogUtils.uploadGameLog(context, gameEntity.id, gameEntity.name, entrance)
} else if (str == context.getString(R.string.attempt)) {
ChainBuilder().apply {
addHandler(UpdateNewSimulatorHandler())
addHandler(GamePermissionHandler())
addHandler(BrowserInstallHandler())
addHandler(PackageCheckHandler())
@ -848,11 +844,8 @@ object DownloadItemUtils {
val isInstalledNewSimulator = SimulatorGameManager.isNewSimulatorInstalled(context)
val isInstalledOldSimulator = SimulatorGameManager.isOldSimulatorInstalled(context)
var simulator = gameEntity.simulator
val newSimulator = Config.getNewSimulatorEntitySetting()
if (!isInstalledOldSimulator && newSimulator != null) {//在没有安装旧的模拟器且有配置新版模拟器 才使用新版模拟器 否则还是用以前旧的
if (newSimulator.active) {
simulator = newSimulator
}
if (!isInstalledOldSimulator) {
simulator = Config.getNewSimulatorEntitySetting()
}
if (downloadEntity != null && SimulatorGameManager.isSimulatorGame(gameEntity) && !isInstalled && !isInstalledNewSimulator) {
SimulatorDownloadManager.getInstance().showDownloadDialog(
@ -914,31 +907,15 @@ object DownloadItemUtils {
}
})
} else {
var downloadEntity = DownloadManager.getInstance().getDownloadEntitySnapshot(gameEntity)
if (downloadEntity == null && gameEntity.getApk().size == 1) {
val entryMap: ArrayMap<String, DownloadEntity> = gameEntity.getEntryMap()
val apkEntity = gameEntity.getApk()[0]
if (entryMap.isNotEmpty()) {
downloadEntity = entryMap[apkEntity.getPlatform()]
}
}
if (downloadEntity != null) {
val xapkStatus = downloadEntity.meta[XapkInstaller.XAPK_UNZIP_STATUS]
if (XapkUnzipStatus.UNZIPPING.name == xapkStatus) {
cancelUnzipTask(downloadEntity)
return
}
when (str) {
context.getString(R.string.resume) -> {
DownloadManager.getInstance().resume(downloadEntity, true)
}
context.getString(R.string.waiting) -> {
Utils.toast(context, "最多只能同时下载三个任务,请稍等")
}
else -> {
DownloadManager.getInstance().pause(downloadEntity.url)
}
}
if (gameEntity.isVGame()) {
context.startActivity(VDownloadManagerActivity.getIntent(context, true))
} else {
context.startActivity(
DownloadManagerActivity.getDownloadMangerIntent(
context,
apk.url, entrance + "+(" + location.split(":").toTypedArray()[0] + ")"
)
)
}
}
}
@ -967,7 +944,7 @@ object DownloadItemUtils {
traceEvent
)
Utils.toast(context, gameEntity.name + "已加入下载队列")
downloadBtn.text = "0%"
downloadBtn.setText(R.string.downloading)
downloadBtn.buttonStyle = DownloadButton.ButtonStyle.DOWNLOADING_NORMAL
DeviceRemindDialog.showDeviceRemindDialog(context, gameEntity)
} else {

View File

@ -1,6 +1,5 @@
package com.gh.common.util
import android.preference.PreferenceManager
import com.gh.common.constant.Config
import com.gh.common.exposure.ExposureUtils
import com.gh.common.simulator.SimulatorDownloadManager
@ -23,7 +22,7 @@ import com.gh.gamecenter.entity.SimpleGameEntity
import com.gh.gamecenter.entity.SimulatorEntity
import com.gh.gamecenter.eventbus.EBDownloadStatus
import com.gh.gamecenter.retrofit.RetrofitManager
import com.gh.gamecenter.setting.view.GameDownloadSettingFragment
import com.gh.gamecenter.setting.compose.activity.ComposeGameDownloadSettingActivity
import com.gh.gamecenter.suggest.SuggestType
import com.gh.vspace.VHelper
import com.halo.assistant.HaloApp
@ -241,20 +240,16 @@ object DownloadObserver {
val gameName = downloadEntity.getMetaExtra(Constants.GAME_NAME)
if (simulatorJson.isEmpty()) return
var simulator = GsonUtils.fromJson(simulatorJson, SimulatorEntity::class.java)
val isInstalled = PackageUtils.isInstalledFromAllPackage(
HaloApp.getInstance().application,
simulator.apk?.packageName
)
val isInstalledNewSimulator =
SimulatorGameManager.isNewSimulatorInstalled(HaloApp.getInstance().application)
val isInstalledOldSimulator =
SimulatorGameManager.isOldSimulatorInstalled(HaloApp.getInstance().application)
val isInstalled = PackageUtils.isInstalledFromAllPackage(HaloApp.getInstance().application, simulator.apk?.packageName)
val isInstalledNewSimulator = SimulatorGameManager.isNewSimulatorInstalled(HaloApp.getInstance().application)
val isInstalledOldSimulator = SimulatorGameManager.isOldSimulatorInstalled(HaloApp.getInstance().application)
// if (!isInstalled && !isInstalledNewSimulator) {
val currentActivity = AppManager.getInstance().currentActivity()
?: return
val newSimulator = Config.getNewSimulatorEntitySetting()
if ((!isInstalledOldSimulator && newSimulator != null && newSimulator.active) || isInstalledNewSimulator) { //如果没有安装任一旧的模拟器 或者下载了新模拟器 则使用新版本模拟器
simulator = newSimulator ?: simulator
if (!isInstalledOldSimulator || isInstalledNewSimulator) { //如果没有安装任一旧的模拟器 或者下载了新模拟器 则使用新版本模拟器
Config.getNewSimulatorEntitySetting().let {
simulator = it!!
}
}
SimulatorDownloadManager.getInstance().showDownloadDialog(
currentActivity, simulator,
@ -266,7 +261,7 @@ object DownloadObserver {
} else {
val downloadType = downloadEntity.getMetaExtra(Constants.EXTRA_DOWNLOAD_TYPE)
// 是否是自动安装
val isAutoInstall = SPUtils.getBoolean(GameDownloadSettingFragment.AUTO_INSTALL_SP_KEY, true)
val isAutoInstall = SPUtils.getBoolean(ComposeGameDownloadSettingActivity.AUTO_INSTALL_SP_KEY, true)
if (downloadType == Constants.SIMULATOR_DOWNLOAD || isAutoInstall) {
if (FileUtils.isEmptyFile(downloadEntity.path)) {
Utils.toast(mApplication, R.string.install_failure_hint)

View File

@ -37,32 +37,6 @@ import java.util.Set;
public class EntranceUtils {
public static void jumpActivityCompat(Context context, Bundle bundle) {
bundle.putBoolean(KEY_REQUIRE_REDIRECT, true);
if (HaloApp.getInstance().isRunningForeground || HaloApp.getInstance().isAlreadyUpAndRunning) {
// 应用正在运行,前台或后台
String to = bundle.getString(KEY_TO);
Class<?> clazz = ClassUtils.forName(to);
if (clazz == null) clazz = MainActivity.class;
if (ToolbarFragment.class.isAssignableFrom(clazz)) { // 兼容ToolbarFragment
ToolBarActivity.startFragmentNewTask(context, (Class<? extends ToolbarFragment>) clazz, bundle);
} else {
Intent intent1 = new Intent(context, clazz);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// 如果 activity 名称有 singleton 的就添加 reorder_to_front 标签 (有点粗暴有点蠢,但暂时就先这样吧 :C )
if (clazz.getSimpleName().toLowerCase().contains("singleton")) {
intent1.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
}
intent1.putExtras(bundle);
context.startActivity(intent1);
}
} else {
// 应用未在运行
context.startActivity(SplashScreenActivity.getSplashScreenIntent(context, bundle));
}
}
public static void jumpActivity(Context context, Bundle bundle) {
bundle.putBoolean(KEY_REQUIRE_REDIRECT, true);

View File

@ -183,11 +183,6 @@ object ErrorHelper {
403210 -> handleVerifyPhoneError(context, errorEntity, realNameConfirmListener, entrance)
// 禁言(发布内容)
403402 -> Utils.toast(context, "您的账号存在违规,不允许发布内容")
// 禁言(点赞)
403403 -> Utils.toast(context, "您的账号存在违规,不允许点赞")
else -> Utils.toast(context, R.string.post_failure_hint)
}
}
@ -408,16 +403,15 @@ object ErrorHelper {
val errorEntity: ErrorEntity? =
httpException?.response()?.errorBody()?.string()?.toObject()
when {
errorEntity?.code == 403099 -> Utils.toast(context, "当前账号正在注销,禁止登录")
// 用户禁止登录
errorEntity?.code == 403401 -> Utils.toast(context, "您的账号存在违规,不允许登录")
// 设备禁止登录
errorEntity?.code == 403404 -> Utils.toast(context, "您的设备存在违规,不允许登录")
errorEntity?.toast?.isNotEmpty() == true -> Utils.toast(context, errorEntity.toast)
errorEntity?.code == 403099 -> {
Utils.toast(context, "当前账号正在注销,禁止登录")
}
errorEntity?.code == 403401 -> {//禁止登录
Utils.toast(context, "网络异常")
}
errorEntity?.toast?.isNotEmpty() == true -> {
Utils.toast(context, errorEntity.toast)
}
else -> Utils.toast(context, R.string.login_failure)
}
} catch (e: Exception) {

View File

@ -5,7 +5,6 @@ import android.content.Context
import android.text.TextUtils
import androidx.appcompat.app.AppCompatActivity
import com.gh.common.DefaultJsApi
import com.gh.common.constant.Config
import com.gh.common.dialog.CertificationDialog
import com.gh.common.exposure.ExposureEvent
import com.gh.common.exposure.ExposureManager
@ -13,9 +12,6 @@ import com.gh.common.exposure.ExposureSource
import com.gh.common.exposure.ExposureType
import com.gh.common.history.HistoryHelper
import com.gh.common.repository.ReservationRepository
import com.gh.common.simulator.NewSimulatorGameManager
import com.gh.common.simulator.SimulatorDownloadManager
import com.gh.common.simulator.SimulatorGameManager
import com.gh.download.DownloadManager
import com.gh.download.dialog.DownloadDialog
import com.gh.gamecenter.R
@ -31,10 +27,8 @@ import com.gh.gamecenter.common.utils.singleToMain
import com.gh.gamecenter.common.view.dsbridge.CompletionHandler
import com.gh.gamecenter.core.runOnUiThread
import com.gh.gamecenter.core.utils.EmptyCallback
import com.gh.gamecenter.core.utils.MtaHelper
import com.gh.gamecenter.core.utils.SPUtils
import com.gh.gamecenter.core.utils.ToastUtils
import com.gh.gamecenter.energy.EnergyBridge
import com.gh.gamecenter.entity.ApkEntity
import com.gh.gamecenter.entity.GameEntity
import com.gh.gamecenter.entity.PluginLocation
@ -43,10 +37,7 @@ import com.gh.gamecenter.login.user.UserManager
import com.gh.gamecenter.retrofit.RetrofitManager
import com.gh.gamecenter.teenagermode.TeenagerModeActivity
import com.gh.vspace.VHelper
import com.lightgame.download.DownloadEntity
import com.lightgame.download.FileUtils
import com.lightgame.utils.Utils
import java.io.File
/**
* 游戏活动下载辅助类
@ -177,13 +168,10 @@ object GameActivityDownloadHelper {
) {
val apk = getApk(gameEntity, event, true) ?: return
val downloadEntity = DownloadManager.getInstance().getDownloadEntitySnapshot(gameEntity)
val str = GameUtils.getDownloadBtnText(context, gameEntity, PluginLocation.only_game)
if (downloadEntity != null &&
str != context.getString(R.string.install) &&
str != context.getString(R.string.launch)
) {
if (downloadEntity != null) {
ToastUtils.toast("${gameEntity.name}已加入下载队列")
} else {
val str = GameUtils.getDownloadBtnText(context, gameEntity, PluginLocation.only_game)
if (str == context.getString(R.string.download) || str == context.getString(R.string.attempt)) {
GamePermissionDialogFragment.show((context as AppCompatActivity), gameEntity, gameEntity.info) {
CertificationDialog.showCertificationDialog(context, gameEntity) {
@ -194,7 +182,7 @@ object GameActivityDownloadHelper {
}
DataLogUtils.uploadGameLog(context, gameEntity.id, gameEntity.name, entrance)
} else if (str == context.getString(R.string.smooth)) {
VHelper.validateVSpaceBeforeAction(context, gameEntity) {
VHelper.validateVSpaceBeforeAction(context, gameEntity, true) {
GamePermissionDialogFragment.show((context as AppCompatActivity), gameEntity, gameEntity.info) {
CertificationDialog.showCertificationDialog(context, gameEntity) {
DialogUtils.checkDownload(context, apk.size) { isSubscribe: Boolean ->
@ -213,73 +201,12 @@ object GameActivityDownloadHelper {
}
}
}
} else if (str == context.getString(R.string.install)) {
val simulatorDownloadEntity = SimulatorGameManager.findDownloadEntityByUrl(apk.url)
if (gameEntity.simulator != null) {
val isInstalled =
PackageUtils.isInstalledFromAllPackage(context, gameEntity.simulator!!.apk!!.packageName)
val isInstalledNewSimulator = SimulatorGameManager.isNewSimulatorInstalled(context)
val isInstalledOldSimulator = SimulatorGameManager.isOldSimulatorInstalled(context)
var simulator = gameEntity.simulator
val newSimulator = Config.getNewSimulatorEntitySetting()
if (!isInstalledOldSimulator && newSimulator != null) {//在没有安装旧的模拟器且有配置新版模拟器 才使用新版模拟器 否则还是用以前旧的
if (newSimulator.active) {
simulator = newSimulator
}
}
if (simulatorDownloadEntity != null && SimulatorGameManager.isSimulatorGame(gameEntity) && !isInstalled && !isInstalledNewSimulator) {
SimulatorDownloadManager.getInstance().showDownloadDialog(
context, simulator,
SimulatorDownloadManager.SimulatorLocation.LAUNCH, gameEntity.id, gameEntity.name!!, null
)
return
}
}
if (gameEntity.isVGame()) {
VHelper.installOrLaunch((context as AppCompatActivity), gameEntity.getUniquePackageName() ?: "")
} else {
downloadEntity?.run {
install(context, gameEntity, apk, this)
}
}
} else if (str == context.getString(R.string.launch)) {
EnergyBridge.postEnergyTask("play_game", gameEntity.id, gameEntity.getApk()[0].packageName)
//启动模拟器游戏
if (SimulatorGameManager.isSimulatorGame(gameEntity)) {
if (NewSimulatorGameManager.shouldShowUpdateNewSimulatorAlert(context)) {
NewSimulatorGameManager.showUpdateNewsSimulator(context, null)
return
}
val simulatorDownloadEntity =
SimulatorGameManager.findDownloadEntityByUrl(gameEntity.getApk()[0].url)
if (simulatorDownloadEntity != null) {
val file = File(simulatorDownloadEntity.path)
if (!file.exists()) {
download(context, gameEntity, apk, false, entrance, location, traceEvent)
return
}
NewFlatLogUtils.logSimulatorGameCardClick("启动")
SimulatorGameManager.launchSimulatorGame(simulatorDownloadEntity, gameEntity)
}
return
}
if (gameEntity.isVGame()) {
VHelper.installOrLaunch((context as AppCompatActivity), gameEntity.getUniquePackageName() ?: "")
return
}
if (entrance.contains("我的游戏")) {
MtaHelper.onEvent("我的游戏_启动", "启动", gameEntity.name)
}
PackageUtils.launchApplicationByPackageName(context, gameEntity.getApk()[0].packageName)
} else if (str == context.getString(R.string.install) || str == context.getString(R.string.launch)) {
ToastUtils.toast("${gameEntity.name}已加入下载队列")
} else if (str == context.getString(R.string.update)) {
DialogUtils.checkDownload(context, apk.size) { isSubscribe: Boolean ->
update(context, gameEntity, apk, entrance, location, isSubscribe, traceEvent)
}
} else {
ToastUtils.toast("${gameEntity.name}已加入下载队列")
}
}
}
@ -367,29 +294,6 @@ object GameActivityDownloadHelper {
}
}
// 安装
private fun install(
context: Context,
gameEntity: GameEntity,
apkEntity: ApkEntity,
downloadEntity: DownloadEntity
) {
val path = downloadEntity.path
when {
FileUtils.isEmptyFile(path) -> {
Utils.toast(context, R.string.install_failure_hint)
DownloadManager.getInstance().cancel(downloadEntity.url)
gameEntity.getEntryMap().remove(apkEntity.getPlatform())
}
PackageUtils.isCanPluggable(apkEntity) -> {
DialogHelper.showPluginDialog(context) { PackageInstaller.uninstall(context, path) }
}
else -> {
PackageInstaller.install(context, downloadEntity)
}
}
}
// 更新
private fun update(
context: Context,

View File

@ -1,17 +1,16 @@
package com.gh.common.util;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import com.gh.common.view.DownloadButton;
import com.gh.gamecenter.core.AppExecutor;
import com.gh.common.constant.Config;
import com.gh.common.simulator.SimulatorGameManager;
import com.gh.common.view.DownloadButton;
import com.gh.download.DownloadManager;
import com.gh.gamecenter.R;
import com.gh.gamecenter.core.AppExecutor;
import com.gh.gamecenter.entity.ApkEntity;
import com.gh.gamecenter.entity.ApkLink;
import com.gh.gamecenter.entity.GameCollectionEntity;
@ -27,6 +26,9 @@ import com.lightgame.download.DownloadStatus;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
public class GameUtils {
/**
@ -78,7 +80,7 @@ public class GameUtils {
@WorkerThread
public static String getDownloadBtnText(Context context, GameEntity gameEntity, PluginLocation pluginLocation) {
if (gameEntity.getApk().size() > 1) {
return "";
return context.getString(R.string.expand);
}
int doneCount = 0; // 下载完成数量

View File

@ -70,7 +70,7 @@ public class InstallUtils {
if (!TextUtils.isEmpty(installVersion) && downloadEntity != null &&
installVersion.equals(downloadEntity.getVersionName())) {
if (!downloadEntity.isPluggable() || PackageUtils.isSignedByGh(context, packageName)) {
EventBus.getDefault().post(new EBPackage(EBPackage.TYPE_INSTALLED, packageName, installVersion));
EventBus.getDefault().post(new EBPackage("安装", packageName, installVersion));
}
}
}

View File

@ -18,6 +18,7 @@ import com.gh.gamecenter.adapter.LibaoDetailAdapter;
import com.gh.gamecenter.common.utils.DialogHelper;
import com.gh.gamecenter.common.utils.ExtensionsKt;
import com.gh.gamecenter.common.utils.NotificationHelper;
import com.gh.gamecenter.core.utils.GsonUtils;
import com.gh.gamecenter.core.utils.ToastUtils;
import com.gh.gamecenter.core.utils.UrlFilterUtils;
import com.gh.gamecenter.entity.ApkEntity;
@ -164,12 +165,6 @@ public class LibaoUtils {
String status = shouldUpdateStatus ? updateStatus(libaoEntity) : libaoEntity.getStatus();
libaoBtn.setTextColor(Color.WHITE);
if (status == null || TextUtils.isEmpty(status)) return;
// 领取限制为活动发放且未领取显示查看
if (ExtensionsKt.toResString(R.string.libao_activity_grant).equals(libaoEntity.getReceiveLimit()) && !status.equals("linged")) {
libaoBtn.setText(R.string.libao_check);
libaoBtn.setBackgroundResource(R.drawable.button_normal_round_style);
return;
}
switch (status) {
case "ling":
libaoBtn.setText(R.string.libao_ling);
@ -360,14 +355,7 @@ public class LibaoUtils {
Utils.toast(context, "还没到开始领取时间");
break;
case "查看":
if (ExtensionsKt.toResString(R.string.libao_activity_grant).equals(libaoEntity.getReceiveLimit())) {
String url = libaoEntity.getActivityLink().getUrl();
DialogHelper.showLibaoActivityDialog(
v.getContext(),
TextUtils.isEmpty(url),
() -> DirectUtils.directToWebView(v.getContext(), url, "查看礼包码弹窗-查看活动详情")
);
} else if (!TextUtils.isEmpty(libaoEntity.getDes())) {
if (!TextUtils.isEmpty(libaoEntity.getDes())) {
DialogHelper.showCenterDialog(v.getContext(), "使用说明", Html.fromHtml(libaoEntity.getDes()), "关闭", "", () -> {
}, () -> {
});

View File

@ -409,7 +409,7 @@ public class LogUtils {
public static void uploadWelcomeDialog(String action, String dialogId, String linkTitle) {
ExposureEntity payload = new ExposureEntity();
payload.setWelcomeDialogId(dialogId);
payload.setWelcomeDialogLinkTitle(linkTitle);
payload.setWelcomeDialogId(linkTitle);
SimpleLogContainerEntity entity = new SimpleLogContainerEntity();
entity.setEvent("dialog");

View File

@ -813,235 +813,4 @@ object NewFlatLogUtils {
log(json, "event", false)
}
//跳过广告
@JvmStatic
fun logOpenScreenAdSkip(adId: String, linkText: String, linkType: String, linkId: String) {
val json = json {
"event" to "open_screen_ad_skip"
"ad_id" to adId
"link_text" to linkText
"link_type" to linkType
"link_id" to linkId
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
//游戏单广场浏览时长
fun logGameCollectSquareStayTime(interval: Long) {
val json = json {
"event" to "game_collect_square_stay_time"
"interval" to interval
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
//游戏单浏览时长
fun logGameCollectStayTime(interval: Long, id: String, title: String) {
val json = json {
"event" to "game_collect_stay_time"
"interval" to interval
"game_collect_id" to id
"game_collect_title" to title
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 游戏存档页面展示事件
fun logGameArchivePageShow(tabName: String) {
val json = json {
"event" to "cloud_save_game_save_page_show"
"tab_name" to tabName
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 云存档管理页面展示事件
fun logCloudArchiveManagePageShow(gameId: String, gameName: String, entrance: String) {
val json = json {
"event" to "cloud_save_manage_page_show"
"game_id" to gameId
"game_name" to gameName
"entrance" to entrance
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 云存档Tab页面展示事件
fun logCloudArchiveTabShow(gameId: String, gameName: String, tabName: String) {
val json = json {
"event" to "cloud_save_tab_page_show"
"game_id" to gameId
"game_name" to gameName
"tab_name" to tabName
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 存档分享弹窗展示事件
fun logCloudArchiveShareDialogShow() {
val json = json {
"event" to "cloud_save_share_dialog_show"
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 存档分享弹窗点击事件
fun logCloudArchiveShareDialogClick(buttonType: String) {
val json = json {
"event" to "cloud_save_share_dialog_click"
"button_type" to buttonType
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 存档分享弹窗分享结果事件
fun logCloudArchiveShareDialogResult(shareResult: String) {
val json = json {
"event" to "cloud_save_share_dialog_result"
"share_result" to shareResult
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 存档删除弹窗展示事件
fun logCloudArchiveDeleteDialogShow() {
val json = json {
"event" to "cloud_save_delete_dialog_show"
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 存档删除弹窗点击事件
fun logCloudArchiveDeleteDialogClick(buttonType: String) {
val json = json {
"event" to "cloud_save_delete_dialog_click"
"button_type" to buttonType
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 上传存档弹窗展示事件
fun logCloudArchiveUploadDialogShow() {
val json = json {
"event" to "cloud_save_upload_dialog_show"
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 上传存档弹窗点击事件
fun logCloudArchiveUploadDialogClick(buttonType: String) {
val json = json {
"event" to "cloud_save_upload_dialog_click"
"button_type" to buttonType
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 畅玩助手下载提示弹窗展示事件
fun logCloudArchiveVSpaceDownloadDialogShow() {
val json = json {
"event" to "cloud_save_halo_fun_download_dialog_show"
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 畅玩助手下载提示弹窗点击事件
fun logCloudArchiveVSpaceDownloadDialogClick(buttonType: String) {
val json = json {
"event" to "cloud_save_halo_fun_download_dialog_click"
"button_type" to buttonType
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 游戏下载提示弹窗展示事件
fun logCloudArchiveGameDownloadDialogShow() {
val json = json {
"event" to "cloud_save_game_download_dialog_show"
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 游戏下载提示弹窗点击事件
fun logCloudArchiveGameDownloadDialogClick(buttonType: String) {
val json = json {
"event" to "cloud_save_game_download_dialog_click"
"button_type" to buttonType
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 推荐游戏页面下载游戏事件
fun logCloudArchiveRecommendGameDownload(gameId: String, gameName: String) {
val json = json {
"event" to "cloud_save_recommend_game_page_download"
"game_id" to gameId
"game_name" to gameName
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 搜索功能关键词上传事件
fun logCloudArchiveSearchKeyUpload(gameId: String, gameName: String, key: String) {
val json = json {
"event" to "cloud_save_search_key_upload"
"game_id" to gameId
"game_name" to gameName
"key" to key
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 云存档Tab展示事件/云存档Tab展示事件
fun logCloudArchiveGameDetailTabRelated(event: String, gameId: String, gameName: String) {
val json = json {
"event" to event
"game_id" to gameId
"game_name" to gameName
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 云存档下载/使用事件
fun logCloudArchiveDownloadOrApply(archiveName: String, entrance: String) {
val json = json {
"event" to "cloud_save_download"
"cloud_save_name" to archiveName
"entrance" to entrance
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
// 存档覆盖风险提示弹窗展示事件/存档覆盖风险提示弹窗点击事件
fun logCloudArchiveApplyDialogRelated(event: String, buttonType: String = "") {
val json = json {
"event" to event
if (buttonType.isNotBlank()) {
"button_type" to buttonType
}
parseAndPutMeta().invoke(this)
}
log(json, "event", false)
}
}

View File

@ -55,11 +55,11 @@ object PackageInstaller {
fun install(context: Context, downloadEntity: DownloadEntity, showUnzipToast: Boolean) {
val pkgPath = downloadEntity.path
val isXapk = XapkInstaller.XAPK_EXTENSION_NAME == pkgPath.getExtension()
val isVGame = downloadEntity.getMetaExtra(Constants.SMOOTH_GAME) == "true"
val isSmoothGame = downloadEntity.getMetaExtra(Constants.SMOOTH_GAME) == "true"
val currentActivity = CurrentActivityHolder.getCurrentActivity() ?: return
if (isVGame) {
if (isSmoothGame) {
VHelper.install(currentActivity, downloadEntity)
return
}

View File

@ -12,10 +12,9 @@ import android.widget.PopupWindow
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import com.gh.gamecenter.R
import com.gh.gamecenter.common.utils.setDrawableEnd
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.common.utils.visibleIf
import com.gh.gamecenter.R
import com.gh.gamecenter.entity.CatalogEntity
import com.gh.gamecenter.entity.SubjectSettingEntity
import com.google.android.flexbox.FlexboxLayout
@ -95,8 +94,13 @@ class CatalogFilterView @JvmOverloads constructor(
}
private fun showSelectTypePopupWindow(containerView: View, typeTv: TextView, typeText: String) {
val drawableUp = ContextCompat.getDrawable(typeTv.context, R.drawable.ic_filter_arrow_up)
val drawableDown = ContextCompat.getDrawable(typeTv.context, R.drawable.ic_filter_arrow_down)
drawableUp?.setBounds(0, 0, drawableUp.minimumWidth, drawableUp.minimumHeight)
drawableDown?.setBounds(0, 0, drawableDown.minimumWidth, drawableDown.minimumHeight)
typeTv.setTextColor(R.color.theme_font.toColor(context))
typeTv.setDrawableEnd(R.drawable.ic_filter_arrow_up)
typeTv.setCompoundDrawables(null, null, drawableUp, null)
val inflater = LayoutInflater.from(typeTv.context)
val layout = inflater.inflate(R.layout.layout_filter_size, null)
@ -141,7 +145,7 @@ class CatalogFilterView @JvmOverloads constructor(
popupWindow.setOnDismissListener {
typeTv.setTextColor(R.color.text_757575.toColor(context))
typeTv.setDrawableEnd(R.drawable.ic_filter_arrow_down)
typeTv.setCompoundDrawables(null, null, drawableDown, null)
mTypePopupWindow = null
}
@ -152,8 +156,13 @@ class CatalogFilterView @JvmOverloads constructor(
}
private fun showSelectCatalogPopupWindow(containerView: View, catalogTv: TextView, catalogText: String) {
val drawableUp = ContextCompat.getDrawable(catalogTv.context, R.drawable.ic_filter_arrow_up)
val drawableDown = ContextCompat.getDrawable(catalogTv.context, R.drawable.ic_filter_arrow_down)
drawableUp?.setBounds(0, 0, drawableUp.minimumWidth, drawableUp.minimumHeight)
drawableDown?.setBounds(0, 0, drawableDown.minimumWidth, drawableDown.minimumHeight)
catalogTv.setTextColor(R.color.theme_font.toColor(context))
catalogTv.setDrawableEnd(R.drawable.ic_filter_arrow_up)
catalogTv.setCompoundDrawables(null, null, drawableUp, null)
val inflater = LayoutInflater.from(catalogTv.context)
val layout = inflater.inflate(R.layout.layout_filter_size, null)
@ -200,7 +209,7 @@ class CatalogFilterView @JvmOverloads constructor(
popupWindow.setOnDismissListener {
catalogTv.setTextColor(R.color.text_757575.toColor(context))
catalogTv.setDrawableEnd(R.drawable.ic_filter_arrow_down)
catalogTv.setCompoundDrawables(null, null, drawableDown, null)
mCatalogPopupWindow = null
}
@ -211,8 +220,13 @@ class CatalogFilterView @JvmOverloads constructor(
}
private fun showSelectSizePopupWindow(containerView: View, sizeTv: TextView, sizeText: String) {
val drawableUp = ContextCompat.getDrawable(sizeTv.context, R.drawable.ic_filter_arrow_up)
val drawableDown = ContextCompat.getDrawable(sizeTv.context, R.drawable.ic_filter_arrow_down)
drawableUp?.setBounds(0, 0, drawableUp.minimumWidth, drawableUp.minimumHeight)
drawableDown?.setBounds(0, 0, drawableDown.minimumWidth, drawableDown.minimumHeight)
sizeTv.setTextColor(R.color.theme_font.toColor(context))
sizeTv.setDrawableEnd(R.drawable.ic_filter_arrow_up)
sizeTv.setCompoundDrawables(null, null, drawableUp, null)
val inflater = LayoutInflater.from(sizeTv.context)
val layout = inflater.inflate(R.layout.layout_filter_size, null)
@ -267,7 +281,7 @@ class CatalogFilterView @JvmOverloads constructor(
popupWindow.setOnDismissListener {
sizeTv.setTextColor(R.color.text_757575.toColor(context))
sizeTv.setDrawableEnd(R.drawable.ic_filter_arrow_down)
sizeTv.setCompoundDrawables(null, null, drawableDown, null)
mSizePopupWindow = null
}

View File

@ -11,10 +11,9 @@ import android.widget.PopupWindow
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import com.gh.gamecenter.R
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.common.utils.setDrawableEnd
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.R
import com.gh.gamecenter.entity.SubjectSettingEntity
import com.google.android.flexbox.FlexboxLayout
@ -90,8 +89,13 @@ class CategoryFilterView @JvmOverloads constructor(
}
private fun showSelectTypePopupWindow(containerView: View, typeTv: TextView, typeText: String) {
val drawableUp = ContextCompat.getDrawable(typeTv.context, R.drawable.ic_filter_arrow_up)
val drawableDown = ContextCompat.getDrawable(typeTv.context, R.drawable.ic_filter_arrow_down)
drawableUp?.setBounds(0, 0, drawableUp.minimumWidth, drawableUp.minimumHeight)
drawableDown?.setBounds(0, 0, drawableDown.minimumWidth, drawableDown.minimumHeight)
typeTv.setTextColor(R.color.theme_font.toColor(context))
typeTv.setDrawableEnd(R.drawable.ic_filter_arrow_up)
typeTv.setCompoundDrawables(null, null, drawableUp, null)
val inflater = LayoutInflater.from(typeTv.context)
val layout = inflater.inflate(R.layout.layout_filter_size, null)
@ -137,7 +141,7 @@ class CategoryFilterView @JvmOverloads constructor(
popupWindow.setOnDismissListener {
typeTv.setTextColor(R.color.text_757575.toColor(context))
typeTv.setDrawableEnd(R.drawable.ic_filter_arrow_down)
typeTv.setCompoundDrawables(null, null, drawableDown, null)
mTypePopupWindow = null
}
@ -148,8 +152,13 @@ class CategoryFilterView @JvmOverloads constructor(
}
private fun showSelectSizePopupWindow(containerView: View, sizeTv: TextView, sizeText: String) {
val drawableUp = ContextCompat.getDrawable(sizeTv.context, R.drawable.ic_filter_arrow_up)
val drawableDown = ContextCompat.getDrawable(sizeTv.context, R.drawable.ic_filter_arrow_down)
drawableUp?.setBounds(0, 0, drawableUp.minimumWidth, drawableUp.minimumHeight)
drawableDown?.setBounds(0, 0, drawableDown.minimumWidth, drawableDown.minimumHeight)
sizeTv.setTextColor(R.color.theme_font.toColor(context))
sizeTv.setDrawableEnd(R.drawable.ic_filter_arrow_up)
sizeTv.setCompoundDrawables(null, null, drawableUp, null)
val inflater = LayoutInflater.from(sizeTv.context)
val layout = inflater.inflate(R.layout.layout_filter_size, null)
@ -205,7 +214,7 @@ class CategoryFilterView @JvmOverloads constructor(
popupWindow.setOnDismissListener {
sizeTv.setTextColor(R.color.text_757575.toColor(context))
sizeTv.setDrawableEnd(R.drawable.ic_filter_arrow_down)
sizeTv.setCompoundDrawables(null, null, drawableDown, null)
mSizePopupWindow = null
}

View File

@ -9,8 +9,8 @@ import android.widget.LinearLayout
import android.widget.PopupWindow
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import com.gh.gamecenter.R
import com.gh.gamecenter.common.utils.setDrawableEnd
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.common.utils.toDrawable
import com.gh.gamecenter.entity.SubjectSettingEntity
@ -112,8 +112,14 @@ class ConfigFilterView @JvmOverloads constructor(
}
private fun showSelectionPopupWindow(containerView: View, sizeTv: TextView, sizeText: String) {
val drawableUp = ContextCompat.getDrawable(sizeTv.context, R.drawable.ic_filter_arrow_up)
val drawableDown =
ContextCompat.getDrawable(sizeTv.context, R.drawable.ic_filter_arrow_down)
drawableUp?.setBounds(0, 0, drawableUp.minimumWidth, drawableUp.minimumHeight)
drawableDown?.setBounds(0, 0, drawableDown.minimumWidth, drawableDown.minimumHeight)
sizeTv.setTextColor(R.color.theme_font.toColor(sizeTv.context))
sizeTv.setDrawableEnd(R.drawable.ic_filter_arrow_up)
sizeTv.setCompoundDrawables(null, null, drawableUp, null)
val inflater = LayoutInflater.from(sizeTv.context)
val layout = inflater.inflate(R.layout.layout_filter_size, null)
@ -172,7 +178,7 @@ class ConfigFilterView @JvmOverloads constructor(
popupWindow.setOnDismissListener {
sizeTv.setTextColor(R.color.text_757575.toColor(sizeTv.context))
sizeTv.setDrawableEnd(R.drawable.ic_filter_arrow_down)
sizeTv.setCompoundDrawables(null, null, drawableDown, null)
mPopupWindow = null
}

View File

@ -45,7 +45,12 @@ class DownloadButton @JvmOverloads constructor(
}
var text: String
get() = mText
get() {
if (showProgress && mText.contains("%")) {
return context.getString(R.string.downloading)
}
return mText
}
set(value) {
mText = value
invalidate()
@ -118,7 +123,11 @@ class DownloadButton @JvmOverloads constructor(
}
fun setText(@StringRes res: Int) {
text = context.getString(res)
text = if (mShowPercent && res == R.string.downloading) {
"${progress / 10}%"
} else {
context.getString(res)
}
invalidate()
}
@ -147,7 +156,6 @@ class DownloadButton @JvmOverloads constructor(
when (buttonStyle) {
ButtonStyle.NORMAL,
ButtonStyle.INSTALL_NORMAL,
ButtonStyle.XAPK_FAILURE,
ButtonStyle.NONE_WITH_HINT,
ButtonStyle.H5_GAME,
ButtonStyle.SPECIAL_DOWNLOAD,
@ -179,7 +187,6 @@ class DownloadButton @JvmOverloads constructor(
progress = 0
mDefaultColor = R.color.white.toColor(context)
}
ButtonStyle.FAILURE,
ButtonStyle.NONE,
ButtonStyle.RESERVED -> {
progressDrawable = null
@ -194,8 +201,6 @@ class DownloadButton @JvmOverloads constructor(
progress = 0
mDefaultColor = R.color.white.toColor(context)
}
ButtonStyle.XAPK_SUCCESS,
ButtonStyle.XAPK_UNZIPPING,
ButtonStyle.DOWNLOADING_NORMAL -> {
if (showProgress) {
progressDrawable =
@ -234,6 +239,18 @@ class DownloadButton @JvmOverloads constructor(
progress = 0
mDefaultColor = R.color.theme_font.toColor(context)
}
ButtonStyle.FAILURE -> {
progressDrawable = null
background = R.drawable.game_item_btn_pause_style.toDrawable(context)
progress = 0
mDefaultColor = R.color.white.toColor(context)
}
ButtonStyle.XAPK_FAILURE,
ButtonStyle.XAPK_SUCCESS,
ButtonStyle.XAPK_UNZIPPING -> {
mDefaultColor = R.color.white.toColor(context)
progressDrawable = R.drawable.progressbar_xapk_detail_style.toDrawable(context)
}
}
mPaintColor = mDefaultColor
}

View File

@ -14,10 +14,9 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.R
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.common.utils.setDrawableEnd
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.R
import com.gh.gamecenter.common.utils.toDrawable
import com.gh.gamecenter.databinding.ItemFilterBinding
import com.gh.gamecenter.databinding.LayoutFilterBinding
@ -108,8 +107,13 @@ class FilterView @JvmOverloads constructor(context: Context, attrs: AttributeSet
subFilterText: String,
selectedCallback: ((String) -> Unit)
) {
val drawableUp = ContextCompat.getDrawable(subFilterTv.context, R.drawable.ic_filter_arrow_up)
val drawableDown = ContextCompat.getDrawable(subFilterTv.context, R.drawable.ic_filter_arrow_down)
drawableUp?.setBounds(0, 0, drawableUp.minimumWidth, drawableUp.minimumHeight)
drawableDown?.setBounds(0, 0, drawableDown.minimumWidth, drawableDown.minimumHeight)
subFilterTv.setTextColor(R.color.theme_font.toColor(context))
subFilterTv.setDrawableEnd(R.drawable.ic_filter_arrow_up)
subFilterTv.setCompoundDrawables(null, null, drawableUp, null)
val inflater = LayoutInflater.from(subFilterTv.context)
val layout = inflater.inflate(R.layout.layout_filter_size, null)
@ -159,7 +163,7 @@ class FilterView @JvmOverloads constructor(context: Context, attrs: AttributeSet
}
popupWindow.setOnDismissListener {
subFilterTv.setDrawableEnd(R.drawable.ic_filter_arrow_down)
subFilterTv.setCompoundDrawables(null, null, drawableDown, null)
}
popupWindow.isTouchable = true

View File

@ -36,7 +36,6 @@ import com.gh.common.util.PackageUtils;
import com.gh.gamecenter.core.utils.PageSwitchDataHelper;
import com.gh.gamecenter.core.utils.SPUtils;
import com.gh.gamecenter.BuildConfig;
import com.gh.gamecenter.core.utils.SentryHelper;
import com.gh.gamecenter.download.DownloadedGameIdAndPackageNameDao;
import com.gh.gamecenter.entity.ApkEntity;
import com.gh.gamecenter.entity.GameEntity;
@ -390,16 +389,12 @@ public class DownloadManager implements DownloadStatusListener {
* 清理不存在本地 APK 文件的任务
*/
public void clearTasksThatFileBeenDeleted() {
try {
for (DownloadEntity entity : getAllDownloadEntity()) {
if (entity.getStatus() == DownloadStatus.done) {
if (FileUtils.isEmptyFile(entity.getPath())) {
cancel(entity.getUrl());
}
for (DownloadEntity entity : getAllDownloadEntity()) {
if (entity.getStatus() == DownloadStatus.done) {
if (FileUtils.isEmptyFile(entity.getPath())) {
cancel(entity.getUrl());
}
}
} catch (Exception e) {
SentryHelper.INSTANCE.onEvent("CLEAR_DELETED_TASK_ERROR", "exception_digest", e.getLocalizedMessage());
}
}
@ -693,14 +688,6 @@ public class DownloadManager implements DownloadStatusListener {
return filterSilentDownloadTask(all);
}
/**
* 获取下载列表中除下载状态为完成以外的任务
*/
public List<DownloadEntity> getAllDownloadEntityExcludeDoneTask() {
List<DownloadEntity> all = getAllDownloadEntity();
return filterDoneDownloadTask(all);
}
/**
* 获取下载列表中的畅玩下载任务快照
*/
@ -741,20 +728,6 @@ public class DownloadManager implements DownloadStatusListener {
return filteredDownloadEntityList;
}
private ArrayList<DownloadEntity> filterDoneDownloadTask(List<DownloadEntity> downloadEntityList) {
ArrayList<DownloadEntity> filteredDownloadEntityList = new ArrayList<>();
if (downloadEntityList == null) return filteredDownloadEntityList;
for (DownloadEntity downloadEntity : downloadEntityList) {
if (downloadEntity.getStatus() != DownloadStatus.done) {
filteredDownloadEntityList.add(downloadEntity);
}
}
return filteredDownloadEntityList;
}
public ArrayMap<String, DownloadEntity> getEntryMap(String name) {
return gameMap.get(name);
}
@ -895,7 +868,7 @@ public class DownloadManager implements DownloadStatusListener {
Utils.log(DownloadManager.class.getSimpleName(), "addObserver");
DataChanger.INSTANCE.addObserver(dataWatcher);
notifyDownloadStatusASAP(dataWatcher);
notifyDownloadedStatusASAP(dataWatcher);
}
/**
@ -907,11 +880,13 @@ public class DownloadManager implements DownloadStatusListener {
}
/**
* 立马通知 dataWatcher 更新下载任务状态
* 立马通知 dataWatcher 更新下载完的任务状态,这里的下载完成是持久状态,不是瞬时状态
*/
private void notifyDownloadStatusASAP(DataWatcher dataWatcher) {
private void notifyDownloadedStatusASAP(DataWatcher dataWatcher) {
for (DownloadEntity downloadEntity : getAllDownloadEntitySnapshots()) {
dataWatcher.onDataInit(downloadEntity);
if (downloadEntity.getStatus() == DownloadStatus.done) {
dataWatcher.onDataInit(downloadEntity);
}
}
}
@ -976,7 +951,7 @@ public class DownloadManager implements DownloadStatusListener {
public void checkAndRetryDownload() {
if (!NetworkUtils.isWifiConnected(mContext)) return;
for (DownloadEntity downloadEntity : DownloadManager.getInstance().getAllDownloadEntityExcludeDoneTask()) {
for (DownloadEntity downloadEntity : DownloadManager.getInstance().getAllDownloadEntityExcludeSilentTask()) {
if (DownloadStatus.neterror.equals(downloadEntity.getStatus())
|| DownloadStatus.timeout.equals(downloadEntity.getStatus())
|| DownloadStatus.subscribe.equals(downloadEntity.getStatus())) {

View File

@ -22,7 +22,7 @@ import com.gh.gamecenter.login.user.UserManager
import com.gh.gamecenter.packagehelper.PackageRepository
import com.gh.gamecenter.packagehelper.PackageViewModel
import com.gh.gamecenter.retrofit.RetrofitManager
import com.gh.gamecenter.setting.view.GameDownloadSettingFragment
import com.gh.gamecenter.setting.compose.activity.ComposeGameDownloadSettingActivity
import com.halo.assistant.HaloApp
import com.lightgame.download.DownloadEntity
import com.lightgame.download.FileUtils
@ -91,7 +91,7 @@ object PackageObserver {
gameId = approximateGameId
}
if (EBPackage.TYPE_INSTALLED == busFour.type) {
if ("安装" == busFour.type) {
mPackageViewModel.addInstalledGame(packageName)
BrowserInstallHelper.onApkInstalled(mDownloadEntity?.path)
@ -109,7 +109,11 @@ object PackageObserver {
DownloadManager.getInstance().cancel(mDownloadEntity.url, false, true, false)
if (SPUtils.getBoolean(GameDownloadSettingFragment.CONCERN_GAME_SP_KEY, true)) { //设置页面控制是否安装后自动关注
if (SPUtils.getBoolean(
ComposeGameDownloadSettingActivity.CONCERN_GAME_SP_KEY,
true
)
) { //设置页面控制是否安装后自动关注
// 安装后关注游戏
val finalDownloadEntity = mDownloadEntity
RetrofitManager.getInstance().api

View File

@ -14,19 +14,17 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.*
import androidx.recyclerview.widget.RecyclerView.SmoothScroller
import com.gh.gamecenter.core.utils.TimeElapsedHelper
import com.gh.gamecenter.common.base.fragment.BaseDraggableDialogFragment
import com.gh.common.exposure.ExposureEvent
import com.gh.common.util.*
import com.gh.download.DownloadManager
import com.gh.gamecenter.BuildConfig
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.activity.ToolBarActivity
import com.gh.gamecenter.common.base.fragment.BaseDraggableDialogFragment
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.utils.goneIf
import com.gh.gamecenter.common.utils.observeNonNull
import com.gh.gamecenter.common.utils.throwExceptionInDebug
import com.gh.gamecenter.core.AppExecutor
import com.gh.gamecenter.core.utils.TimeElapsedHelper
import com.gh.gamecenter.databinding.DialogDownloadBinding
import com.gh.gamecenter.entity.ApkEntity
import com.gh.gamecenter.entity.GameEntity
@ -50,9 +48,6 @@ class DownloadDialog : BaseDraggableDialogFragment() {
private var mAdapter: DownloadDialogAdapter? = null
private var mTraceEvent: ExposureEvent? = null
private var mPlatformName: String = ""
private var mPackageName: String = ""
private var mParentBundle: Bundle? = null
// 合集页面保持和后台一样的顺序
private var mCollectionAdapter: DownloadDialogAdapter? = null
@ -96,9 +91,6 @@ class DownloadDialog : BaseDraggableDialogFragment() {
EventBus.getDefault().register(this)
super.onCreate(savedInstanceState)
mParentBundle = requireActivity().intent.extras?.getBundle(ToolBarActivity.NORMAL_FRAGMENT_BUNDLE)
mPlatformName = mParentBundle?.getString(EntranceConsts.KEY_PLATFORM, "") ?: ""
mPackageName = mParentBundle?.getString(EntranceConsts.KEY_PACKAGENAME, "") ?: ""
mGameEntity = requireArguments().getParcelable(GameEntity::class.java.simpleName)!!
mEntrance = requireArguments().getString(EntranceConsts.KEY_ENTRANCE) ?: ""
mLocation = requireArguments().getString(EntranceConsts.KEY_LOCATION) ?: ""
@ -114,7 +106,6 @@ class DownloadDialog : BaseDraggableDialogFragment() {
DownloadDialogAdapter(requireContext(), mViewModel, itemList, false, mTraceEvent, mEntrance, mLocation)
mBinding.contentList.layoutManager = createLayoutManager(itemList)
mBinding.contentList.adapter = mAdapter
performAutoDownload(itemList, mBinding.contentList)
})
mViewModel.collectionLiveData.observe(this, Observer { collection ->
@ -154,7 +145,7 @@ class DownloadDialog : BaseDraggableDialogFragment() {
)
mBinding.collectionList.layoutManager = createLayoutManager(itemList)
mBinding.collectionList.adapter = mCollectionAdapter
performAutoDownload(itemList, mBinding.collectionList)
if (mAdapter != null) collectionEnterAnimation()
} else {
mBinding.title.text = ("选择下载" + mGameEntity?.pluginDesc + "版本")
@ -170,41 +161,6 @@ class DownloadDialog : BaseDraggableDialogFragment() {
mElapsedHelper = TimeElapsedHelper()
}
//自动下载
private fun performAutoDownload(itemList: List<DownloadDialogItemData>, recyclerView: RecyclerView) {
if (mPlatformName.isEmpty() && mPackageName.isEmpty()) return
AppExecutor.uiExecutor.executeWithDelay({
recyclerView.adapter?.let {
for (i in 0 until it.itemCount) {
val apkEntity = itemList[i].normal ?: continue
val apkCollection = apkEntity.apkCollection
if (apkCollection != null) {
if (apkCollection.name == mPlatformName) {
scrollAndDownload(recyclerView, false, i)
break
}
}
if (apkEntity.getPlatformName() == mPlatformName || apkEntity.packageName == mPackageName) {
scrollAndDownload(recyclerView, true, i)
break
}
}
}
}, 200)
}
private fun scrollAndDownload(recyclerView: RecyclerView, isResetBundle: Boolean, position: Int) {
recyclerView.scrollToPosition(position)
AppExecutor.uiExecutor.executeWithDelay({
val viewHolder = recyclerView.findViewHolderForAdapterPosition(position)
viewHolder?.itemView?.performClick()
if (isResetBundle) {
mParentBundle?.putString(EntranceConsts.KEY_PLATFORM, "")
mParentBundle?.putString(EntranceConsts.KEY_PACKAGENAME, "")
}
}, 200)
}
@SuppressLint("ClickableViewAccessibility")
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
mBinding = DialogDownloadBinding.bind(layoutInflater.inflate(R.layout.dialog_download, container, false))

View File

@ -83,7 +83,7 @@ class DownloadDialogItemViewHolder(val binding: DownloadDialogItemBinding) : Bas
binding.containerView.setBackgroundResource(R.drawable.download_dialog_item_background)
binding.status.removeDrawable()
binding.status.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null)
changeRecommendUI(apkEntity, listData, position)
if (apkLink != null) {
@ -95,7 +95,12 @@ class DownloadDialogItemViewHolder(val binding: DownloadDialogItemBinding) : Bas
binding.remark.goneIf(apkLink.remark.isEmpty())
binding.status.text = "点击查看"
binding.status.setDrawableEnd(R.drawable.download_dialog_collection_status_link)
binding.status.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
ContextCompat.getDrawable(binding.status.context, R.drawable.download_dialog_collection_status_link),
null
)
binding.containerView.setBackgroundResource(R.drawable.download_dialog_installed_background)
itemView.setTag(DownloadDialogAdapter.ITEM_TAG_KEY, DownloadDialogItemStatus.LINK)
} else if (apkCollection != null || (!isCollectionPage && apkEntity.downloadInstruction.isNotEmpty())) {
@ -144,7 +149,15 @@ class DownloadDialogItemViewHolder(val binding: DownloadDialogItemBinding) : Bas
binding.status.visibility = View.VISIBLE
binding.status.text = "可更新"
binding.status.setDrawableEnd(R.drawable.download_dialog_collection_status_update)
binding.status.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
ContextCompat.getDrawable(
binding.status.context,
R.drawable.download_dialog_collection_status_update
),
null
)
binding.downloadStatusIcon.visibility = View.GONE
itemView.setTag(DownloadDialogAdapter.ITEM_TAG_KEY, DownloadDialogItemStatus.UPDATE)
} else if (PackageUtils.getGhId(apkEntity.packageName) == gameEntity.id ||
@ -171,7 +184,15 @@ class DownloadDialogItemViewHolder(val binding: DownloadDialogItemBinding) : Bas
// 点击启动
binding.status.text = "点击启动"
itemView.setTag(DownloadDialogAdapter.ITEM_TAG_KEY, DownloadDialogItemStatus.LAUNCH)
binding.status.setDrawableEnd(R.drawable.download_dialog_collection_status_launch)
binding.status.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
ContextCompat.getDrawable(
binding.status.context,
R.drawable.download_dialog_collection_status_launch
),
null
)
}
} else {
binding.downloadStatusIcon.visibility = View.VISIBLE

View File

@ -1,25 +0,0 @@
package com.gh.download.simple
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
class AutoUnregisteredSimpleDownloadListener(var id: String, fragment: Fragment, var listener: DownloadListener) {
init {
fragment.parentFragmentManager.registerFragmentLifecycleCallbacks(
object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentViewDestroyed(fm: FragmentManager, f: Fragment) {
super.onFragmentViewDestroyed(fm, f)
if (f === fragment) {
DownloadMessageHandler.unregisterListener(id, listener)
fragment.parentFragmentManager.unregisterFragmentLifecycleCallbacks(this)
}
}
}, false
)
DownloadMessageHandler.registerListener(id, listener)
}
fun unregisteredListener() {
DownloadMessageHandler.unregisterListener(id, listener)
}
}

View File

@ -1,105 +0,0 @@
package com.gh.download.simple
import com.lg.download.DownloadError
import com.lg.download.DownloadStatus
import com.gh.gamecenter.R
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.common.utils.roundTo
import com.gh.gamecenter.common.utils.setDebouncedClickListener
import com.gh.gamecenter.core.utils.ToastUtils
import com.lightgame.utils.Utils
open class DownloadButtonHelper(
private val mDownloadId: String,
private val mProgressView: SimpleProgressView,
) : DownloadListener {
private var mProgressText = ""
init {
mProgressView.setTag(R.string.app_name, mDownloadId)
mProgressView.setTextSize(12F.dip2px().toFloat())
}
override fun onError(error: DownloadError) {
Utils.log(error)
}
override fun onProgress(progress: Float) {
if (mProgressView.getTag(R.string.app_name) == mDownloadId) {
val realTimeDownloadEntity = DownloadMessageHandler.findEntity(mDownloadId)
mProgressText = "${progress.roundTo(1)}%"
mProgressView.progress = (progress).toInt()
if (realTimeDownloadEntity?.status == DownloadStatus.DOWNLOADING) {
mProgressView.text = mProgressText
}
}
}
override fun onSizeReceived(fileSize: Long) {
//nothing for sonar
}
override fun onStatusChanged(status: DownloadStatus) {
if (mProgressView.getTag(R.string.app_name) == mDownloadId) {
when (status) {
DownloadStatus.PAUSED -> {
mProgressView.text = "继续"
mProgressView.setDebouncedClickListener {
SimpleDownloadManager.resume(mDownloadId)
}
updateProgressViewStyle(mProgressView)
}
DownloadStatus.QUEUED,
DownloadStatus.WAITINGWIFI -> {
mProgressView.text = "等待"
mProgressView.setOnClickListener {
}
updateProgressViewStyle(mProgressView, isWaiting = true)
}
DownloadStatus.DOWNLOADING -> {
mProgressView.setOnClickListener {
SimpleDownloadManager.pause(mDownloadId)
onStatusChanged(status = DownloadStatus.PAUSED)
}
updateProgressViewStyle(mProgressView)
}
DownloadStatus.COMPLETED -> {
mProgressView.text = "安装"
mProgressView.progress = 100
mProgressView.setOnClickListener {
ToastUtils.toast("安装")
}
updateProgressViewStyle(mProgressView)
}
else -> {
mProgressView.text = "下载"
// do nothing
}
}
}
}
override fun onSpeedChanged(speed: Float) {}
private fun updateProgressViewStyle(
progressView: SimpleProgressView,
isEmpty: Boolean = false,
isWaiting: Boolean = false
) {
when {
isEmpty -> {
// do nothing
}
isWaiting -> {
// do nothing
}
else -> {
// do nothing
}
}
}
}

View File

@ -1,37 +0,0 @@
package com.gh.download.simple
import androidx.lifecycle.LiveData
import androidx.room.*
import io.reactivex.Single
@Dao
interface DownloadDao {
@Query("select * from SimpleDownloadEntity where id = :id")
fun getDownloadEntityById(id: String): SimpleDownloadEntity?
@Query("select * from SimpleDownloadEntity")
fun getAllDownloadEntity(): List<SimpleDownloadEntity>
@Query("select * from SimpleDownloadEntity where status == 1")
fun getAllDownloadingEntity(): List<SimpleDownloadEntity>
@Query("select * from SimpleDownloadEntity where status == 3")
fun getAllDownloadedEntity(): List<SimpleDownloadEntity>
@Query("select * from SimpleDownloadEntity")
fun getAllDownloadEntityLiveData(): LiveData<List<SimpleDownloadEntity>>
@Query("select * from SimpleDownloadEntity")
fun getAllDownloadEntitySingle(): Single<List<SimpleDownloadEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertDownloadEntity(entity: SimpleDownloadEntity)
@Update(onConflict = OnConflictStrategy.REPLACE)
fun updateDownloadEntity(entity: SimpleDownloadEntity)
@Delete
fun deleteDownloadEntity(entity: SimpleDownloadEntity)
}

View File

@ -1,16 +0,0 @@
package com.gh.download.simple
import com.lg.download.DownloadError
import com.lg.download.DownloadStatus
interface DownloadListener {
fun onError(error: DownloadError)
fun onProgress(progress: Float)
fun onSizeReceived(fileSize: Long)
fun onStatusChanged(status: DownloadStatus)
fun onSpeedChanged(speed: Float)
}

View File

@ -1,297 +0,0 @@
package com.gh.download.simple
import android.annotation.SuppressLint
import com.gh.gamecenter.core.utils.ToastUtils
import com.lg.download.*
import com.lg.download.listener.InnerDownloadListener
import com.lg.ndownload.DownloadConfig
import java.net.URLConnection
import java.util.concurrent.ConcurrentHashMap
import kotlin.collections.ArrayList
/**
* 下载信息管理类
*/
object DownloadMessageHandler : InnerDownloadListener {
// 单页可订阅的监听数最少从 3 开始, 如果值为 5 的话有可能出现状态无法更新的情况 (fragment onDestroy 回调慢)
private const val MAX_LISTENER_SIZE = 5
private lateinit var mDownloadDao: DownloadDao
private val mGlobalStatusChangedListenerList by lazy {
arrayListOf<((SimpleDownloadEntity, DownloadStatus) -> Unit)>()
}
/**
* map key: 下载 id
*
* map value:
* pair first-> 下载实体
* pair second-> 对应页面的下载回调
*/
private var mListenerMap: ConcurrentHashMap<String, FixedSizeStack<DownloadListener>> = ConcurrentHashMap()
var downloadList = arrayListOf<SimpleDownloadEntity>()
@SuppressLint("CheckResult")
fun init(downloadDao: DownloadDao) {
mDownloadDao = downloadDao
updateDownloadList()
}
/**
* 注册全局回调(为避免影响下载性能,目前仅对接了状态变更回调)
*/
fun registerGlobalStatusChangedListener(listener: ((SimpleDownloadEntity, DownloadStatus) -> Unit)) {
mGlobalStatusChangedListenerList.add(listener)
}
/**
* 状态回调
* @param id 下载 id
* @param status 下载状态
*/
override fun onStatusChanged(id: String, status: DownloadStatus) {
val entity = findEntity(id)
if (entity != null) {
entity.status = status
if (status == DownloadStatus.COMPLETED) {
SimpleDownloadManager.resumeQueuedTask()
}
ExecutorProvider.getInstance().backgroundExecutor.execute {
updateDownloadToDatabase(entity)
updateDownloadList()
}
}
for (listener in mGlobalStatusChangedListenerList) {
listener.invoke(entity!!, status)
}
val listenerList = mListenerMap[id] ?: return
ExecutorProvider.getInstance().mainThreadExecutor.execute {
safeIteratorList(listenerList) {
it.onStatusChanged(status)
}
}
}
/**
* 重定向中的回调
* @param id 下载 id
* @param connection 未重定向前的原始连接
* @param config 下载配置
*/
override fun onRedirectingUrl(id: String?, connection: URLConnection?, config: DownloadConfig?) {
}
/**
* 重定向完成后的回调
* @param id 下载 id
* @param connection 重定向完成后的连接
* @param redirectedUrl 重定向完成的最终地址
*/
override fun onRedirectedUrl(id: String, connection: URLConnection, redirectedUrl: String) {
val entity = findEntity(id) ?: return
entity.url = redirectedUrl
// 更新数据库数据
updateDownloadToDatabase(entity, updateDownloadList = true)
}
/**
* 进度回调,带频率控制,适合用来更新 UI
* @param id 下载 id
* @param progress 进度 0~1
*/
override fun onProgress(id: String, progress: Float) {
val entity = findEntity(id) ?: return
entity.progress = progress * 100
updateDownloadToDatabase(entity)
val listenerList = mListenerMap[id] ?: return
ExecutorProvider.getInstance().mainThreadExecutor.execute {
safeIteratorList(listenerList) {
it.onProgress(progress * 100)
}
}
updateDownloadList()
}
/**
* 没有频率控制的进度回调,适合做一些轻度的操作
* @param id 下载 id
* @param progress 进度 0~1
*/
override fun onProgressWithoutThrottle(id: String?, progress: Float) {
}
/**
* 速度回调,带频率控制,适合用来更新 UI
* @param id 下载 id
* @param speed 下载速度,单位为字节
*/
override fun onSpeedChanged(id: String, speed: Float) {
val listenerList = mListenerMap[id] ?: return
ExecutorProvider.getInstance().mainThreadExecutor.execute {
safeIteratorList(listenerList) {
it.onSpeedChanged(speed)
}
}
findEntity(id)?.run {
this.speed = speed
}
}
/**
* 错误回调
* @param id 下载 id
* @param error 错误类型
* @param exception 包裹错误的 Exception
*/
override fun onError(id: String, error: DownloadError?, exception: Exception) {
error ?: return
when (error) {
DownloadError.EMPTY_URL,
DownloadError.HTTP_NOT_FOUND,
DownloadError.CONTENT_LENGTH_IS_ZERO -> {
ToastUtils.toast("下载链接异常,请检查")
}
else -> {
// 想怎么处理就怎么处理
}
}
val listenerList = mListenerMap[id] ?: return
ExecutorProvider.getInstance().mainThreadExecutor.execute {
safeIteratorList(listenerList) {
it.onError(error)
}
}
}
/**
* 文件大小获取成功回调
* @param id 下载 id
* @param fileSize 文件大小,单位为字节
*/
override fun onSizeReceived(id: String, fileSize: Long) {
val entity = findEntity(id) ?: return
entity.totalBytes = fileSize
updateDownloadToDatabase(entity, updateDownloadList = true)
val listenerList = mListenerMap[id] ?: return
ExecutorProvider.getInstance().mainThreadExecutor.execute {
safeIteratorList(listenerList) {
it.onSizeReceived(fileSize)
}
}
updateDownloadList()
}
fun registerListener(id: String, listener: DownloadListener) {
var listenerList = mListenerMap[id]
if (listenerList == null) {
listenerList = FixedSizeStack(MAX_LISTENER_SIZE)
listenerList.push(listener)
mListenerMap[id] = listenerList
} else {
listenerList.push(listener)
}
// Post download status if it could be obtain from database.
val entityFromDatabase = findEntity(id)
if (entityFromDatabase != null) {
listener.onProgress(entityFromDatabase.progress)
listener.onStatusChanged(entityFromDatabase.status)
}
}
fun unregisterListener(id: String, listener: DownloadListener) {
ExecutorProvider.getInstance().mainThreadExecutor.execute {
mListenerMap[id]?.remove(listener)
}
}
/**
* 从下载列表中取 downloadEntity
* TODO 不应该直接修改 downloadEntity 内存的值,不然会有莫名其妙的问题
*/
fun findEntity(id: String): SimpleDownloadEntity? {
try {
return downloadList.firstOrNull { it.id == id }
} catch (e: Exception) {
e.printStackTrace()
}
return null
}
private fun updateDownloadList() {
downloadList = ArrayList(mDownloadDao.getAllDownloadEntity())
}
fun insertDownloadToDatabase(downloadEntity: SimpleDownloadEntity) {
mDownloadDao.insertDownloadEntity(downloadEntity)
updateDownloadList()
}
fun updateDownloadToDatabase(
downloadEntity: SimpleDownloadEntity,
updateDownloadList: Boolean = false
) {
mDownloadDao.updateDownloadEntity(downloadEntity)
if (updateDownloadList) {
updateDownloadList()
}
}
fun deleteDownloadOfDatabase(downloadEntity: SimpleDownloadEntity) {
mDownloadDao.deleteDownloadEntity(downloadEntity)
updateDownloadList()
}
/*****
* 迭代的时候针对temp Stack进行迭代
*/
private fun safeIteratorList(
sourceList: FixedSizeStack<DownloadListener>?,
function: (arg: DownloadListener) -> (Unit)
) {
sourceList?.apply {
if (this.size > 0) {
// FIXME 高频遍历时会产生巨量临时的 FixedSizeStack
val tempStack = FixedSizeStack<DownloadListener>(MAX_LISTENER_SIZE)
tempStack.addAll(sourceList)
tempStack.forEach { listener ->
listener?.apply {
function(this)
}
}
}
}
}
}

View File

@ -1,35 +0,0 @@
package com.gh.download.simple
import androidx.room.TypeConverter
import com.lg.download.DownloadStatus
class DownloadStatusConverter {
@TypeConverter
fun fromGameStatus(status: DownloadStatus): Int {
return when (status) {
DownloadStatus.UNKNOWN -> 0
DownloadStatus.DOWNLOADING -> 1
DownloadStatus.PAUSED -> 2
DownloadStatus.COMPLETED -> 3
DownloadStatus.CANCELLED -> 4
DownloadStatus.AUTOPAUSED -> 5
DownloadStatus.WAITINGWIFI -> 6
DownloadStatus.QUEUED -> 7
}
}
@TypeConverter
fun toGameStatus(status: Int): DownloadStatus {
return when (status) {
0 -> DownloadStatus.UNKNOWN
1 -> DownloadStatus.DOWNLOADING
2 -> DownloadStatus.PAUSED
3 -> DownloadStatus.COMPLETED
4 -> DownloadStatus.CANCELLED
5 -> DownloadStatus.AUTOPAUSED
6 -> DownloadStatus.WAITINGWIFI
7 -> DownloadStatus.QUEUED
else -> DownloadStatus.UNKNOWN
}
}
}

View File

@ -1,19 +0,0 @@
package com.gh.download.simple
import java.util.*
/**
* A stack that holds fixed size listeners.
*
* You may wonder why using a stack.
* I just can't find a proper way to handle these listeners.
* If you do have a simple and easy way to achieve the same goal, let me know, please. :)
*/
class FixedSizeStack<T>(private var maxSize: Int) : Stack<T>() {
override fun push(item: T): T {
while (this.size >= maxSize) {
this.removeAt(0)
}
return super.push(item)
}
}

View File

@ -1,30 +0,0 @@
package com.gh.download.simple
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.halo.assistant.HaloApp
@Database(
entities = [SimpleDownloadEntity::class],
version = 1,
exportSchema = false
)
@TypeConverters(DownloadStatusConverter::class)
abstract class SimpleDownloadDatabase : RoomDatabase() {
abstract fun downloadDao(): DownloadDao
companion object {
@JvmStatic
val instance by lazy {
Room.databaseBuilder(
HaloApp.getInstance().application,
SimpleDownloadDatabase::class.java,
"SIMPLE_DOWNLOAD_DATABASE"
).build()
}
}
}

View File

@ -1,29 +0,0 @@
package com.gh.download.simple
import android.os.Parcelable
import androidx.annotation.Keep
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.lg.download.DownloadStatus
import kotlinx.parcelize.Parcelize
@Keep
@Entity(tableName = "SimpleDownloadEntity")
@Parcelize
data class SimpleDownloadEntity(
@PrimaryKey(autoGenerate = false)
var id: String,
var desc: String = "",
var url: String = "",
var dirPath: String = "",
var fileName: String = "",
var displayName: String = "",
var packageName: String = "",
var downloadedBytes: Long = 0,
var totalBytes: Long = 0,
var progress: Float = 0F,
var status: DownloadStatus = DownloadStatus.UNKNOWN,
var speed: Float = 0F,
var version: String = "",
var icon: String = "",
) : Parcelable

View File

@ -1,95 +0,0 @@
package com.gh.download.simple
import com.halo.assistant.HaloApp
import com.lg.download.*
import com.lg.ndownload.DownloadConfig
import com.lg.ndownload.DownloadDbManager
import com.lg.ndownload.DownloadQueue
import com.lightgame.download.FileUtils
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
object SimpleDownloadManager {
private const val MAX_DOWNLOADING_TASK = 2
private val mDownloadQueue by lazy { DownloadQueue.getInstance() }
private val mExecutor by lazy { Executors.newCachedThreadPool() }
fun init() {
ExecutorProvider.getInstance().backgroundExecutor.execute {
DownloadDbManager.init(HaloApp.getInstance())
}
// 设置最大同时下载任务数 (可选)
DownloadQueue.getInstance().setMaxDownloadingTask(MAX_DOWNLOADING_TASK)
}
/**
* 继续任务
*/
fun resume(id: String) {
mDownloadQueue.resume(id)
}
/**
* 下载任务
*/
fun download(config: DownloadConfig) {
val downloadStatus = mDownloadQueue.getStatus(config.uniqueId)
if (downloadStatus != DownloadStatus.PAUSED) {
ExecutorProvider.getInstance().backgroundExecutor.execute {
DownloadMessageHandler.insertDownloadToDatabase(getDownloadEntity(config))
mDownloadQueue.submitNewTask(config)
}
} else {
resume(config.uniqueId)
}
}
private fun getDownloadEntity(config: DownloadConfig): SimpleDownloadEntity {
return SimpleDownloadEntity(
id = config.uniqueId,
url = config.url,
fileName = config.fileName,
dirPath = config.pathToStore,
displayName = config.fileName,
icon = "",
)
}
/**
* 暂停任务
*/
fun pause(id: String) {
mDownloadQueue.pause(id)
}
/**
* 继续排队中的任务
*/
fun resumeQueuedTask() {
mDownloadQueue.resumeQueuedTask()
}
/**
* 取消任务
*/
fun cancel(id: String) {
ExecutorProvider.getInstance().backgroundExecutor.execute {
mDownloadQueue.pause(id)
mDownloadQueue.cancel(id)
DownloadMessageHandler.findEntity(id)?.let {
FileUtils.deleteFile(it.dirPath + it.fileName)
DownloadMessageHandler.deleteDownloadOfDatabase(it)
}
// 清除下载数据库那边的 id
DownloadDbManager.getInstance().delete(id)
}
}
fun getExecutor(): ExecutorService = mExecutor
}

View File

@ -1,81 +0,0 @@
package com.gh.download.simple
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.widget.ProgressBar
import androidx.annotation.Keep
import com.gh.gamecenter.core.utils.DisplayUtils
@Keep
class SimpleProgressView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
ProgressBar(context, attrs, defStyle) {
private var mWidth = 0
private var mHalfWidth = 0
private val mMatrix: Matrix
private var mHalfTextWidth = 0F
private val mTextPaint: Paint
private var mTextSize = 0F
private var mTextColor = Color.WHITE
private var mText: String? = "打开"
init {
max = MAX_LENGTH
mTextSize = DisplayUtils.sp2px(context, 12F).toFloat()
mMatrix = Matrix()
mTextPaint = Paint()
mTextPaint.isAntiAlias = true
mTextPaint.color = mTextColor
mTextPaint.style = Paint.Style.FILL_AND_STROKE
mTextPaint.typeface = Typeface.DEFAULT_BOLD
mTextPaint.textSize = mTextSize
mTextPaint.textAlign = Paint.Align.CENTER
}
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
mWidth = width
mHalfWidth = mWidth / 2
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
if (mText != null) {
setProgressByPixels(mWidth * progress / MAX_LENGTH)
val fontMetrics = mTextPaint.fontMetricsInt
val baseline = (height - fontMetrics.bottom - fontMetrics.top) / 2
canvas.drawText(mText!!, mHalfWidth.toFloat(), baseline.toFloat(), mTextPaint)
}
}
var text: String?
get() = mText
set(text) {
mText = text
postInvalidate()
}
fun setTextColor(color: Int) {
mTextColor = color
mTextPaint.color = color
}
fun setTextSize(size: Float) {
mTextSize = size
mTextPaint.textSize = size
}
private fun setProgressByPixels(pixels: Int) {
if (pixels >= mHalfWidth - mHalfTextWidth) {
mMatrix.setTranslate(pixels - (mHalfWidth - mHalfTextWidth), 0F)
} else {
mMatrix.setTranslate(0F, 0F)
}
}
companion object {
const val MAX_LENGTH = 100
}
}

View File

@ -6,14 +6,15 @@ import android.content.Intent
import android.os.Bundle
import android.view.View
import com.gh.base.DownloadToolbarActivity
import com.gh.gamecenter.common.constant.Constants
import com.gh.common.exposure.ExposureEvent
import com.gh.common.exposure.ExposureEvent.Companion.createEvent
import com.gh.common.exposure.ExposureManager.log
import com.gh.common.exposure.ExposureTraceUtils.appendTrace
import com.gh.common.exposure.ExposureType
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.base.activity.BaseActivity
import com.gh.gamecenter.core.utils.DisplayUtils
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.entity.GameEntity
import com.gh.gamecenter.gamedetail.GameDetailFragment
import com.halo.assistant.HaloApp
@ -165,33 +166,6 @@ class GameDetailActivity : DownloadToolbarActivity() {
startGameDetailActivity(context, gameId, entrance, -1, traceEvent = traceEvent)
}
@JvmStatic
fun startGameDetailActivity(
context: Context,
gameId: String,
entrance: String?,
defaultTab: Int = -1,
isSkipGameComment: Boolean = false,
scrollToLibao: Boolean = false,
openVideoStreaming: Boolean = false,
openPlatformWindow: Boolean = false,
traceEvent: ExposureEvent? = null
) {
startGameDetailActivity(
context,
gameId,
entrance,
defaultTab,
isSkipGameComment,
scrollToLibao,
openVideoStreaming,
openPlatformWindow,
null,
null,
traceEvent
)
}
/**
* @param gameId 游戏Id
* @param defaultTab 默认定位到哪个tab
@ -199,8 +173,6 @@ class GameDetailActivity : DownloadToolbarActivity() {
* @param scrollToLibao 滚动到礼包区域
* @param openVideoStreaming 是否打开视频流
* @param openPlatformWindow 打开多版本下载弹窗
* @param platformName 平台名称
* @param packageName 包名
* @param traceEvent 曝光事件
*/
@JvmStatic
@ -213,8 +185,6 @@ class GameDetailActivity : DownloadToolbarActivity() {
scrollToLibao: Boolean = false,
openVideoStreaming: Boolean = false,
openPlatformWindow: Boolean = false,
platformName: String? = null,
packageName: String? = null,
traceEvent: ExposureEvent? = null
) {
val bundle = Bundle()
@ -254,12 +224,6 @@ class GameDetailActivity : DownloadToolbarActivity() {
}
if (openPlatformWindow) {
bundle.putBoolean(EntranceConsts.KEY_OPEN_PLATFORM_WINDOW, true)
if (!platformName.isNullOrEmpty()) {
bundle.putString(EntranceConsts.KEY_PLATFORM, platformName)
}
if (!packageName.isNullOrEmpty()) {
bundle.putString(EntranceConsts.KEY_PACKAGENAME, packageName)
}
}
if (scrollToLibao) {
bundle.putInt(EntranceConsts.KEY_TARGET, GameDetailFragment.INDEX_TRENDES)

View File

@ -1,7 +1,7 @@
package com.gh.gamecenter;
import static com.gh.gamecenter.common.constant.Constants.LOGIN_TAG;
import static com.gh.gamecenter.common.constant.Constants.LOGOUT_TAG;
import static com.gh.gamecenter.login.utils.LoginHelper.WEIBO_SCOPE;
import static com.gh.gamecenter.common.constant.EntranceConsts.ENTRANCE_BROWSER;
import static com.gh.gamecenter.common.constant.EntranceConsts.HOST_LAUNCH_SIMULATOR_GAME;
import static com.gh.gamecenter.common.constant.EntranceConsts.HOST_QQ;
@ -14,7 +14,7 @@ import static com.gh.gamecenter.common.constant.EntranceConsts.KEY_TO;
import static com.gh.gamecenter.common.constant.EntranceConsts.KEY_TYPE;
import static com.gh.gamecenter.common.utils.ExtensionsKt.observableToMain;
import static com.gh.gamecenter.fragment.MainWrapperFragment.INDEX_PERSONAL;
import static com.gh.gamecenter.login.utils.LoginHelper.WEIBO_SCOPE;
import static com.gh.gamecenter.common.constant.Constants.LOGIN_TAG;
import android.annotation.SuppressLint;
import android.app.Activity;
@ -26,7 +26,6 @@ import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.text.Html;
@ -40,15 +39,9 @@ import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import com.facebook.drawee.view.SimpleDraweeView;
import com.gh.common.DefaultUrlHandler;
import com.gh.common.constant.Config;
import com.gh.common.exposure.ExposureEvent;
import com.gh.common.exposure.ExposureManager;
import com.gh.common.exposure.ExposureSource;
import com.gh.common.exposure.ExposureType;
import com.gh.common.history.HistoryDatabase;
import com.gh.common.history.HistoryHelper;
import com.gh.common.repository.ReservationRepository;
@ -65,7 +58,8 @@ import com.gh.common.util.ErrorHelper;
import com.gh.common.util.HomePluggableHelper;
import com.gh.common.util.LogUtils;
import com.gh.common.util.LunchType;
import com.gh.common.util.NewFlatLogUtils;
import com.gh.gamecenter.common.eventbus.EBReuse;
import com.gh.gamecenter.common.utils.NotificationHelper;
import com.gh.common.util.PackageInstaller;
import com.gh.common.util.PackageUtils;
import com.gh.common.util.PlatformUtils;
@ -78,17 +72,12 @@ import com.gh.gamecenter.common.base.fragment.BaseFragment_ViewPager;
import com.gh.gamecenter.common.base.fragment.ToolbarFragment;
import com.gh.gamecenter.common.constant.Constants;
import com.gh.gamecenter.common.constant.EntranceConsts;
import com.gh.gamecenter.common.entity.LinkEntity;
import com.gh.gamecenter.common.entity.NotificationUgc;
import com.gh.gamecenter.common.eventbus.EBReuse;
import com.gh.gamecenter.common.exposure.meta.MetaUtil;
import com.gh.gamecenter.common.retrofit.BiResponse;
import com.gh.gamecenter.common.retrofit.Response;
import com.gh.gamecenter.common.utils.DeviceUtils;
import com.gh.gamecenter.common.utils.DialogHelper;
import com.gh.gamecenter.common.utils.ExtensionsKt;
import com.gh.gamecenter.common.utils.ImageUtils;
import com.gh.gamecenter.common.utils.NotificationHelper;
import com.gh.gamecenter.common.utils.ShareUtils;
import com.gh.gamecenter.core.AppExecutor;
import com.gh.gamecenter.core.utils.ClassUtils;
@ -97,21 +86,21 @@ import com.gh.gamecenter.core.utils.GsonUtils;
import com.gh.gamecenter.core.utils.MtaHelper;
import com.gh.gamecenter.core.utils.SPUtils;
import com.gh.gamecenter.core.utils.SentryHelper;
import com.gh.gamecenter.core.utils.TimeUtils;
import com.gh.gamecenter.core.utils.ToastUtils;
import com.gh.gamecenter.core.utils.UrlFilterUtils;
import com.gh.gamecenter.download.DownloadFragment;
import com.gh.gamecenter.entity.GameEntity;
import com.gh.gamecenter.entity.InnerMetaInfoEntity;
import com.gh.gamecenter.common.entity.NotificationUgc;
import com.gh.gamecenter.entity.StartupAdEntity;
import com.gh.gamecenter.eventbus.EBNetworkState;
import com.gh.gamecenter.eventbus.EBSkip;
import com.gh.gamecenter.fragment.MainWrapperFragment;
import com.gh.gamecenter.home.skip.PackageSkipActivity;
import com.gh.gamecenter.login.user.UserManager;
import com.gh.gamecenter.login.utils.QuickLoginHelper;
import com.gh.gamecenter.manager.DataCollectionManager;
import com.gh.gamecenter.manager.UpdateManager;
import com.gh.gamecenter.login.user.UserManager;
import com.gh.gamecenter.packagehelper.PackageViewModel;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.gh.gamecenter.room.AppDatabase;
@ -147,7 +136,6 @@ import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
@ -171,9 +159,6 @@ public class MainActivity extends BaseActivity {
public final static String SWITCH_TO_COMMUNITY = "switch_to_community";
public final static String SWITCH_TO_VIDEO = "switch_to_video";
public final static String SHOW_AD = "show_ad";
private final static int COUNTDOWN_AD = 100;
private final static int countdownMaxCount = 3;
private int countdownCount = 0;
private final static String CURRENT_PAGE = "current_page";
@ -195,7 +180,6 @@ public class MainActivity extends BaseActivity {
showAd = getIntent().getBooleanExtra(SHOW_AD, false) && savedInstanceState == null;
HaloApp.getInstance().initFresco();
HaloApp.getInstance().isAlreadyUpAndRunning = true;
super.onCreate(savedInstanceState);
setStatusBarColor(Color.TRANSPARENT);
@ -308,7 +292,7 @@ public class MainActivity extends BaseActivity {
}
if (showAd) {
observeStartUp();
observeAd();
} else {
checkDialog();
}
@ -490,95 +474,38 @@ public class MainActivity extends BaseActivity {
}
}
private void observeStartUp() {
if (!showAd) {
hideStartUp();
hideStartUpAd();
return;
}
final StartupAdEntity startUp = AdHelper.getStartUp();
if (startUp != null) {
showStartUp(startUp);
AppExecutor.getUiExecutor().executeWithDelay(() -> {
hideStartUp();
observeStartUpAd();
}, 2000);
} else {
observeStartUpAd();
}
}
private void observeStartUpAd() {
final StartupAdEntity startUpAd = AdHelper.getStartUpAd();
if (startUpAd != null && !TextUtils.isEmpty(startUpAd.getImg())) {
final String showedTodayTimestamp = SPUtils.getString(Constants.SP_STARTUP_AD_TIMESTAMP, "");
final String rule = startUpAd.getRule();
switch (rule) {
case "each":
showStartUpAd(startUpAd);
break;
case "once":
if (TextUtils.isEmpty(showedTodayTimestamp)
|| !showedTodayTimestamp.contains(startUpAd.getId())) {
showStartUpAd(startUpAd);
} else {
hideStartUpAd();
}
break;
case "everyday":
final String today = TimeUtils.getToday();
if (TextUtils.isEmpty(showedTodayTimestamp)
|| !showedTodayTimestamp.contains(today)
|| !showedTodayTimestamp.contains(startUpAd.getId())) {
showStartUpAd(startUpAd);
} else {
hideStartUpAd();
}
break;
default:
hideStartUpAd();
break;
private void observeAd() {
AdHelper.startupAd.observe(this, startupAdEntity -> {
if (showAd) {
if (startupAdEntity == null) {
hideAd(true);
} else {
showAd(startupAdEntity);
AppExecutor.getUiExecutor().execute(() -> {
AppExecutor.getUiExecutor().executeWithDelay(() -> hideAd(true), 2000);
});
}
}
SPUtils.setString(Constants.SP_STARTUP_AD_TIMESTAMP, startUpAd.getId() + TimeUtils.getToday());
} else {
hideStartUpAd();
}
});
AppExecutor.getUiExecutor().executeWithDelay(() -> hideAd(false), 950);
}
@Override
protected void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == COUNTDOWN_AD) {
countdownCount++;
TextView jumpBtn = findViewById(R.id.jumpBtn);
jumpBtn.setText(String.format(Locale.CHINA, "跳过 %d", countdownMaxCount - countdownCount));
if (countdownMaxCount < countdownCount) {
hideStartUpAd();
} else {
mBaseHandler.sendEmptyMessageDelayed(COUNTDOWN_AD, 1000);
private void hideAd(boolean forceToHide) {
if (forceToHide || AdHelper.startupAd.getValue() == null) {
showAd = false;
getIntent().putExtra(SHOW_AD, false);
View view = findViewById(R.id.maskContainer);
if (view != null) {
view.setVisibility(View.GONE);
ExtensionsKt.removeFromParent(view);
}
}
}
private void hideStartUp() {
View maskContainer = findViewById(R.id.maskContainer);
if (maskContainer != null) {
maskContainer.setVisibility(View.GONE);
ExtensionsKt.removeFromParent(maskContainer);
checkDialog();
}
}
private void hideStartUpAd() {
showAd = false;
getIntent().putExtra(SHOW_AD, false);
View startAdContainer = findViewById(R.id.startAdContainer);
if (startAdContainer != null) {
startAdContainer.setVisibility(View.GONE);
ExtensionsKt.removeFromParent(startAdContainer);
}
checkDialog();
}
private void checkDialog() {
// 检查通知权限
checkNotificationPermission();
@ -590,53 +517,9 @@ public class MainActivity extends BaseActivity {
});
}
private void showStartUpAd(StartupAdEntity ad) {
View startAdContainer = findViewById(R.id.startAdContainer);
View jumpBtn = findViewById(R.id.jumpBtn);
TextView jumpDetailBtn = findViewById(R.id.jumpDetailBtn);
SimpleDraweeView adImage = findViewById(R.id.adImage);
startAdContainer.setVisibility(View.VISIBLE);
jumpDetailBtn.setText(ad.getDesc());
ExtensionsKt.setDrawableEnd(jumpDetailBtn, VectorDrawableCompat.create(getResources(), R.drawable.ic_startup_ad_arrow, null), null, null);
ImageUtils.display(adImage, ad.getImg());
startAdContainer.setOnClickListener(v -> {
// do nothing 只是为了点击拦截事件,避免传递到下面的页面
});
jumpBtn.setOnClickListener(v -> {
mBaseHandler.removeMessages(COUNTDOWN_AD);
hideStartUpAd();
LinkEntity linkEntity = ad.getJump();
NewFlatLogUtils.logOpenScreenAdSkip(
ad.getId(),
linkEntity.getText() != null ? linkEntity.getText() : "",
linkEntity.getType() != null ? linkEntity.getType() : "",
linkEntity.getLink() != null ? linkEntity.getLink() : ""
);
});
List<ExposureSource> sources = new ArrayList<>();
sources.add(new ExposureSource("开屏广告", ad.getId()));
final ExposureEvent event = ExposureEvent.createEvent(null, sources, null, ExposureType.EXPOSURE);
ExposureManager.INSTANCE.log(event);
if (ad.getButton()) {
jumpDetailBtn.setOnClickListener(v -> {
DirectUtils.directToLinkPage(this, ad.getJump(), "(启动广告)", "", event);
v.postDelayed(() -> {
mBaseHandler.removeMessages(COUNTDOWN_AD);
hideStartUpAd();
}, 1000);
});
jumpDetailBtn.setVisibility(View.VISIBLE);
LogUtils.logStartAd("watch_start_ads", ad);
} else {
LogUtils.logStartAd("start_ads", ad);
}
mBaseHandler.sendEmptyMessageDelayed(COUNTDOWN_AD, 1000);
}
private void showStartUp(StartupAdEntity ad) {
private void showAd(StartupAdEntity ad) {
TextView adContentTv = findViewById(R.id.adContentTv);
View containerView = findViewById(R.id.maskContainer);
containerView.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
containerView.setElevation(500F);
}
@ -646,12 +529,12 @@ public class MainActivity extends BaseActivity {
adContentTv.setText(ad.getDesc());
adContentTv.setVisibility(View.VISIBLE);
if (ad.getButton()) {
View adBtn = findViewById(R.id.adBtn);
adBtn.setOnClickListener(v -> {
View btn = findViewById(R.id.adBtn);
btn.setOnClickListener((v) -> {
DirectUtils.directToLinkPage(this, ad.getJump(), "(启动广告)", "");
LogUtils.logStartAd("click_watch_start_ads", ad);
});
adBtn.setVisibility(View.VISIBLE);
btn.setVisibility(View.VISIBLE);
LogUtils.logStartAd("watch_start_ads", ad);
} else {
LogUtils.logStartAd("start_ads", ad);

View File

@ -40,6 +40,7 @@ import com.gh.download.DownloadManager;
import com.gh.gamecenter.adapter.viewholder.DetailViewHolder;
import com.gh.gamecenter.common.callback.OnRequestCallBackListener;
import com.gh.gamecenter.common.constant.EntranceConsts;
import com.gh.gamecenter.common.eventbus.EBReuse;
import com.gh.gamecenter.common.retrofit.Response;
import com.gh.gamecenter.common.utils.ExtensionsKt;
import com.gh.gamecenter.common.utils.ShareUtils;
@ -56,10 +57,9 @@ import com.gh.gamecenter.eventbus.EBConcernChanged;
import com.gh.gamecenter.eventbus.EBDownloadStatus;
import com.gh.gamecenter.eventbus.EBNetworkState;
import com.gh.gamecenter.eventbus.EBPackage;
import com.gh.gamecenter.common.eventbus.EBReuse;
import com.gh.gamecenter.newsdetail.NewsDetailAdapter;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.gh.gamecenter.setting.view.SettingsFragment;
import com.gh.gamecenter.setting.compose.activity.ComposeSettingActivity;
import com.lightgame.download.DataWatcher;
import com.lightgame.download.DownloadEntity;
import com.lightgame.utils.Utils;
@ -319,7 +319,7 @@ public class NewsDetailActivity extends DownloadToolbarActivity implements OnCli
}
sp = PreferenceManager.getDefaultSharedPreferences(this);
fontsize = sp.getInt(SettingsFragment.FONT_SIZE_SP_KEY, 1);
fontsize = sp.getInt(ComposeSettingActivity.FONT_SIZE_SP_KEY, 1);
if (fontsize == 0) {
fontsize = 1;
}
@ -556,14 +556,14 @@ public class NewsDetailActivity extends DownloadToolbarActivity implements OnCli
if ((R11 - R12) > scrollSize && fontsize > 1) {
fontsize--;
adapter.setFontSize(fontsize);
sp.edit().putInt(SettingsFragment.FONT_SIZE_SP_KEY, fontsize).apply();
sp.edit().putInt(ComposeSettingActivity.FONT_SIZE_SP_KEY, fontsize).apply();
String fontSizeText = getFontSize(fontsize);
Utils.toast(this, fontSizeText);
}
if ((R11 - R12) < -scrollSize && fontsize < 4) {
fontsize++;
adapter.setFontSize(fontsize);
sp.edit().putInt(SettingsFragment.FONT_SIZE_SP_KEY, fontsize).apply();
sp.edit().putInt(ComposeSettingActivity.FONT_SIZE_SP_KEY, fontsize).apply();
String fontSizeText = getFontSize(fontsize);
Utils.toast(this, fontSizeText);
}

View File

@ -137,7 +137,7 @@ public class SkipActivity extends BaseActivity {
if (!TextUtils.isEmpty(qaId)) {
DirectUtils.directToQa(this, qaTitle, qaId);
} else if ("vgame".equals(suggestionType)) {
DirectUtils.directToFeedbackCompat(this, content, "game", isQaFeedback, qaContentId, EntranceConsts.ENTRANCE_BROWSER);
DirectUtils.directToFeedback(this, content, "game", isQaFeedback, qaContentId, EntranceConsts.ENTRANCE_BROWSER);
} else {
DirectUtils.directToFeedback(this, content, null, isQaFeedback, qaContentId, EntranceConsts.ENTRANCE_BROWSER);
}

View File

@ -1,6 +1,5 @@
package com.gh.gamecenter
import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
@ -26,7 +25,6 @@ import com.gh.common.util.GameSubstituteRepositoryHelper.updateGameSubstituteRep
import com.gh.common.util.UsageStatsHelper.checkAndPostUsageStats
import com.gh.download.DownloadManager
import com.gh.gamecenter.common.base.activity.BaseActivity
import com.gh.gamecenter.common.callback.SimpleCallback
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.tracker.TrackerLogger
@ -62,8 +60,6 @@ class SplashScreenActivity : BaseActivity() {
private var mShouldPrefetchData = true
private val mPermissions = arrayOf(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
PermissionHelper.PERMISSION_GET_INSTALLED_LIST
)
@ -154,41 +150,42 @@ class SplashScreenActivity : BaseActivity() {
private fun showPrivacyDialog(guideLayout: ViewPager) {
NewPrivacyPolicyDialogFragment.show(this, null) { isSuccess: Boolean ->
if (isSuccess) {
// guideLayout.visibility = View.VISIBLE
// SPUtils.setBoolean(Constants.SP_BRAND_NEW_USER, false)
//
// // 恢复畅玩数据
// VHelper.recoverVDataIfPossible()
//
// requestPermission()
//
// // 检查是否有旧版本光环,有就删掉
// AppExecutor.ioExecutor.execute { deleteOutdatedUpdatePackage() }
// if (mStartMainActivityDirectly) {
// launchMainActivity()
// }
guideLayout.visibility = View.VISIBLE
SPUtils.setBoolean(Constants.SP_BRAND_NEW_USER, false)
mShouldPrefetchData = false
prefetchData()
// 恢复畅玩数据
VHelper.recoverVDataIfPossible()
val callback = object : SimpleCallback<Boolean> {
override fun onCallback(arg: Boolean) {
// Dialog dismiss 后的回调
guideLayout.visibility = View.VISIBLE
SPUtils.setBoolean(Constants.SP_BRAND_NEW_USER, false)
if (arg) {
requestPermission()
} else {
mStartMainActivityDirectly = false
}
}
requestPermission()
// 检查是否有旧版本光环,有就删掉
AppExecutor.ioExecutor.execute { deleteOutdatedUpdatePackage() }
if (mStartMainActivityDirectly) {
launchMainActivity()
} else {
mShouldPrefetchData = false
prefetchData()
}
mViewModel?.showPrivacyPolicy({
DialogUtils.showPrivacyPolicyDialog(this@SplashScreenActivity, it, callback)
}, {
DialogUtils.showPrivacyPolicyDialog(this@SplashScreenActivity, PrivacyPolicyEntity.createDefaultData(), callback)
})
// val callback = object : SimpleCallback<Boolean> {
// override fun onCallback(arg: Boolean) {
// // Dialog dismiss 后的回调
// guideLayout.visibility = View.VISIBLE
// SPUtils.setBoolean(Constants.SP_BRAND_NEW_USER, false)
// if (arg) {
// requestPermission()
// } else {
// mStartMainActivityDirectly = false
// }
// }
// }
//
// mViewModel?.showPrivacyPolicy({
// DialogUtils.showPrivacyPolicyDialog(this@SplashScreenActivity, it, callback)
// }, {
// DialogUtils.showPrivacyPolicyDialog(this@SplashScreenActivity, PrivacyPolicyEntity.createDefaultData(), callback)
// })
} else {
DialogUtils.showPrivacyPolicyDisallowDialog(
this,
@ -258,6 +255,7 @@ class SplashScreenActivity : BaseActivity() {
SPUtils.setLong(Constants.SP_GH_LAST_UPDATE_TIME, PackageUtils.getHaloLastUpdateTime())
HaloApp.getInstance().postInit(true)
TrackerLogger.logAppLaunchSuccessful()
AdHelper.getStartUpAd()
if (mShouldPrefetchData) {
prefetchData()
}
@ -387,10 +385,10 @@ class SplashScreenActivity : BaseActivity() {
private fun checkAndRequestPermission() {
if (EasyPermissions.hasPermissions(this, *mPermissions)) {
// 恢复畅玩数据
VHelper.recoverVDataIfPossible()
// VHelper.recoverVDataIfPossible()
// 检查是否有旧版本光环,有就删掉
AppExecutor.ioExecutor.execute { deleteOutdatedUpdatePackage() }
// AppExecutor.ioExecutor.execute { deleteOutdatedUpdatePackage() }
if (mStartMainActivityDirectly) {
if (com.gh.gamecenter.common.BuildConfig.BUILD_TIME != 0L) {
showGitLogDialogIfNeeded()
@ -479,7 +477,7 @@ class SplashScreenActivity : BaseActivity() {
intent.action = Intent.ACTION_MAIN
intent.addCategory(Intent.CATEGORY_LAUNCHER)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.putExtras(bundle ?: Bundle())
intent.putExtras(bundle!!)
return intent
}
}

View File

@ -5,22 +5,18 @@ import android.content.Context;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.text.HtmlCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import com.gh.common.util.DirectUtils;
import com.gh.common.view.DownloadButton;
import com.gh.gamecenter.common.callback.OnRequestCallBackListener;
import com.gh.gamecenter.common.utils.ExtensionsKt;
@ -46,7 +42,6 @@ import com.gh.gamecenter.entity.LibaoStatusEntity;
import com.gh.gamecenter.entity.MeEntity;
import com.gh.gamecenter.entity.UserDataLibaoEntity;
import com.gh.gamecenter.common.retrofit.Response;
import com.gh.gamecenter.game.GameItemViewHolder;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.gh.gamecenter.suggest.SuggestType;
import com.lightgame.adapter.BaseRecyclerAdapter;
@ -201,8 +196,6 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
ExtensionsKt.setRootBackgroundColor(holder.binding.getRoot(), R.color.background_white);
if (mLibaoEntity.getGame() != null) {
holder.binding.libaodetailGameIcon.displayGameIcon(mLibaoEntity.getGame().getIcon(), mLibaoEntity.getGame().getIconSubscript());
GameEntity gameEntity = mLibaoEntity.getGame().toGameEntity();
GameItemViewHolder.initGameSubtitle(gameEntity, holder.binding.gameSubtitleTv, null, null, false);
} else {
holder.binding.libaodetailGameIcon.displayGameIcon(mLibaoEntity.getIcon(), null);
}
@ -328,32 +321,6 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
}
holder.binding.libaodetailCondition.setVisibility(View.VISIBLE);
holder.binding.libaodetailCondition.setText(content);
} else if (ExtensionsKt.toResString(R.string.libao_activity_grant).equals(mLibaoEntity.getReceiveLimit())) {
holder.binding.libaodetailCondition.setVisibility(View.VISIBLE);
String url = mLibaoEntity.getActivityLink().getUrl();
if (TextUtils.isEmpty(url)) {
holder.binding.libaodetailCondition.setText("领取条件:通过活动获得");
} else {
SpannableStringBuilder content = new SpannableStringBuilder("领取条件:通过活动获得,查看详情");
content.setSpan(new ClickableSpan() {
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(ExtensionsKt.toColor(R.color.theme_font, mContext));
ds.setUnderlineText(false);
}
@Override
public void onClick(@NonNull View widget) {
DirectUtils.directToWebView(mContext, url, "礼包详情-领取条件-查看活动详情");
}
}, 12, content.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.binding.libaodetailCondition.setText(content);
holder.binding.libaodetailCondition.setMovementMethod(new LinkMovementMethod());
ExtensionsKt.setDrawableEnd(holder.binding.libaodetailCondition, com.gh.gamecenter.common.R.drawable.ic_libao_activity_arrow, null, null);
holder.binding.libaodetailCondition.setCompoundDrawablePadding(DisplayUtils.dip2px(4F));
}
}
if (mLibaoDetailEntity.getTime() != null) {
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm", Locale.CHINA);

View File

@ -4,7 +4,6 @@ import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
@ -12,7 +11,6 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;
import com.airbnb.lottie.LottieAnimationView;
import com.gh.common.chain.BrowserInstallHandler;
import com.gh.common.chain.CertificationHandler;
import com.gh.common.chain.ChainBuilder;
@ -38,8 +36,6 @@ import com.gh.common.simulator.SimulatorDownloadManager;
import com.gh.common.simulator.SimulatorGameManager;
import com.gh.common.util.CheckLoginUtils;
import com.gh.common.util.DirectUtils;
import com.gh.common.xapk.XapkInstaller;
import com.gh.common.xapk.XapkUnzipStatus;
import com.gh.gamecenter.common.constant.EntranceConsts;
import com.gh.gamecenter.common.utils.DataLogUtils;
import com.gh.common.util.DetailDownloadUtils;
@ -69,7 +65,6 @@ import com.gh.gamecenter.entity.SimulatorEntity;
import com.gh.gamecenter.eventbus.EBScroll;
import com.gh.gamecenter.gamedetail.GameDetailFragment;
import com.gh.gamecenter.gamedetail.dialog.GamePermissionDialogFragment;
import com.gh.gamecenter.manager.PackagesManager;
import com.gh.gamecenter.teenagermode.TeenagerModeActivity;
import com.gh.vspace.VDownloadManagerActivity;
import com.gh.vspace.VHelper;
@ -101,18 +96,14 @@ public class DetailViewHolder {
public View downloadBottom;
public DownloadButton mDownloadPb;
public LottieAnimationView mDownloadTips;
public TextView mOverlayTv; // 额外的文字 (用于一些含图片的情况)
public TextView mMultiVersionDownloadTv; // 多版本下载文字
// 注意View的命名
public DetailViewHolder(View view, GameEntity gameEntity, DownloadEntity downloadEntity,
boolean isNewsDetail, String entrance, String name, String title, @Nullable ExposureEvent traceEvent) {
downloadBottom = view.findViewById(R.id.detail_ll_bottom);
mDownloadPb = view.findViewById(R.id.detail_progressbar);
mDownloadTips = view.findViewById(R.id.downloadTipsLottie);
mOverlayTv = view.findViewById(R.id.overlayTv);
mMultiVersionDownloadTv = view.findViewById(R.id.multiVersionDownloadTv);
this.gameEntity = gameEntity;
this.downloadEntity = downloadEntity;
@ -202,43 +193,6 @@ public class DetailViewHolder {
}
v.setTag(null);
if (mViewHolder.mDownloadPb.getButtonStyle() != DownloadButton.ButtonStyle.INSTALL_NORMAL
&& mViewHolder.mDownloadPb.getButtonStyle() != DownloadButton.ButtonStyle.INSTALL_PLUGIN
&& mViewHolder.mDownloadPb.getButtonStyle() != DownloadButton.ButtonStyle.LAUNCH_OR_OPEN) {
if (mGameEntity.isVGame() && !VHelper.INSTANCE.shouldLaunchGameAfterInstallation()) {
// 畅玩游戏的非真实点击下载按钮下载不需要滚动到特定地方
} else {
EventBus.getDefault().post(new EBScroll(Constants.EB_GAME_DETAIL, mGameEntity.getId()));
}
}
if (mDownloadEntity == null) {
mDownloadEntity = DownloadManager.getInstance().getDownloadEntitySnapshot(mGameEntity);
}
if (mDownloadEntity != null) {
String xapkStatus = mDownloadEntity.getMeta().get(XapkInstaller.XAPK_UNZIP_STATUS);
if (XapkUnzipStatus.UNZIPPING.name().equals(xapkStatus)) {
XapkInstaller.cancelUnzipTask(mDownloadEntity);
return;
} else if (XapkUnzipStatus.FAILURE.name().equals(xapkStatus)) {
PermissionHelper.checkStoragePermissionBeforeAction(mViewHolder.context, () -> {
if (mDownloadEntity != null) {
final String path = mDownloadEntity.getPath();
if (FileUtils.isEmptyFile(path)) {
Utils.toast(mViewHolder.context, R.string.install_failure_hint);
DownloadManager.getInstance().cancel(mDownloadEntity.getUrl());
} else {
PackageInstaller.install(mViewHolder.context, mDownloadEntity);
}
}
});
return;
}
}
switch (mViewHolder.mDownloadPb.getButtonStyle()) {
case NONE_WITH_HINT:
case NONE:
@ -275,6 +229,7 @@ public class DetailViewHolder {
builder.addHandler(new CheckStoragePermissionHandler());
if (mGameEntity.getApk().size() == 1) {
ApkEntity apk = mGameEntity.getApk().get(0);
builder.addHandler(new BrowserInstallHandler());
builder.addHandler(new PackageCheckHandler());
builder.addHandler(new DownloadDialogHelperHandler());
@ -284,7 +239,7 @@ public class DetailViewHolder {
builder.addHandler(new CheckDownloadHandler());
builder.setProcessEndCallback(o -> {
download((boolean) o);
DialogUtils.checkDownload(mViewHolder.context, apk.getSize(), this::download);
return null;
});
final ChainHandler chainHandler = builder.buildHandlerChain();
@ -314,7 +269,7 @@ public class DetailViewHolder {
if (mGameEntity.getApk().size() == 1) {
//启动模拟器游戏
if (SimulatorGameManager.isSimulatorGame(mGameEntity)) {
if (NewSimulatorGameManager.shouldShowUpdateNewSimulatorAlert(mViewHolder.context)) {
if (NewSimulatorGameManager.shouldShowUpdateNewSimulatorAlert(mViewHolder.context)){
NewSimulatorGameManager.showUpdateNewsSimulator(mViewHolder.context, null);
return;
}
@ -360,10 +315,9 @@ public class DetailViewHolder {
boolean isInstalledNewSimulator = SimulatorGameManager.isNewSimulatorInstalled(mViewHolder.context);
boolean isInstalledOldSimulator = SimulatorGameManager.isOldSimulatorInstalled(mViewHolder.context);
SimulatorEntity simulator = mGameEntity.getSimulator();
SimulatorEntity newSimulator = Config.getNewSimulatorEntitySetting();
if (!isInstalledOldSimulator && newSimulator != null) {
if (newSimulator.getActive()) {
simulator = newSimulator;
if (!isInstalledOldSimulator){
if (Config.getNewSimulatorEntitySetting() != null){
simulator = Config.getNewSimulatorEntitySetting();
}
}
@ -381,7 +335,7 @@ public class DetailViewHolder {
PermissionHelper.checkStoragePermissionBeforeAction(mViewHolder.context, () -> {
if (mDownloadEntity == null) {
mDownloadEntity = DownloadManager.getInstance().getDownloadEntitySnapshot(mGameEntity);
mDownloadEntity = DownloadManager.getInstance().getDownloadEntityByUrl(mGameEntity.getApk().get(0).getUrl());
}
if (mDownloadEntity != null) {
@ -457,24 +411,6 @@ public class DetailViewHolder {
DirectUtils.directForumDetail(mViewHolder.context, info.getBbsId(), mEntrance);
}
break;
case WAITING:
Utils.toast(mViewHolder.context, "最多只能同时下载三个任务,请稍等");
break;
case DOWNLOADING_NORMAL:
case DOWNLOADING_PLUGIN:
if (mDownloadEntity == null) {
mDownloadEntity = DownloadManager.getInstance().getDownloadEntitySnapshot(mGameEntity);
}
if (mDownloadEntity != null) {
if (downloadText.contains("继续加载")) {
DownloadManager.getInstance().resume(mDownloadEntity, true);
} else {
DownloadManager.getInstance().pause(mDownloadEntity.getUrl());
mViewHolder.mDownloadPb.setText("继续加载 " + mDownloadEntity.getPercent() + "%");
}
}
break;
default:
if (mGameEntity.isVGame()) {
mViewHolder.context.startActivity(VDownloadManagerActivity.getIntent(mViewHolder.context, true));
@ -486,6 +422,12 @@ public class DetailViewHolder {
}
break;
}
if (mViewHolder.mDownloadPb.getButtonStyle() != DownloadButton.ButtonStyle.INSTALL_NORMAL
&& mViewHolder.mDownloadPb.getButtonStyle() != DownloadButton.ButtonStyle.INSTALL_PLUGIN
&& mViewHolder.mDownloadPb.getButtonStyle() != DownloadButton.ButtonStyle.LAUNCH_OR_OPEN) {
EventBus.getDefault().post(new EBScroll(Constants.EB_GAME_DETAIL, mGameEntity.getId()));
}
}
private void showOffServiceDialog(GameEntity.Dialog dialog) {
@ -530,7 +472,7 @@ public class DetailViewHolder {
DownloadButton.ButtonStyle.DOWNLOADING_PLUGIN : DownloadButton.ButtonStyle.DOWNLOADING_NORMAL);
DeviceRemindDialog.Companion.showDeviceRemindDialog(mViewHolder.context, mGameEntity);
if (mGameEntity.isVGame() && mViewHolder.context.getString(R.string.download).equals(method) && VHelper.INSTANCE.shouldLaunchGameAfterInstallation()) {
if (mGameEntity.isVGame() && mViewHolder.context.getString(R.string.download).equals(method)) {
mViewHolder.context.startActivity(VSpaceLoadingActivity.getIntent(mViewHolder.context, mGameEntity, false));
}
} else {

View File

@ -15,6 +15,10 @@ public class GameTestViewHolder extends GameViewHolder {
gameDownloadBtn = binding.home2DownloadBtn;
gameDes = binding.home2GameDes;
gameLabelList = binding.home2LabelList;
gameInfo = binding.home2GameLlInfo;
gameProgressbar = binding.home2GameProgressbar;
gameDownloadSpeed = binding.home2DownloadSpeed;
gameDownloadPercentage = binding.home2DownloadPercentage;
gameServerType = binding.home2GameServerType;
}

View File

@ -1,7 +1,6 @@
package com.gh.gamecenter.adapter.viewholder;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -9,13 +8,10 @@ import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import com.airbnb.lottie.LottieAnimationView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.gh.common.view.DownloadButton;
import com.gh.common.view.GameIconView;
import com.gh.gamecenter.R;
import com.gh.gamecenter.common.utils.ExtensionsKt;
import com.gh.gamecenter.common.view.DrawableView;
import com.gh.common.view.GameIconView;
import com.gh.gamecenter.databinding.GameItemBinding;
import com.gh.gamecenter.entity.ColorEntity;
import com.gh.gamecenter.entity.GameEntity;
@ -27,13 +23,15 @@ public class GameViewHolder extends RecyclerView.ViewHolder {
public DownloadButton gameDownloadBtn;
public TextView gameDes;
public LinearLayout gameLabelList;
public View gameInfo;
public ProgressBar gameProgressbar;
@Nullable
public View recommendContainer;
public TextView recommendTv;
public SimpleDraweeView recommendIv;
public TextView gameDownloadSpeed;
public TextView gameDownloadPercentage;
public TextView gameServerType;
public LottieAnimationView gameDownloadTips;
public TextView multiVersionDownloadTv;
@Nullable
public TextView gameRating;
@ -48,9 +46,11 @@ public class GameViewHolder extends RecyclerView.ViewHolder {
public GameViewHolder(GameItemBinding binding) {
super(binding.getRoot());
gameDownloadBtn = binding.downloadBtn;
gameProgressbar = binding.gameProgressbar;
gameInfo = binding.gameInfo;
gameDownloadPercentage = binding.downloadPercentage;
gameDes = binding.gameDes;
gameDownloadTips = binding.downloadTipsLottie;
multiVersionDownloadTv = binding.multiVersionDownloadTv;
gameDownloadSpeed = binding.downloadSpeed;
gameRating = binding.gameRating;
recommendContainer = binding.recommendContainer;
recommendTv = binding.recommendTv;
@ -65,13 +65,7 @@ public class GameViewHolder extends RecyclerView.ViewHolder {
} else if (serverLabel != null) {
gameServerType.setVisibility(View.VISIBLE);
gameServerType.setText(serverLabel.getValue());
if (gameEntity.isUseDefaultServerStyle()) {
gameServerType.setBackground(ExtensionsKt.toDrawable(R.drawable.server_label_default_bg));
gameServerType.setTextColor(ExtensionsKt.toColor(R.color.text_server_label));
} else {
gameServerType.setBackground(DrawableView.getServerDrawable(serverLabel.getColor()));
gameServerType.setTextColor(ExtensionsKt.toColor(R.color.white));
}
gameServerType.setBackground(DrawableView.getServerDrawable(serverLabel.getColor()));
} else {
gameServerType.setVisibility(View.GONE);
}

View File

@ -1,44 +0,0 @@
package com.gh.gamecenter.aidl
import android.app.Service
import android.content.Intent
import android.os.IBinder
import com.gh.vspace.VArchiveHelper
import com.gh.vspace.VHelper
import com.lg.vclient.interfaces.ICommunicationManager
import com.lg.vspace.remote.model.VGameInstallerResult
import com.lightgame.utils.Utils
class CommunicationService : Service() {
private var mBinder: ICommunicationManager.Stub = object : ICommunicationManager.Stub() {
override fun archiveUnzipCompleted(packageName: String, isSuccess: Boolean) {
Utils.log(VHelper.LOG_TAG, "包名 $packageName 应用存档的结果是 $isSuccess")
VArchiveHelper.onApplyGameArchiveFinished(packageName, isSuccess)
}
override fun archiveinPackageCompleted(packageName: String, isSuccess: Boolean) {
Utils.log(VHelper.LOG_TAG, "包名 $packageName 保存存档的结果是 $isSuccess")
VArchiveHelper.onSaveGameArchiveFinished(packageName, isSuccess)
}
override fun installGameCompleted(packageName: String, params: VGameInstallerResult) {
Utils.log(VHelper.LOG_TAG, "包名 $packageName 安装的结果是 ${params.status}")
VHelper.onInstallFinished(packageName, params)
}
override fun connectionCompleted() {
Utils.log(VHelper.LOG_TAG, "服务回调连接成功")
VHelper.onConnectionCompleted(shouldReconnect = true)
}
}
override fun onBind(intent: Intent?): IBinder {
return mBinder
}
}

View File

@ -28,7 +28,6 @@ import com.gh.gamecenter.core.utils.NumberUtils
import com.gh.gamecenter.databinding.AmwayCommentItemBinding
import com.gh.gamecenter.eventbus.EBDownloadStatus
import com.gh.gamecenter.game.GameAndPosition
import com.gh.gamecenter.game.GameItemViewHolder
import com.gh.gamecenter.game.vertical.GameVerticalAdapter
import com.gh.gamecenter.gamedetail.rating.RatingFragment
import com.gh.gamecenter.gamedetail.rating.RatingReplyActivity
@ -207,7 +206,6 @@ class AmwayAdapter(
) {
val context = binding.root.context
val amway = itemData.amwayCommentItem!!
val gameEntity = amway.game.toGameEntity()
binding.gameContainer.background = R.drawable.selector_f8f8f8.toDrawable(context)
binding.commentContainer.background = R.drawable.selector_f8f8f8.toDrawable(context)
@ -239,8 +237,7 @@ class AmwayAdapter(
)
}
itemData.exposureEvent = ExposureEvent.createEvent(gameEntity, basicExposureSource)
GameItemViewHolder.initGameSubtitle(gameEntity, binding.gameSubtitleTv)
itemData.exposureEvent = ExposureEvent.createEvent(amway.game.toGameEntity(), basicExposureSource)
binding.gameContainer.setOnClickListener {
GameDetailActivity.startGameDetailActivity(

View File

@ -142,20 +142,23 @@ class AmwayViewModel(application: Application) : ListViewModel<AmwayCommentEntit
override fun mergeResultLiveData() {
mResultLiveData.addSource(mListLiveData) { list ->
val subjectListCopy = LinkedList(mAmwaySubjectList)
var subjectPosition = 0
val itemDataList = arrayListOf<AmwayListItemData>()
for (i in list.indices) {
mAmwaySubjectList.forEach { subjectEntity ->
if (subjectEntity.position != -1 && subjectEntity.position == i) {
LegacyHomeSubjectTransformer.transform(
itemDataList as ArrayList<LegacyHomeItemData>,
subjectEntity,
subjectPosition++,
{ AmwayListItemData() },
{ addGamePositionAndPackage(itemDataList.size - 1, it) }
)
}
// 在位置 3, 6, 9 穿插专题数据
if (subjectListCopy.isNotEmpty()
&& (i != 0 && i % 2 == 0)
) {
LegacyHomeSubjectTransformer.transform(
itemDataList as ArrayList<LegacyHomeItemData>,
subjectListCopy.poll(),
subjectPosition++,
{ AmwayListItemData() },
{ addGamePositionAndPackage(itemDataList.size - 1, it) }
)
}
itemDataList.add(AmwayListItemData(amwayCommentItem = list[i]).apply { blockPosition = i + 1 })
}

View File

@ -5,7 +5,10 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
import com.gh.gamecenter.R
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.common.utils.DialogHelper
import com.gh.gamecenter.common.utils.observeNonNull
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.common.utils.viewModelProviderFromParent
import com.gh.gamecenter.databinding.FragmentAmwaySearchDefaultBinding
import com.gh.gamecenter.eventbus.EBSearch
import com.gh.gamecenter.search.SearchDefaultFragment
@ -65,11 +68,13 @@ class AmwaySearchDefaultFragment : SearchDefaultFragment() {
headTitle.textSize = 16F
headActionTv.text = "清空"
headActionTv.setTextColor(R.color.text_subtitleDesc.toColor(requireContext()))
headActionTv.setDrawableStart(VectorDrawableCompat.create(
resources,
R.drawable.search_history_delete,
null
))
headActionTv.setCompoundDrawablesWithIntrinsicBounds(
VectorDrawableCompat.create(
resources,
R.drawable.search_history_delete,
null
), null, null, null
)
headActionTv.setOnClickListener {
DialogHelper.showCenterWarningDialog(requireContext(), "清空记录", "确定清空历史搜索记录?", confirmClickCallback = {
mSearchDao.deleteAll()

View File

@ -181,7 +181,7 @@ class NewCatalogListFragment : ListFragment<GameEntity, NewCatalogListViewModel>
// 安装/卸载 事件
@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(busFour: EBPackage) {
if (busFour.isInstalledOrUninstalled()) {
if ("安装" == busFour.type || "卸载" == busFour.type) {
mAdapter?.notifyDataSetChanged()
}
}

View File

@ -163,7 +163,7 @@ class NewCategoryListFragment : ListFragment<GameEntity, NewCategoryListViewMode
// 安装/卸载 事件
@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(busFour: EBPackage) {
if (busFour.isInstalledOrUninstalled()) {
if ("安装" == busFour.type || "卸载" == busFour.type) {
mAdapter?.notifyDataSetChanged()
}
}

View File

@ -5,27 +5,28 @@ import android.util.SparseArray
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.constant.ItemViewType
import com.gh.common.databind.BindingAdapters
import com.gh.common.exposure.ExposureEvent
import com.gh.common.exposure.ExposureSource
import com.gh.common.exposure.ExposureType
import com.gh.common.exposure.IExposable
import com.gh.common.util.DownloadItemUtils
import com.gh.common.util.*
import com.gh.gamecenter.common.view.DrawableView
import com.gh.gamecenter.GameDetailActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.adapter.viewholder.GameViewHolder
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.baselist.ListAdapter
import com.gh.gamecenter.common.constant.ItemViewType
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.common.view.DrawableView
import com.gh.gamecenter.common.viewholder.FooterViewHolder
import com.gh.gamecenter.core.utils.PageSwitchDataHelper
import com.gh.gamecenter.core.utils.StringUtils
import com.gh.gamecenter.adapter.viewholder.GameViewHolder
import com.gh.gamecenter.common.baselist.ListAdapter
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.common.utils.toBinding
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.common.utils.toDrawable
import com.gh.gamecenter.core.utils.*
import com.gh.gamecenter.databinding.CategoryGameItemBinding
import com.gh.gamecenter.entity.GameEntity
import com.gh.gamecenter.eventbus.EBDownloadStatus
import com.gh.gamecenter.game.GameItemViewHolder
import com.lightgame.download.DownloadEntity
class CategoryV2ListAdapter(
@ -228,7 +229,12 @@ class CategoryV2ListAdapter(
BindingAdapters.setGameName(gameName, gameEntity, false, null)
BindingAdapters.setTextSize(gameRating, if (gameEntity.commentCount > 3) 12 else 10)
BindingAdapters.setGameTags(labelList, gameEntity)
gameRating.setDrawableStart(if (gameEntity.commentCount > 3) R.drawable.game_horizontal_rating.toDrawable() else null)
gameRating.setCompoundDrawablesWithIntrinsicBounds(
if (gameEntity.commentCount > 3) R.drawable.game_horizontal_rating.toDrawable() else null,
null,
null,
null
)
gameRating.text = if (gameEntity.commentCount > 3) {
if (gameEntity.star == 10.0F) "10" else gameEntity.star.toString()
} else ""
@ -239,8 +245,6 @@ class CategoryV2ListAdapter(
)
)
gameDes.text = gameEntity.decoratedDes
GameItemViewHolder.initGameSubtitle(gameEntity, gameSubtitleTv, gameDesSpace, root)
}
}
@ -254,14 +258,7 @@ class CategoryV2ListAdapter(
serverLabel != null -> {
binding.gameKaifuType.visibility = View.VISIBLE
binding.gameKaifuType.text = serverLabel.value
if (gameEntity.isUseDefaultServerStyle()) {
binding.gameKaifuType.background =
R.drawable.server_label_default_bg.toDrawable(binding.root.context)
binding.gameKaifuType.setTextColor(R.color.text_server_label.toColor(binding.root.context))
} else {
binding.gameKaifuType.background = DrawableView.getServerDrawable(serverLabel.color)
binding.gameKaifuType.setTextColor(R.color.white.toColor(binding.root.context))
}
binding.gameKaifuType.background = DrawableView.getServerDrawable(serverLabel.color)
}
else -> binding.gameKaifuType.visibility = View.GONE
}
@ -274,7 +271,11 @@ class CategoryV2ListAdapter(
inner class CategoryGameViewHolder(val binding: CategoryGameItemBinding) : GameViewHolder(binding.root) {
init {
gameDownloadBtn = binding.downloadBtn
gameProgressbar = binding.gameProgressbar
gameInfo = binding.gameInfo
gameDownloadPercentage = binding.downloadPercentage
gameDes = binding.gameDes
gameDownloadSpeed = binding.downloadSpeed
gameRating = binding.gameRating
recommendContainer = binding.recommendContainer
recommendTv = binding.recommendTv

View File

@ -310,7 +310,7 @@ class CategoryV2ListFragment : ListFragment<GameEntity, CategoryV2ListViewModel>
// 安装/卸载 事件
@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(busFour: EBPackage) {
if (busFour.isInstalledOrUninstalled()) {
if ("安装" == busFour.type || "卸载" == busFour.type) {
mAdapter?.notifyDataSetChanged()
}
}

View File

@ -1,367 +0,0 @@
package com.gh.gamecenter.cloudarchive
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.MenuItem
import android.view.Window
import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.Fragment
import com.gh.common.util.CheckLoginUtils
import com.gh.common.util.DirectUtils
import com.gh.common.util.DownloadItemUtils
import com.gh.common.util.NewFlatLogUtils
import com.gh.common.view.DownloadButton
import com.gh.download.DownloadManager
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.activity.BaseActivity_TabLayout
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.eventbus.EBReuse
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.core.utils.CurrentActivityHolder
import com.gh.gamecenter.core.utils.MD5Utils
import com.gh.gamecenter.core.utils.SPUtils
import com.gh.gamecenter.databinding.ActivityCloudArchiveManagerBinding
import com.gh.gamecenter.databinding.DialogUploadArchiveBinding
import com.gh.gamecenter.entity.ArchiveEntity
import com.gh.gamecenter.entity.GameEntity
import com.gh.gamecenter.manager.PackagesManager
import com.gh.vspace.VArchiveHelper
import com.gh.vspace.VHelper
import com.lightgame.download.DataWatcher
import com.lightgame.download.DownloadEntity
import com.lightgame.download.DownloadStatus
import com.lightgame.utils.Utils
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.io.File
class CloudArchiveManagerActivity : BaseActivity_TabLayout() {
private lateinit var mBinding: ActivityCloudArchiveManagerBinding
private var mGameEntity: GameEntity? = null
private var mArchiveConfigUrl = ""
private var mArchiveFragment: MyArchiveFragment? = null
private var mDownloadArchiveFragment: MyDownloadArchiveFragment? = null
private var mShareArchiveFragment: MyShareArchiveFragment? = null
private val mViewModel: CloudArchiveManagerViewModel by lazy {
viewModelProvider(
CloudArchiveManagerViewModel.Factory(
gameId = mGameEntity?.id ?: "",
configUrl = mArchiveConfigUrl
)
)
}
private val dataWatcher = object : DataWatcher() {
override fun onDataChanged(downloadEntity: DownloadEntity) {
if (downloadEntity.gameId == mViewModel.gameId) {
if (mGameEntity?.getApk()?.size == 1) {
updateDownloadBtn(downloadEntity, mBinding.downloadBtn, mGameEntity)
}
}
}
override fun onDataInit(downloadEntity: DownloadEntity) {
onDataChanged(downloadEntity)
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mGameEntity = intent.getParcelableExtra<GameEntity?>(EntranceConsts.KEY_GAME)?.apply {
setEntryMap(DownloadManager.getInstance().getEntryMap(name))
}
mArchiveConfigUrl = intent.getStringExtra(EntranceConsts.KEY_ARCHIVE_CONFIG_URL) ?: ""
mBinding = ActivityCloudArchiveManagerBinding.bind(mContentView)
setNavigationTitle("云存档")
setToolbarMenu(R.menu.menu_cloud_archive_manager)
updateStatusBarColor(R.color.background_white, R.color.background_white)
NewFlatLogUtils.logCloudArchiveManagePageShow(mGameEntity?.id ?: "", mGameEntity?.name ?: "", mEntrance)
mBinding.run {
mGameEntity?.let {
gameIconView.displayGameIcon(it)
gameNameTv.text = it.name
}
controlUploadGameArchive()
uploadTv.setOnClickListener {
when {
// 检查是否已安装游戏、本地是否存在存档数据
!VHelper.isInstalled(mGameEntity?.getUniquePackageName()) || !VHelper.checkArchiveExist(
mGameEntity?.getUniquePackageName() ?: "", mViewModel.archiveConfigStr
) -> toast("暂未检测到本地的存档数据,请玩会儿游戏再试~")
else -> {
NewFlatLogUtils.logCloudArchiveUploadDialogShow()
showUploadDialog()
}
}
}
}
mViewModel.uploadSuccess.observeNonNull(this) {
if (it) {
mArchiveFragment?.onLoadRefresh()
toast("上传成功")
} else {
toast("上传失败")
}
}
}
override fun onMenuItemClick(item: MenuItem?): Boolean {
if (item?.itemId == R.id.menu_help) {
if (EnvHelper.isDevEnv) {
DirectUtils.directToArticle(this, DEV_HELP_ARTICLE_ID, "云存档管理")
} else {
DirectUtils.directToArticle(this, HELP_ARTICLE_ID, "云存档管理")
}
return true
}
return super.onMenuItemClick(item)
}
override fun getLayoutId(): Int = R.layout.activity_cloud_archive_manager
override fun initFragmentList(fragments: MutableList<Fragment>) {
fragments.add(MyArchiveFragment().apply { mArchiveFragment = this }.with(intent.extras))
fragments.add(MyDownloadArchiveFragment().apply { mDownloadArchiveFragment = this }.with(intent.extras))
fragments.add(MyShareArchiveFragment().apply { mShareArchiveFragment = this }.with(intent.extras))
}
override fun initTabTitleList(tabTitleList: MutableList<String>) {
tabTitleList.add("我的存档")
tabTitleList.add("我的下载")
tabTitleList.add("我的分享")
}
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
mCheckedIndex = position
NewFlatLogUtils.logCloudArchiveTabShow(
mGameEntity?.id ?: "",
mGameEntity?.name ?: "",
if (position == MY_ARCHIVE_INDEX) "我的存档" else if (position == MY_DOWNLOAD_ARCHIVE_INDEX) "我的下载" else "我的分享"
)
controlUploadGameArchive()
}
override fun onResume() {
super.onResume()
initDownloadBtn()
DownloadManager.getInstance().addObserver(dataWatcher)
}
private fun initDownloadBtn() {
mGameEntity?.let { gameEntity ->
DownloadItemUtils.updateDownloadButton(this, mBinding.downloadBtn, gameEntity)
DownloadItemUtils.setOnClickListener(this, mBinding.downloadBtn, gameEntity, 0, null, mEntrance, "")
}
}
override fun onPause() {
super.onPause()
DownloadManager.getInstance().removeObserver(dataWatcher)
}
fun controlUploadGameArchive() {
val shouldShowUploadGameArchive =
(mCheckedIndex == MY_ARCHIVE_INDEX) || (mCheckedIndex == MY_DOWNLOAD_ARCHIVE_INDEX && mDownloadArchiveFragment?.isEmpty == true)
showUploadGameArchive(shouldShowUploadGameArchive)
}
private fun showUploadGameArchive(show: Boolean) {
mBinding.uploadContainer.goneIf(!show || !CheckLoginUtils.isLogin())
mBinding.divider.goneIf(!show || !CheckLoginUtils.isLogin())
}
private fun showUploadDialog() {
val dialog = Dialog(this)
val binding = DialogUploadArchiveBinding.inflate(layoutInflater)
binding.run {
clearIv.setOnClickListener {
contentEt.text.clear()
}
contentEt.doOnTextChanged { text, _, _, _ ->
clearIv.goneIf(text?.length == 0)
confirmTv.isEnabled = text?.length != 0
confirmTv.alpha = if (text?.length != 0) 1F else 0.4F
}
confirmTv.setOnClickListener {
NewFlatLogUtils.logCloudArchiveUploadDialogClick("确定")
if (contentEt.text.trim().length in 3..30) {
saveAndUploadArchive(contentEt.text.toString().trim())
dialog.dismiss()
} else {
toast("存档名称限制3~30个字符")
}
}
cancelTv.setOnClickListener {
NewFlatLogUtils.logCloudArchiveUploadDialogClick("取消")
dialog.dismiss()
}
}
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setContentView(binding.root)
dialog.setCanceledOnTouchOutside(true)
dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog.show()
}
private fun saveAndUploadArchive(archiveName: String) {
val pathName = "${VArchiveHelper.archivePath}${
MD5Utils.getContentMD5(
System.currentTimeMillis().toString()
)
}.zip"
VArchiveHelper.saveGameArchive(
this@CloudArchiveManagerActivity,
mGameEntity?.getUniquePackageName() ?: "",
mViewModel.archiveConfigStr,
File(pathName)
) { entity ->
OssUploadUtils.uploadFile(
pathName,
OssUploadUtils.UploadType.GAME_ARCHIVE,
object : OssUploadUtils.OnUploadFileListener {
override fun onSuccess(url: String) {
mViewModel.postArchive(ArchiveEntity().apply {
name = archiveName
this.url = url
configUrl = mArchiveConfigUrl
md5 = entity.md5
gameVersion = entity.gameVersion
})
}
override fun onError(e: Throwable?) {
toast("上传失败")
}
},
null,
mGameEntity?.id ?: "",
entity.md5
)
}
}
private fun updateDownloadBtn(
downloadEntity: DownloadEntity?, downloadBtn: DownloadButton, gameEntity: GameEntity?
) {
// 青少年模式显示查看
if (SPUtils.getBoolean(Constants.SP_TEENAGER_MODE)) {
downloadBtn.text = "查看"
downloadBtn.buttonStyle = DownloadButton.ButtonStyle.TEENAGER_MODE
return
}
if (downloadEntity != null) {
val status = downloadEntity.status
var btnText = getString(R.string.downloading)
var backgroundType = DownloadButton.ButtonStyle.NORMAL
downloadBtn.apply {
when (status) {
DownloadStatus.downloading -> {
btnText = "${downloadEntity.percent}%"
backgroundType = DownloadButton.ButtonStyle.DOWNLOADING_NORMAL
progress = (downloadEntity.percent * 10).toInt()
setOnClickListener {
DownloadManager.getInstance().pause(downloadEntity.url)
}
}
DownloadStatus.waiting -> {
btnText = getString(R.string.waiting)
setOnClickListener { Utils.toast(this@CloudArchiveManagerActivity, "最多只能同时下载三个任务,请稍等"); }
}
DownloadStatus.pause, DownloadStatus.timeout, DownloadStatus.neterror, DownloadStatus.subscribe, DownloadStatus.overflow -> {
btnText = getString(R.string.resume)
setOnClickListener {
DownloadManager.getInstance().resume(downloadEntity, true)
}
}
DownloadStatus.done -> {
if (PackagesManager.isCanUpdate(
gameEntity?.id, gameEntity?.getApk()?.firstOrNull()?.packageName
)
) {
btnText = getString(R.string.update)
setOnClickListener {
PackagesManager.getUpdateList().firstOrNull { it.id == downloadEntity.gameId }?.let {
VHelper.updateOrReDownload(downloadEntity, it)
}
}
} else {
btnText = getString(R.string.launch)
setOnClickListener {
CurrentActivityHolder.getCurrentActivity()?.let {
VHelper.installOrLaunch(it, downloadEntity.packageName)
}
}
}
}
else -> {
// do nothing
}
}
text = btnText
buttonStyle = backgroundType
}
} else {
downloadBtn.buttonStyle = DownloadButton.ButtonStyle.NORMAL
downloadBtn.text = "畅玩"
}
}
override fun onDarkModeChanged() {
super.onDarkModeChanged()
updateStatusBarColor(R.color.background_white, R.color.background_white)
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(reuse: EBReuse) {
when (reuse.type) {
Constants.LOGIN_TAG -> {
controlUploadGameArchive()
}
"download" -> {
mBinding.downloadBtn.performClick()
}
}
}
fun updateMyArchive() {
mArchiveFragment?.onLoadRefresh()
}
fun updateMyDownloadArchive() {
mDownloadArchiveFragment?.onLoadRefresh()
}
fun updateMyShareArchive() {
mShareArchiveFragment?.onLoadRefresh()
}
companion object {
const val MY_ARCHIVE_INDEX = 0
const val MY_DOWNLOAD_ARCHIVE_INDEX = 1
const val MY_SHARE_ARCHIVE_INDEX = 2
private const val DEV_HELP_ARTICLE_ID = "173387"
private const val HELP_ARTICLE_ID = "202342"
@JvmStatic
fun getIntent(context: Context, gameEntity: GameEntity, configUrl: String, entrance: String): Intent {
return Intent(context, CloudArchiveManagerActivity::class.java).apply {
putExtra(EntranceConsts.KEY_GAME, gameEntity)
putExtra(EntranceConsts.KEY_ARCHIVE_CONFIG_URL, configUrl)
putExtra(EntranceConsts.KEY_ENTRANCE, entrance)
}
}
}
}

View File

@ -1,221 +0,0 @@
package com.gh.gamecenter.cloudarchive
import android.annotation.SuppressLint
import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.gh.common.util.NewFlatLogUtils
import com.gh.gamecenter.common.baselist.ListViewModel
import com.gh.gamecenter.common.baselist.LoadType
import com.gh.gamecenter.common.retrofit.BiResponse
import com.gh.gamecenter.common.utils.toRequestBody
import com.gh.gamecenter.entity.ArchiveEntity
import com.gh.gamecenter.retrofit.RetrofitManager
import com.gh.vspace.VArchiveHelper
import com.halo.assistant.HaloApp
import com.lightgame.utils.Utils
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import okhttp3.*
import java.io.IOException
class CloudArchiveManagerViewModel(
application: Application,
private val mType: MyArchiveFragment.Type = MyArchiveFragment.Type.MY_ARCHIVE,
val gameId: String,
val configUrl: String
) :
ListViewModel<ArchiveEntity, ArchiveEntity>(application) {
var archiveConfigStr = ""
private val mApi = RetrofitManager.getInstance().newApi
val uploadSuccess = MutableLiveData<Boolean>()
val shareSuccess = MutableLiveData<Boolean>()
init {
if (configUrl.isNotEmpty()) getArchiveConfigString(configUrl)
}
override fun mergeResultLiveData() {
mResultLiveData.addSource(mListLiveData) { list ->
list.forEach { it.gameId = gameId }
mResultLiveData.postValue(list)
}
}
override fun provideDataObservable(page: Int): Observable<List<ArchiveEntity>>? = when (mType) {
MyArchiveFragment.Type.MY_ARCHIVE -> {
mApi.getMyArchives(gameId, page)
}
MyArchiveFragment.Type.MY_DOWNLOAD_ARCHIVE -> null
MyArchiveFragment.Type.MY_SHARE_ARCHIVE -> mApi.getMyShareArchives(gameId, page)
}
override fun provideDataSingle(page: Int): Single<MutableList<ArchiveEntity>>? {
return if (mType == MyArchiveFragment.Type.MY_DOWNLOAD_ARCHIVE) {
Single.create { emitter ->
val downloadList = VArchiveHelper.vArchiveEntityListLiveData.value
val archiveEntityList = arrayListOf<ArchiveEntity>()
if (downloadList != null) {
for (vArchiveEntity in downloadList) {
if (vArchiveEntity.gameId == gameId && vArchiveEntity.type == 1) {
archiveEntityList.add(
ArchiveEntity(
id = vArchiveEntity.id,
name = vArchiveEntity.name,
gameId = vArchiveEntity.gameId,
desc = vArchiveEntity.descContent,
url = vArchiveEntity.url,
configUrl = vArchiveEntity.configUrl,
md5 = vArchiveEntity.md5,
time = ArchiveEntity.Time(update = vArchiveEntity.time),
gameVersion = vArchiveEntity.gameVersion
)
)
}
}
}
emitter.onSuccess(archiveEntityList)
}
} else {
null
}
}
@SuppressLint("CheckResult")
fun postArchive(archiveEntity: ArchiveEntity) {
val paramsMap = mapOf(
"name" to archiveEntity.name,
"url" to archiveEntity.url,
"config_url" to archiveEntity.configUrl,
"game_version" to archiveEntity.gameVersion,
"md5" to archiveEntity.md5
)
mApi.postMyArchive(gameId, paramsMap.toRequestBody())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : BiResponse<ResponseBody>() {
override fun onSuccess(data: ResponseBody) {
uploadSuccess.postValue(true)
}
override fun onFailure(exception: Exception) {
super.onFailure(exception)
uploadSuccess.postValue(false)
}
})
}
@SuppressLint("CheckResult")
fun shareArchive(archiveEntity: ArchiveEntity, shareName: String, shareDesc: String) {
val paramsMap = mapOf(
"share_name" to shareName,
"share_desc" to shareDesc,
"is_shared" to true
)
mApi.patchMyArchive(gameId, archiveEntity.id, paramsMap.toRequestBody())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : BiResponse<ResponseBody>() {
override fun onSuccess(data: ResponseBody) {
shareSuccess.postValue(true)
Utils.toast(getApplication(), "分享成功")
NewFlatLogUtils.logCloudArchiveShareDialogResult("分享成功")
}
override fun onFailure(exception: Exception) {
super.onFailure(exception)
shareSuccess.postValue(false)
Utils.toast(getApplication(), "分享失败")
NewFlatLogUtils.logCloudArchiveShareDialogResult("分享失败")
}
})
}
@SuppressLint("CheckResult")
fun cancelShareArchive(archiveEntity: ArchiveEntity) {
val paramsMap = mapOf(
"is_shared" to false
)
mApi.patchMyArchive(gameId, archiveEntity.id, paramsMap.toRequestBody())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : BiResponse<ResponseBody>() {
override fun onSuccess(data: ResponseBody) {
load(LoadType.REFRESH)
Utils.toast(getApplication(), "取消分享成功")
}
override fun onFailure(exception: Exception) {
super.onFailure(exception)
Utils.toast(getApplication(), "取消分享失败")
}
})
}
@SuppressLint("CheckResult")
fun editMyArchive(archiveEntity: ArchiveEntity) {
val paramsMap = mapOf(
"name" to archiveEntity.name
)
mApi.patchMyArchive(gameId, archiveEntity.id, paramsMap.toRequestBody())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : BiResponse<ResponseBody>() {
override fun onSuccess(data: ResponseBody) {
load(LoadType.REFRESH)
}
})
}
@SuppressLint("CheckResult")
fun deleteArchive(archiveEntity: ArchiveEntity) {
mApi.deleteMyArchive(gameId, archiveEntity.id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : BiResponse<ResponseBody>() {
override fun onSuccess(data: ResponseBody) {
load(LoadType.REFRESH)
Utils.toast(getApplication(), "删除成功")
}
override fun onFailure(exception: Exception) {
super.onFailure(exception)
Utils.toast(getApplication(), "删除失败")
}
})
}
// 通过url获取config字符串内容
private fun getArchiveConfigString(url: String) {
OkHttpClient().newCall(
Request.Builder()
.url(url)
.build()
)
.enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
e.printStackTrace()
}
override fun onResponse(call: Call, response: Response) {
archiveConfigStr = response.body()?.string() ?: ""
}
})
}
class Factory(
val type: MyArchiveFragment.Type = MyArchiveFragment.Type.MY_ARCHIVE,
val gameId: String,
val configUrl: String
) : ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return CloudArchiveManagerViewModel(HaloApp.getInstance().application, type, gameId, configUrl) as T
}
}
}

View File

@ -1,109 +0,0 @@
package com.gh.gamecenter.cloudarchive
import android.content.Context
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import com.gh.common.util.ArchiveDownloadButtonHelper
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.baselist.ListAdapter
import com.gh.gamecenter.common.constant.ItemViewType
import com.gh.gamecenter.common.utils.formatTime
import com.gh.gamecenter.common.utils.toBinding
import com.gh.gamecenter.common.viewholder.FooterViewHolder
import com.gh.gamecenter.databinding.ItemMyArchiveBinding
import com.gh.gamecenter.databinding.ItemMyShareArchiveBinding
import com.gh.gamecenter.entity.ArchiveEntity
class MyArchiveAdapter(
context: Context,
private val mFragment: Fragment,
private val mViewModel: CloudArchiveManagerViewModel,
private val mType: MyArchiveFragment.Type,
private val mPackageName: String
) : ListAdapter<ArchiveEntity>(context) {
override fun getItemViewType(position: Int): Int {
return if (position == itemCount - 1) ItemViewType.ITEM_FOOTER else ItemViewType.ITEM_BODY
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder =
if (viewType == ItemViewType.ITEM_FOOTER) FooterViewHolder(
mLayoutInflater.inflate(
R.layout.refresh_footerview,
parent,
false
)
) else if (mType == MyArchiveFragment.Type.MY_SHARE_ARCHIVE) {
MyShareArchiveItemViewHolder(parent.toBinding())
} else {
MyArchiveItemViewHolder(parent.toBinding())
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is MyArchiveItemViewHolder) {
val entity = mEntityList[position]
holder.binding.run {
titleTv.text = entity.name
timeTv.text = entity.time.update.formatTime("yyyy-MM-dd HH:mm")
versionTv.text = "版本:${entity.gameVersion}"
optionsIv.setOnClickListener {
MyArchiveOptionDialogFragment.show(mContext as AppCompatActivity, mViewModel, mType, entity)
}
val entrance = if (mType == MyArchiveFragment.Type.MY_ARCHIVE) "云存档-我的存档" else "云存档-我的下载"
ArchiveDownloadButtonHelper.bindItem(
mContext,
entrance,
mFragment,
mPackageName,
entity,
actionTv
) {
if (mContext is CloudArchiveManagerActivity) {
(mContext as CloudArchiveManagerActivity).updateMyShareArchive()
(mContext as CloudArchiveManagerActivity).updateMyDownloadArchive()
}
}
}
}
if (holder is MyShareArchiveItemViewHolder) {
val entity = mEntityList[position]
holder.binding.run {
titleTv.text = entity.name
timeTv.text = entity.time.update.formatTime("yyyy-MM-dd HH:mm")
versionTv.text = "版本:${entity.gameVersion}"
descTv.text = entity.desc
optionsIv.setOnClickListener {
MyArchiveOptionDialogFragment.show(mContext as AppCompatActivity, mViewModel, mType, entity)
}
ArchiveDownloadButtonHelper.bindItem(
mContext,
"云存档-我的分享",
mFragment,
mPackageName,
entity,
actionTv
) {
if (mContext is CloudArchiveManagerActivity) {
(mContext as CloudArchiveManagerActivity).updateMyArchive()
(mContext as CloudArchiveManagerActivity).updateMyDownloadArchive()
}
}
}
}
if (holder is FooterViewHolder) {
holder.initItemPadding()
holder.initFooterViewHolder(mViewModel, mIsLoading, mIsNetworkError, mIsOver)
}
}
override fun getItemCount(): Int = if (mEntityList.isNullOrEmpty()) 0 else mEntityList.size + FOOTER_ITEM_COUNT
class MyArchiveItemViewHolder(val binding: ItemMyArchiveBinding) : BaseRecyclerViewHolder<Any>(binding.root)
class MyShareArchiveItemViewHolder(val binding: ItemMyShareArchiveBinding) :
BaseRecyclerViewHolder<Any>(binding.root)
}

View File

@ -1,145 +0,0 @@
package com.gh.gamecenter.cloudarchive
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.gh.common.util.CheckLoginUtils
import com.gh.common.util.NewFlatLogUtils
import com.gh.gamecenter.R
import com.gh.gamecenter.common.baselist.ListAdapter
import com.gh.gamecenter.common.baselist.ListFragment
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.eventbus.EBReuse
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.common.view.CustomDividerItemDecoration
import com.gh.gamecenter.databinding.FragmentMyArchiveBinding
import com.gh.gamecenter.entity.ArchiveEntity
import com.gh.gamecenter.entity.GameEntity
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
open class MyArchiveFragment : ListFragment<ArchiveEntity, CloudArchiveManagerViewModel>() {
protected var mGameEntity: GameEntity? = null
protected var mType: Type = Type.MY_ARCHIVE
protected val mBinding: FragmentMyArchiveBinding by lazy { FragmentMyArchiveBinding.inflate(layoutInflater) }
protected val mViewModel: CloudArchiveManagerViewModel by lazy {
viewModelProvider(
CloudArchiveManagerViewModel.Factory(
mType, mGameEntity?.id ?: "", ""
)
)
}
protected val mAdapter by lazy {
MyArchiveAdapter(
requireContext(),
this,
provideListViewModel(),
mType,
mGameEntity?.getUniquePackageName() ?: ""
)
}
override fun getLayoutId(): Int = 0
override fun getInflatedLayout() = mBinding.root
override fun provideListAdapter(): ListAdapter<*> = mAdapter
override fun provideListViewModel(): CloudArchiveManagerViewModel = mViewModel
override fun getItemDecoration(): RecyclerView.ItemDecoration =
CustomDividerItemDecoration(requireContext(), notDecorateTheLastTwoItems = true).apply {
setDrawable(R.drawable.divider_item_line_space_16.toDrawable(requireContext())!!)
}
override fun onCreate(savedInstanceState: Bundle?) {
mGameEntity = requireArguments().getParcelable(EntranceConsts.KEY_GAME)
super.onCreate(savedInstanceState)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mBinding.reuseNoneData.root.setBackgroundColor(R.color.background_white.toColor(requireContext()))
mBinding.reuseDataException.root.setBackgroundColor(R.color.background_white.toColor(requireContext()))
mBinding.reuseNoConnection.root.setBackgroundColor(R.color.background_white.toColor(requireContext()))
mBinding.reuseNoLogin.root.setBackgroundColor(R.color.background_white.toColor(requireContext()))
mBinding.reuseNoneData.reuseNoneDataTv.text = "还没有存档噢~"
mBinding.reuseNoneData.reuseNoneDataDescTv.text = "点击下方按钮上传您的游戏存档吧!"
mBinding.reuseNoneData.reuseNoneDataDescTv.visibility = View.VISIBLE
mBinding.reuseNoLogin.reuseNoneDataTv.text = "登录光环助手查看您的游戏存档~"
mBinding.reuseNoLogin.reuseResetLoadTv.text = "立即登录"
mBinding.reuseNoLogin.reuseNoneDataDescTv.visibility = View.GONE
mBinding.reuseNoLogin.reuseResetLoadTv.visibility = View.VISIBLE
mBinding.reuseNoLogin.reuseResetLoadTv.layoutParams =
mBinding.reuseNoLogin.reuseResetLoadTv.layoutParams.apply { width = 136F.dip2px() }
mBinding.reuseNoLogin.reuseResetLoadTv.setOnClickListener {
ifLogin("云存档-我的存档")
}
mBinding.reuseNoLogin.root.goneIf(CheckLoginUtils.isLogin())
mViewModel.shareSuccess.observeNonNull(viewLifecycleOwner) {
if (it && requireActivity() is CloudArchiveManagerActivity) {
(requireActivity() as CloudArchiveManagerActivity).updateMyShareArchive()
}
}
if (mType == Type.MY_ARCHIVE) {
NewFlatLogUtils.logCloudArchiveTabShow(mGameEntity?.id ?: "", mGameEntity?.name ?: "", "我的存档")
}
}
override fun onLoadEmpty() {
super.onLoadEmpty()
mBinding.tipsTv.visibility = View.GONE
}
override fun onLoadNotFound() {
super.onLoadNotFound()
mBinding.tipsTv.visibility = View.GONE
}
override fun onLoadError() {
super.onLoadError()
mBinding.tipsTv.visibility = View.GONE
}
override fun onLoadDone() {
super.onLoadDone()
mBinding.tipsTv.visibility = View.VISIBLE
}
override fun onLoadRefresh() {
super.onLoadRefresh()
mBinding.reuseNoLogin.root.goneIf(CheckLoginUtils.isLogin())
}
@Subscribe(threadMode = ThreadMode.MAIN)
open fun onEventMainThread(reuse: EBReuse) {
if (reuse.type == Constants.LOGIN_TAG) {
onLoadRefresh()
}
}
override fun onDarkModeChanged() {
super.onDarkModeChanged()
mBinding.reuseNoneData.root.setBackgroundColor(R.color.background_white.toColor(requireContext()))
mBinding.reuseDataException.root.setBackgroundColor(R.color.background_white.toColor(requireContext()))
mBinding.reuseNoConnection.root.setBackgroundColor(R.color.background_white.toColor(requireContext()))
mBinding.reuseNoLogin.root.setBackgroundColor(R.color.background_white.toColor(requireContext()))
}
enum class Type(val value: String) {
MY_ARCHIVE("my_archive"),
MY_DOWNLOAD_ARCHIVE("my_download_archive"),
MY_SHARE_ARCHIVE("my_share_archive");
companion object {
fun fromString(typeString: String): Type {
return values().find { typeString == it.value } ?: MY_ARCHIVE
}
}
}
}

View File

@ -1,241 +0,0 @@
package com.gh.gamecenter.cloudarchive
import android.app.Activity
import android.app.Dialog
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import androidx.core.widget.doOnTextChanged
import com.gh.common.util.NewFlatLogUtils
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.fragment.BaseDialogFragment
import com.gh.gamecenter.common.eventbus.EBReuse
import com.gh.gamecenter.common.utils.DialogHelper
import com.gh.gamecenter.common.utils.goneIf
import com.gh.gamecenter.common.utils.setRootBackgroundDrawable
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.core.runOnIoThread
import com.gh.gamecenter.databinding.DialogEditArchiveBinding
import com.gh.gamecenter.databinding.DialogMyArchiveOptionBinding
import com.gh.gamecenter.databinding.DialogShareArchiveBinding
import com.gh.gamecenter.entity.ArchiveEntity
import com.gh.vspace.VArchiveHelper
import com.halo.assistant.HaloApp
import com.lightgame.download.FileUtils
import org.greenrobot.eventbus.EventBus
class MyArchiveOptionDialogFragment(private val mViewModel: CloudArchiveManagerViewModel) : BaseDialogFragment() {
private lateinit var mBinding: DialogMyArchiveOptionBinding
private var mType = MyArchiveFragment.Type.MY_ARCHIVE
private var mGameId = ""
private var mArchiveEntity: ArchiveEntity? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return DialogMyArchiveOptionBinding.inflate(layoutInflater, null, false).apply {
mBinding = this
}.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mGameId = mViewModel.gameId
mType = MyArchiveFragment.Type.fromString(requireArguments().getString(KEY_ARCHIVE_TYPE, ""))
mArchiveEntity = requireArguments().getParcelable(KEY_ARCHIVE)
mBinding.editTv.goneIf(mType != MyArchiveFragment.Type.MY_ARCHIVE)
mBinding.shareTv.goneIf(mType != MyArchiveFragment.Type.MY_ARCHIVE)
mBinding.deleteTv.setOnClickListener {
NewFlatLogUtils.logCloudArchiveDeleteDialogShow()
DialogHelper.showDialog(
requireContext(),
"提示",
"删除存档数据后将无法恢复,\n" +
"是否删除?",
"确定删除",
"取消",
confirmClickCallback = {
NewFlatLogUtils.logCloudArchiveDeleteDialogClick("确定")
mArchiveEntity?.let { entity ->
when (mType) {
MyArchiveFragment.Type.MY_ARCHIVE -> {
if (VArchiveHelper.isArchiveDownloaded(entity.md5)) {
deleteLocalArchive(entity.md5)
}
mViewModel.deleteArchive(entity)
EventBus.getDefault().post(EBReuse("RefreshShareArchive"))
}
MyArchiveFragment.Type.MY_DOWNLOAD_ARCHIVE -> {
if (VArchiveHelper.isArchiveDownloaded(entity.md5)) {
deleteLocalArchive(entity.md5)
EventBus.getDefault().post(EBReuse("RefreshArchive"))
}
}
MyArchiveFragment.Type.MY_SHARE_ARCHIVE -> {
mViewModel.cancelShareArchive(entity)
}
}
}
},
cancelClickCallback = {
NewFlatLogUtils.logCloudArchiveDeleteDialogClick("取消")
},
uiModificationCallback = {
it.confirmTv.setTextColor(R.color.theme_red.toColor(requireContext()))
},
extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true)
)
dismissAllowingStateLoss()
}
mBinding.editTv.setOnClickListener {
showEditDialog()
dismissAllowingStateLoss()
}
mBinding.shareTv.setOnClickListener {
NewFlatLogUtils.logCloudArchiveShareDialogShow()
showShareDialog()
dismissAllowingStateLoss()
}
mBinding.cancelBtn.setOnClickListener {
dismissAllowingStateLoss()
}
}
private fun deleteLocalArchive(md5: String) {
VArchiveHelper.deleteArchive(md5)
val pathName = VArchiveHelper.getArchiveFilePath(md5)
if (pathName.isNotEmpty()) {
runOnIoThread { FileUtils.deleteFile(pathName) }
}
}
private fun showEditDialog() {
val dialog = Dialog(requireActivity())
val binding = DialogEditArchiveBinding.inflate(layoutInflater)
binding.run {
descTv.text = "当前存档名《${mArchiveEntity?.name}》,修改为"
clearIv.setOnClickListener {
contentEt.text.clear()
}
contentEt.doOnTextChanged { text, _, _, _ ->
clearIv.goneIf(text?.length == 0)
confirmTv.isEnabled = text?.length != 0
confirmTv.alpha = if (text?.length != 0) 1F else 0.4F
}
confirmTv.setOnClickListener {
mArchiveEntity?.let { entity ->
mViewModel.editMyArchive(entity.copy(name = contentEt.text.toString().trim()))
}
dialog.dismiss()
}
cancelTv.setOnClickListener {
dialog.dismiss()
}
}
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setContentView(binding.root)
dialog.setCanceledOnTouchOutside(true)
dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog.show()
}
private fun showShareDialog() {
val dialog = Dialog(requireActivity())
val binding = DialogShareArchiveBinding.inflate(layoutInflater)
binding.run {
mArchiveEntity?.let {
titleEt.setText(it.name)
clearTitleIv.goneIf(it.name.isEmpty())
}
clearTitleIv.setOnClickListener {
titleEt.text.clear()
}
clearDescIv.setOnClickListener {
descEt.text.clear()
}
titleEt.doOnTextChanged { text, _, _, _ ->
clearTitleIv.goneIf(text?.length == 0)
confirmTv.isEnabled = (text?.length != 0 && descEt.text.isNotEmpty())
confirmTv.alpha = if (text?.length != 0 && descEt.text.isNotEmpty()) 1F else 0.4F
}
descEt.doOnTextChanged { text, _, _, _ ->
clearDescIv.goneIf(text?.length == 0)
confirmTv.isEnabled = (text?.length != 0 && titleEt.text.isNotEmpty())
confirmTv.alpha = if (text?.length != 0 && titleEt.text.isNotEmpty()) 1F else 0.4F
}
confirmTv.setOnClickListener {
mArchiveEntity?.let { entity ->
mViewModel.shareArchive(entity, titleEt.text.toString().trim(), descEt.text.toString().trim())
}
NewFlatLogUtils.logCloudArchiveShareDialogClick("分享")
dialog.dismiss()
}
cancelTv.setOnClickListener {
NewFlatLogUtils.logCloudArchiveShareDialogClick("取消")
dialog.dismiss()
}
}
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setContentView(binding.root)
dialog.setCanceledOnTouchOutside(true)
dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog.show()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
dismissAllowingStateLoss()
}
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val createDialog = super.onCreateDialog(savedInstanceState)
createDialog.setCanceledOnTouchOutside(true)
val window = createDialog.window
window?.setGravity(Gravity.BOTTOM)
window?.setWindowAnimations(R.style.community_publication_animation)
return createDialog
}
override fun onStart() {
super.onStart()
val width = HaloApp.getInstance().application.resources.displayMetrics.widthPixels
val height = dialog?.window?.attributes?.height ?: ViewGroup.LayoutParams.WRAP_CONTENT
dialog?.window?.setLayout(width, height)
}
override fun onDarkModeChanged() {
super.onDarkModeChanged()
if (::mBinding.isInitialized) {
mBinding.run {
root.setRootBackgroundDrawable(R.drawable.background_shape_white_radius_12_top_only)
line1.setBackgroundColor(R.color.divider.toColor(requireContext()))
cancelBtn.setTextColor(R.color.text_subtitle.toColor(requireContext()))
}
}
}
companion object {
const val KEY_ARCHIVE_TYPE = "archive_type"
const val KEY_ARCHIVE = "archive"
fun show(
activity: AppCompatActivity,
mViewModel: CloudArchiveManagerViewModel,
archiveType: MyArchiveFragment.Type,
archiveEntity: ArchiveEntity
) {
MyArchiveOptionDialogFragment(mViewModel).apply {
arguments = bundleOf(
KEY_ARCHIVE_TYPE to archiveType.value,
KEY_ARCHIVE to archiveEntity
)
}.show(activity.supportFragmentManager, MyArchiveOptionDialogFragment::class.java.name)
}
}
}

View File

@ -1,55 +0,0 @@
package com.gh.gamecenter.cloudarchive
import android.os.Bundle
import android.view.View
import com.gh.gamecenter.common.baselist.LoadType
import com.gh.gamecenter.common.eventbus.EBReuse
import com.gh.gamecenter.core.AppExecutor
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
class MyDownloadArchiveFragment : MyArchiveFragment() {
var isEmpty = false
override fun onCreate(savedInstanceState: Bundle?) {
mType = Type.MY_DOWNLOAD_ARCHIVE
super.onCreate(savedInstanceState)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mBinding.reuseNoneData.reuseNoneDataTv.text = "还没有存档噢~"
mBinding.reuseNoneData.reuseNoneDataDescTv.text = "去看看大家上传的热门存档吧!"
}
override fun onLoadDone() {
super.onLoadDone()
isEmpty = false
mBinding.tipsTv.visibility = View.GONE
if (requireActivity() is CloudArchiveManagerActivity) {
(requireActivity() as CloudArchiveManagerActivity).controlUploadGameArchive()
}
}
override fun onLoadEmpty() {
super.onLoadEmpty()
isEmpty = true
if (requireActivity() is CloudArchiveManagerActivity) {
(requireActivity() as CloudArchiveManagerActivity).controlUploadGameArchive()
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
override fun onEventMainThread(reuse: EBReuse) {
super.onEventMainThread(reuse)
if ("RefreshArchive" == reuse.type) {
AppExecutor.uiExecutor.executeWithDelay({
mListViewModel.load(LoadType.REFRESH)
if (requireActivity() is CloudArchiveManagerActivity) {
(requireActivity() as CloudArchiveManagerActivity).updateMyArchive()
(requireActivity() as CloudArchiveManagerActivity).updateMyShareArchive()
}
}, 200)
}
}
}

View File

@ -1,48 +0,0 @@
package com.gh.gamecenter.cloudarchive
import android.os.Bundle
import android.view.View
import com.gh.gamecenter.common.baselist.LoadType
import com.gh.gamecenter.common.eventbus.EBReuse
import com.gh.gamecenter.core.AppExecutor
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
class MyShareArchiveFragment : MyArchiveFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
mType = Type.MY_SHARE_ARCHIVE
super.onCreate(savedInstanceState)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mBinding.tipsTv.visibility = View.GONE
mBinding.reuseNoneData.reuseNoneDataTv.text = "还没有您分享存档噢~"
mBinding.reuseNoneData.reuseNoneDataDescTv.text = "快快把您的有趣存档分享给大家吧!"
}
override fun onLoadDone() {
super.onLoadDone()
mBinding.tipsTv.visibility = View.GONE
if (requireActivity() is CloudArchiveManagerActivity) {
(requireActivity() as CloudArchiveManagerActivity).controlUploadGameArchive()
}
}
override fun onLoadEmpty() {
super.onLoadEmpty()
if (requireActivity() is CloudArchiveManagerActivity) {
(requireActivity() as CloudArchiveManagerActivity).controlUploadGameArchive()
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
override fun onEventMainThread(reuse: EBReuse) {
super.onEventMainThread(reuse)
if ("RefreshShareArchive" == reuse.type) {
AppExecutor.uiExecutor.executeWithDelay({
mListViewModel.load(LoadType.REFRESH)
}, 200)
}
}
}

View File

@ -14,7 +14,6 @@ import com.gh.gamecenter.common.syncpage.ISyncAdapterHandler;
import com.gh.common.util.CollectionUtils;
import com.gh.gamecenter.common.utils.DialogHelper;
import com.gh.gamecenter.common.utils.ExtensionsKt;
import com.gh.gamecenter.common.view.DrawableView;
import com.gh.gamecenter.core.utils.DisplayUtils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.common.viewholder.FooterViewHolder;
@ -233,11 +232,6 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> implements ISyncAda
}
});
mPopupBinding.checkAllCb.setCompoundDrawablesWithIntrinsicBounds(
DrawableView.getCheckSelectorDrawable(
mContext
), null, null, null
);
mPopupBinding.checkAllCb.setOnClickListener(v -> {
if (mPopupBinding.checkAllCb.isChecked()) {
selectItems.clear();

View File

@ -16,7 +16,6 @@ import com.gh.gamecenter.common.callback.OnListClickListener;
import com.gh.gamecenter.common.constant.ItemViewType;
import com.gh.gamecenter.common.utils.DialogHelper;
import com.gh.gamecenter.common.utils.ExtensionsKt;
import com.gh.gamecenter.common.view.DrawableView;
import com.gh.gamecenter.core.utils.DisplayUtils;
import com.gh.gamecenter.common.utils.ImageUtils;
import com.gh.common.util.NewsUtils;
@ -362,11 +361,6 @@ public class ArticleAdapter extends ListAdapter<NewsEntity> {
}
});
mPopupBinding.checkAllCb.setCompoundDrawablesWithIntrinsicBounds(
DrawableView.getCheckSelectorDrawable(
mContext
), null, null, null
);
mPopupBinding.checkAllCb.setOnClickListener(v -> {
if (mPopupBinding.checkAllCb.isChecked()) {
selectItems.clear();

View File

@ -18,7 +18,6 @@ import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.databinding.CommunityAnswerItemBinding
import com.gh.gamecenter.databinding.PopupHistoryOptionBinding
import com.gh.gamecenter.common.entity.CommunityEntity
import com.gh.gamecenter.common.view.DrawableView
import com.gh.gamecenter.history.ManageOption
import com.gh.gamecenter.qa.answer.CommunityAnswerItemViewHolder
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
@ -173,11 +172,6 @@ class CommunityArticleAdapter(
}, extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true))
}
mPopupBinding?.checkAllCb?.setCompoundDrawablesWithIntrinsicBounds(
DrawableView.getCheckSelectorDrawable(
mContext
), null, null, null
)
mPopupBinding?.checkAllCb?.setOnClickListener {
if (mPopupBinding?.checkAllCb?.isChecked == true) {
selectItems.clear()

View File

@ -24,7 +24,6 @@ import com.gh.gamecenter.adapter.viewholder.GameCollectionItemViewHolder
import com.gh.gamecenter.common.baselist.ListAdapter
import com.gh.gamecenter.collection.GamesCollectionFragment.Companion.TYPE_USER
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.common.view.DrawableView
import com.gh.gamecenter.core.utils.*
import com.gh.gamecenter.databinding.ItemGameCollectionFlexTagBinding
import com.gh.gamecenter.databinding.PopupHistoryOptionBinding
@ -425,11 +424,6 @@ class GamesCollectionAdapter(
}, extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true))
}
mPopupBinding?.checkAllCb?.setCompoundDrawablesWithIntrinsicBounds(
DrawableView.getCheckSelectorDrawable(
mContext
), null, null, null
)
mPopupBinding?.checkAllCb?.setOnClickListener {
if (mPopupBinding?.checkAllCb?.isChecked == true) {
selectItems.clear()

View File

@ -3,7 +3,6 @@ package com.gh.gamecenter.collection
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.drawable.StateListDrawable
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
@ -18,7 +17,6 @@ import com.gh.gamecenter.R
import com.gh.gamecenter.common.viewholder.FooterViewHolder
import com.gh.gamecenter.common.baselist.ListAdapter
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.common.view.DrawableView
import com.gh.gamecenter.databinding.PopupHistoryOptionBinding
import com.gh.gamecenter.databinding.VideoNewItemBinding
import com.gh.gamecenter.entity.MyVideoEntity
@ -168,11 +166,6 @@ class VideoAdapter(
}, extraConfig = DialogHelper.Config(centerTitle = true, centerContent = true))
}
mPopupBinding?.checkAllCb?.setCompoundDrawablesWithIntrinsicBounds(
DrawableView.getCheckSelectorDrawable(
mContext
), null, null, null
)
mPopupBinding?.checkAllCb?.setOnClickListener {
if (mPopupBinding?.checkAllCb?.isChecked == true) {
selectItems.clear()

View File

@ -14,9 +14,8 @@ import com.gh.common.exposure.ExposureEvent
import com.gh.common.exposure.ExposureSource
import com.gh.common.exposure.ExposureType
import com.gh.common.exposure.IExposable
import com.gh.common.util.DirectUtils
import com.gh.common.util.DownloadItemUtils
import com.gh.common.util.HomeBottomBarHelper
import com.gh.common.util.*
import com.gh.common.util.DialogUtils
import com.gh.common.util.NewFlatLogUtils
import com.gh.gamecenter.BlockActivity
import com.gh.gamecenter.GameDetailActivity
@ -26,6 +25,7 @@ import com.gh.gamecenter.adapter.viewholder.GameViewHolder
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.baselist.ListAdapter
import com.gh.gamecenter.common.baselist.LoadStatus
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.constant.ItemViewType
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.common.viewholder.FooterViewHolder
@ -48,8 +48,7 @@ class DiscoveryAdapter(
private val mViewModel: DiscoveryViewModel,
private val mBaseExposureSource: ArrayList<ExposureSource>,
private val mOuterSequence: Int,
private val mEntrance: String,
private val mDislikeCallback: (anchorView: View, position: Int, gameEntity: GameEntity) -> Unit
private val mEntrance: String
) : ListAdapter<DiscoveryItemData>(context), IExposable {
private val mExposureEventSparseArray: SparseArray<ExposureEvent> = SparseArray()
@ -151,7 +150,7 @@ class DiscoveryAdapter(
)
}
holder.itemView.setOnLongClickListener {
mDislikeCallback.invoke(holder.itemView, position, gameEntity)
discoveryFeedback(position, gameEntity)
true
}
DownloadItemUtils.setOnClickListener(
@ -175,7 +174,12 @@ class DiscoveryAdapter(
labelTv.goneIf(labels.size < index + 1) {
labelTv.setTextColor(R.color.text_subtitle.toColor(mContext))
labelTv.background = R.drawable.bg_shape_white_radius_4.toDrawable(mContext)
labelTv.setDrawableEnd(R.drawable.ic_interest_arrow)
labelTv.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
R.drawable.ic_interest_arrow.toDrawable(mContext),
null
)
labels[index].text = labels[index].linkText
labelTv.text = labels[index].title
labelTv.setOnClickListener {
@ -234,6 +238,21 @@ class DiscoveryAdapter(
return if (mEntityList == null || mEntityList.isEmpty()) return 0 else mEntityList.size + 1
}
private fun discoveryFeedback(position: Int, gameEntity: GameEntity) {
DialogUtils.showReportReasonDialog(
mContext,
Constants.FEEDBACK_REASON_LIST.toList() as ArrayList<String>,
"不喜欢的原因"
) { reason, _ ->
mViewModel.discoveryFeedback(gameEntity.id, reason, gameEntity.type ?: "") {
NewFlatLogUtils.logDiscoverPageNotInterest(gameEntity.id, gameEntity.name ?: "")
mViewModel.forceRefresh = true
mEntityList.removeAt(position)
notifyItemRemoved(position)
}
}
}
fun notifyItemByDownload(download: DownloadEntity) {
val positionAndPackageMap = mViewModel.positionAndPackageMap
for (key in positionAndPackageMap.keys) {
@ -279,7 +298,11 @@ class DiscoveryAdapter(
class DiscoveryGameViewHolder(val binding: DiscoveryGameItemBinding) : GameViewHolder(binding.root) {
init {
gameDownloadBtn = binding.downloadBtn
gameProgressbar = binding.gameProgressbar
gameInfo = binding.gameInfo
gameDownloadPercentage = binding.downloadPercentage
gameDes = binding.gameDes
gameDownloadSpeed = binding.downloadSpeed
gameRating = binding.gameRating
recommendContainer = binding.recommendContainer
recommendIv = binding.recommendIv
@ -297,7 +320,12 @@ class DiscoveryAdapter(
gameIconView.displayGameIcon(gameEntity)
BindingAdapters.setGameName(gameName, gameEntity, false, null)
BindingAdapters.setTextSize(gameRating, if (gameEntity.commentCount > 3) 12 else 10)
gameRating.setDrawableStart(if (gameEntity.commentCount > 3) R.drawable.game_horizontal_rating.toDrawable() else null)
gameRating.setCompoundDrawablesWithIntrinsicBounds(
if (gameEntity.commentCount > 3) R.drawable.game_horizontal_rating.toDrawable() else null,
null,
null,
null
)
gameRating.text = if (gameEntity.commentCount > 3) {
if (gameEntity.star == 10.0F) "10" else gameEntity.star.toString()
} else {
@ -324,14 +352,19 @@ class DiscoveryAdapter(
recommendReasonTv.text =
"${gameEntity.columnRank!!.name}·第${gameEntity.columnRank!!.position}"
recommendReasonTv.setTextColor(R.color.theme_yellow.toColor(binding.root.context))
recommendReasonTv.setDrawableStart(R.drawable.ic_discovery_rank)
recommendReasonTv.setCompoundDrawablesWithIntrinsicBounds(
R.drawable.ic_discovery_rank.toDrawable(binding.root.context),
null,
null,
null
)
recommendReasonTv.background =
R.drawable.bg_discovery_recommend.toDrawable(binding.root.context)
recommendReasonTv.visibility = View.VISIBLE
} else if (gameEntity.type == "recommend") {
recommendReasonTv.text = "其他玩家推荐"
recommendReasonTv.setTextColor(R.color.theme_font.toColor(binding.root.context))
recommendReasonTv.removeDrawable()
recommendReasonTv.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null)
recommendReasonTv.background = R.drawable.bg_discovery_rank.toDrawable(binding.root.context)
recommendReasonTv.visibility = View.VISIBLE
}

View File

@ -1,12 +1,8 @@
package com.gh.gamecenter.discovery
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -24,16 +20,14 @@ import com.gh.gamecenter.common.baselist.LazyListFragment
import com.gh.gamecenter.common.baselist.ListAdapter
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.common.utils.getBitmapFromView
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.core.AppExecutor
import com.gh.gamecenter.core.utils.SPUtils
import com.gh.gamecenter.core.utils.ToastUtils
import com.gh.gamecenter.databinding.LayoutDiscoveryGuideBinding
import com.gh.gamecenter.databinding.LayoutPopupDiscoveryDislikeBinding
import com.gh.gamecenter.entity.GameEntity
import com.gh.gamecenter.eventbus.EBDownloadStatus
import com.gh.gamecenter.eventbus.EBPackage
import com.google.android.flexbox.FlexboxLayout
import com.lightgame.download.DataWatcher
import com.lightgame.download.DownloadEntity
import org.greenrobot.eventbus.Subscribe
@ -142,18 +136,12 @@ class DiscoveryFragment : LazyListFragment<DiscoveryItemData, DiscoveryViewModel
arguments?.getParcelable<ExposureSource>(EntranceConsts.KEY_EXPOSURE_SOURCE)?.let { add(it) }
}
val outerSequence = requireArguments().getInt(EntranceConsts.KEY_POSITION, -1)
val dislikeCallback: (anchorView: View, position: Int, gameEntity: GameEntity) -> Unit =
{ view, position, entity ->
showDislikeWindow(view, position, entity)
}
return mAdapter ?: DiscoveryAdapter(
requireContext(),
mListViewModel,
basicExposureSource,
outerSequence,
"发现页",
dislikeCallback,
"发现页"
).also { mAdapter = it }
}
@ -242,78 +230,6 @@ class DiscoveryFragment : LazyListFragment<DiscoveryItemData, DiscoveryViewModel
}
}
private fun showDislikeWindow(view: View, position: Int, gameEntity: GameEntity) {
val decorView = requireActivity().window.decorView as? FrameLayout
val binding = LayoutPopupDiscoveryDislikeBinding.inflate(LayoutInflater.from(requireContext()), decorView, true)
binding.reasonFlex.removeAllViews()
Constants.FEEDBACK_REASON_LIST.toList().forEach {
val popupItem = getPopupItem(it)
val params =
FlexboxLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
binding.reasonFlex.addView(popupItem, params)
popupItem.setOnClickListener {
mListViewModel.discoveryFeedback(gameEntity.id, popupItem.text.toString(), gameEntity.type ?: "") {
NewFlatLogUtils.logDiscoverPageNotInterest(gameEntity.id, gameEntity.name ?: "")
mListViewModel.forceRefresh = true
mAdapter?.entityList?.removeAt(position)
mAdapter?.notifyItemRemoved(position)
decorView?.removeView(binding.root)
ToastUtils.showToast("已根据你的偏好优化推荐机制~", Gravity.CENTER)
}
}
}
binding.root.setOnClickListener {
decorView?.removeView(it)
}
binding.contentView.visibility = View.INVISIBLE
binding.contentView.post {
val (windowPosition, isNeedShowUp) = getWindowPosition(view, binding.contentView, 36F.dip2px())
(binding.contentView.layoutParams as RelativeLayout.LayoutParams).run {
topMargin = windowPosition[1]
binding.contentView.layoutParams = this
}
binding.anchorUpIv.goneIf(isNeedShowUp)
binding.anchorDownIv.goneIf(!isNeedShowUp)
binding.contentView.visibility = View.VISIBLE
}
}
private fun getPopupItem(reason: String): TextView {
return TextView(requireContext()).apply {
height = 32F.dip2px()
text = reason
textSize = 12F
includeFontPadding = false
setTextColor(R.color.text_subtitle.toColor(requireContext()))
gravity = Gravity.CENTER
setPadding(12F.dip2px(), 0F.dip2px(), 12F.dip2px(), 0F.dip2px())
background = R.drawable.bg_shape_space_radius_8.toDrawable(requireContext())
}
}
private fun getWindowPosition(
anchorView: View,
contentView: View,
distanceY: Int = 0
): Pair<IntArray, Boolean> {
val windowPos = IntArray(2)
val anchorLoc = IntArray(2)
anchorView.getLocationInWindow(anchorLoc)
val anchorHeight = anchorView.height
val screenHeight = anchorView.context.resources.displayMetrics.heightPixels
contentView.measure(0, 0)
val contentViewWidth = contentView.width
val contentViewHeight = contentView.height
val isNeedShowUp = screenHeight - anchorLoc[1] - anchorHeight < contentViewHeight
windowPos[1] = if (isNeedShowUp) {
anchorLoc[1] - contentViewHeight + distanceY
} else {
anchorLoc[1] + anchorHeight - distanceY
}
windowPos[0] = (anchorLoc[0] - contentViewWidth + anchorView.width) / 2
return Pair(windowPos, isNeedShowUp)
}
override fun onDarkModeChanged() {
super.onDarkModeChanged()
mListRv?.recycledViewPool?.clear()
@ -334,7 +250,7 @@ class DiscoveryFragment : LazyListFragment<DiscoveryItemData, DiscoveryViewModel
// 安装/卸载 事件
@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(busFour: EBPackage) {
if (busFour.isInstalledOrUninstalled()) {
if ("安装" == busFour.type || "卸载" == busFour.type) {
mAdapter?.notifyDataSetChanged()
}
}

View File

@ -8,7 +8,6 @@ import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DefaultItemAnimator;
@ -90,79 +89,81 @@ public class GameDownloadFragment extends BaseFragment implements View.OnClickLi
}
if (location != null) {
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
// 检查对应下载列表中是否存在该数据
boolean isContains = false;
for (DownloadEntity entity : adapter.getDownloadingList()) {
if (entity.getUrl().equals(downloadEntity.getUrl())) {
isContains = true;
break;
}
}
if (isContains) {
// 删除下载中列表对应数据
if (adapter.getDownloadingList().size() == 1) {
location = adapter.getLocation(downloadEntity.getUrl());
if (location != null) {
adapter.getDownloadingList().remove(location.intValue());
adapter.initLocationMap();
adapter.notifyItemRangeRemoved(adapter.getBase(), 2);
if (!"pause".equals(adapter.getStatusMap().get(downloadEntity.getUrl()))) {
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
// 检查对应下载列表中是否存在该数据
boolean isContains = false;
for (DownloadEntity entity : adapter.getDownloadingList()) {
if (entity.getUrl().equals(downloadEntity.getUrl())) {
isContains = true;
break;
}
}
if (isContains) {
// 删除下载中列表对应数据
if (adapter.getDownloadingList().size() == 1) {
location = adapter.getLocation(downloadEntity.getUrl());
if (location != null) {
adapter.getDownloadingList().remove(location.intValue());
adapter.initLocationMap();
adapter.notifyItemRangeRemoved(adapter.getBase(), 2);
}
} else {
location = adapter.getLocation(downloadEntity.getUrl());
if (location != null) {
adapter.getDownloadingList().remove(location.intValue());
adapter.initLocationMap();
adapter.notifyItemRemoved(adapter.getBase() + location + 1);
adapter.notifyItemChanged(adapter.getBase() + 1);
}
}
// 添加进已完成列表
if (adapter.getDoneList().isEmpty()) {
adapter.getDoneList().add(0, downloadEntity);
adapter.initLocationMap();
adapter.notifyItemRangeInserted(0, 2);
} else {
adapter.getDoneList().add(0, downloadEntity);
adapter.initLocationMap();
adapter.notifyItemInserted(1);
}
} else {
location = adapter.getLocation(downloadEntity.getUrl());
if (location != null) {
adapter.getDownloadingList().remove(location.intValue());
adapter.initLocationMap();
adapter.notifyItemRemoved(adapter.getBase() + location + 1);
adapter.notifyItemChanged(adapter.getBase() + 1);
adapter.notifyItemChanged(location + 1);
}
}
// 添加进已完成列表
if (adapter.getDoneList().isEmpty()) {
adapter.getDoneList().add(0, downloadEntity);
adapter.initLocationMap();
adapter.notifyItemRangeInserted(0, 2);
} else {
adapter.getDoneList().add(0, downloadEntity);
adapter.initLocationMap();
adapter.notifyItemInserted(1);
}
adapter.getUrlMap().put(PackageUtils.getPackageNameByPath(HaloApp.getInstance().getApplication(),
downloadEntity.getPath()), downloadEntity.getUrl());
// 用户焦点在下载管理页面时有任务完成,直接把所有下载完成的任务标记为已读
DownloadManager.getInstance().markDownloadedTaskAsRead();
} else if (DownloadStatus.cancel.equals(downloadEntity.getStatus())) { // 有可能由于网络劫持造成的
adapter.initMap();
adapter.notifyDataSetChanged();
int listSize = adapter.getDownloadingList().size() + adapter.getDoneList().size();
if (listSize == 0) {
EventBus.getDefault().post(new EBDownloadChanged("download", View.GONE, listSize));
if (mBinding.reuseNoneData.getRoot().getVisibility() == View.GONE) {
mBinding.reuseNoneData.getRoot().setVisibility(View.VISIBLE);
}
} else {
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE,
adapter.getDownloadingList().size()));
}
} else {
location = adapter.getLocation(downloadEntity.getUrl());
if (location != null) {
adapter.notifyItemChanged(location + 1);
if (location != null && adapter.getDownloadingList().size() > location) {
adapter.getDownloadingList().set(location, downloadEntity);
adapter.notifyItemChanged(adapter.getBase() + location + 1);
}
}
adapter.getUrlMap().put(PackageUtils.getPackageNameByPath(HaloApp.getInstance().getApplication(),
downloadEntity.getPath()), downloadEntity.getUrl());
// 用户焦点在下载管理页面时有任务完成,直接把所有下载完成的任务标记为已读
DownloadManager.getInstance().markDownloadedTaskAsRead();
} else if (DownloadStatus.cancel.equals(downloadEntity.getStatus())) { // 有可能由于网络劫持造成的
adapter.initMap();
adapter.notifyDataSetChanged();
int listSize = adapter.getDownloadingList().size() + adapter.getDoneList().size();
if (listSize == 0) {
EventBus.getDefault().post(new EBDownloadChanged("download", View.GONE, listSize));
if (mBinding.reuseNoneData.getRoot().getVisibility() == View.GONE) {
mBinding.reuseNoneData.getRoot().setVisibility(View.VISIBLE);
}
} else {
EventBus.getDefault().post(new EBDownloadChanged("download", View.VISIBLE,
adapter.getDownloadingList().size()));
if (downloadEntity.getStatus() == DownloadStatus.neterror) {
adapter.notifyItemChanged(adapter.getBase());
}
} else {
location = adapter.getLocation(downloadEntity.getUrl());
if (location != null && adapter.getDownloadingList().size() > location) {
adapter.getDownloadingList().set(location, downloadEntity);
adapter.notifyItemChanged(adapter.getBase() + location + 1);
}
}
if (downloadEntity.getStatus() == DownloadStatus.neterror) {
adapter.notifyItemChanged(adapter.getBase());
}
} else {
if (!adapter.getDeleteList().contains(downloadEntity.getUrl())) {
@ -347,7 +348,7 @@ public class GameDownloadFragment extends BaseFragment implements View.OnClickLi
if (url != null) {
Integer location = adapter.getLocation(url);
if (location != null) {
if (EBPackage.TYPE_INSTALLED.equals(busFour.getType())) {
if ("安装".equals(busFour.getType())) {
// DownloadEntity downloadEntity = DownloadManager.getInstance(getActivity()).get(url);
// if (downloadEntity == null
// || !downloadEntity.isPlugin() // 不是插件游戏,自己删除数据库数据和安装包

View File

@ -60,8 +60,6 @@ class GameDownloadFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
private final List<DownloadEntity> mDownloadingList;
private final List<DownloadEntity> mDownloadedList;
private final ArrayMap<String, String> xapkStatusMap;
// 1、此处的所有MAP只是对DownloadManager内部Map的引用
// 2、任何对下载器任务的操作通过DownloadManager处理由DownloadManager处理之后抛出对应的状态变化事件
// 3、监听下载任务状态变化刷新界面
@ -88,7 +86,6 @@ class GameDownloadFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
deleteList = new ArrayList<>();
mDownloadedList = new ArrayList<>();
xapkStatusMap = new ArrayMap<>();
}
@NonNull
@ -109,7 +106,8 @@ class GameDownloadFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
viewHolder.binding.getRoot().setBackground(ContextCompat.getDrawable(mContext, R.drawable.reuse_listview_item_style));
viewHolder.binding.dmItemTvTitle.setTextColor(ContextCompat.getColor(mContext, R.color.text_title));
ExtensionsKt.removeDrawable(viewHolder.binding.dmItemTvSpeed);
viewHolder.binding.dmItemTvDownloads.setTextColor(ContextCompat.getColor(mContext, R.color.text_subtitleDesc));
viewHolder.binding.dmItemTvSpeed.setTextColor(ContextCompat.getColor(mContext, R.color.text_9a9a9a));
final DownloadEntity downloadEntity;
if (mDownloadedList.size() != 0 && position > 0 && position <= mDownloadedList.size()) {
@ -158,112 +156,114 @@ class GameDownloadFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
}
DownloadStatus status = downloadEntity.getStatus();
String xapkStatus = downloadEntity.getMeta().get(XapkInstaller.XAPK_UNZIP_STATUS);
if (status.equals(DownloadStatus.done)) {
if (XapkUnzipStatus.UNZIPPING.name().equals(xapkStatus)) {
// XAPK状态有几率在SUCCESS后返回UNZIPPING, 此处对UNZIPPING之前的状态做一个判断
if (XapkUnzipStatus.SUCCESS.name().equals(xapkStatusMap.get(downloadEntity.getUrl()))) {
XapkInstaller.cancelUnzipTask(downloadEntity);
return;
}
String percent = downloadEntity.getMeta().get(XapkInstaller.XAPK_UNZIP_PERCENT);
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.XAPK_UNZIPPING);
viewHolder.binding.dmItemTvStartorpause.setProgress((int) (Float.parseFloat(percent == null ? "0" : percent) * 10));
viewHolder.binding.dmItemTvStartorpause.setText(percent + "%");
viewHolder.binding.dmItemTvSpeed.setTextColor(mContext.getResources().getColor(R.color.text_subtitleDesc));
viewHolder.binding.dmItemTvSpeed.setText(R.string.unzipping);
return;
} else if (XapkUnzipStatus.FAILURE.name().equals(xapkStatus)) {
viewHolder.binding.dmItemTvStartorpause.setText(R.string.install);
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.INSTALL_NORMAL);
viewHolder.binding.dmItemTvStartorpause.setProgress((int) (downloadEntity.getPercent() * 10));
viewHolder.binding.dmItemTvSpeed.setTextColor(ContextCompat.getColor(mContext, R.color.theme_red));
viewHolder.binding.dmItemTvSpeed.setText("解压失败");
ExtensionsKt.setDrawableStart(viewHolder.binding.dmItemTvSpeed, R.drawable.unzip_failure_hint, null, null);
return;
} else if (XapkUnzipStatus.SUCCESS.name().equals(xapkStatus)) {
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.XAPK_SUCCESS);
viewHolder.binding.dmItemTvStartorpause.setProgress(1000);
viewHolder.binding.dmItemTvStartorpause.setText(R.string.hundred_percent);
}
if (xapkStatus != null && !xapkStatus.isEmpty()) {
xapkStatusMap.put(downloadEntity.getUrl(), xapkStatus);
}
viewHolder.binding.dmItemTvSpeed.setTextColor(ContextCompat.getColor(mContext, R.color.text_subtitleDesc));
viewHolder.binding.dmItemTvSpeed.setText("加载完成");
viewHolder.binding.dmItemTvStartorpause.setText(R.string.install);
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
viewHolder.binding.dmItemTvDownloads.setLayoutParams(lparams);
viewHolder.binding.dmItemTvDownloads.setTextColor(0xFF9A9A9A);
viewHolder.binding.dmItemTvDownloads.setText("下载完成");
viewHolder.binding.dmItemIvDelete.setVisibility(View.VISIBLE);
if (downloadEntity.isPluggable()
&& PackagesManager.isInstalled(downloadEntity.getPackageName())) {
viewHolder.binding.dmItemTvStartorpause.setText("安装");
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.INSTALL_PLUGIN);
} else {
viewHolder.binding.dmItemTvStartorpause.setText("安装");
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.INSTALL_NORMAL);
}
} else if (status.equals(DownloadStatus.downloading) || status.equals(DownloadStatus.redirected)) {
viewHolder.binding.dmItemTvSpeed.setTextColor(ContextCompat.getColor(mContext, R.color.theme_font));
viewHolder.binding.dmItemTvSpeed.setText(String.format("%s(剩%s)",
SpeedUtils.getSpeed(downloadEntity.getSpeed()),
SpeedUtils.getRemainTime(downloadEntity.getSize(), downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024)));
viewHolder.binding.dmItemTvStartorpause.setText(downloadEntity.getPercent() + "%");
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.DOWNLOADING_NORMAL);
viewHolder.binding.dmItemTvStartorpause.setProgress((int) (downloadEntity.getPercent() * 10));
viewHolder.binding.dmItemTvSpeed.setText(R.string.hundred_percent);
} else if (status.equals(DownloadStatus.downloading)) {
if (!"pause".equals(statusMap.get(downloadEntity.getUrl()))) {
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
0, LinearLayout.LayoutParams.WRAP_CONTENT);
lparams.weight = 4;
viewHolder.binding.dmItemTvDownloads.setLayoutParams(lparams);
viewHolder.binding.dmItemTvDownloads.setTextColor(ContextCompat.getColor(mContext, R.color.theme_font));
viewHolder.binding.dmItemTvDownloads.setText(String.format("%s(剩%s)",
SpeedUtils.getSpeed(downloadEntity.getSpeed()),
SpeedUtils.getRemainTime(downloadEntity.getSize(), downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024)));
viewHolder.binding.dmItemIvDelete.setVisibility(View.GONE);
viewHolder.binding.dmItemTvStartorpause.setText("暂停");
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.PAUSE);
viewHolder.binding.dmItemTvSpeed.setText(downloadEntity.getPercent() + "%");
}
} else if (status.equals(DownloadStatus.waiting)) {
viewHolder.binding.dmItemTvSpeed.setTextColor(ContextCompat.getColor(mContext, R.color.text_subtitleDesc));
viewHolder.binding.dmItemTvSpeed.setText(R.string.waiting);
viewHolder.binding.dmItemTvStartorpause.setText(R.string.waiting);
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
viewHolder.binding.dmItemTvDownloads.setLayoutParams(lparams);
viewHolder.binding.dmItemTvDownloads.setTextColor(0xFF9A9A9A);
viewHolder.binding.dmItemTvDownloads.setText("等待中");
viewHolder.binding.dmItemIvDelete.setVisibility(View.VISIBLE);
viewHolder.binding.dmItemTvStartorpause.setText("等待");
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.WAITING);
viewHolder.binding.dmItemTvSpeed.setText(downloadEntity.getPercent() + "%");
} else if (status.equals(DownloadStatus.pause)
|| status.equals(DownloadStatus.timeout)
|| status.equals(DownloadStatus.neterror)
|| status.equals(DownloadStatus.subscribe)) {
viewHolder.binding.dmItemTvStartorpause.setText(R.string.resume);
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
viewHolder.binding.dmItemIvDelete.setVisibility(View.VISIBLE);
viewHolder.binding.dmItemTvStartorpause.setText("继续");
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.NORMAL);
viewHolder.binding.dmItemTvSpeed.setTextColor(ContextCompat.getColor(mContext, R.color.text_subtitleDesc));
viewHolder.binding.dmItemTvSpeed.setText(downloadEntity.getPercent() + "%");
viewHolder.binding.dmItemTvDownloads.setLayoutParams(lparams);
viewHolder.binding.dmItemTvDownloads.setTextColor(0xFF9A9A9A);
if (status.equals(DownloadStatus.timeout)
|| status.equals(DownloadStatus.neterror)
|| status.equals(DownloadStatus.subscribe)) {
viewHolder.binding.dmItemTvSpeed.setText("等待WIFI");
viewHolder.binding.dmItemTvDownloads.setText("已暂停连接WiFi自动下载");
} else {
viewHolder.binding.dmItemTvSpeed.setText("已暂停");
viewHolder.binding.dmItemTvDownloads.setText("已暂停");
}
} else if (status.equals(DownloadStatus.overflow)) {
viewHolder.binding.dmItemTvSpeed.setTextColor(ContextCompat.getColor(mContext, R.color.text_subtitleDesc));
viewHolder.binding.dmItemTvSpeed.setText("数据异常,请重新下载");
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
viewHolder.binding.dmItemTvDownloads.setLayoutParams(lparams);
viewHolder.binding.dmItemTvDownloads.setTextColor(mContext.getResources().getColor(R.color.theme_red));
viewHolder.binding.dmItemTvDownloads.setText("数据异常,请重新下载");
viewHolder.binding.dmItemIvDelete.setVisibility(View.VISIBLE);
viewHolder.binding.dmItemTvStartorpause.setText("失败");
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.FAILURE);
viewHolder.binding.dmItemTvSpeed.setText(downloadEntity.getPercent() + "%");
}
String xapkStatus = downloadEntity.getMeta().get(XapkInstaller.XAPK_UNZIP_STATUS);
if (XapkUnzipStatus.UNZIPPING.name().equals(xapkStatus)) {
viewHolder.binding.dmItemTvStartorpause.setText("取消");
String percent = downloadEntity.getMeta().get(XapkInstaller.XAPK_UNZIP_PERCENT);
viewHolder.binding.dmItemProgressbar.setProgress((int) (Float.parseFloat(percent == null ? "0" : percent) * 10));
viewHolder.binding.dmItemProgressbar.setProgressDrawable(mContext.getResources().getDrawable(R.drawable.progressbar_xapk_style));
viewHolder.binding.dmItemTvSpeed.setText((percent + "%"));
viewHolder.binding.dmItemTvSpeed.setTextColor(mContext.getResources().getColor(R.color.theme_font));
viewHolder.binding.dmItemTvDownloads.setText("解压中");
viewHolder.binding.unzipFailureHint.setVisibility(View.GONE);
} else if (XapkUnzipStatus.FAILURE.name().equals(xapkStatus)) {
viewHolder.binding.dmItemProgressbar.setProgress((int) (downloadEntity.getPercent() * 10));
viewHolder.binding.dmItemProgressbar.setProgressDrawable(mContext.getResources().getDrawable(R.drawable.progressbar_bg_style));
viewHolder.binding.dmItemTvDownloads.setTextColor(ContextCompat.getColor(mContext, R.color.text_F10000));
viewHolder.binding.unzipFailureHint.setVisibility(View.VISIBLE);
viewHolder.binding.dmItemTvDownloads.setText("解压失败");
} else {
viewHolder.binding.dmItemProgressbar.setProgress((int) (downloadEntity.getPercent() * 10));
viewHolder.binding.dmItemProgressbar.setProgressDrawable(mContext.getResources().getDrawable(R.drawable.progressbar_bg_style));
viewHolder.binding.unzipFailureHint.setVisibility(View.GONE);
viewHolder.binding.dmItemTvSpeed.setTextColor(mContext.getResources().getColor(R.color.text_9a9a9a));
}
viewHolder.binding.dmItemTvStartorpause.setOnClickListener(v -> {
String str = ((DownloadButton) v).getText();
final String url = downloadEntity.getUrl();
DownloadManager.getInstance().put(url, System.currentTimeMillis());
if (XapkUnzipStatus.UNZIPPING.name().equals(xapkStatus)) {
XapkInstaller.cancelUnzipTask(downloadEntity);
return;
} else if (XapkUnzipStatus.FAILURE.name().equals(xapkStatus)) {
PermissionHelper.checkStoragePermissionBeforeAction(mContext, () -> {
final String path = downloadEntity.getPath();
if (downloadEntity.isPluggable()
&& PackagesManager.isInstalled(downloadEntity.getPackageName())) {
showPluginDialog(downloadEntity.getPath());
} else {
if (FileUtils.isEmptyFile(path)) {
Utils.toast(mContext, R.string.install_failure_hint);
removeDownload(downloadEntity);
} else {
PackageInstaller.install(mContext, downloadEntity);
}
}
});
return;
}
switch (status) {
case pause:
case timeout:
case neterror:
case subscribe:
switch (str) {
case "继续":
case "下载":
PermissionHelper.checkStoragePermissionBeforeAction(mContext, () -> {
// 下载管理不用判断是否大于50M
DialogUtils.checkDownload(mContext, Float.toString(100F), isSubscribe -> {
@ -273,65 +273,72 @@ class GameDownloadFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
notifyItemChanged(mDownloadedList.isEmpty() ? 0 : 1 + mDownloadedList
.size());
} else {
viewHolder.binding.dmItemTvSpeed.setTextColor(ContextCompat.getColor(mContext, R.color.theme_font));
viewHolder.binding.dmItemTvSpeed.setText(String.format("%s(剩%s)",
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
0, LinearLayout.LayoutParams.WRAP_CONTENT);
lparams.weight = 4;
viewHolder.binding.dmItemTvDownloads.setLayoutParams(lparams);
viewHolder.binding.dmItemTvDownloads.setTextColor(ContextCompat.getColor(mContext, R.color.theme_font));
viewHolder.binding.dmItemTvDownloads.setText(String.format("%s(剩%s)",
SpeedUtils.getSpeed(downloadEntity.getSpeed()),
SpeedUtils.getRemainTime(downloadEntity.getSize(),
downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024)));
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.DOWNLOADING_NORMAL);
viewHolder.binding.dmItemTvStartorpause.setText(downloadEntity.getPercent() + "%");
viewHolder.binding.dmItemTvStartorpause.setProgress((int) (downloadEntity.getPercent() * 10));
viewHolder.binding.dmItemIvDelete.setVisibility(View.GONE);
viewHolder.binding.dmItemTvStartorpause.setText("暂停");
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.PAUSE);
statusMap.put(url, DownloadStatus.downloading.getStatus());
notifyItemChanged(mDownloadedList.isEmpty() ? 0 : 1 + mDownloadedList
.size());
DownloadManager.getInstance().resume(downloadEntity, true);
// Message msg = Message.obtain();
// msg.what = DownloadConfig.CONTINUE_DOWNLOAD_TASK;
// msg.obj = url;
// DownloadManager.getInstance().sendMessageDelayed(msg, 1000);
Message msg = Message.obtain();
msg.what = DownloadConfig.CONTINUE_DOWNLOAD_TASK;
msg.obj = url;
DownloadManager.getInstance().sendMessageDelayed(msg, 1000);
}
});
});
break;
case done:
if (str.equals(mContext.getString(R.string.install))) {
PermissionHelper.checkStoragePermissionBeforeAction(mContext, () -> {
final String path = downloadEntity.getPath();
if (downloadEntity.isPluggable()
&& PackagesManager.isInstalled(downloadEntity.getPackageName())) {
showPluginDialog(downloadEntity.getPath());
case "安装":
PermissionHelper.checkStoragePermissionBeforeAction(mContext, () -> {
final String path = downloadEntity.getPath();
if (downloadEntity.isPluggable()
&& PackagesManager.isInstalled(downloadEntity.getPackageName())) {
showPluginDialog(downloadEntity.getPath());
} else {
if (FileUtils.isEmptyFile(path)) {
Utils.toast(mContext, R.string.install_failure_hint);
removeDownload(downloadEntity);
} else {
if (FileUtils.isEmptyFile(path)) {
Utils.toast(mContext, R.string.install_failure_hint);
removeDownload(downloadEntity);
} else {
PackageInstaller.install(mContext, downloadEntity);
}
PackageInstaller.install(mContext, downloadEntity);
}
});
} else if (str.equals(mContext.getString(R.string.launch))) {
PackageUtils.launchApplicationByPackageName(mContext, downloadEntity.getPackageName());
}
}
});
break;
case redirected:
case downloading:
viewHolder.binding.dmItemTvStartorpause.setText(R.string.resume);
case "暂停":
viewHolder.binding.dmItemTvStartorpause.setText("继续");
viewHolder.binding.dmItemTvStartorpause.setButtonStyle(DownloadButton.ButtonStyle.NORMAL);
viewHolder.binding.dmItemTvSpeed.setText("已暂停");
viewHolder.binding.dmItemTvSpeed.setTextColor(ContextCompat.getColor(mContext, R.color.text_subtitleDesc));
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
viewHolder.binding.dmItemTvDownloads.setLayoutParams(lparams);
viewHolder.binding.dmItemTvDownloads.setTextColor(0xFF9A9A9A);
viewHolder.binding.dmItemTvDownloads.setText("已暂停");
viewHolder.binding.dmItemIvDelete.setVisibility(View.VISIBLE);
statusMap.put(url, DownloadStatus.pause.getStatus());
notifyItemChanged(mDownloadedList.isEmpty() ? 0 : 1 + mDownloadedList.size());
// Message msg = Message.obtain();
// msg.what = DownloadConfig.PAUSE_DOWNLOAD_TASK;
// msg.obj = url;
// DownloadManager.getInstance().sendMessageDelayed(msg, 1000);
Message msg = Message.obtain();
msg.what = DownloadConfig.PAUSE_DOWNLOAD_TASK;
msg.obj = url;
DownloadManager.getInstance().sendMessageDelayed(msg, 1000);
DownloadManager.getInstance().pause(downloadEntity.getUrl());
// DownloadManager.getInstance().pause(downloadEntity);
break;
case waiting:
case "等待":
Utils.toast(mContext, "最多只能同时下载三个任务,请稍等");
break;
case overflow:
case "启动":
PackageUtils.launchApplicationByPackageName(mContext, downloadEntity.getPackageName());
break;
case "失败":
DialogHelper.showCenterDialog(mContext
, "下载失败"
, "安装包数据校验失败,无法完成下载,建议删除任务重新下载"
@ -339,18 +346,39 @@ class GameDownloadFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
}, () -> {
});
break;
case "取消":
XapkInstaller.cancelUnzipTask(downloadEntity);
break;
}
// DataUtils.onMtaEvent(HaloApp.getInstance().getApplication(), "下载管理", "游戏下载", str);
});
viewHolder.binding.dmItemTvDownloads.setOnClickListener(v -> {
if (viewHolder.binding.unzipFailureHint.getVisibility() == View.VISIBLE) {
DialogUtils.showUnzipFailureDialog(mContext, downloadEntity);
} else if (viewHolder.binding.dmItemIvDelete.getVisibility() == View.VISIBLE) {
showDeleteDialog(downloadEntity, viewHolder.getPosition());
}
});
viewHolder.binding.dmItemIvDelete.setOnClickListener(v -> {
if (viewHolder.binding.dmItemIvDelete.getVisibility() == View.VISIBLE) {
showDeleteDialog(downloadEntity, viewHolder.getPosition());
}
});
if (downloadEntity.getUrl().equals(url)) {
viewHolder.binding.getRoot().setBackgroundColor(ContextCompat.getColor(mContext, R.color.select));
} else {
viewHolder.binding.getRoot().setBackgroundResource(R.drawable.reuse_listview_item_style);
}
viewHolder.binding.getRoot().setOnLongClickListener(v -> {
showDeleteDialog(viewHolder.binding.dmItemTvStartorpause, downloadEntity, viewHolder.getPosition());
return true;
if (viewHolder.binding.dmItemIvDelete.getVisibility() == View.VISIBLE) {
showDeleteDialog(downloadEntity, viewHolder.getPosition());
return true;
}
return false;
});
} else if (holder instanceof DownloadHeadViewHolder) {
@ -538,31 +566,23 @@ class GameDownloadFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
}
// 显示删除提示框
private void showDeleteDialog(DownloadButton downloadButton, final DownloadEntity entry, final int position) {
boolean autoPause = DownloadStatus.downloading.equals(entry.getStatus());
if (autoPause) {
downloadButton.performClick();
}
private void showDeleteDialog(final DownloadEntity entry, final int position) {
String xapkStatus = entry.getMeta().get(XapkInstaller.XAPK_UNZIP_STATUS);
String contentText;
String msg;
if (XapkUnzipStatus.UNZIPPING.name().equals(xapkStatus)) {
contentText = "游戏正在解压安装哦,确定删除?";
msg = "游戏正在解压安装哦,确定删除?";
} else if (mDownloadedList.size() != 0 && position <= mDownloadedList.size()) {
contentText = "游戏还没安装哦,确定删除?";
msg = "游戏还没安装哦,确定删除?";
} else {
contentText = "游戏还没下载完,确定删除?";
msg = "游戏还没下载完,确定删除?";
}
DialogHelper.showDeleteDialog(mContext, "删除游戏", contentText, "删除", "再等等", () -> {
DialogHelper.showCenterWarningDialog(mContext, "删除下载", msg, () -> {
removeDownload(entry);
if (XapkUnzipStatus.UNZIPPING.name().equals(xapkStatus)) {
XapkInstaller.cancelUnzipTask(entry);
}
}, () -> {
if (autoPause) {
downloadButton.performClick();
}
}, true);
});
}
public void initLocationMap() {

View File

@ -0,0 +1,180 @@
//package com.gh.gamecenter.download
//
//import android.graphics.Color
//import android.os.Bundle
//import android.view.View
//import android.widget.LinearLayout
//import android.widget.TextView
//import androidx.lifecycle.Observer
//import androidx.lifecycle.ViewModelProviders
//import androidx.recyclerview.widget.DefaultItemAnimator
//import androidx.recyclerview.widget.RecyclerView
//import butterknife.BindView
//import com.ethanhua.skeleton.Skeleton
//import com.ethanhua.skeleton.ViewSkeletonScreen
//import com.gh.gamecenter.common.callback.OnRequestCallBackListener
//import com.gh.common.exposure.ExposureListener
//import com.gh.common.util.DownloadItemUtils
//import com.gh.gamecenter.common.utils.isSimulatorGame
//import com.gh.gamecenter.common.view.FixLinearLayoutManager
//import com.gh.gamecenter.common.view.VerticalItemDecoration
//import com.gh.download.DownloadManager
//import com.gh.gamecenter.MainActivity
//import com.gh.gamecenter.R
//import com.gh.gamecenter.entity.GameEntity
//import com.gh.gamecenter.entity.GameInstall
//import com.gh.gamecenter.eventbus.EBDownloadStatus
//import com.gh.gamecenter.common.eventbus.EBReuse
//import com.gh.gamecenter.fragment.MainWrapperFragment
//import com.gh.gamecenter.manager.PackagesManager
//import com.gh.gamecenter.common.base.fragment.NormalFragment
//import com.gh.gamecenter.packagehelper.PackageViewModel
//import com.lightgame.download.DataWatcher
//import com.lightgame.download.DownloadEntity
//import com.lightgame.download.DownloadStatus
//import org.greenrobot.eventbus.Subscribe
//import org.greenrobot.eventbus.ThreadMode
//
//// 时间不够,不重构了,直接把原 Activity 改成 Fragment 就算了
//class InstalledGameFragment : NormalFragment(), OnRequestCallBackListener<Any> {
//
// @BindView(R.id.fm_install_rv_show)
// lateinit var mInstallRv: RecyclerView
//
// @BindView(R.id.reuse_nodata_skip)
// lateinit var mNoDataSkip: LinearLayout
//
// @BindView(R.id.reuse_nodata_skip_tv_hint)
// lateinit var mNoDataSkipHint: TextView
//
// @BindView(R.id.reuse_nodata_skip_tv_btn)
// lateinit var mNoDataSkipBtn: TextView
//
// @BindView(R.id.list_skeleton)
// lateinit var mListSkeleton: View
//
// private var mPackageViewModel: PackageViewModel? = null
// private var mAdapter: InstalledGameFragmentAdapter? = null
// private var mExposureListener: ExposureListener? = null
//
// private var mSkeleton: ViewSkeletonScreen? = null
//
// private var isEverpause = false
//
// private val dataWatcher = object : DataWatcher() {
// override fun onDataChanged(downloadEntity: DownloadEntity) {
// if (downloadEntity.status == DownloadStatus.done && downloadEntity.isSimulatorGame()) {
// DownloadManager.getInstance().getEntryMap(downloadEntity.name)[downloadEntity.platform] = downloadEntity
// mPackageViewModel?.getGameInstalledLiveData()?.value?.let {
// mAdapter?.initData(PackagesManager.filterSameApk(PackagesManager.filterDownloadBlackPackage(it as MutableList<GameInstall>?)))
// }
// return
// }
// val locationList = mAdapter!!.locationMap[downloadEntity.packageName]
// if (locationList != null && locationList.size != 0) {
// var gameEntity: GameEntity?
// for (location in locationList) {
// if (location < mAdapter!!.gameList.size) {
// gameEntity = mAdapter!!.gameList[location]
// if (gameEntity != null) {
// DownloadItemUtils.processDate(gameEntity, downloadEntity, mAdapter, location)
// }
// }
// }
// }
// }
// }
//
// override fun onCreate(savedInstanceState: Bundle?) {
// super.onCreate(savedInstanceState)
// mNoDataSkip.visibility = View.GONE
// mSkeleton = Skeleton.bind(mListSkeleton).shimmer(false).load(R.layout.activity_install_skeleton).show()
// mNoDataSkipHint.text = "暂无游戏"
// mNoDataSkipBtn.text = "去首页看看"
// mNoDataSkipBtn.setOnClickListener {
// MainActivity.skipToMainActivity(requireContext(), MainWrapperFragment.INDEX_HOME)
// }
//
// mInstallRv.layoutManager = FixLinearLayoutManager(requireContext())
// (mInstallRv.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false
// mAdapter = InstalledGameFragmentAdapter(this)
// mExposureListener = ExposureListener(this, mAdapter!!)
// mInstallRv.addItemDecoration(VerticalItemDecoration(requireContext(), 8f, true))
// mInstallRv.addOnScrollListener(mExposureListener!!)
// mInstallRv.adapter = mAdapter
//
// mPackageViewModel = ViewModelProviders.of(this, PackageViewModel.Factory()).get(PackageViewModel::class.java)
// mPackageViewModel?.getGameInstalledLiveData()?.observe(this,
// Observer { gameInstalls -> mAdapter?.initData(PackagesManager.filterSameApk(PackagesManager.filterDownloadBlackPackage(gameInstalls as MutableList<GameInstall>?))) })
// }
//
// override fun getLayoutId(): Int {
// return R.layout.fragment_my_game
// }
//
// override fun onResume() {
// super.onResume()
// if (isEverpause) {
// for (entity in mAdapter!!.gameList) {
// entity.setEntryMap(DownloadManager.getInstance().getEntryMap(entity.name))
// }
// mAdapter!!.notifyDataSetChanged()
// }
// isEverpause = false
// DownloadManager.getInstance().addObserver(dataWatcher)
// }
//
// override fun onPause() {
// super.onPause()
// isEverpause = true
// DownloadManager.getInstance().removeObserver(dataWatcher)
// }
//
// override fun loadDone() {
// mSkeleton!!.hide()
// }
//
// override fun loadDone(obj: Any) {
//
// }
//
// override fun loadError() {
//
// }
//
// override fun loadEmpty() {
// mSkeleton?.hide()
// mInstallRv.visibility = View.GONE
// mNoDataSkip.visibility = View.VISIBLE
// mNoDataSkip.setBackgroundColor(Color.WHITE)
// }
//
// // 打开下载按钮事件
// @Subscribe(threadMode = ThreadMode.MAIN)
// fun onEventMainThread(reuse: EBReuse) {
// if (("Refresh" == reuse.type || "PlatformChanged" == reuse.type) && mAdapter != null) {
// mAdapter?.notifyDataSetChanged()
// }
// }
//
// //下载被删除事件
// @Subscribe(threadMode = ThreadMode.MAIN)
// fun onEventMainThread(status: EBDownloadStatus) {
// if ("delete" == status.status) {
// DownloadManager.getInstance().removePlatform(status.name, status.platform)
//
// val locationList = mAdapter!!.locationMap[status.packageName]
// var gameEntity: GameEntity?
// if (locationList != null && locationList.size != 0) {
// for (location in locationList) {
// gameEntity = mAdapter!!.gameList[location]
// if (gameEntity != null && gameEntity.getEntryMap() != null) {
// gameEntity.getEntryMap().remove(status.platform)
// }
// }
// mAdapter?.notifyDataSetChanged()
// }
// }
// }
//
//}

View File

@ -0,0 +1,382 @@
//package com.gh.gamecenter.download;
//
//import android.text.TextUtils;
//import android.view.View;
//import android.view.ViewGroup;
//
//import com.gh.gamecenter.common.constant.ItemViewType;
//import com.gh.common.exposure.ExposureEvent;
//import com.gh.common.exposure.ExposureSource;
//import com.gh.common.exposure.ExposureType;
//import com.gh.common.exposure.IExposable;
//import com.gh.common.filter.RegionSettingHelper;
//import com.gh.common.simulator.SimulatorGameManager;
//import com.gh.common.util.ApkActiveUtils;
//import com.gh.common.util.DataCollectionUtils;
//import com.gh.common.util.DownloadItemUtils;
//import com.gh.common.util.ExtensionsKt;
//import com.gh.common.util.GameUtils;
//import com.gh.common.util.PackageUtils;
//import com.gh.common.util.PlatformUtils;
//import com.gh.gamecenter.core.utils.ThirdPartyPackageHelper;
//import com.gh.download.DownloadManager;
//import com.gh.gamecenter.GameDetailActivity;
//import com.gh.gamecenter.R;
//import com.gh.gamecenter.common.viewholder.FooterViewHolder;
//import com.gh.gamecenter.adapter.viewholder.GameViewHolder;
//import com.gh.gamecenter.databinding.GameItemBinding;
//import com.gh.gamecenter.entity.ApkEntity;
//import com.gh.gamecenter.entity.GameCollectionEntity;
//import com.gh.gamecenter.entity.GameEntity;
//import com.gh.gamecenter.entity.GameInstall;
//import com.gh.gamecenter.game.GameItemViewHolder;
//import com.gh.gamecenter.manager.PackagesManager;
//import com.gh.gamecenter.retrofit.Response;
//import com.gh.gamecenter.retrofit.RetrofitManager;
//import com.lightgame.adapter.BaseRecyclerAdapter;
//import com.lightgame.download.DownloadEntity;
//
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.List;
//
//import androidx.annotation.Nullable;
//import androidx.collection.ArrayMap;
//import androidx.recyclerview.widget.RecyclerView.ViewHolder;
//
//import io.reactivex.Observable;
//import io.reactivex.android.schedulers.AndroidSchedulers;
//import io.reactivex.schedulers.Schedulers;
//import retrofit2.HttpException;
//
///**
// * Created by LGT on 2016/8/12.
// * 已安装界面-数据适配器
// */
//public class InstalledGameFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> implements IExposable {
//
// private InstalledGameFragment mFragment;
//
// private ArrayList<GameEntity> gameList;
// private List<GameInstall> sortedList;
//
// //下载用到的map
// private ArrayMap<String, ArrayList<Integer>> locationMap;
//
// private boolean isRemove;
//
// private ArrayList<ExposureSource> mExposureSource;
//
// public InstalledGameFragmentAdapter(InstalledGameFragment fragment) {
// super(fragment.requireContext());
// mFragment = fragment;
//
// gameList = new ArrayList<>();
// sortedList = new ArrayList<>();
//
// locationMap = new ArrayMap<>();
//
// isRemove = false;
//
// mExposureSource = new ArrayList<>();
// mExposureSource.add(new ExposureSource("下载管理", ""));
// mExposureSource.add(new ExposureSource("已安装", ""));
// }
//
// public void initData(List<GameInstall> list) {
// List<DownloadEntity> downloadEntityList = DownloadManager.getInstance().getAllSimulatorDownloadEntity();
// for (DownloadEntity entity : downloadEntityList) {
// GameInstall gameInstall = new GameInstall();
// gameInstall.setId(entity.getGameId());
// list.add(gameInstall);
// }
//
// for (GameInstall gameInstall : list) {
// Object gh_id = PackageUtils.getMetaData(mContext, gameInstall.getPackageName(), "gh_id");
// if (gh_id != null && !gh_id.equals(gameInstall.getId())) {
// gameInstall.setId(gh_id.toString());
// } else {
// String gameId = ThirdPartyPackageHelper.getGameId(gameInstall.getPackageName());
// if (!TextUtils.isEmpty(gameId)) {
// gameInstall.setId(gameId);
// }
// }
// }
//
// sortedList.clear();
// //gameList.clear();
// sortedList.addAll(list);
//
// if (sortedList.isEmpty()) {
// mFragment.loadEmpty();
// } else {
// List<String> ids = new ArrayList<>();
// Collections.sort(sortedList, (lhs, rhs) -> {
// if (rhs == null || lhs == null) {
// return 0;
// }
// // 按安装时间排序
// if (rhs.getInstallTime() > lhs.getInstallTime()) {
// return 1;
// } else if (rhs.getInstallTime() < lhs.getInstallTime()) {
// return -1;
// } else {
// return 0;
// }
// });
// for (GameInstall info : sortedList) {
// if (!ids.contains(info.getId()) && !RegionSettingHelper.shouldThisGameBeFiltered(info.getId())) {
// ids.add(info.getId());
// }
// }
// initGameList(ids);
// }
// }
//
// //获取游戏简介
// private void initGameList(List<String> ids) {
// final List<GameEntity> result = new ArrayList<>();
//
// List<Observable<GameEntity>> sequences = new ArrayList<>();
// for (String id : ids) {
// sequences.add(RetrofitManager.getInstance().getApi().getGameDigest(id));
// }
// Observable.mergeDelayError(sequences)
// .map(ApkActiveUtils.filterMapper)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(new Response<GameEntity>() {
// @Override
// public void onComplete() {
// processingData(result);
// }
//
// @Override
// public void onFailure(@Nullable HttpException e) {
// processingData(result);
// }
//
// @Override
// public void onNext(GameEntity response) {
// ApkActiveUtils.filterHideApk(response);
// result.add(response);
// }
// });
// }
//
// private void processingData(List<GameEntity> gameList) {
// ArrayList<GameEntity> newGameList = new ArrayList<>();
// if (gameList.size() != 0) {
// for (int i = 0, size = sortedList.size(); i < size; i++) {
// String id = sortedList.get(i).getId();
// for (GameEntity entity : gameList) {
// if (entity.getId().equals(id)) {
// GameEntity newEntity = entity.clone();
// newEntity.setLibaoExists(entity.isLibaoExists());
//
// // 下载管理不显示镜像游戏,不然会有奇怪的问题
// if (entity.shouldUseMirrorInfo()) {
// continue;
// }
//
// if (newEntity.getApk().size() > 1) {
// for (ApkEntity apkEntity : newEntity.getApk()) {
// String packageName = sortedList.get(i).getPackageName();
// if (packageName.equals(apkEntity.getPackageName())) {
// ArrayList<ApkEntity> list = new ArrayList<>();
// list.add(apkEntity);
// newEntity.setApk(list);
//
// if (PackageUtils.isCanPluggable(apkEntity)) {
// GameCollectionEntity pluggableCollection =
// GameUtils.getPluggableCollectionFromGameEntity(entity, packageName);
// if (pluggableCollection != null) {
// newEntity.setPluggableCollection(pluggableCollection);
// }
// }
// break;
// }
// }
// }
// newGameList.add(newEntity);
// break;
// }
// }
// }
// for (GameEntity entity : newGameList) {
// entity.setEntryMap(DownloadManager.getInstance().getEntryMap(entity.getName()));
// }
// }
//
// this.gameList.clear();
// this.gameList.addAll(newGameList);
//
// if (this.gameList.size() != 0) {
// isRemove = true;
// notifyDataSetChanged();
// initLocationMap();
//
// mFragment.loadDone();
// } else {
// mFragment.loadEmpty();
// }
// }
//
// private void initLocationMap() {
// locationMap.clear();
// GameEntity gameEntity;
// ArrayList<Integer> list;
// for (int i = 0; i < gameList.size(); i++) {
// gameEntity = gameList.get(i);
// if (gameEntity.getApk() != null && gameEntity.getApk().size() != 0) {
// for (ApkEntity apkEntity : gameEntity.getApk()) {
// list = locationMap.get(apkEntity.getPackageName());
// if (list == null) {
// list = new ArrayList<>();
// locationMap.put(apkEntity.getPackageName(), list);
// }
// list.add(i);
// }
// }
// }
// }
//
// public ArrayList<GameEntity> getGameList() {
// return gameList;
// }
//
// public ArrayMap<String, ArrayList<Integer>> getLocationMap() {
// return locationMap;
// }
//
// @Override
// public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// switch (viewType) {
// case ItemViewType.GAME_NORMAL:
// return new GameItemViewHolder(GameItemBinding.bind(
// mLayoutInflater.inflate(R.layout.game_item, parent, false)));
// case ItemViewType.LOADING:
// return new FooterViewHolder(
// mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false));
// default:
// break;
// }
// return null;
// }
//
// @Override
// public void onBindViewHolder(final ViewHolder holder, int position) {
// if (holder instanceof GameItemViewHolder) {
// GameEntity gameEntity = ExtensionsKt.safelyGetInRelease(gameList, position);
// if (gameEntity != null) {
// initGameNormal((GameItemViewHolder) holder, gameEntity);
// }
// }
// }
//
// @Override
// public int getItemViewType(int position) {
// if (gameList.size() != 0 && position >= 0 && position < gameList.size()) {
// return ItemViewType.GAME_NORMAL;
// }
//
// return ItemViewType.LOADING;
// }
//
// @Override
// public int getItemCount() {
// if (gameList.isEmpty() && !isRemove) {
// return 1;
// }
// if (isRemove) {
// return gameList.size();
// }
// return gameList.size() + 1;
// }
//
// private void initGameNormal(final GameItemViewHolder holder, final GameEntity gameEntity) {
// gameEntity.setCollection(new ArrayList<>()); // 清空集合,防止下载按钮会因为存在集合而清空合集包的状态判断
// holder.initServerType(gameEntity);
// GameItemBinding binding = holder.getBinding();
//
// binding.setGame(gameEntity);
// binding.setIsShowPlatform(true);
// binding.executePendingBindings();
//
// String name;
// if (gameEntity.getApk().size() > 0) {
// name = String.format("%s - %s", gameEntity.getName(),
// PlatformUtils.getInstance(mContext).getPlatformName(gameEntity.getApk().get(0).getPlatform()));
// // TODO Fresco 未来可能不用 ImageView 作为基类,使用 setImageDrawable 有风险
// binding.gameIconView.getIconIv().setImageDrawable(PackageUtils.getIconByPackageName(mContext, gameEntity.getApk().get(0).getPackageName()));
// binding.gameIconView.getIconDecoratorIv().setVisibility(View.GONE);
// if (SimulatorGameManager.isSimulatorGame(gameEntity)) {
// binding.gameDes.setText(String.format("V%s", gameEntity.getApk().get(0).getVersion()));
// } else {
// binding.gameDes.setText(String.format("V%s", PackageUtils.getVersionNameByPackageName(gameEntity.getApk().get(0).getPackageName())));
// }
// } else {
// name = gameEntity.getName();
// binding.gameIconView.displayGameIcon(gameEntity.getRawIconInAdvanced(), gameEntity.getIconSubscript());
// binding.gameDes.setText(gameEntity.getBrief());
// }
// if (SimulatorGameManager.isSimulatorGame(gameEntity)) {
// binding.gameIconView.displayGameIcon(gameEntity.getIcon(), gameEntity.getIconSubscript());
// }
//
// binding.gameName.setText(name);
//
// generateExposureEvent(gameEntity);
//
// DownloadItemUtils.setOnClickListener(
// mContext,
// binding.downloadBtn,
// gameEntity,
// 1,
// InstalledGameFragmentAdapter.this,
// "(我的光环-已安装)", "我的光环-已安装" + ":" + gameEntity.getName(),
// gameEntity.getExposureEvent()
//// , () -> MtaHelper.onEvent("下载管理", "已安装", binding.downloadBtn.getText().toString())
// );
//
// DownloadItemUtils.updateItem(mContext, gameEntity, new GameViewHolder(binding), !gameEntity.isPluggable());
//
// holder.itemView.setOnClickListener(v -> {
// DataCollectionUtils.uploadClick(mContext, "列表", "我的光环-我的游戏", gameEntity.getName());
// GameDetailActivity.startGameDetailActivity(mContext, gameEntity.getId(), "(我的光环:我的游戏)", gameEntity.getExposureEvent());
// });
//
// // 强制修改该列表安装状态(如果该包是合集且安装了合集内任意一个光环的游戏包都不显示插件化)
// ArrayList<ApkEntity> apkList = gameEntity.getApk();
// if (holder.getBinding().downloadBtn.getText().toString().contains("化") && apkList.size() == 1) {
// ApkEntity apkEntity = apkList.get(0);
// GameCollectionEntity pluggableCollection = gameEntity.getPluggableCollection();
// if (pluggableCollection != null && pluggableCollection.getPackages().contains(apkEntity.getPackageName())) {
// for (String pkg : pluggableCollection.getPackages()) {
// Object ghId = PackageUtils.getGhId(pkg);
// if (PackagesManager.isInstalled(pkg) && ghId != null && gameEntity.getId().equals(ghId.toString())) {
// holder.getBinding().downloadBtn.setText(R.string.launch);
// holder.getBinding().downloadBtn.setBackgroundResource(R.drawable.download_button_normal_style);
// }
// }
// }
// }
// }
//
// private void generateExposureEvent(GameEntity gameEntity) {
// ExposureEvent event = ExposureEvent.createEvent(gameEntity, mExposureSource, null, ExposureType.EXPOSURE);
// gameEntity.setExposureEvent(event);
// }
//
// @Nullable
// @Override
// public ExposureEvent getEventByPosition(int pos) {
// return gameList.get(pos).getExposureEvent();
// }
//
// @Nullable
// @Override
// public List<ExposureEvent> getEventListByPosition(int pos) {
// return null;
// }
//}

View File

@ -25,7 +25,6 @@ import com.gh.gamecenter.databinding.FragmentMyGameBinding
import com.gh.gamecenter.entity.GameEntity
import com.gh.gamecenter.entity.GameInstall
import com.gh.gamecenter.eventbus.EBDownloadStatus
import com.gh.gamecenter.eventbus.EBPackage
import com.gh.gamecenter.fragment.MainWrapperFragment
import com.gh.gamecenter.manager.PackagesManager
import com.gh.gamecenter.packagehelper.PackageRepository
@ -47,6 +46,8 @@ class NewInstalledGameFragment : ToolbarFragment() {
private var mSkeleton: ViewSkeletonScreen? = null
private var mItemDecoration: VerticalItemDecoration? = null
private var isEverpause = false
private val dataWatcher = object : DataWatcher() {
override fun onDataChanged(downloadEntity: DownloadEntity) {
if (downloadEntity.status == DownloadStatus.done && downloadEntity.isSimulatorGame()) {
@ -134,6 +135,7 @@ class NewInstalledGameFragment : ToolbarFragment() {
}
private fun updateNoDataView() {
val layoutParam = mBinding.reuseNoneData.reuseResetLoadTv.layoutParams
layoutParam.width = DisplayUtils.dip2px(150F)
mBinding.reuseNoneData.reuseResetLoadTv.layoutParams = layoutParam
@ -177,12 +179,30 @@ class NewInstalledGameFragment : ToolbarFragment() {
override fun onResume() {
super.onResume()
val gameList = mInstallGameViewModel.gameListLiveData.value
if (isEverpause && !gameList.isNullOrEmpty()) {
for (entity in gameList) {
entity.setEntryMap(
DownloadManager.getInstance().getEntryMap(entity.name)
)
}
mInstallGameViewModel.gameListLiveData.postValue(gameList)
}
if (isEverpause) {
mInstallGameViewModel.initData(
PackagesManager.filterSameApk(
PackagesManager.filterDownloadBlackPackage(mPackageViewModel?.getGameInstalledLiveData()?.value as MutableList<GameInstall>?)
)
)
}
isEverpause = false
DownloadManager.getInstance().addObserver(dataWatcher)
updateNoDataView()
}
override fun onPause() {
super.onPause()
isEverpause = true
DownloadManager.getInstance().removeObserver(dataWatcher)
}
@ -214,17 +234,6 @@ class NewInstalledGameFragment : ToolbarFragment() {
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(packageEb: EBPackage) {
if (packageEb.isInstalledOrUninstalled()) {
mInstallGameViewModel.initData(
PackagesManager.filterSameApk(
PackagesManager.filterDownloadBlackPackage(mPackageViewModel?.getGameInstalledLiveData()?.value as MutableList<GameInstall>?)
)
)
}
}
override fun onDarkModeChanged() {
super.onDarkModeChanged()
mBinding.root.setBackgroundColor(R.color.background.toColor(requireContext()))

View File

@ -1,27 +1,29 @@
package com.gh.gamecenter.download
import android.annotation.SuppressLint
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.view.setPadding
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.core.utils.CurrentActivityHolder
import com.gh.common.exposure.ExposureEvent
import com.gh.common.exposure.ExposureEvent.Companion.createEvent
import com.gh.common.exposure.ExposureSource
import com.gh.common.exposure.IExposable
import com.gh.common.util.*
import com.gh.common.util.DialogUtils
import com.gh.common.view.DownloadButton
import com.gh.gamecenter.common.view.BugFixedPopupWindow
import com.gh.download.DownloadManager
import com.gh.download.dialog.DownloadDialog
import com.gh.gamecenter.DownloadManagerActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.common.view.BugFixedPopupWindow
import com.gh.gamecenter.core.utils.CurrentActivityHolder
import com.gh.gamecenter.databinding.*
import com.gh.gamecenter.entity.GameUpdateEntity
import com.gh.gamecenter.eventbus.EBSkip
@ -42,23 +44,7 @@ class UpdatableGameAdapter(private var mViewModel: UpdatableGameViewModel) :
}
}
val positionAndPackageMap = HashMap<String, Int>()
fun submitList(dataList: ArrayList<UpdatableGameViewModel.UpdatableDataItem>) {
positionAndPackageMap.clear()
// 记录游戏位置
if (dataList.isNotEmpty()) {
for (i in 0 until dataList.size) {
val entity = dataList[i].normalUpdate
?: dataList[i].normalUpdateWithArrow
?: dataList[i].otherVersionUpdate
?: dataList[i].ignoredUpdate
if (entity != null) {
val packages = entity.id + entity.packageName
positionAndPackageMap[packages + i] = i
}
}
}
mItemList = dataList
notifyDataSetChanged()
}
@ -112,18 +98,26 @@ class UpdatableGameAdapter(private var mViewModel: UpdatableGameViewModel) :
if (itemData.header != null) {
holder.binding.infoTv.setTextColor(R.color.text_title.toColor(mContext))
holder.binding.root.setOnClickListener(null)
holder.binding.infoTv.removeDrawable()
holder.binding.infoTv.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
null,
null
)
} else {
holder.binding.infoTv.setTextColor(R.color.text_subtitleDesc.toColor(mContext))
holder.binding.root.setOnClickListener {
mViewModel.toggleIgnoredUpdateVisibility()
}
holder.binding.infoTv.setDrawableEnd(
holder.binding.infoTv.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
if (mViewModel.isIgnoredUpdateExpanded()) {
R.drawable.ic_arrow_up_grey.toDrawable()
} else {
R.drawable.ic_arrow_down_grey.toDrawable()
}
},
null
)
}
}
@ -193,9 +187,19 @@ class UpdatableGameAdapter(private var mViewModel: UpdatableGameViewModel) :
mViewModel.toggleOtherVersionVisibility(itemData.miscPackageName)
}
if (itemData.otherVersionUpdateHint == true) {
holder.binding.selectorTv.setDrawableEnd(R.drawable.ic_arrow_up_blue)
holder.binding.selectorTv.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
R.drawable.ic_arrow_up_blue.toDrawable(),
null
)
} else {
holder.binding.selectorTv.setDrawableEnd(R.drawable.ic_arrow_down_blue)
holder.binding.selectorTv.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
R.drawable.ic_arrow_down_blue.toDrawable(),
null
)
}
holder.binding.closeHintTv.enlargeTouchArea()
holder.binding.closeHintTv.setOnClickListener {
@ -276,7 +280,7 @@ class UpdatableGameAdapter(private var mViewModel: UpdatableGameViewModel) :
}
private fun updateUpdateBtn(
updateBtn: DownloadButton,
updateBtn: TextView,
downloadEntity: DownloadEntity?,
update: GameUpdateEntity,
pluginDesc: String,
@ -285,50 +289,55 @@ class UpdatableGameAdapter(private var mViewModel: UpdatableGameViewModel) :
if (downloadEntity == null) {
if (PackagesManager.isCanUpdate(update.id, update.packageName)) {
updateBtn.setText(R.string.update)
updateBtn.buttonStyle = DownloadButton.ButtonStyle.NORMAL
updateBtn.setTextColor(Color.WHITE)
updateBtn.setBackgroundResource(R.drawable.download_button_normal_style)
} else if (update.isPluggable) {
updateBtn.text = "${pluginDesc}"
updateBtn.setTextColor(Color.WHITE)
val samePackageNameDownloadEntity =
downloadManager.getDownloadEntityByPackageName(update.packageName)
if (samePackageNameDownloadEntity == null || samePackageNameDownloadEntity.url == update.url) {
updateBtn.isClickable = true
updateBtn.buttonStyle = DownloadButton.ButtonStyle.PLUGIN
updateBtn.setBackgroundResource(R.drawable.download_button_pluggable_style)
} else {
updateBtn.isClickable = false
updateBtn.buttonStyle = DownloadButton.ButtonStyle.PLUGIN
updateBtn.setBackgroundResource(R.drawable.game_item_btn_pause_up)
}
} else {
updateBtn.setText(R.string.launch)
updateBtn.buttonStyle = DownloadButton.ButtonStyle.LAUNCH_OR_OPEN
updateBtn.setTextColor(Color.WHITE)
updateBtn.setBackgroundResource(R.drawable.download_button_normal_style)
}
} else {
when (downloadEntity.status) {
DownloadStatus.downloading -> {
updateBtn.text = "${downloadEntity.percent}%"
updateBtn.buttonStyle =
if (update.isPluggable) DownloadButton.ButtonStyle.DOWNLOADING_PLUGIN else DownloadButton.ButtonStyle.DOWNLOADING_NORMAL
updateBtn.progress = (downloadEntity.percent * 10).toInt()
}
DownloadStatus.waiting -> {
updateBtn.setText(R.string.waiting)
updateBtn.buttonStyle = DownloadButton.ButtonStyle.WAITING
}
DownloadStatus.timeout,
DownloadStatus.neterror,
DownloadStatus.subscribe,
DownloadStatus.overflow,
DownloadStatus.pause -> {
updateBtn.setText(R.string.resume)
updateBtn.buttonStyle = DownloadButton.ButtonStyle.NORMAL
}
DownloadStatus.done -> {
if (update.isPluggable) {
if (downloadEntity.status == DownloadStatus.done) {
updateBtn.setText(R.string.install)
updateBtn.buttonStyle =
if (update.isPluggable) DownloadButton.ButtonStyle.INSTALL_PLUGIN else DownloadButton.ButtonStyle.INSTALL_NORMAL
updateBtn.setTextColor(Color.WHITE)
updateBtn.setBackgroundResource(R.drawable.download_button_pluggable_style)
} else {
updateBtn.setText(R.string.downloading)
updateBtn.setTextColor(
ContextCompat.getColorStateList(
updateBtn.context,
R.color.text_downloading_style
)
)
updateBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style)
}
else -> {
// do nothing
} else {
if (downloadEntity.status == DownloadStatus.done) {
updateBtn.setText(R.string.install)
updateBtn.setTextColor(Color.WHITE)
updateBtn.setBackgroundResource(R.drawable.download_button_normal_style)
} else {
updateBtn.setText(R.string.downloading)
updateBtn.setTextColor(
ContextCompat.getColorStateList(
updateBtn.context,
R.color.text_downloading_style
)
)
updateBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style)
}
}
}
@ -354,14 +363,24 @@ class UpdatableGameAdapter(private var mViewModel: UpdatableGameViewModel) :
)
return@checkDownload
} else {
updateBtn.text = "0%"
updateBtn.buttonStyle = DownloadButton.ButtonStyle.DOWNLOADING_PLUGIN
updateBtn.progress = 0
updateBtn.setText(R.string.downloading)
updateBtn.setTextColor(
ContextCompat.getColorStateList(
updateBtn.context,
R.color.text_plugining_style
)
)
updateBtn.setBackgroundResource(R.drawable.game_item_btn_plugining_style)
}
} else {
updateBtn.text = "0%"
updateBtn.buttonStyle = DownloadButton.ButtonStyle.DOWNLOADING_NORMAL
updateBtn.progress = 0
updateBtn.setText(R.string.downloading)
updateBtn.setTextColor(
ContextCompat.getColorStateList(
updateBtn.context,
R.color.text_downloading_style
)
)
updateBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style)
}
mViewModel.update(update, isSubscribe)
@ -377,25 +396,20 @@ class UpdatableGameAdapter(private var mViewModel: UpdatableGameViewModel) :
}
} else if (updateBtn.context.getString(R.string.launch) == str) {
PackageUtils.launchApplicationByPackageName(updateBtn.context, update.packageName)
} else if (updateBtn.context.getString(R.string.resume) == str) {
if (downloadEntity != null) {
DownloadManager.getInstance().resume(downloadEntity, true)
updateBtn.text = "${downloadEntity.percent}%"
updateBtn.buttonStyle = DownloadButton.ButtonStyle.DOWNLOADING_NORMAL
updateBtn.progress = (downloadEntity.percent * 10).toInt()
}
} else if (updateBtn.context.getString(R.string.downloading) == str) {
mViewModel.refreshList()
EventBus.getDefault().post(
EBSkip(
DownloadManagerActivity.TAG,
DownloadManagerActivity.INDEX_DOWNLOAD
)
)
} else if (updateBtn.context.getString(R.string.install) == str) {
PackageInstaller.install(
updateBtn.context,
DownloadManager.getInstance()
.getDownloadEntityByUrl(update.url)
)
} else {
if (downloadEntity != null) {
DownloadManager.getInstance().pause(downloadEntity.url)
updateBtn.setText(R.string.resume)
updateBtn.buttonStyle = DownloadButton.ButtonStyle.NORMAL
}
}
}
}
@ -405,17 +419,6 @@ class UpdatableGameAdapter(private var mViewModel: UpdatableGameViewModel) :
createEvent(updateEntity.transformGameEntity(), mExposureSource)
}
fun notifyItemByDownload(download: DownloadEntity) {
for (key in positionAndPackageMap.keys) {
if (key.contains(download.packageName) && key.contains(download.gameId)) {
val position = positionAndPackageMap[key]
if (position != null && mItemList != null && position < (mItemList?.size ?: 0)) {
notifyItemChanged(position)
}
}
}
}
companion object {
const val TYPE_DIVIDER = 233
const val TYPE_HEADER = 234

View File

@ -2,7 +2,6 @@ package com.gh.gamecenter.download
import android.view.View
import com.gh.common.exposure.ExposureListener
import com.gh.download.DownloadManager
import com.gh.gamecenter.MainActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.fragment.LazyFragment
@ -17,8 +16,6 @@ import com.gh.gamecenter.eventbus.EBDownloadStatus
import com.gh.gamecenter.fragment.MainWrapperFragment
import com.gh.gamecenter.packagehelper.PackageRepository
import com.gh.gamecenter.packagehelper.PackageViewModel
import com.lightgame.download.DataWatcher
import com.lightgame.download.DownloadEntity
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
@ -29,17 +26,6 @@ class UpdatableGameFragment : LazyFragment() {
private var mBinding: FragmentGameUpdatableBinding? = null
private var mAdapter: UpdatableGameAdapter? = null
private val dataWatcher = object : DataWatcher() {
override fun onDataChanged(downloadEntity: DownloadEntity) {
mAdapter?.notifyItemByDownload(downloadEntity)
}
override fun onDataInit(downloadEntity: DownloadEntity) {
mAdapter?.notifyItemByDownload(downloadEntity)
}
}
override fun getRealLayoutId() = R.layout.fragment_game_updatable
override fun onRealLayoutInflated(inflatedView: View) {
mBinding = FragmentGameUpdatableBinding.bind(inflatedView)
@ -66,13 +52,8 @@ class UpdatableGameFragment : LazyFragment() {
override fun onFragmentResume() {
super.onFragmentResume()
DownloadManager.getInstance().addObserver(dataWatcher)
updateNoDataView()
}
override fun onFragmentPause() {
super.onFragmentPause()
DownloadManager.getInstance().removeObserver(dataWatcher)
updateNoDataView()
}
override fun initRealView() {
@ -80,7 +61,6 @@ class UpdatableGameFragment : LazyFragment() {
mBinding?.run {
mAdapter = UpdatableGameAdapter(mViewModel!!)
recyclerView.itemAnimator = null
recyclerView.layoutManager = FixLinearLayoutManager(requireContext())
recyclerView.adapter = mAdapter?.also {
recyclerView.addOnScrollListener(ExposureListener(this@UpdatableGameFragment, it))

View File

@ -32,10 +32,6 @@ data class AmwayCommentEntity(
@SerializedName("new_star")
var star: Float,
var subtitle: String? = "",
@SerializedName("subtitle_style")
var subtitleStyle: TagStyleEntity? = null,
// 曝光用的位置
var sequence: Int = 0,
var outerSequence: Int = 0
@ -54,9 +50,6 @@ data class AmwayCommentEntity(
gameEntity.iconSubscript = iconSubscript
gameEntity.platform = ""
gameEntity.subtitle = subtitle ?: ""
gameEntity.subtitleStyle = subtitleStyle
gameEntity.sequence = sequence
gameEntity.outerSequence = outerSequence
return gameEntity

View File

@ -1,40 +0,0 @@
package com.gh.gamecenter.entity
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
@Parcelize
data class ArchiveEntity(
@SerializedName("_id")
var id: String = "",
var name: String = "",
var desc: String = "",
var url: String = "",
@SerializedName("config_url")
var configUrl: String = "",
var md5: String = "",
@SerializedName("game_version")
var gameVersion: String = "",
var count: Count = Count(),
var time: Time = Time(),
@SerializedName("is_shared")
var isShared: Boolean = false,
var user: UserEntity = UserEntity(),
// 本地字段
@SerializedName("game_id")
var gameId: String = ""
) : Parcelable {
@Parcelize
data class Count(
var usage: Int = 0,
) : Parcelable
@Parcelize
data class Time(
var create: Long = 0L,
var update: Long = 0L,
) : Parcelable
}

View File

@ -308,10 +308,6 @@ data class GameEntity(
// 游戏分类,用于埋点使用
var gameType: String = "",
//游戏存档 需要使用
var configUrl: String = "",
//是否广告,用于曝光使用
var isAdData: Boolean = false
) : Parcelable {
constructor(id: String?) : this() {
@ -616,18 +612,6 @@ data class GameEntity(
}
}
fun isUseDefaultServerStyle(): Boolean {
return if (serverLabel == null) {
false
} else {
serverLabel?.value == "公测"
|| serverLabel?.value == "不删档内测"
|| serverLabel?.value == "删档内测"
|| serverLabel?.value == "即将开测"
|| serverLabel?.value == "明日开测"
}
}
fun isSpecialDownload() = RegionSettingHelper.shouldThisGameShowSpecialDownload(id)
fun toSimpleGame(): SimpleGame {
@ -696,8 +680,6 @@ data class GameEntity(
gameEntity.simulatorType = simulatorType
gameEntity.displayContent = displayContent
gameEntity.isPlatformRecommend = isPlatformRecommend
gameEntity.adIconActive = adIconActive
gameEntity.isAdData = isAdData
return gameEntity
}
@ -894,11 +876,7 @@ data class SimpleGame(
@SerializedName("recommend_text")
var recommendText: String = "",
@SerializedName("download_status")
var downloadStatus: String = "",
var subtitle: String? = "",
@SerializedName("subtitle_style")
var subtitleStyle: TagStyleEntity? = null,
var downloadStatus: String = ""
) : Parcelable {
@IgnoredOnParcel
@ -924,8 +902,6 @@ data class SimpleGame(
gameEntity.recommendStar = recommendStar
gameEntity.recommendText = recommendText
gameEntity.downloadStatus = downloadStatus
gameEntity.subtitle = subtitle ?: ""
gameEntity.subtitleStyle = subtitleStyle
return gameEntity
}

View File

@ -16,9 +16,6 @@ data class HistoryGameEntity(
var tag: ArrayList<String>? = null,
var isLibaoExist: Boolean = false,
var subtitle: String = "",
var subtitleStyle: TagStyleEntity? = null,
@SerializedName("tag_style")
var tagStyle: ArrayList<TagStyleEntity> = ArrayList(),
@ -34,8 +31,6 @@ data class HistoryGameEntity(
gameEntity.des = des
gameEntity.rawIcon = icon
gameEntity.iconSubscript = iconSubscript
gameEntity.subtitle = subtitle
gameEntity.subtitleStyle = subtitleStyle
gameEntity.name = name
gameEntity.tagStyle = tagStyle
gameEntity.isLibaoExists = isLibaoExist

View File

@ -30,6 +30,4 @@ data class HomeContent(
val secondLineRecommend: String = "",
@SerializedName("recommend_tag")
val recommendTag: String = "",
@SerializedName("ad_icon_active")
val adIconActive: Boolean = false,
)

View File

@ -35,24 +35,11 @@ data class LibaoEntity(
var expires: Int = 0,//过期时间
@SerializedName("libao_active")
var libaoActive: Boolean = false,//后台礼包是否被隐藏
@SerializedName("receive_limit")
var receiveLimit: String = "", //领取限制,暂时只有"通过活动自动发放"->“activity_grant”
@SerializedName("activity_link")
var activityLink: ActivityLink = ActivityLink(), //关联活动链接数据
@SerializedName("app_and_plugin_hide")
var appAndPluginHide: Boolean = false, //app和插件内不显示
//本地字段
var clickReceiveBtnIn: Boolean = false//是否是点击列表领取按钮进入
) : Parcelable {
@Parcelize
data class ActivityLink(
var link: String = "",
var text: String = "",
var url: String = ""
) : Parcelable
fun getIcon(): String {
return if (game != null) {
game!!.getIcon()

Some files were not shown because too many files have changed in this diff Show More