1、接入并联调小程序跳转
2、添加直接跳转未下载资源的逻辑
This commit is contained in:
shenzuqiang 2026-03-05 16:36:04 +08:00
parent cfc1767f0e
commit 0875f2da9a
11 changed files with 687 additions and 277 deletions

View File

@ -4,10 +4,10 @@
<selectionStates> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-03-04T10:36:17.441189700Z"> <DropdownSelection timestamp="2026-03-05T07:51:25.715983900Z">
<Target type="DEFAULT_BOOT"> <Target type="DEFAULT_BOOT">
<handle> <handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=Y5DELZR46DZTCI9D" /> <DeviceId pluginId="PhysicalDevice" identifier="serial=JRBI89BIE6AI5TG6" />
</handle> </handle>
</Target> </Target>
</DropdownSelection> </DropdownSelection>

View File

@ -52,11 +52,9 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.permissions.ExperimentalPermissionsApi import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.img.rabbit.bean.response.UserInfoEntity
import com.img.rabbit.config.Constants import com.img.rabbit.config.Constants
import com.img.rabbit.config.Constants.agreementUrl import com.img.rabbit.config.Constants.agreementUrl
import com.img.rabbit.config.Constants.privacyUrl import com.img.rabbit.config.Constants.privacyUrl
@ -64,8 +62,8 @@ import com.img.rabbit.pages.LoadingCallback
import com.img.rabbit.pages.LoginScreen import com.img.rabbit.pages.LoginScreen
import com.img.rabbit.pages.LoginScreenType import com.img.rabbit.pages.LoginScreenType
import com.img.rabbit.pages.MainScreen import com.img.rabbit.pages.MainScreen
import com.img.rabbit.pages.dialog.TipsDialog
import com.img.rabbit.pages.dialog.TipsUniMpDialog import com.img.rabbit.pages.dialog.TipsUniMpDialog
import com.img.rabbit.pages.dialog.TipsUniMpToPageDialog
import com.img.rabbit.pages.dialog.UpdateDialog import com.img.rabbit.pages.dialog.UpdateDialog
import com.img.rabbit.provider.storage.GlobalStateManager import com.img.rabbit.provider.storage.GlobalStateManager
import com.img.rabbit.provider.storage.PreferenceUtil import com.img.rabbit.provider.storage.PreferenceUtil
@ -74,6 +72,7 @@ import com.img.rabbit.utils.AppUpdate
import com.img.rabbit.utils.ChannelUtils import com.img.rabbit.utils.ChannelUtils
import com.img.rabbit.utils.FileUtils import com.img.rabbit.utils.FileUtils
import com.img.rabbit.utils.UniAppUtils import com.img.rabbit.utils.UniAppUtils
import com.img.rabbit.utils.UniMpUpdate
import com.img.rabbit.utils.UpdateUtils import com.img.rabbit.utils.UpdateUtils
import com.img.rabbit.utils.UrlLinkUtils.openAgreement import com.img.rabbit.utils.UrlLinkUtils.openAgreement
import com.img.rabbit.viewmodel.GeneralViewModel import com.img.rabbit.viewmodel.GeneralViewModel
@ -99,7 +98,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
enableEdgeToEdge() enableEdgeToEdge()
setContent { setContent {
val scope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
val splashViewModel: SplashViewModel = viewModel() val splashViewModel: SplashViewModel = viewModel()
val generalViewModel: GeneralViewModel = viewModel() val generalViewModel: GeneralViewModel = viewModel()
@ -107,13 +106,13 @@ class MainActivity : ComponentActivity(), LoadingCallback {
val context = LocalContext.current val context = LocalContext.current
var showSplash by remember { mutableStateOf(false) } var showSplash by remember { mutableStateOf(false) }
var globalLogin by mutableStateOf(GlobalStateManager(context).globalLoginNotifyFlow().collectAsState(initial = false)) var globalLogin by mutableStateOf(GlobalStateManager(context).globalLoginNotifyFlow().collectAsState(initial = false))
var globalLogout by mutableStateOf(GlobalStateManager(context).globalLogoutNotifyFlow().collectAsState(initial = false)) var globalLogout by mutableStateOf(GlobalStateManager(context).globalLogoutNotifyFlow().collectAsState(initial = false))
var globalBind by mutableStateOf(GlobalStateManager(context).globalBindNotifyFlow().collectAsState(initial = false)) var globalBind by mutableStateOf(GlobalStateManager(context).globalBindNotifyFlow().collectAsState(initial = false))
var globalUnBind by mutableStateOf(GlobalStateManager(context).globalUnBindNotifyFlow().collectAsState(initial = false)) var globalUnBind by mutableStateOf(GlobalStateManager(context).globalUnBindNotifyFlow().collectAsState(initial = false))
var globalUpdate by mutableStateOf(GlobalStateManager(context).globalUpdateNotifyFlow().collectAsState(initial = false)) var globalUpdate by mutableStateOf(GlobalStateManager(context).globalUpdateNotifyFlow().collectAsState(initial = false))
val globalUniUpdate by GlobalStateManager(context).globalUniUpdateNotifyFlow().collectAsState(initial = false) val globalUniUpdate by GlobalStateManager(context).globalUniUpdateNotifyFlow().collectAsState(initial = false)
val globalUniDownload by GlobalStateManager(context).globalUniDownloadNotifyFlow().collectAsState(initial = false)
val globalLoading by GlobalStateManager(context).isGlobalLoadingFlow().collectAsState(initial = false) val globalLoading by GlobalStateManager(context).isGlobalLoadingFlow().collectAsState(initial = false)
LaunchedEffect(generalViewModel.agreementStatus.value) { LaunchedEffect(generalViewModel.agreementStatus.value) {
@ -231,18 +230,76 @@ class MainActivity : ComponentActivity(), LoadingCallback {
} }
} }
//提示下载小程序资源(在跳转指定页面时,未下载资源需要提示)
val progressWGTToPageState = mutableFloatStateOf(0f)
if(globalUniDownload == true){
UniAppUtils.currentDownloadUniMp?.let {
UniAppUtils.downloadReleaseWgt(
coroutineScope,
it,
onProgress = { uniState, progress ->
when (uniState) {
UniMpUpdate.DOWNLOAD_START -> {
//资源开始下载
progressWGTToPageState.floatValue = 0f
Log.i("HomeScreen","DOWNLOAD_START")
}
UniMpUpdate.DOWNLOAD_FINISH -> {
//资源下载完成
progressWGTToPageState.floatValue = 1f
Log.i("HomeScreen","DOWNLOAD_FINISH")
coroutineScope.launch {
GlobalStateManager(context).storeGlobalUniDownloadNotify(false)
}
}
UniMpUpdate.DOWNLOAD_FAIL -> {
//资源下载失败
progressWGTToPageState.floatValue = -1f
Log.i("HomeScreen","DOWNLOAD_FAIL")
coroutineScope.launch {
GlobalStateManager(context).storeGlobalUniDownloadNotify(false)
}
}
else -> {
//资源下载进度
if(progress != null){
progressWGTToPageState.floatValue = progress
Log.i("HomeScreen","DOWNLOAD_PROGRESS:$progress")
}
}
}
},
onRelease = {
//资源下载完成后,启动小程序到指定位置
val uniMpEntity = UniAppUtils.currentDownloadUniMp
if(uniMpEntity!=null){
UniAppUtils.startUniMpPage(context = context, uniMpId = uniMpEntity.unimp_id, uniMpType = uniMpEntity.unimp_type, pagePath = UniAppUtils.currentUniMpJumpPatch?:"")
}
}
)
TipsUniMpToPageDialog(
title = "下载资源",
content1 = "需要下载完资源才能运行,请稍后...",
content2 = null,
downProgress = progressWGTToPageState
)
}
}
//UniApp更新提示 //UniApp更新提示
val isDownloadingWGT = mutableStateOf(false) val isDownloadingWGT = mutableStateOf(false)
val progressWGTState = mutableFloatStateOf(0f) val progressWGTState = mutableFloatStateOf(0f)
if(globalUniUpdate == true){ if(globalUniUpdate == true){
generalViewModel.currentUpdateUniMp?.let { UniAppUtils.currentUpdateUniMp?.let {
TipsUniMpDialog( TipsUniMpDialog(
title = "资源包更新", title = "资源包更新",
content1 = "是否确定更新资源包", content1 = "是否确定更新资源包",
content2 = null, content2 = null,
cancel = "取消", cancel = "取消",
confirm = "确定", confirm = "确定",
scope = scope, scope = coroutineScope,
data = it, data = it,
isStartDown = isDownloadingWGT, isStartDown = isDownloadingWGT,
downProgress = progressWGTState, downProgress = progressWGTState,
@ -250,7 +307,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
if(!isUpdateFinish && !isCancel && data != null){ if(!isUpdateFinish && !isCancel && data != null){
isDownloadingWGT.value = true isDownloadingWGT.value = true
}else{ }else{
scope.launch { GlobalStateManager(context).storeGlobalUniUpdateNotify(false) } coroutineScope.launch { GlobalStateManager(context).storeGlobalUniUpdateNotify(false) }
} }
} }
) )
@ -266,19 +323,19 @@ class MainActivity : ComponentActivity(), LoadingCallback {
newVersion = "V${PreferenceUtil.getUserConfig()?.config?.versionEntity?.version}", newVersion = "V${PreferenceUtil.getUserConfig()?.config?.versionEntity?.version}",
desc = PreferenceUtil.getUserConfig()?.config?.versionEntity?.description?:"", desc = PreferenceUtil.getUserConfig()?.config?.versionEntity?.description?:"",
url = PreferenceUtil.getUserConfig()?.config?.versionEntity?.url?:"", url = PreferenceUtil.getUserConfig()?.config?.versionEntity?.url?:"",
scope = scope, scope = coroutineScope,
isStartDown = isStartDownload, isStartDown = isStartDownload,
downProgress = progressState downProgress = progressState
){ state, isCancel, url -> ){ state, isCancel, url ->
if(isCancel) { if(isCancel) {
scope.launch { coroutineScope.launch {
GlobalStateManager(context).storeGlobalUpdateNotify(state) GlobalStateManager(context).storeGlobalUpdateNotify(state)
} }
} }
if(!isCancel){ if(!isCancel){
isStartDownload.value = true isStartDownload.value = true
UpdateUtils.download( UpdateUtils.download(
scope = scope, scope = coroutineScope,
url = url, url = url,
filePath = FileUtils.getInstance().cacheDownLoadDir.absolutePath, filePath = FileUtils.getInstance().cacheDownLoadDir.absolutePath,
fileName = AppUpdate.getFileNameFromUrl(url), fileName = AppUpdate.getFileNameFromUrl(url),
@ -290,7 +347,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
filePath?.let { filePath?.let {
UpdateUtils.install(context,it) UpdateUtils.install(context,it)
} }
scope.launch { coroutineScope.launch {
GlobalStateManager(context).storeGlobalUpdateNotify(state) GlobalStateManager(context).storeGlobalUpdateNotify(state)
} }
} }

View File

@ -258,81 +258,6 @@ fun TipsUniMpDialog(
} }
} }
//取消
// Row(
// modifier = Modifier
// .fillMaxWidth()
// .padding(start = 18.dp, end = 18.dp, bottom = 20.dp)
// ) {
// Box(
// modifier = Modifier
// .fillMaxWidth()
// .wrapContentHeight()
// .weight(1f)
// .background(
// Color(0x00000000),
// shape = RoundedCornerShape(359.dp),
// )
// .border(
// width = 1.dp,
// color = Color(0xFF000000),
// shape = RoundedCornerShape(359.dp)
// )
// .clickable(
// indication = null,
// interactionSource = remember { MutableInteractionSource() }
// ) {
// onStatusChange(false, true, data)
// }
// ) {
// Text(
// cancel,
// color = Color(0xFF1A1A1A),
// fontSize = 16.sp,
// fontWeight = FontWeight.Bold,
// modifier = Modifier
// .wrapContentWidth()
// .wrapContentHeight()
// .padding(vertical = 12.dp)
// .align(Alignment.Center)
// )
// }
//
// Box(
// modifier = Modifier
// .width(11.dp)
// )
//
// //确定
// Box(
// modifier = Modifier
// .fillMaxWidth()
// .wrapContentHeight()
// .weight(1f)
// .background(
// Color(0xFF252525),
// shape = RoundedCornerShape(359.dp),
// )
// .clickable(
// indication = null,
// interactionSource = remember { MutableInteractionSource() }
// ) {
// onStatusChange(false, false, data)
// }
// ) {
// Text(
// confirm,
// color = Color(0xFFC2FF43),
// fontSize = 16.sp,
// fontWeight = FontWeight.Bold,
// modifier = Modifier
// .wrapContentWidth()
// .wrapContentHeight()
// .padding(vertical = 12.dp)
// .align(Alignment.Center)
// )
// }
// }
} }
} }

View File

@ -0,0 +1,149 @@
package com.img.rabbit.pages.dialog
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.img.rabbit.R
@Composable
fun TipsUniMpToPageDialog(
title: String?,
content1: String?,
content2: String?,
downProgress: MutableState<Float>,
){
val context = LocalContext.current
Column(
modifier = Modifier
.fillMaxSize()
.background(Color(0x80000000))
.clickable(
indication = null,
interactionSource = remember { MutableInteractionSource() }
) { },
verticalArrangement = Arrangement.Center
){
Box(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(horizontal = 36.dp)
.background(Color.White, shape = RoundedCornerShape(26.dp))
.align(Alignment.CenterHorizontally)
.clickable(
indication = null,
interactionSource = remember { MutableInteractionSource() }
) {
//什么都不用做,只是解决点击穿透问题
}
) {
Image(
painter = painterResource(id = R.mipmap.ic_dialog_top_mask1),
contentDescription = null,
contentScale = ContentScale.FillWidth,
modifier = Modifier
.fillMaxWidth()
)
Column(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(top = 46.dp)
) {
if(!title.isNullOrEmpty()){
Text(
text = title,
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
color = Color(0xFF1A1A1A),
modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
)
}
Box(
modifier = Modifier
.fillMaxWidth()
.height(14.dp)
)
if(!content1.isNullOrEmpty()){
Text(
text = content1,
fontSize = 12.sp,
fontWeight = FontWeight.Normal,
color = Color(0xFF767676),
modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
)
}
if(!content2.isNullOrEmpty()){
Text(
text = content2,
fontSize = 12.sp,
fontWeight = FontWeight.Normal,
color = Color(0xFF767676),
modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
)
}
Box(
modifier = Modifier
.fillMaxWidth()
.height(16.dp)
)
Row(
modifier = Modifier
.fillMaxWidth()
.padding(start = 18.dp, end = 18.dp, bottom = 20.dp)
) {
Column(
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp)
) {
// 使用 LinearProgressIndicator 显示确定性进度
LinearProgressIndicator(
progress = { downProgress.value }, // 使用 Lambda 更新进度0~1
modifier = Modifier.fillMaxWidth().height(8.dp)
)
Text(text = "下载进度: ${(downProgress.value * 100).toInt()}%")
}
}
}
}
}
}

View File

@ -28,8 +28,8 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateMapOf
@ -58,10 +58,8 @@ import com.img.rabbit.pages.LoadingCallback
import com.img.rabbit.provider.storage.GlobalStateManager import com.img.rabbit.provider.storage.GlobalStateManager
import com.img.rabbit.provider.storage.PreferenceUtil import com.img.rabbit.provider.storage.PreferenceUtil
import com.img.rabbit.route.ScreenRoute import com.img.rabbit.route.ScreenRoute
import com.img.rabbit.utils.MMKVUtils.put
import com.img.rabbit.utils.UniAppUtils import com.img.rabbit.utils.UniAppUtils
import com.img.rabbit.utils.UniMpUpdate import com.img.rabbit.utils.UniMpUpdate
import com.img.rabbit.utils.UniState
import com.img.rabbit.viewmodel.GeneralViewModel import com.img.rabbit.viewmodel.GeneralViewModel
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -83,6 +81,9 @@ fun HomeScreen(
// 只有当当前路由处于首页 Tab 之一时,才激活 BackHandler // 只有当当前路由处于首页 Tab 之一时,才激活 BackHandler
var lastClickTime by remember { mutableLongStateOf(0L) } var lastClickTime by remember { mutableLongStateOf(0L) }
val globalUserConfig by GlobalStateManager(context).globalUserConfigNotifyFlow().collectAsState(initial = false)
BackHandler(enabled = (currentRoute == ScreenRoute.Home.route)) { BackHandler(enabled = (currentRoute == ScreenRoute.Home.route)) {
val currentTime = System.currentTimeMillis() val currentTime = System.currentTimeMillis()
if (currentTime - lastClickTime > 2000) { if (currentTime - lastClickTime > 2000) {
@ -102,6 +103,16 @@ fun HomeScreen(
} }
} }
var homeIconConfig by remember { mutableStateOf(PreferenceUtil.getUserConfig()?.config?.homeIconEntity) }
var uniVersionConfig by remember { mutableStateOf(PreferenceUtil.getUserConfig()?.config?.uniVersionEntity) }
LaunchedEffect(globalUserConfig) {
if(globalUserConfig == true){
homeIconConfig = PreferenceUtil.getUserConfig()?.config?.homeIconEntity
uniVersionConfig = PreferenceUtil.getUserConfig()?.config?.uniVersionEntity
}
}
Column( Column(
modifier = Modifier modifier = Modifier
.background(Color.White) .background(Color.White)
@ -124,14 +135,14 @@ fun HomeScreen(
shape = RoundedCornerShape(topStart = 18.dp, topEnd = 18.dp) shape = RoundedCornerShape(topStart = 18.dp, topEnd = 18.dp)
) )
){ ){
val homeIconConfig = PreferenceUtil.getUserConfig()?.config?.homeIconEntity val homeIconConfig = homeIconConfig
//大于9时每排展示3个否则每排展示4个 //大于9时每排展示3个否则每排展示4个
val columnsCount = if((homeIconConfig?.size?:0) >= 9){ 3 }else{ 4 } val columnsCount = if((homeIconConfig?.size?:0) >= 9){ 3 }else{ 4 }
val rows = homeIconConfig?.chunked(columnsCount)?:emptyList() val rows = homeIconConfig?.chunked(columnsCount)?:emptyList()
item { item {
//通过配置展示-AD1(模拟器) //通过配置展示-AD1(模拟器)
val uniVersionConfig = PreferenceUtil.getUserConfig()?.config?.uniVersionEntity val uniVersionConfig = uniVersionConfig
if(uniVersionConfig?.isNotEmpty() == true){ if(uniVersionConfig?.isNotEmpty() == true){
val uniVersionSize = uniVersionConfig.size val uniVersionSize = uniVersionConfig.size
//模拟器 //模拟器
@ -161,29 +172,50 @@ fun HomeScreen(
// 处理点击事件,微信模拟器 // 处理点击事件,微信模拟器
if (UniAppUtils.isDownloadUniMp(uniMp)) { if (UniAppUtils.isDownloadUniMp(uniMp)) {
//强制更新(更新释放新版本并启动) //强制更新(更新释放新版本并启动)
UniAppUtils.downloadWGT(context, scope, uniMp){ uniState, filePath, progress -> UniAppUtils.downloadWGT(
progressPair[uniMpId]?: mutableMapOf<String, Float>().apply{put(uniMpId, 0f)} context,
scope,
uniMp
) { uniState, filePath, progress ->
progressPair[uniMpId]
?: mutableMapOf<String, Float>().apply {
put(
uniMpId,
0f
)
}
when (uniState) { when (uniState) {
UniMpUpdate.DOWNLOAD_START -> { UniMpUpdate.DOWNLOAD_START -> {
//资源开始下载 //资源开始下载
progressPair.apply { put(uniMpId, 0f) } progressPair.apply { put(uniMpId, 0f) }
Log.i("HomeScreen", "DOWNLOAD_START") Log.i("HomeScreen", "DOWNLOAD_START")
} }
UniMpUpdate.DOWNLOAD_FINISH -> { UniMpUpdate.DOWNLOAD_FINISH -> {
//资源下载完成 //资源下载完成
progressPair.apply { put(uniMpId, 1f) } progressPair.apply { put(uniMpId, 1f) }
Log.i("HomeScreen", "DOWNLOAD_FINISH") Log.i("HomeScreen", "DOWNLOAD_FINISH")
} }
UniMpUpdate.DOWNLOAD_FAIL -> { UniMpUpdate.DOWNLOAD_FAIL -> {
//资源下载失败 //资源下载失败
progressPair.apply { put(uniMpId, -1f) } progressPair.apply { put(uniMpId, -1f) }
Log.i("HomeScreen", "DOWNLOAD_FAIL") Log.i("HomeScreen", "DOWNLOAD_FAIL")
} }
else -> { else -> {
//资源下载进度 //资源下载进度
if (progress != null) { if (progress != null) {
progressPair.apply { put(uniMpId, progress) } progressPair.apply {
Log.i("HomeScreen","DOWNLOAD_PROGRESS:$progress") put(
uniMpId,
progress
)
}
Log.i(
"HomeScreen",
"DOWNLOAD_PROGRESS:$progress"
)
} }
} }
@ -191,9 +223,11 @@ fun HomeScreen(
} }
} else if (UniAppUtils.isUpdate(uniMp)) { } else if (UniAppUtils.isUpdate(uniMp)) {
// 提示更新1、更新释放新版本并启动2、直接启动现有版本 // 提示更新1、更新释放新版本并启动2、直接启动现有版本
generalViewModel.currentUpdateUniMp = uniMp UniAppUtils.currentUpdateUniMp = uniMp
scope.launch { scope.launch {
GlobalStateManager(context).storeGlobalUniUpdateNotify(true) GlobalStateManager(context).storeGlobalUniUpdateNotify(
true
)
} }
} else { } else {
loadingCallback?.showLoading() loadingCallback?.showLoading()
@ -210,7 +244,9 @@ fun HomeScreen(
model = uniIcon, model = uniIcon,
contentDescription = "微信模拟器图标", contentDescription = "微信模拟器图标",
contentScale = ContentScale.FillWidth, contentScale = ContentScale.FillWidth,
modifier = Modifier.fillMaxWidth().aspectRatio(168/96f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(168 / 96f),
fallback = painterResource(id = R.mipmap.ic_wx_mock), fallback = painterResource(id = R.mipmap.ic_wx_mock),
error = painterResource(id = R.mipmap.ic_wx_mock) error = painterResource(id = R.mipmap.ic_wx_mock)
) )
@ -218,17 +254,27 @@ fun HomeScreen(
//下载完成前显示 //下载完成前显示
if((progressPair[uniMpId]?:0f) > 0f && (progressPair[uniMpId]?:0f) < 1f){ if((progressPair[uniMpId]?:0f) > 0f && (progressPair[uniMpId]?:0f) < 1f){
Box( Box(
modifier = Modifier.fillMaxWidth().aspectRatio(168/96f).background(Color( modifier = Modifier
.fillMaxWidth()
.aspectRatio(168 / 96f)
.background(
Color(
0x66000000 0x66000000
), RoundedCornerShape(18.dp)), ), RoundedCornerShape(18.dp)
),
){ ){
Column( Column(
modifier = Modifier.fillMaxWidth().align(Alignment.Center).padding(horizontal = 12.dp) modifier = Modifier
.fillMaxWidth()
.align(Alignment.Center)
.padding(horizontal = 12.dp)
) { ) {
// 使用 LinearProgressIndicator 显示确定性进度 // 使用 LinearProgressIndicator 显示确定性进度
LinearProgressIndicator( LinearProgressIndicator(
progress = { progressPair[uniMpId]?:0f }, // 使用 Lambda 更新进度0~1 progress = { progressPair[uniMpId]?:0f }, // 使用 Lambda 更新进度0~1
modifier = Modifier.fillMaxWidth().height(8.dp) modifier = Modifier
.fillMaxWidth()
.height(8.dp)
) )
Text( Text(
text = "下载${((progressPair[uniMpId]?:0f) * 100).toInt()}%", text = "下载${((progressPair[uniMpId]?:0f) * 100).toInt()}%",
@ -256,29 +302,50 @@ fun HomeScreen(
// 处理点击事件,微信模拟器 // 处理点击事件,微信模拟器
if (UniAppUtils.isDownloadUniMp(uniMp)) { if (UniAppUtils.isDownloadUniMp(uniMp)) {
//强制更新(更新释放新版本并启动) //强制更新(更新释放新版本并启动)
UniAppUtils.downloadWGT(context, scope, uniMp){ uniState, filePath, progress -> UniAppUtils.downloadWGT(
progressPair[uniMpId]?: mutableMapOf<String, Float>().apply{put(uniMpId, 0f)} context,
scope,
uniMp
) { uniState, filePath, progress ->
progressPair[uniMpId]
?: mutableMapOf<String, Float>().apply {
put(
uniMpId,
0f
)
}
when (uniState) { when (uniState) {
UniMpUpdate.DOWNLOAD_START -> { UniMpUpdate.DOWNLOAD_START -> {
//资源开始下载 //资源开始下载
progressPair.apply { put(uniMpId, 0f) } progressPair.apply { put(uniMpId, 0f) }
Log.i("HomeScreen", "DOWNLOAD_START") Log.i("HomeScreen", "DOWNLOAD_START")
} }
UniMpUpdate.DOWNLOAD_FINISH -> { UniMpUpdate.DOWNLOAD_FINISH -> {
//资源下载完成 //资源下载完成
progressPair.apply { put(uniMpId, 1f) } progressPair.apply { put(uniMpId, 1f) }
Log.i("HomeScreen", "DOWNLOAD_FINISH") Log.i("HomeScreen", "DOWNLOAD_FINISH")
} }
UniMpUpdate.DOWNLOAD_FAIL -> { UniMpUpdate.DOWNLOAD_FAIL -> {
//资源下载失败 //资源下载失败
progressPair.apply { put(uniMpId, -1f) } progressPair.apply { put(uniMpId, -1f) }
Log.i("HomeScreen", "DOWNLOAD_FAIL") Log.i("HomeScreen", "DOWNLOAD_FAIL")
} }
else -> { else -> {
//资源下载进度 //资源下载进度
if (progress != null) { if (progress != null) {
progressPair.apply { put(uniMpId, progress) } progressPair.apply {
Log.i("HomeScreen","DOWNLOAD_PROGRESS:$progress") put(
uniMpId,
progress
)
}
Log.i(
"HomeScreen",
"DOWNLOAD_PROGRESS:$progress"
)
} }
} }
@ -286,9 +353,11 @@ fun HomeScreen(
} }
} else if (UniAppUtils.isUpdate(uniMp)) { } else if (UniAppUtils.isUpdate(uniMp)) {
// 提示更新1、更新释放新版本并启动2、直接启动现有版本 // 提示更新1、更新释放新版本并启动2、直接启动现有版本
generalViewModel.currentUpdateUniMp = uniMp UniAppUtils.currentUpdateUniMp = uniMp
scope.launch { scope.launch {
GlobalStateManager(context).storeGlobalUniUpdateNotify(true) GlobalStateManager(context).storeGlobalUniUpdateNotify(
true
)
} }
} else { } else {
loadingCallback?.showLoading() loadingCallback?.showLoading()
@ -306,7 +375,9 @@ fun HomeScreen(
model = uniIcon, model = uniIcon,
contentDescription = "支付宝模拟器", contentDescription = "支付宝模拟器",
contentScale = ContentScale.FillWidth, contentScale = ContentScale.FillWidth,
modifier = Modifier.fillMaxWidth().aspectRatio(168/96f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(168 / 96f),
fallback = painterResource(id = R.mipmap.ic_alipay_mock), fallback = painterResource(id = R.mipmap.ic_alipay_mock),
error = painterResource(id = R.mipmap.ic_alipay_mock) error = painterResource(id = R.mipmap.ic_alipay_mock)
) )
@ -314,17 +385,27 @@ fun HomeScreen(
//下载完成前显示 //下载完成前显示
if((progressPair[uniMpId]?:0f) > 0f && (progressPair[uniMpId]?:0f) < 1f){ if((progressPair[uniMpId]?:0f) > 0f && (progressPair[uniMpId]?:0f) < 1f){
Box( Box(
modifier = Modifier.fillMaxWidth().aspectRatio(168/96f).background(Color( modifier = Modifier
.fillMaxWidth()
.aspectRatio(168 / 96f)
.background(
Color(
0x66000000 0x66000000
), RoundedCornerShape(18.dp)), ), RoundedCornerShape(18.dp)
),
){ ){
Column( Column(
modifier = Modifier.fillMaxWidth().align(Alignment.Center).padding(horizontal = 12.dp) modifier = Modifier
.fillMaxWidth()
.align(Alignment.Center)
.padding(horizontal = 12.dp)
) { ) {
// 使用 LinearProgressIndicator 显示确定性进度 // 使用 LinearProgressIndicator 显示确定性进度
LinearProgressIndicator( LinearProgressIndicator(
progress = { progressPair[uniMpId]?:0f }, // 使用 Lambda 更新进度0~1 progress = { progressPair[uniMpId]?:0f }, // 使用 Lambda 更新进度0~1
modifier = Modifier.fillMaxWidth().height(8.dp) modifier = Modifier
.fillMaxWidth()
.height(8.dp)
) )
Text( Text(
text = "下载${((progressPair[uniMpId]?:0f) * 100).toInt()}%", text = "下载${((progressPair[uniMpId]?:0f) * 100).toInt()}%",
@ -345,14 +426,46 @@ fun HomeScreen(
//通过配置展示-AD2 //通过配置展示-AD2
Row(Modifier.fillMaxWidth()) { Row(Modifier.fillMaxWidth()) {
for (item in rowItems) { for (item in rowItems) {
Box(Modifier.weight(1f)) { Box(
modifier = Modifier
.weight(1f)
.clickable(
indication = null,
interactionSource = remember { MutableInteractionSource() }
) {
val uniVersion =
PreferenceUtil.getUserConfig()?.config?.uniVersionEntity?.firstOrNull { it.unimp_type == item.type }
if(uniVersion == null){
Toast.makeText(context, "无可用资源...", Toast.LENGTH_SHORT).show()
return@clickable
}
val uniMpId = uniVersion.unimp_id
UniAppUtils.currentUniMpJumpPatch = item.url
val wgtExists = UniAppUtils.wgtIsExists(uniMpId)
if(!wgtExists){
//是否下载
scope.launch {
UniAppUtils.currentDownloadUniMp = uniVersion
GlobalStateManager(context).storeGlobalUniDownloadNotify(true)
}
}else {
UniAppUtils.startUniMpPage(context = context, uniMpId = uniMpId, uniMpType = item.type, pagePath = item.url)
}
}
) {
Column { Column {
Box(modifier = Modifier.fillMaxWidth().height(8.dp)) Box(modifier = Modifier
.fillMaxWidth()
.height(8.dp))
AsyncImage( AsyncImage(
model = item.icon, model = item.icon,
contentDescription = item.text, contentDescription = item.text,
contentScale = ContentScale.FillWidth, contentScale = ContentScale.FillWidth,
modifier = Modifier.width(48.dp).aspectRatio(48/48f).align(Alignment.CenterHorizontally), modifier = Modifier
.width(48.dp)
.aspectRatio(48 / 48f)
.align(Alignment.CenterHorizontally),
fallback = painterResource(id = R.mipmap.ic_alipay_mock), fallback = painterResource(id = R.mipmap.ic_alipay_mock),
error = painterResource(id = R.mipmap.ic_alipay_mock) error = painterResource(id = R.mipmap.ic_alipay_mock)
) )
@ -361,7 +474,9 @@ fun HomeScreen(
fontSize = 12.sp, fontSize = 12.sp,
fontWeight = FontWeight.Normal, fontWeight = FontWeight.Normal,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -407,7 +522,9 @@ fun HomeScreen(
){ ){
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_size_bg), painter = painterResource(id = R.mipmap.ic_home_size_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(166/68f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(166 / 68f),
contentDescription = null, contentDescription = null,
) )
@ -418,10 +535,13 @@ fun HomeScreen(
) { ) {
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxWidth().weight(0.25f) .fillMaxWidth()
.weight(0.25f)
) )
Column( Column(
modifier = Modifier.wrapContentSize().weight(0.75f) modifier = Modifier
.wrapContentSize()
.weight(0.75f)
) { ) {
Text( Text(
text = "标准一寸", text = "标准一寸",
@ -464,7 +584,9 @@ fun HomeScreen(
){ ){
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_size_bg), painter = painterResource(id = R.mipmap.ic_home_size_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(166/68f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(166 / 68f),
contentDescription = null, contentDescription = null,
) )
@ -475,10 +597,13 @@ fun HomeScreen(
) { ) {
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxWidth().weight(0.25f) .fillMaxWidth()
.weight(0.25f)
) )
Column( Column(
modifier = Modifier.wrapContentSize().weight(0.75f) modifier = Modifier
.wrapContentSize()
.weight(0.75f)
) { ) {
Text( Text(
text = "小一寸", text = "小一寸",
@ -523,7 +648,9 @@ fun HomeScreen(
){ ){
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_size_bg), painter = painterResource(id = R.mipmap.ic_home_size_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(166/68f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(166 / 68f),
contentDescription = null, contentDescription = null,
) )
@ -534,10 +661,13 @@ fun HomeScreen(
) { ) {
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxWidth().weight(0.25f) .fillMaxWidth()
.weight(0.25f)
) )
Column( Column(
modifier = Modifier.wrapContentSize().weight(0.75f) modifier = Modifier
.wrapContentSize()
.weight(0.75f)
) { ) {
Text( Text(
text = "标准二寸", text = "标准二寸",
@ -581,7 +711,9 @@ fun HomeScreen(
){ ){
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_size_bg), painter = painterResource(id = R.mipmap.ic_home_size_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(166/68f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(166 / 68f),
contentDescription = null, contentDescription = null,
) )
@ -592,10 +724,13 @@ fun HomeScreen(
) { ) {
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxWidth().weight(0.25f) .fillMaxWidth()
.weight(0.25f)
) )
Column( Column(
modifier = Modifier.wrapContentSize().weight(0.75f) modifier = Modifier
.wrapContentSize()
.weight(0.75f)
) { ) {
Text( Text(
text = "小二寸", text = "小二寸",
@ -652,7 +787,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_certificate_bg), painter = painterResource(id = R.mipmap.ic_home_certificate_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(80f/50f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(80f / 50f),
contentDescription = null, contentDescription = null,
) )
@ -667,7 +804,9 @@ fun HomeScreen(
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
lineHeight = 12.sp, lineHeight = 12.sp,
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
Text( Text(
text = "26x32mm", text = "26x32mm",
@ -675,7 +814,9 @@ fun HomeScreen(
fontWeight = FontWeight.Normal, fontWeight = FontWeight.Normal,
lineHeight = 10.sp, lineHeight = 10.sp,
color = Color(0xFFAAAAAA), color = Color(0xFFAAAAAA),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -703,7 +844,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_certificate_bg), painter = painterResource(id = R.mipmap.ic_home_certificate_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(80f/50f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(80f / 50f),
contentDescription = null, contentDescription = null,
) )
@ -718,7 +861,9 @@ fun HomeScreen(
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
lineHeight = 12.sp, lineHeight = 12.sp,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
Text( Text(
text = "33x48mm", text = "33x48mm",
@ -726,7 +871,9 @@ fun HomeScreen(
fontWeight = FontWeight.Normal, fontWeight = FontWeight.Normal,
lineHeight = 10.sp, lineHeight = 10.sp,
color = Color(0xFFAAAAAA), color = Color(0xFFAAAAAA),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -754,7 +901,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_certificate_bg), painter = painterResource(id = R.mipmap.ic_home_certificate_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(80f/50f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(80f / 50f),
contentDescription = null, contentDescription = null,
) )
@ -769,7 +918,9 @@ fun HomeScreen(
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
lineHeight = 12.sp, lineHeight = 12.sp,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
Text( Text(
text = "22x32mm", text = "22x32mm",
@ -777,7 +928,9 @@ fun HomeScreen(
fontWeight = FontWeight.Normal, fontWeight = FontWeight.Normal,
lineHeight = 10.sp, lineHeight = 10.sp,
color = Color(0xFFAAAAAA), color = Color(0xFFAAAAAA),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -805,7 +958,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_certificate_bg), painter = painterResource(id = R.mipmap.ic_home_certificate_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(80f/50f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(80f / 50f),
contentDescription = null, contentDescription = null,
) )
@ -820,7 +975,9 @@ fun HomeScreen(
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
lineHeight = 12.sp, lineHeight = 12.sp,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
Text( Text(
text = "26x32mm", text = "26x32mm",
@ -828,7 +985,9 @@ fun HomeScreen(
fontWeight = FontWeight.Normal, fontWeight = FontWeight.Normal,
lineHeight = 10.sp, lineHeight = 10.sp,
color = Color(0xFFAAAAAA), color = Color(0xFFAAAAAA),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -859,7 +1018,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_certificate_bg), painter = painterResource(id = R.mipmap.ic_home_certificate_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(80f/50f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(80f / 50f),
contentDescription = null, contentDescription = null,
) )
@ -874,7 +1035,9 @@ fun HomeScreen(
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
lineHeight = 12.sp, lineHeight = 12.sp,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
Text( Text(
text = "26x32mm", text = "26x32mm",
@ -882,7 +1045,9 @@ fun HomeScreen(
fontWeight = FontWeight.Normal, fontWeight = FontWeight.Normal,
lineHeight = 10.sp, lineHeight = 10.sp,
color = Color(0xFFAAAAAA), color = Color(0xFFAAAAAA),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -910,7 +1075,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_certificate_bg), painter = painterResource(id = R.mipmap.ic_home_certificate_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(80f/50f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(80f / 50f),
contentDescription = null, contentDescription = null,
) )
@ -925,7 +1092,9 @@ fun HomeScreen(
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
lineHeight = 12.sp, lineHeight = 12.sp,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
Text( Text(
text = "33x48mm", text = "33x48mm",
@ -933,7 +1102,9 @@ fun HomeScreen(
fontWeight = FontWeight.Normal, fontWeight = FontWeight.Normal,
lineHeight = 10.sp, lineHeight = 10.sp,
color = Color(0xFFAAAAAA), color = Color(0xFFAAAAAA),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -961,7 +1132,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_certificate_bg), painter = painterResource(id = R.mipmap.ic_home_certificate_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(80f/50f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(80f / 50f),
contentDescription = null, contentDescription = null,
) )
@ -976,7 +1149,9 @@ fun HomeScreen(
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
lineHeight = 12.sp, lineHeight = 12.sp,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
Text( Text(
text = "40x60mm", text = "40x60mm",
@ -984,7 +1159,9 @@ fun HomeScreen(
fontWeight = FontWeight.Normal, fontWeight = FontWeight.Normal,
lineHeight = 10.sp, lineHeight = 10.sp,
color = Color(0xFFAAAAAA), color = Color(0xFFAAAAAA),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -1012,7 +1189,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_certificate_bg), painter = painterResource(id = R.mipmap.ic_home_certificate_bg),
modifier = Modifier.fillMaxWidth().aspectRatio(80f/50f), modifier = Modifier
.fillMaxWidth()
.aspectRatio(80f / 50f),
contentDescription = null, contentDescription = null,
) )
@ -1027,7 +1206,9 @@ fun HomeScreen(
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
lineHeight = 12.sp, lineHeight = 12.sp,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
Text( Text(
text = "35x45mm", text = "35x45mm",
@ -1035,7 +1216,9 @@ fun HomeScreen(
fontWeight = FontWeight.Normal, fontWeight = FontWeight.Normal,
lineHeight = 10.sp, lineHeight = 10.sp,
color = Color(0xFFAAAAAA), color = Color(0xFFAAAAAA),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -1080,7 +1263,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_other_1_puzzle), painter = painterResource(id = R.mipmap.ic_home_other_1_puzzle),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally), modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally),
contentDescription = null, contentDescription = null,
) )
@ -1089,7 +1274,10 @@ fun HomeScreen(
fontSize = 12.sp, fontSize = 12.sp,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().padding(top = 12.dp).align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.padding(top = 12.dp)
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -1119,7 +1307,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_other_2_format), painter = painterResource(id = R.mipmap.ic_home_other_2_format),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally), modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally),
contentDescription = null, contentDescription = null,
) )
@ -1128,7 +1318,10 @@ fun HomeScreen(
fontSize = 12.sp, fontSize = 12.sp,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().padding(top = 12.dp).align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.padding(top = 12.dp)
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -1162,7 +1355,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_other_3_size), painter = painterResource(id = R.mipmap.ic_home_other_3_size),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally), modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally),
contentDescription = null, contentDescription = null,
) )
@ -1171,7 +1366,10 @@ fun HomeScreen(
fontSize = 12.sp, fontSize = 12.sp,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().padding(top = 12.dp).align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.padding(top = 12.dp)
.align(Alignment.CenterHorizontally)
) )
} }
} }
@ -1201,7 +1399,9 @@ fun HomeScreen(
) { ) {
Image( Image(
painter = painterResource(id = R.mipmap.ic_home_other_4_camera), painter = painterResource(id = R.mipmap.ic_home_other_4_camera),
modifier = Modifier.wrapContentSize().align(Alignment.CenterHorizontally), modifier = Modifier
.wrapContentSize()
.align(Alignment.CenterHorizontally),
contentDescription = null, contentDescription = null,
) )
@ -1210,14 +1410,19 @@ fun HomeScreen(
fontSize = 12.sp, fontSize = 12.sp,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
color = Color(0xFF1A1A1A), color = Color(0xFF1A1A1A),
modifier = Modifier.wrapContentSize().padding(top = 12.dp).align(Alignment.CenterHorizontally) modifier = Modifier
.wrapContentSize()
.padding(top = 12.dp)
.align(Alignment.CenterHorizontally)
) )
} }
} }
} }
Box( Box(
modifier = Modifier.fillMaxWidth().height(56.dp) modifier = Modifier
.fillMaxWidth()
.height(56.dp)
) )
} }
} }

View File

@ -27,6 +27,8 @@ class GlobalStateManager(
private val GLOBAL_UNBIND_NOTIFY = booleanPreferencesKey("global_unbind_notify") private val GLOBAL_UNBIND_NOTIFY = booleanPreferencesKey("global_unbind_notify")
private val GLOBAL_UPDATE_NOTIFY = booleanPreferencesKey("global_update_notify") private val GLOBAL_UPDATE_NOTIFY = booleanPreferencesKey("global_update_notify")
private val GLOBAL_UNI_UPDATE_NOTIFY = booleanPreferencesKey("global_uni_update_notify") private val GLOBAL_UNI_UPDATE_NOTIFY = booleanPreferencesKey("global_uni_update_notify")
private val GLOBAL_UNI_DOWNLOAD_NOTIFY = booleanPreferencesKey("global_uni_download_notify")
private val GLOBAL_USER_CONFIG_NOTIFY = booleanPreferencesKey("global_user_config_notify")
} }
suspend fun storeGlobalLoading(value: Boolean) { suspend fun storeGlobalLoading(value: Boolean) {
@ -130,4 +132,32 @@ class GlobalStateManager(
} }
} }
suspend fun storeGlobalUniDownloadNotify(value: Boolean) {
context.storeData.edit { preferences ->
preferences[GLOBAL_UNI_DOWNLOAD_NOTIFY] = value
}
}
fun globalUniDownloadNotifyFlow(): Flow<Boolean?> {
return context.storeData.data.map {
preferences ->
preferences[GLOBAL_UNI_DOWNLOAD_NOTIFY]
}
}
suspend fun storeGlobalUserConfigNotify(value: Boolean) {
context.storeData.edit { preferences ->
preferences[GLOBAL_USER_CONFIG_NOTIFY] = value
}
}
fun globalUserConfigNotifyFlow(): Flow<Boolean?> {
return context.storeData.data.map {
preferences ->
preferences[GLOBAL_USER_CONFIG_NOTIFY]
}
}
} }

View File

@ -1,6 +1,8 @@
package com.img.rabbit.provider.storage package com.img.rabbit.provider.storage
import android.text.TextUtils import android.text.TextUtils
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import com.img.rabbit.bean.response.UserConfigEntity import com.img.rabbit.bean.response.UserConfigEntity
@ -78,8 +80,6 @@ object PreferenceUtil {
return mmkv.decodeBool(KEY_AGREEMENT, false) return mmkv.decodeBool(KEY_AGREEMENT, false)
} }
fun saveUserConfig(config: UserConfigEntity) { fun saveUserConfig(config: UserConfigEntity) {
val resultJson = Gson().toJson(config) val resultJson = Gson().toJson(config)
mmkv.encode(KEY_USER_CONFIG, resultJson) mmkv.encode(KEY_USER_CONFIG, resultJson)

View File

@ -1,28 +1,24 @@
package com.img.rabbit.utils package com.img.rabbit.utils
import android.content.Context import android.content.Context
import android.content.Intent
import android.util.Log import android.util.Log
import android.widget.Toast import android.widget.Toast
import androidx.compose.runtime.snapshots.SnapshotStateMap
import com.bumptech.glide.Glide
import com.github.gzuliyujiang.oaid.DeviceIdentifier import com.github.gzuliyujiang.oaid.DeviceIdentifier
import com.img.rabbit.BuildConfig import com.img.rabbit.BuildConfig
import com.img.rabbit.bean.response.UniVersionEntity import com.img.rabbit.bean.response.UniVersionEntity
import com.img.rabbit.config.Constants import com.img.rabbit.config.Constants
import com.img.rabbit.pages.LoadingCallback import com.img.rabbit.config.Constants.LOG_REQUEST
import com.img.rabbit.provider.storage.GlobalStateManager
import com.img.rabbit.provider.storage.PreferenceUtil import com.img.rabbit.provider.storage.PreferenceUtil
import com.img.rabbit.provider.storage.PreferenceUtil.getBDVID import com.img.rabbit.provider.storage.PreferenceUtil.getBDVID
import com.img.rabbit.provider.utils.HeadParamUtils.applicationContext import com.img.rabbit.provider.utils.HeadParamUtils.applicationContext
import com.img.rabbit.provider.utils.HeadParamUtils.getAppVersionName import com.img.rabbit.provider.utils.HeadParamUtils.getAppVersionName
import com.img.rabbit.uni.UniMPSplashView import com.img.rabbit.uni.UniMPSplashView
import com.img.rabbit.viewmodel.GeneralViewModel
import io.dcloud.feature.sdk.DCUniMPSDK import io.dcloud.feature.sdk.DCUniMPSDK
import io.dcloud.feature.sdk.Interface.IUniMP import io.dcloud.feature.sdk.Interface.IUniMP
import io.dcloud.feature.unimp.config.UniMPOpenConfiguration import io.dcloud.feature.unimp.config.UniMPOpenConfiguration
import io.dcloud.feature.unimp.config.UniMPReleaseConfiguration import io.dcloud.feature.unimp.config.UniMPReleaseConfiguration
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.io.File import java.io.File
import kotlin.jvm.java import kotlin.jvm.java
@ -30,10 +26,13 @@ import kotlin.jvm.java
object UniAppUtils { object UniAppUtils {
val uniMpPair = mutableMapOf<String?, IUniMP?>() val uniMpPair = mutableMapOf<String?, IUniMP?>()
// private var wechatIUniMP: IUniMP? = null
// fun getWechatIUniMP(): IUniMP?{ //当前正在更新的小程序
// return wechatIUniMP var currentUpdateUniMp: UniVersionEntity? = null
// } //当前正在下载的小程序
var currentDownloadUniMp: UniVersionEntity? = null
//仅当跳转指定小程序时,才需要跳转指定位置
var currentUniMpJumpPatch: String? = null
/** /**
* 是否存在更新 * 是否存在更新
*/ */
@ -57,6 +56,17 @@ object UniAppUtils {
return isUpdateForce(uniVersion) || !(FileUtils.getInstance().fileIsExists(wgtFile) && FileUtils.getFileSize(wgtFile) > 0) return isUpdateForce(uniVersion) || !(FileUtils.getInstance().fileIsExists(wgtFile) && FileUtils.getFileSize(wgtFile) > 0)
} }
fun wgtIsExists(uniMpId: String): Boolean{
val wgtName = String.format("%s.wgt", uniMpId)
val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
//判断wgt是否下载
return FileUtils.getInstance().fileIsExists(wgtFile) && FileUtils.getFileSize(wgtFile) > 0
}
private fun isRelease(uniMpId: String): Boolean{
return DCUniMPSDK.getInstance().isExistsApp(uniMpId)
}
/** /**
* 检查更新 * 检查更新
*/ */
@ -120,27 +130,66 @@ object UniAppUtils {
onResult(false) onResult(false)
} }
//释放资源 /**
* 启动小程序并直达指定页面
*/
fun startUniMpPage(context: Context, uniMpId: String, uniMpType: String, pagePath: String){
if(isRelease(uniMpId)){
releaseWgt(uniMpId){
// 启动直达页面
startUniMpToPage(context, uniMpId, uniMpType, pagePath)
}
}else{
if(uniMpPair[uniMpId]?.isRuning == true){
uniMpPair[uniMpId]?.closeUniMP()
}
// 启动直达页面
startUniMpToPage(context, uniMpId, uniMpType, pagePath)
}
}
private fun startUniMpToPage(context: Context, uniMpId: String, uniMpType: String, pagePath: String){
// 启动直达页面
val configuration = getUniMPOpenConfiguration()
if(uniMpType == "wx"){
configuration.splashClass = UniMPSplashView::class.java
}
configuration.path = pagePath
uniMpPair[uniMpId] = DCUniMPSDK.getInstance().openUniMP(context, uniMpId, configuration)
}
private fun releaseWgt(versionEntity: UniVersionEntity, onReleaseWgt: (isSuccess: Boolean, versionEntity: UniVersionEntity) -> Unit) { private fun releaseWgt(versionEntity: UniVersionEntity, onReleaseWgt: (isSuccess: Boolean, versionEntity: UniVersionEntity) -> Unit) {
val wgtName = String.format("%s.wgt", versionEntity.unimp_id) releaseWgt(versionEntity.unimp_id){ isSuccess ->
if(isSuccess){
onReleaseWgt(true, versionEntity)
}else{
onReleaseWgt(false, versionEntity)
}
}
}
//释放资源
private fun releaseWgt(uniMpId: String, onReleaseWgt: (isSuccess: Boolean) -> Unit) {
val wgtName = String.format("%s.wgt", uniMpId)
val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName) val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
val uniMPReleaseConfiguration = UniMPReleaseConfiguration().apply { val uniMPReleaseConfiguration = UniMPReleaseConfiguration().apply {
wgtPath = wgtFile.path wgtPath = wgtFile.path
password = "6462"////没有密码可以不写 password = "6462"////没有密码可以不写
} }
DCUniMPSDK.getInstance().releaseWgtToRunPath(versionEntity.unimp_id, uniMPReleaseConfiguration DCUniMPSDK.getInstance().releaseWgtToRunPath(uniMpId, uniMPReleaseConfiguration
) { code, _ -> ) { code, _ ->
if (code == 1) { if (code == 1) {
//释放wgt完成 //释放wgt完成
onReleaseWgt(true, versionEntity) onReleaseWgt(true)
} else { } else {
//释放wgt失败 //释放wgt失败
Toast.makeText(applicationContext, "小程序加载失败,请清除缓存后重试!", Toast.LENGTH_SHORT).show() Toast.makeText(applicationContext, "小程序加载失败,请清除缓存后重试!", Toast.LENGTH_SHORT).show()
onReleaseWgt(false, versionEntity) onReleaseWgt(false)
} }
} }
} }
/** /**
* 下载wgt文件 * 下载wgt文件
*/ */
@ -156,56 +205,44 @@ object UniAppUtils {
distributeUniMp(context, uniVersion) { loading ->} distributeUniMp(context, uniVersion) { loading ->}
} }
} }
/*
if (wechatIUniMP?.isRuning == true) {
Log.i("UniAppUtils", "startUniMp: 运行中...")
onResult(UniState.START_OFF, runFile.path, 1f)
return
} }
if(isUpdateUniMP && DCUniMPSDK.getInstance().isExistsApp(uniMpID)){ /**
//资源已释放,直接运行 * 下载并释放资源但不会启动
loadUniMp(uniMpID, uniVersion.unimp_type){ loading ->
onResult(if(loading) UniState.START_OFF else UniState.START_FAIL, runFile.path, if(loading)1f else 0f)
}
return
}
if (FileUtils.getInstance().fileIsExists(wgtFile) && FileUtils.getFileSize(wgtFile) > 0 && !uniVersion.force) {
if (!isUpdateUniMP) {
//文件存在,且不是强制更新,直接启动
onResult(UniState.START_ON, wgtFile.path, 1f)
startUniMp(uniMpID, uniVersion.unimp_type, wgtFile){loading->
onResult(if(loading) UniState.START_OFF else UniState.START_FAIL, wgtFile.path, if(loading)1f else 0f)
}
} else {
//文件存在,有更新,提示用户更新
scope.launch { applicationContext?.let { GlobalStateManager(it).storeGlobalUniUpdateNotify(true) } }
}
return
}
//直接更新
downloadUniMp(scope, uniVersion){uniState, filePath, progress ->
if(uniState == UniState.FINISH_DOWNLOAD){
PreferenceUtil.saveWgtVersion(uniVersion.version)
startUniMp(uniVersion.unimp_id, uniVersion.unimp_type, wgtFile){loading->
onResult(if(loading) UniState.START_OFF else UniState.START_FAIL, wgtFile.path, if(loading)1f else 0f)
}
}else{
onResult(uniState, filePath, progress)
}
}
*/ */
} fun downloadReleaseWgt(scope: CoroutineScope, uniVersion: UniVersionEntity, onProgress:(state: UniMpUpdate, progress: Float?) -> Unit,onRelease:(isSuccess: Boolean) -> Unit){
fun isStartOn(uniVersion: UniVersionEntity): Boolean{
val uniMpID = uniVersion.unimp_id val uniMpID = uniVersion.unimp_id
val wgtName = String.format("%s.wgt", uniMpID) val wgtName = String.format("%s.wgt", uniMpID)
val isUpdateUniMP: Boolean = checkUpdate(uniVersion, PreferenceUtil.getWgtVersion()?:"0.0.0") val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
val file = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
return FileUtils.getInstance().fileIsExists(file) && FileUtils.getFileSize(file) > 0 && !isUpdateUniMP onProgress(UniMpUpdate.DOWNLOAD_START, 0f)
downloadUniMp(scope, uniVersion){uniState, _, progress ->
onProgress(UniMpUpdate.DOWNLOAD_LOADING, progress)
if(uniState == UniMpUpdate.DOWNLOAD_FINISH){
onProgress(UniMpUpdate.DOWNLOAD_FINISH, 1f)
scope.launch {
val uniMPReleaseConfiguration = UniMPReleaseConfiguration().apply {
wgtPath = wgtFile.path
password = "6462"////没有密码可以不写
}
DCUniMPSDK.getInstance().releaseWgtToRunPath(uniMpID, uniMPReleaseConfiguration
) { code, _ ->
if (code == 1) {
//释放wgt完成
Log.i("UniAppUtils", "下载并释放wgt完成!")
onRelease(true)
} else {
//释放wgt失败
Log.i("UniAppUtils", "释放wgt失败...")
onRelease(false)
}
}
}
}else if(uniState == UniMpUpdate.DOWNLOAD_FAIL){
Log.i("UniAppUtils", "下载wgt失败...")
onProgress(UniMpUpdate.DOWNLOAD_FAIL, -1f)
}
}
} }
@ -239,6 +276,24 @@ object UniAppUtils {
} }
private fun getUniMPOpenConfiguration(): UniMPOpenConfiguration{ private fun getUniMPOpenConfiguration(): UniMPOpenConfiguration{
val stringBuilder = StringBuilder()
stringBuilder.append("-------------> 📤 header start<-------------\n")
stringBuilder.append("│ x-token = ${PreferenceUtil.getXToken()}\n")
stringBuilder.append("│ x-version = android\n")
stringBuilder.append("│ x-platform = ${getAppVersionName()}\n")
stringBuilder.append("│ x-device-id = ${DeviceIdentifier.getAndroidID(applicationContext)}\n")
stringBuilder.append("│ x-mobile-brand = ${android.os.Build.BRAND}\n")
stringBuilder.append("│ x-mobile-model = ${android.os.Build.MODEL}\n")
stringBuilder.append("│ x-channel = ${ChannelUtils.getChannel(applicationContext)}\n")
stringBuilder.append("│ x-package = ${BuildConfig.APPLICATION_ID}\n")
stringBuilder.append("│ x-click-id = ${getBDVID()}\n")
stringBuilder.append("│ host = ${Constants.RELEASE_BASE_URL}\n")
stringBuilder.append("│ decrypt = ${Constants.AESDecrypt}\n")
stringBuilder.append("│ decrypt = ${Constants.Signature}\n")
stringBuilder.append("-------------> header end <-------------")
Log.i("UniAppUtils", stringBuilder.toString())
return UniMPOpenConfiguration().apply { return UniMPOpenConfiguration().apply {
extraData.put("x-token", PreferenceUtil.getXToken()?:"") extraData.put("x-token", PreferenceUtil.getXToken()?:"")
extraData.put("x-version", getAppVersionName()?:"") extraData.put("x-version", getAppVersionName()?:"")
@ -246,10 +301,10 @@ object UniAppUtils {
extraData.put("x-device-id", DeviceIdentifier.getAndroidID(applicationContext)) extraData.put("x-device-id", DeviceIdentifier.getAndroidID(applicationContext))
extraData.put("x-mobile-brand", android.os.Build.BRAND) extraData.put("x-mobile-brand", android.os.Build.BRAND)
extraData.put("x-mobile-model", android.os.Build.MODEL) extraData.put("x-mobile-model", android.os.Build.MODEL)
extraData.put("x-channel", "rabbit_${ChannelUtils.getChannel(applicationContext)}") extraData.put("x-channel", ChannelUtils.getChannel(applicationContext))
extraData.put("x-package", BuildConfig.APPLICATION_ID) extraData.put("x-package", BuildConfig.APPLICATION_ID)
extraData.put("x-click-id",getBDVID()) extraData.put("x-click-id",getBDVID())
extraData.put("host", Constants.RELEASE_BASE_URL) extraData.put("host", "${Constants.RELEASE_BASE_URL}/")
extraData.put("decrypt", Constants.AESDecrypt) extraData.put("decrypt", Constants.AESDecrypt)
extraData.put("encrypt", Constants.Signature) extraData.put("encrypt", Constants.Signature)
} }
@ -260,21 +315,5 @@ enum class UniMpUpdate{
DOWNLOAD_START, DOWNLOAD_START,
DOWNLOAD_LOADING, DOWNLOAD_LOADING,
DOWNLOAD_FINISH, DOWNLOAD_FINISH,
DOWNLOAD_FAIL, DOWNLOAD_FAIL
UPDATE_SHOW,
UPDATE_HIDE
}
enum class UniState{
START_DOWNLOAD,
DOWNLOAD_LOADING,
FINISH_DOWNLOAD,
FAIL_DOWNLOAD,
START_UPDATE,
UPDATE_LOADING,
FINISH_UPDATE,
FAIL_UPDATE,
START_ON,
START_OFF,
START_FAIL,
} }

View File

@ -61,9 +61,6 @@ class GeneralViewModel(application: Application) : AndroidViewModel(application)
private val _agreementStatus = MutableLiveData<Boolean>() private val _agreementStatus = MutableLiveData<Boolean>()
val agreementStatus: LiveData<Boolean> = _agreementStatus val agreementStatus: LiveData<Boolean> = _agreementStatus
var currentUpdateUniMp: UniVersionEntity? = null
init { init {
// 注册网络监听 // 注册网络监听
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

View File

@ -15,21 +15,28 @@ import com.g.gysdk.GYManager
import com.g.gysdk.GYResponse import com.g.gysdk.GYResponse
import com.g.gysdk.GyCallBack import com.g.gysdk.GyCallBack
import com.g.gysdk.GyConfig import com.g.gysdk.GyConfig
import com.github.gzuliyujiang.oaid.DeviceIdentifier
import com.google.gson.JsonObject import com.google.gson.JsonObject
import com.img.rabbit.bean.local.ErrorBean import com.img.rabbit.bean.local.ErrorBean
import com.img.rabbit.bean.local.OnekeyPreLogin import com.img.rabbit.bean.local.OnekeyPreLogin
import com.img.rabbit.bean.response.LoginInfoEntity import com.img.rabbit.bean.response.LoginInfoEntity
import com.img.rabbit.bean.response.UniVersionEntity
import com.img.rabbit.bean.response.UserConfigEntity
import com.img.rabbit.provider.api.ApiManager import com.img.rabbit.provider.api.ApiManager
import com.img.rabbit.provider.api.ResultVo import com.img.rabbit.provider.api.ResultVo
import com.img.rabbit.provider.storage.GlobalStateManager import com.img.rabbit.provider.storage.GlobalStateManager
import com.img.rabbit.provider.storage.PreferenceUtil import com.img.rabbit.provider.storage.PreferenceUtil
import com.img.rabbit.provider.utils.HeadParamUtils.applicationContext
import com.img.rabbit.utils.MMKVUtils import com.img.rabbit.utils.MMKVUtils
import com.img.rabbit.utils.UniAppUtils
import com.tencent.mm.opensdk.modelmsg.SendAuth import com.tencent.mm.opensdk.modelmsg.SendAuth
import com.tencent.mm.opensdk.openapi.IWXAPI import com.tencent.mm.opensdk.openapi.IWXAPI
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.RequestBody.Companion.toRequestBody
@ -89,12 +96,13 @@ class LoginViewModel : BaseViewModel() {
fun requestUserConfig(){ fun requestUserConfig(){
mLaunch { mLaunch {
val oaid = MMKVUtils.getString("oaid") ?: "" val oaid = MMKVUtils.getString("oaid") ?: ""
//val response = ApiManager.serviceVo.getUserConfig(oaid, Build.VERSION.SDK_INT, "", DeviceIdentifier.getAndroidID(applicationContext), MMKVUtils.getString("gt_cid") ?: "") val response = ApiManager.serviceVo.getUserConfig(oaid, Build.VERSION.SDK_INT, "", DeviceIdentifier.getAndroidID(applicationContext), MMKVUtils.getString("gt_cid") ?: "")
val response = ApiManager.serviceVo.getUserConfig()
if (response.status) { if (response.status) {
PreferenceUtil.saveXToken(response.data.token) PreferenceUtil.saveXToken(response.data.token)
PreferenceUtil.setTimeDiff(response.data.nowtime.toLong() - System.currentTimeMillis() / 1000) PreferenceUtil.setTimeDiff(response.data.nowtime.toLong() - System.currentTimeMillis() / 1000)
PreferenceUtil.saveUserConfig(response.data) PreferenceUtil.saveUserConfig(response.data)
applicationContext?.let { GlobalStateManager(it) }?.storeGlobalUserConfigNotify(true)
}else{ }else{
Log.w("LoginViewModel", "获取配置失败: code=${response.code}, message=${response.message}") Log.w("LoginViewModel", "获取配置失败: code=${response.code}, message=${response.message}")
} }

View File

@ -39,11 +39,11 @@ interface ServiceVo {
*/ */
@GET("/api/user/config") @GET("/api/user/config")
suspend fun getUserConfig( suspend fun getUserConfig(
// @Query("oaid") oaid: String, @Query("oaid") oaid: String,
// @Query("os_version") osVersion: Int, @Query("os_version") osVersion: Int,
// @Query("ua") ua: String, @Query("ua") ua: String,
// @Query("imei") imei: String, @Query("imei") imei: String,
// @Query("cid") cid: String, @Query("cid") cid: String,
): ResultVo<UserConfigEntity> ): ResultVo<UserConfigEntity>
@GET("api/alipay/app_param") @GET("api/alipay/app_param")