parent
6598b54e85
commit
8dfffa0c95
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.img.rabbit.bean.local
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class UniMpVersionBean(
|
||||||
|
val uniId: String, // id
|
||||||
|
val version: String, // 版本
|
||||||
|
)
|
||||||
|
|
@ -5,7 +5,7 @@ import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class UniVersionEntity(
|
class UniVersionEntity(
|
||||||
var version: String = "",
|
var version: String = "0.0.0",
|
||||||
var url: String = "",
|
var url: String = "",
|
||||||
var last_version_force: String = "",
|
var last_version_force: String = "",
|
||||||
var force: Boolean = false,
|
var force: Boolean = false,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.img.rabbit.pages
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
|
@ -61,6 +62,7 @@ sealed class TabItem(val title: String, val router:String, val normalIconRes: In
|
||||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(generalViewModel: GeneralViewModel, loginViewModel: LoginViewModel) {
|
fun MainScreen(generalViewModel: GeneralViewModel, loginViewModel: LoginViewModel) {
|
||||||
|
val context = LocalContext.current
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
val networkStatus by generalViewModel.networkStatus.observeAsState(initial = true)
|
val networkStatus by generalViewModel.networkStatus.observeAsState(initial = true)
|
||||||
val isNavigationBarVisible by generalViewModel.isNavigationBarVisible.observeAsState(initial = true)
|
val isNavigationBarVisible by generalViewModel.isNavigationBarVisible.observeAsState(initial = true)
|
||||||
|
|
@ -89,12 +91,18 @@ fun MainScreen(generalViewModel: GeneralViewModel, loginViewModel: LoginViewMode
|
||||||
Log.w("NetworkStatus","网络断开")
|
Log.w("NetworkStatus","网络断开")
|
||||||
//延迟500ms,确保页面初始化完成后,再跳转网络错误页面
|
//延迟500ms,确保页面初始化完成后,再跳转网络错误页面
|
||||||
delay(500)
|
delay(500)
|
||||||
|
|
||||||
|
Toast.makeText(context, "网络已断开,请检查网络设置!", Toast.LENGTH_SHORT).show()
|
||||||
|
/*
|
||||||
navController.navigate("netError")
|
navController.navigate("netError")
|
||||||
generalViewModel.setNavigationBarVisible(false)
|
generalViewModel.setNavigationBarVisible(false)
|
||||||
|
*/
|
||||||
}else{
|
}else{
|
||||||
|
/*
|
||||||
if(navBackStackEntry?.destination?.route == "home"||navBackStackEntry?.destination?.route == "mine"){
|
if(navBackStackEntry?.destination?.route == "home"||navBackStackEntry?.destination?.route == "mine"){
|
||||||
generalViewModel.setNavigationBarVisible(true)
|
generalViewModel.setNavigationBarVisible(true)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
Log.w("NetworkStatus","网络已连接")
|
Log.w("NetworkStatus","网络已连接")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +110,7 @@ fun MainScreen(generalViewModel: GeneralViewModel, loginViewModel: LoginViewMode
|
||||||
Scaffold(
|
Scaffold(
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
if (isNavigationBarVisible) {
|
if (isNavigationBarVisible) {
|
||||||
Box {
|
Box(modifier = Modifier.height(52.dp)) {
|
||||||
NavigationBar(
|
NavigationBar(
|
||||||
containerColor = Color.White,
|
containerColor = Color.White,
|
||||||
contentColor = Color.Transparent
|
contentColor = Color.Transparent
|
||||||
|
|
@ -135,7 +143,7 @@ fun MainScreen(generalViewModel: GeneralViewModel, loginViewModel: LoginViewMode
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(1.dp)
|
.height(1.dp)
|
||||||
.background(Color.Gray.copy(alpha = 0.3f))
|
.background(Color(0x1AD0D0D0))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,18 +126,11 @@ fun HomeScreen(
|
||||||
.background(Color.White)
|
.background(Color.White)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
){
|
){
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.ic_home_top_mask),
|
|
||||||
contentDescription = null,
|
|
||||||
contentScale = ContentScale.FillWidth,
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
)
|
|
||||||
LazyColumn (
|
LazyColumn (
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.offset(y = (-17).dp)
|
.padding(bottom = 52.dp)
|
||||||
.padding(bottom = 56.dp)
|
|
||||||
.background(
|
.background(
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
shape = RoundedCornerShape(topStart = 18.dp, topEnd = 18.dp)
|
shape = RoundedCornerShape(topStart = 18.dp, topEnd = 18.dp)
|
||||||
|
|
@ -149,280 +142,300 @@ fun HomeScreen(
|
||||||
val rows = homeIconConfig?.chunked(columnsCount)?:emptyList()
|
val rows = homeIconConfig?.chunked(columnsCount)?:emptyList()
|
||||||
|
|
||||||
item {
|
item {
|
||||||
//通过配置展示-AD1(模拟器)
|
Column(
|
||||||
val uniVersionConfig = uniVersionConfig
|
) {
|
||||||
if(uniVersionConfig?.isNotEmpty() == true){
|
|
||||||
val uniVersionSize = uniVersionConfig.size
|
|
||||||
//模拟器
|
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(id = R.mipmap.ic_home_title_0_mock),
|
painter = painterResource(id = R.mipmap.ic_home_top_mask),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
contentScale = ContentScale.Crop,
|
contentScale = ContentScale.FillWidth,
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxWidth()
|
||||||
.wrapContentWidth()
|
|
||||||
.padding(start = 16.dp, end = 16.dp, top = 12.dp)
|
|
||||||
)
|
)
|
||||||
Row(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(start = 16.dp, end = 16.dp, top = 12.dp)
|
.offset(y = (-17).dp)
|
||||||
){
|
.background(
|
||||||
Box(
|
color = Color.White,
|
||||||
modifier = Modifier
|
shape = RoundedCornerShape(topStart = 18.dp, topEnd = 18.dp)
|
||||||
.wrapContentWidth()
|
)
|
||||||
.weight(1f)
|
) {
|
||||||
.clickable(
|
//通过配置展示-AD1(模拟器)
|
||||||
indication = null,
|
val uniVersionConfig = uniVersionConfig
|
||||||
interactionSource = remember { MutableInteractionSource() }
|
if(uniVersionConfig?.isNotEmpty() == true){
|
||||||
) {
|
val uniVersionSize = uniVersionConfig.size
|
||||||
val uniMp = uniVersionConfig[0]
|
//模拟器
|
||||||
val uniMpId = uniMp.unimp_id
|
Image(
|
||||||
// 处理点击事件,微信模拟器
|
painter = painterResource(id = R.mipmap.ic_home_title_0_mock),
|
||||||
if (UniAppUtils.isDownloadUniMp(uniMp)) {
|
contentDescription = null,
|
||||||
//强制更新(更新释放新版本并启动)
|
contentScale = ContentScale.Crop,
|
||||||
UniAppUtils.downloadWGT(
|
modifier = Modifier
|
||||||
context,
|
.wrapContentWidth()
|
||||||
scope,
|
.padding(start = 16.dp, end = 16.dp, top = 12.dp)
|
||||||
uniMp
|
)
|
||||||
) { uniState, _, progress ->
|
Row(
|
||||||
progressPair[uniMpId]
|
|
||||||
?: mutableMapOf<String, Float>().apply { put(uniMpId, 0f) }
|
|
||||||
when (uniState) {
|
|
||||||
UniMpUpdate.DOWNLOAD_START -> {
|
|
||||||
//资源开始下载
|
|
||||||
progressPair.apply { put(uniMpId, 0f) }
|
|
||||||
Log.i("HomeScreen", "DOWNLOAD_START")
|
|
||||||
}
|
|
||||||
|
|
||||||
UniMpUpdate.DOWNLOAD_FINISH -> {
|
|
||||||
//资源下载完成
|
|
||||||
progressPair.apply { put(uniMpId, 1f) }
|
|
||||||
Log.i("HomeScreen", "DOWNLOAD_FINISH")
|
|
||||||
}
|
|
||||||
|
|
||||||
UniMpUpdate.DOWNLOAD_FAIL -> {
|
|
||||||
//资源下载失败
|
|
||||||
progressPair.apply { put(uniMpId, -1f) }
|
|
||||||
Log.i("HomeScreen", "DOWNLOAD_FAIL")
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
//资源下载进度
|
|
||||||
if (progress != null) {
|
|
||||||
progressPair.apply {
|
|
||||||
put(
|
|
||||||
uniMpId,
|
|
||||||
progress
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Log.i(
|
|
||||||
"HomeScreen",
|
|
||||||
"DOWNLOAD_PROGRESS:$progress"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (UniAppUtils.isUpdate(uniMp)) {
|
|
||||||
// 提示更新(1、更新释放新版本并启动;2、直接启动现有版本)
|
|
||||||
UniAppUtils.currentUpdateUniMp = uniMp
|
|
||||||
scope.launch {
|
|
||||||
GlobalStateManager(context).storeGlobalUniUpdateNotify(
|
|
||||||
true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
loadingCallback?.showLoading()
|
|
||||||
//启动uni小程序(1、直接启动;2、释放并启动)
|
|
||||||
UniAppUtils.distributeUniMp(context, uniMp) {
|
|
||||||
loadingCallback?.hideLoading()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
val uniMpId = uniVersionConfig[0].unimp_id
|
|
||||||
val uniIcon = uniVersionConfig[0].icon
|
|
||||||
AsyncImage(
|
|
||||||
model = uniIcon,
|
|
||||||
contentDescription = "微信模拟器图标",
|
|
||||||
contentScale = ContentScale.FillWidth,
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.aspectRatio(168 / 96f),
|
.padding(start = 16.dp, end = 16.dp, top = 12.dp)
|
||||||
fallback = painterResource(id = R.mipmap.ic_wx_mock),
|
){
|
||||||
error = painterResource(id = R.mipmap.ic_wx_mock)
|
|
||||||
)
|
|
||||||
|
|
||||||
//下载完成前显示
|
|
||||||
if((progressPair[uniMpId]?:0f) > 0f && (progressPair[uniMpId]?:0f) < 1f){
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.wrapContentWidth()
|
||||||
.aspectRatio(168 / 96f)
|
.weight(1f)
|
||||||
.background(
|
.clickable(
|
||||||
Color(
|
indication = null,
|
||||||
0x66000000
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
), RoundedCornerShape(18.dp)
|
) {
|
||||||
),
|
val uniMp = uniVersionConfig[0]
|
||||||
){
|
val uniMpId = uniMp.unimp_id
|
||||||
Column(
|
// 处理点击事件,微信模拟器
|
||||||
modifier = Modifier
|
if (UniAppUtils.isDownloadUniMp(uniMp)) {
|
||||||
.fillMaxWidth()
|
//强制更新(更新释放新版本并启动)
|
||||||
.align(Alignment.Center)
|
UniAppUtils.downloadWGT(
|
||||||
.padding(horizontal = 12.dp)
|
context,
|
||||||
) {
|
scope,
|
||||||
// 使用 LinearProgressIndicator 显示确定性进度
|
uniMp
|
||||||
LinearProgressIndicator(
|
) { uniState, _, progress ->
|
||||||
progress = { progressPair[uniMpId]?:0f }, // 使用 Lambda 更新进度0~1
|
progressPair[uniMpId]
|
||||||
modifier = Modifier
|
?: mutableMapOf<String, Float>().apply { put(uniMpId, 0f) }
|
||||||
.fillMaxWidth()
|
when (uniState) {
|
||||||
.height(8.dp)
|
UniMpUpdate.DOWNLOAD_START -> {
|
||||||
)
|
//资源开始下载
|
||||||
Text(
|
progressPair.apply { put(uniMpId, 0f) }
|
||||||
text = "下载${((progressPair[uniMpId]?:0f) * 100).toInt()}%",
|
Log.i("HomeScreen", "DOWNLOAD_START")
|
||||||
color = Color.White,
|
}
|
||||||
fontSize = 12.sp,
|
|
||||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
UniMpUpdate.DOWNLOAD_FINISH -> {
|
||||||
Box(modifier = Modifier.width(7.dp))
|
//资源下载完成
|
||||||
Box(
|
progressPair.apply { put(uniMpId, 1f) }
|
||||||
modifier = Modifier
|
Log.i("HomeScreen", "DOWNLOAD_FINISH")
|
||||||
.wrapContentWidth()
|
}
|
||||||
.weight(1f)
|
|
||||||
.clickable(
|
UniMpUpdate.DOWNLOAD_FAIL -> {
|
||||||
indication = null,
|
//资源下载失败
|
||||||
interactionSource = remember { MutableInteractionSource() }
|
progressPair.apply { put(uniMpId, -1f) }
|
||||||
) {
|
Log.i("HomeScreen", "DOWNLOAD_FAIL")
|
||||||
val uniMp = uniVersionConfig[1]
|
}
|
||||||
val uniMpId = uniMp.unimp_id
|
|
||||||
// 处理点击事件,微信模拟器
|
else -> {
|
||||||
if (UniAppUtils.isDownloadUniMp(uniMp)) {
|
//资源下载进度
|
||||||
//强制更新(更新释放新版本并启动)
|
if (progress != null) {
|
||||||
UniAppUtils.downloadWGT(
|
progressPair.apply {
|
||||||
context,
|
put(
|
||||||
scope,
|
uniMpId,
|
||||||
uniMp
|
progress
|
||||||
) { uniState, _, progress ->
|
)
|
||||||
progressPair[uniMpId]
|
}
|
||||||
?: mutableMapOf<String, Float>().apply {
|
Log.i(
|
||||||
put(
|
"HomeScreen",
|
||||||
uniMpId,
|
"DOWNLOAD_PROGRESS:$progress"
|
||||||
0f
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (UniAppUtils.isUpdate(uniMp)) {
|
||||||
|
// 提示更新(1、更新释放新版本并启动;2、直接启动现有版本)
|
||||||
|
UniAppUtils.currentUpdateUniMp = uniMp
|
||||||
|
scope.launch {
|
||||||
|
GlobalStateManager(context).storeGlobalUniUpdateNotify(
|
||||||
|
true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
when (uniState) {
|
} else {
|
||||||
UniMpUpdate.DOWNLOAD_START -> {
|
loadingCallback?.showLoading()
|
||||||
//资源开始下载
|
//启动uni小程序(1、直接启动;2、释放并启动)
|
||||||
progressPair.apply { put(uniMpId, 0f) }
|
UniAppUtils.distributeUniMp(context, uniMp) {
|
||||||
Log.i("HomeScreen", "DOWNLOAD_START")
|
loadingCallback?.hideLoading()
|
||||||
}
|
|
||||||
|
|
||||||
UniMpUpdate.DOWNLOAD_FINISH -> {
|
|
||||||
//资源下载完成
|
|
||||||
progressPair.apply { put(uniMpId, 1f) }
|
|
||||||
Log.i("HomeScreen", "DOWNLOAD_FINISH")
|
|
||||||
}
|
|
||||||
|
|
||||||
UniMpUpdate.DOWNLOAD_FAIL -> {
|
|
||||||
//资源下载失败
|
|
||||||
progressPair.apply { put(uniMpId, -1f) }
|
|
||||||
Log.i("HomeScreen", "DOWNLOAD_FAIL")
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
//资源下载进度
|
|
||||||
if (progress != null) {
|
|
||||||
progressPair.apply {
|
|
||||||
put(
|
|
||||||
uniMpId,
|
|
||||||
progress
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Log.i(
|
|
||||||
"HomeScreen",
|
|
||||||
"DOWNLOAD_PROGRESS:$progress"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (UniAppUtils.isUpdate(uniMp)) {
|
) {
|
||||||
// 提示更新(1、更新释放新版本并启动;2、直接启动现有版本)
|
val uniMpId = uniVersionConfig[0].unimp_id
|
||||||
UniAppUtils.currentUpdateUniMp = uniMp
|
val uniIcon = uniVersionConfig[0].icon
|
||||||
scope.launch {
|
AsyncImage(
|
||||||
GlobalStateManager(context).storeGlobalUniUpdateNotify(
|
model = uniIcon,
|
||||||
true
|
contentDescription = "微信模拟器图标",
|
||||||
)
|
contentScale = ContentScale.FillWidth,
|
||||||
}
|
|
||||||
} else {
|
|
||||||
loadingCallback?.showLoading()
|
|
||||||
//启动uni小程序(1、直接启动;2、释放并启动)
|
|
||||||
UniAppUtils.distributeUniMp(context, uniMp) {
|
|
||||||
loadingCallback?.hideLoading()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
val uniMpId = uniVersionConfig[1].unimp_id
|
|
||||||
val uniIcon = uniVersionConfig[1].icon
|
|
||||||
if(uniVersionSize>1){
|
|
||||||
AsyncImage(
|
|
||||||
model = uniIcon,
|
|
||||||
contentDescription = "支付宝模拟器",
|
|
||||||
contentScale = ContentScale.FillWidth,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.aspectRatio(168 / 96f),
|
|
||||||
fallback = painterResource(id = R.mipmap.ic_alipay_mock),
|
|
||||||
error = painterResource(id = R.mipmap.ic_alipay_mock)
|
|
||||||
)
|
|
||||||
|
|
||||||
//下载完成前显示
|
|
||||||
if((progressPair[uniMpId]?:0f) > 0f && (progressPair[uniMpId]?:0f) < 1f){
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.aspectRatio(168 / 96f)
|
.aspectRatio(168 / 96f),
|
||||||
.background(
|
fallback = painterResource(id = R.mipmap.ic_wx_mock),
|
||||||
Color(
|
error = painterResource(id = R.mipmap.ic_wx_mock)
|
||||||
0x66000000
|
)
|
||||||
), RoundedCornerShape(18.dp)
|
|
||||||
),
|
//下载完成前显示
|
||||||
){
|
if((progressPair[uniMpId]?:0f) > 0f && (progressPair[uniMpId]?:0f) < 1f){
|
||||||
Column(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.align(Alignment.Center)
|
.aspectRatio(168 / 96f)
|
||||||
.padding(horizontal = 12.dp)
|
.background(
|
||||||
) {
|
Color(
|
||||||
// 使用 LinearProgressIndicator 显示确定性进度
|
0x66000000
|
||||||
LinearProgressIndicator(
|
), RoundedCornerShape(18.dp)
|
||||||
progress = { progressPair[uniMpId]?:0f }, // 使用 Lambda 更新进度0~1
|
),
|
||||||
|
){
|
||||||
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(8.dp)
|
.align(Alignment.Center)
|
||||||
)
|
.padding(horizontal = 12.dp)
|
||||||
Text(
|
) {
|
||||||
text = "下载${((progressPair[uniMpId]?:0f) * 100).toInt()}%",
|
// 使用 LinearProgressIndicator 显示确定性进度
|
||||||
color = Color.White,
|
LinearProgressIndicator(
|
||||||
fontSize = 12.sp,
|
progress = { progressPair[uniMpId]?:0f }, // 使用 Lambda 更新进度0~1
|
||||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
modifier = Modifier
|
||||||
textAlign = TextAlign.Center,
|
.fillMaxWidth()
|
||||||
)
|
.height(8.dp)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "下载${((progressPair[uniMpId]?:0f) * 100).toInt()}%",
|
||||||
|
color = Color.White,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Box(modifier = Modifier.width(7.dp))
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.wrapContentWidth()
|
||||||
|
.weight(1f)
|
||||||
|
.clickable(
|
||||||
|
indication = null,
|
||||||
|
interactionSource = remember { MutableInteractionSource() }
|
||||||
|
) {
|
||||||
|
val uniMp = uniVersionConfig[1]
|
||||||
|
val uniMpId = uniMp.unimp_id
|
||||||
|
// 处理点击事件,微信模拟器
|
||||||
|
if (UniAppUtils.isDownloadUniMp(uniMp)) {
|
||||||
|
//强制更新(更新释放新版本并启动)
|
||||||
|
UniAppUtils.downloadWGT(
|
||||||
|
context,
|
||||||
|
scope,
|
||||||
|
uniMp
|
||||||
|
) { uniState, _, progress ->
|
||||||
|
progressPair[uniMpId]
|
||||||
|
?: mutableMapOf<String, Float>().apply {
|
||||||
|
put(
|
||||||
|
uniMpId,
|
||||||
|
0f
|
||||||
|
)
|
||||||
|
}
|
||||||
|
when (uniState) {
|
||||||
|
UniMpUpdate.DOWNLOAD_START -> {
|
||||||
|
//资源开始下载
|
||||||
|
progressPair.apply { put(uniMpId, 0f) }
|
||||||
|
Log.i("HomeScreen", "DOWNLOAD_START")
|
||||||
|
}
|
||||||
|
|
||||||
|
UniMpUpdate.DOWNLOAD_FINISH -> {
|
||||||
|
//资源下载完成
|
||||||
|
progressPair.apply { put(uniMpId, 1f) }
|
||||||
|
Log.i("HomeScreen", "DOWNLOAD_FINISH")
|
||||||
|
}
|
||||||
|
|
||||||
|
UniMpUpdate.DOWNLOAD_FAIL -> {
|
||||||
|
//资源下载失败
|
||||||
|
progressPair.apply { put(uniMpId, -1f) }
|
||||||
|
Log.i("HomeScreen", "DOWNLOAD_FAIL")
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
//资源下载进度
|
||||||
|
if (progress != null) {
|
||||||
|
progressPair.apply {
|
||||||
|
put(
|
||||||
|
uniMpId,
|
||||||
|
progress
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Log.i(
|
||||||
|
"HomeScreen",
|
||||||
|
"DOWNLOAD_PROGRESS:$progress"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (UniAppUtils.isUpdate(uniMp)) {
|
||||||
|
// 提示更新(1、更新释放新版本并启动;2、直接启动现有版本)
|
||||||
|
UniAppUtils.currentUpdateUniMp = uniMp
|
||||||
|
scope.launch {
|
||||||
|
GlobalStateManager(context).storeGlobalUniUpdateNotify(
|
||||||
|
true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
loadingCallback?.showLoading()
|
||||||
|
//启动uni小程序(1、直接启动;2、释放并启动)
|
||||||
|
UniAppUtils.distributeUniMp(context, uniMp) {
|
||||||
|
loadingCallback?.hideLoading()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
val uniMpId = uniVersionConfig[1].unimp_id
|
||||||
|
val uniIcon = uniVersionConfig[1].icon
|
||||||
|
if(uniVersionSize>1){
|
||||||
|
AsyncImage(
|
||||||
|
model = uniIcon,
|
||||||
|
contentDescription = "支付宝模拟器",
|
||||||
|
contentScale = ContentScale.FillWidth,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.aspectRatio(168 / 96f),
|
||||||
|
fallback = painterResource(id = R.mipmap.ic_alipay_mock),
|
||||||
|
error = painterResource(id = R.mipmap.ic_alipay_mock)
|
||||||
|
)
|
||||||
|
|
||||||
|
//下载完成前显示
|
||||||
|
if((progressPair[uniMpId]?:0f) > 0f && (progressPair[uniMpId]?:0f) < 1f){
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.aspectRatio(168 / 96f)
|
||||||
|
.background(
|
||||||
|
Color(
|
||||||
|
0x66000000
|
||||||
|
), RoundedCornerShape(18.dp)
|
||||||
|
),
|
||||||
|
){
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.align(Alignment.Center)
|
||||||
|
.padding(horizontal = 12.dp)
|
||||||
|
) {
|
||||||
|
// 使用 LinearProgressIndicator 显示确定性进度
|
||||||
|
LinearProgressIndicator(
|
||||||
|
progress = { progressPair[uniMpId]?:0f }, // 使用 Lambda 更新进度0~1
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(8.dp)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "下载${((progressPair[uniMpId]?:0f) * 100).toInt()}%",
|
||||||
|
color = Color.White,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
items(rows) {rowItems ->
|
items(rows) {rowItems ->
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ package com.img.rabbit.provider.storage
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.GsonBuilder
|
import com.google.gson.GsonBuilder
|
||||||
|
import com.google.gson.JsonArray
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import com.img.rabbit.bean.local.UniMpVersionBean
|
||||||
import com.img.rabbit.bean.response.UserConfigEntity
|
import com.img.rabbit.bean.response.UserConfigEntity
|
||||||
import com.img.rabbit.bean.response.LoginInfoEntity
|
import com.img.rabbit.bean.response.LoginInfoEntity
|
||||||
import com.img.rabbit.bean.response.UserInfoEntity
|
import com.img.rabbit.bean.response.UserInfoEntity
|
||||||
|
|
@ -10,6 +13,7 @@ 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.MMKVUtils.mmkv
|
import com.img.rabbit.utils.MMKVUtils.mmkv
|
||||||
import com.img.rabbit.utils.appwalle.ChannelReader
|
import com.img.rabbit.utils.appwalle.ChannelReader
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -159,12 +163,31 @@ object PreferenceUtil {
|
||||||
return mmkv.decodeString(KEY_WX_CODE, null)
|
return mmkv.decodeString(KEY_WX_CODE, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveWgtVersion(wgtVersion: String) {
|
fun saveWgtVersion(uniId:String, wgtVersion: String) {
|
||||||
mmkv.encode(KEY_WGT_VERSION, wgtVersion)
|
val json = mmkv.decodeString(KEY_WGT_VERSION, null)
|
||||||
|
val versions = if (!json.isNullOrEmpty()) {
|
||||||
|
Json.decodeFromString<MutableList<UniMpVersionBean>>(json)
|
||||||
|
} else {
|
||||||
|
mutableListOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
val existingIndex = versions.indexOfFirst { it.uniId == uniId }
|
||||||
|
if (existingIndex != -1) {
|
||||||
|
versions[existingIndex] = versions[existingIndex].copy(version = wgtVersion)
|
||||||
|
} else {
|
||||||
|
versions.add(UniMpVersionBean(uniId = uniId, version = wgtVersion))
|
||||||
|
}
|
||||||
|
|
||||||
|
mmkv.encode(KEY_WGT_VERSION, Json.encodeToString(versions))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getWgtVersion(): String? {
|
fun getWgtVersion(uniId:String): String? {
|
||||||
return mmkv.decodeString(KEY_WGT_VERSION, null)
|
val json = mmkv.decodeString(KEY_WGT_VERSION, null)
|
||||||
|
if(json.isNullOrEmpty()){
|
||||||
|
return "0.0.0"
|
||||||
|
}
|
||||||
|
val versions = Json.decodeFromString<MutableList<UniMpVersionBean>>(json)
|
||||||
|
return versions.find { it.uniId == uniId }?.version
|
||||||
}
|
}
|
||||||
|
|
||||||
//真实的服务器时间
|
//真实的服务器时间
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.img.rabbit.provider.utils
|
||||||
|
|
||||||
|
|
||||||
|
object NetworkUtils {
|
||||||
|
//实时更新网络状态
|
||||||
|
var globalNetworkStatus: Boolean = false
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.img.rabbit.uni;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import com.img.rabbit.R;
|
||||||
|
|
||||||
|
import io.dcloud.feature.sdk.Interface.IDCUniMPAppSplashView;
|
||||||
|
|
||||||
|
public class UniMPAlipaySplashView implements IDCUniMPAppSplashView {
|
||||||
|
FrameLayout splashView;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getSplashView(Context context, String appid, String s1, String s2) {
|
||||||
|
splashView = new FrameLayout(context);
|
||||||
|
ImageView imageView = new ImageView(context);
|
||||||
|
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||||
|
imageView.setImageResource(R.mipmap.ic_launch_alipay_unimp);
|
||||||
|
splashView.addView(imageView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
|
return splashView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCloseSplash(ViewGroup rootView) {
|
||||||
|
if(rootView != null)
|
||||||
|
rootView.removeView(splashView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ import com.img.rabbit.R;
|
||||||
|
|
||||||
import io.dcloud.feature.sdk.Interface.IDCUniMPAppSplashView;
|
import io.dcloud.feature.sdk.Interface.IDCUniMPAppSplashView;
|
||||||
|
|
||||||
public class UniMPSplashView implements IDCUniMPAppSplashView {
|
public class UniMPWxSplashView implements IDCUniMPAppSplashView {
|
||||||
FrameLayout splashView;
|
FrameLayout splashView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -11,7 +11,8 @@ 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.UniMPAlipaySplashView
|
||||||
|
import com.img.rabbit.uni.UniMPWxSplashView
|
||||||
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
|
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
|
||||||
import com.tencent.mm.opensdk.openapi.IWXAPI
|
import com.tencent.mm.opensdk.openapi.IWXAPI
|
||||||
import io.dcloud.feature.sdk.DCUniMPSDK
|
import io.dcloud.feature.sdk.DCUniMPSDK
|
||||||
|
|
@ -58,14 +59,14 @@ object UniAppUtils {
|
||||||
* 是否存在更新
|
* 是否存在更新
|
||||||
*/
|
*/
|
||||||
fun isUpdate(uniVersion: UniVersionEntity): Boolean{
|
fun isUpdate(uniVersion: UniVersionEntity): Boolean{
|
||||||
return checkUpdate(uniVersion, PreferenceUtil.getWgtVersion()?:"0.0.0")
|
return checkUpdate(uniVersion, PreferenceUtil.getWgtVersion(uniVersion.unimp_id)?:"0.0.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否强制更新
|
* 是否强制更新
|
||||||
*/
|
*/
|
||||||
private fun isUpdateForce(uniVersion: UniVersionEntity): Boolean{
|
private fun isUpdateForce(uniVersion: UniVersionEntity): Boolean{
|
||||||
return checkUpdate(uniVersion, PreferenceUtil.getWgtVersion()?:"0.0.0") && uniVersion.force
|
return checkUpdate(uniVersion, PreferenceUtil.getWgtVersion(uniVersion.unimp_id)?:"0.0.0") && uniVersion.force
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -96,8 +97,8 @@ object UniAppUtils {
|
||||||
if(version.isEmpty()){
|
if(version.isEmpty()){
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
val newVersions = version.split("\\.")
|
val newVersions = version.split(".")
|
||||||
val originVersions = currentVersion.split("\\.")
|
val originVersions = currentVersion.split(".")
|
||||||
|
|
||||||
if(newVersions.size != 3){
|
if(newVersions.size != 3){
|
||||||
return false
|
return false
|
||||||
|
|
@ -144,7 +145,9 @@ object UniAppUtils {
|
||||||
Log.i("UniAppUtils", "startUniMp: 重新加载...")
|
Log.i("UniAppUtils", "startUniMp: 重新加载...")
|
||||||
val configuration = getUniMPOpenConfiguration()
|
val configuration = getUniMPOpenConfiguration()
|
||||||
if(uniVersion.unimp_type == "wx"){
|
if(uniVersion.unimp_type == "wx"){
|
||||||
configuration.splashClass = UniMPSplashView::class.java
|
configuration.splashClass = UniMPWxSplashView::class.java
|
||||||
|
}else if("alipay" == uniVersion.unimp_type){
|
||||||
|
configuration.splashClass = UniMPAlipaySplashView::class.java
|
||||||
}
|
}
|
||||||
updateUniMp(uniVersion.unimp_id, DCUniMPSDK.getInstance().openUniMP(context, uniVersion.unimp_id, configuration))
|
updateUniMp(uniVersion.unimp_id, DCUniMPSDK.getInstance().openUniMP(context, uniVersion.unimp_id, configuration))
|
||||||
}
|
}
|
||||||
|
|
@ -174,11 +177,15 @@ object UniAppUtils {
|
||||||
// 启动直达页面
|
// 启动直达页面
|
||||||
val configuration = getUniMPOpenConfiguration()
|
val configuration = getUniMPOpenConfiguration()
|
||||||
if(uniMpType == "wx"){
|
if(uniMpType == "wx"){
|
||||||
configuration.splashClass = UniMPSplashView::class.java
|
configuration.splashClass = UniMPWxSplashView::class.java
|
||||||
|
}
|
||||||
|
if(uniMpType == "wx"){
|
||||||
|
configuration.splashClass = UniMPWxSplashView::class.java
|
||||||
|
}else if("alipay" == uniMpType){
|
||||||
|
configuration.splashClass = UniMPAlipaySplashView::class.java
|
||||||
}
|
}
|
||||||
configuration.path = pagePath
|
configuration.path = pagePath
|
||||||
updateUniMp(uniMpId, DCUniMPSDK.getInstance().openUniMP(context, uniMpId, configuration))
|
updateUniMp(uniMpId, DCUniMPSDK.getInstance().openUniMP(context, uniMpId, configuration))
|
||||||
// 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) {
|
||||||
|
|
@ -225,6 +232,7 @@ object UniAppUtils {
|
||||||
downloadUniMp(scope, uniVersion){uniState, filePath, progress ->
|
downloadUniMp(scope, uniVersion){uniState, filePath, progress ->
|
||||||
onProgress(uniState, filePath, progress)
|
onProgress(uniState, filePath, progress)
|
||||||
if(uniState == UniMpUpdate.DOWNLOAD_FINISH){
|
if(uniState == UniMpUpdate.DOWNLOAD_FINISH){
|
||||||
|
PreferenceUtil.saveWgtVersion(uniVersion.unimp_id, uniVersion.version)
|
||||||
distributeUniMp(context, uniVersion) { _ ->}
|
distributeUniMp(context, uniVersion) { _ ->}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -242,6 +250,7 @@ object UniAppUtils {
|
||||||
downloadUniMp(scope, uniVersion){uniState, _, progress ->
|
downloadUniMp(scope, uniVersion){uniState, _, progress ->
|
||||||
onProgress(UniMpUpdate.DOWNLOAD_LOADING, progress)
|
onProgress(UniMpUpdate.DOWNLOAD_LOADING, progress)
|
||||||
if(uniState == UniMpUpdate.DOWNLOAD_FINISH){
|
if(uniState == UniMpUpdate.DOWNLOAD_FINISH){
|
||||||
|
PreferenceUtil.saveWgtVersion(uniVersion.unimp_id, uniVersion.version)
|
||||||
onProgress(UniMpUpdate.DOWNLOAD_FINISH, 1f)
|
onProgress(UniMpUpdate.DOWNLOAD_FINISH, 1f)
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val uniMPReleaseConfiguration = UniMPReleaseConfiguration().apply {
|
val uniMPReleaseConfiguration = UniMPReleaseConfiguration().apply {
|
||||||
|
|
@ -278,6 +287,7 @@ object UniAppUtils {
|
||||||
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 path = FileUtils.getInstance().cacheUniAppDir.absolutePath
|
val path = FileUtils.getInstance().cacheUniAppDir.absolutePath
|
||||||
|
Log.i("UniAppUtils", "下载wgt---->downloadUniMp: $path/$wgtName ------>${uniVersion.url}")
|
||||||
UpdateUtils.download(
|
UpdateUtils.download(
|
||||||
scope = scope,
|
scope = scope,
|
||||||
url = uniVersion.url,
|
url = uniVersion.url,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.img.rabbit.viewmodel
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import com.img.rabbit.provider.utils.NetworkUtils.globalNetworkStatus
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
@ -12,6 +13,10 @@ open class BaseViewModel : ViewModel() {
|
||||||
val isLoading = mutableStateOf(false)
|
val isLoading = mutableStateOf(false)
|
||||||
|
|
||||||
fun mLaunch(block: suspend () -> Unit) {
|
fun mLaunch(block: suspend () -> Unit) {
|
||||||
|
if (!globalNetworkStatus) {
|
||||||
|
isLoading.value = false // 加载完成
|
||||||
|
return
|
||||||
|
}
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
block()
|
block()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.img.rabbit.viewmodel
|
package com.img.rabbit.viewmodel
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Application
|
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Context.RECEIVER_EXPORTED
|
import android.content.Context.RECEIVER_EXPORTED
|
||||||
|
|
@ -14,28 +13,24 @@ import android.net.NetworkRequest
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.lifecycle.AndroidViewModel
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import com.img.rabbit.config.Constants
|
import com.img.rabbit.config.Constants
|
||||||
import com.img.rabbit.provider.api.ApiManager
|
import com.img.rabbit.provider.api.ApiManager
|
||||||
import com.img.rabbit.provider.storage.PreferenceUtil
|
import com.img.rabbit.provider.storage.PreferenceUtil
|
||||||
|
import com.img.rabbit.provider.utils.HeadParamUtils
|
||||||
|
import com.img.rabbit.provider.utils.NetworkUtils.globalNetworkStatus
|
||||||
import com.tencent.mm.opensdk.constants.ConstantsAPI
|
import com.tencent.mm.opensdk.constants.ConstantsAPI
|
||||||
import com.tencent.mm.opensdk.openapi.IWXAPI
|
import com.tencent.mm.opensdk.openapi.IWXAPI
|
||||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory
|
import com.tencent.mm.opensdk.openapi.WXAPIFactory
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
@SuppressLint("ObsoleteSdkInt")
|
@SuppressLint("ObsoleteSdkInt")
|
||||||
class GeneralViewModel(application: Application) : AndroidViewModel(application) {
|
class GeneralViewModel: BaseViewModel(){
|
||||||
lateinit var api: IWXAPI
|
lateinit var api: IWXAPI
|
||||||
lateinit var receiver: BroadcastReceiver
|
lateinit var receiver: BroadcastReceiver
|
||||||
private val _networkStatus = MutableLiveData<Boolean>()
|
private val _networkStatus = MutableLiveData<Boolean>()
|
||||||
val networkStatus: LiveData<Boolean> = _networkStatus
|
val networkStatus: LiveData<Boolean> = _networkStatus
|
||||||
fun setNetworkStatus(status: Boolean) {
|
|
||||||
_networkStatus.value = status
|
|
||||||
}
|
|
||||||
|
|
||||||
private val _serverTime = mutableStateOf<Long?>(null)
|
private val _serverTime = mutableStateOf<Long?>(null)
|
||||||
val serverTime: State<Long?> = _serverTime
|
val serverTime: State<Long?> = _serverTime
|
||||||
|
|
@ -44,15 +39,17 @@ class GeneralViewModel(application: Application) : AndroidViewModel(application)
|
||||||
val isNavigationBarVisible: LiveData<Boolean> = _isNavigationBarVisible
|
val isNavigationBarVisible: LiveData<Boolean> = _isNavigationBarVisible
|
||||||
|
|
||||||
private val connectivityManager =
|
private val connectivityManager =
|
||||||
application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
HeadParamUtils.applicationContext?.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
|
||||||
private val networkCallback = object : ConnectivityManager.NetworkCallback() {
|
private val networkCallback = object : ConnectivityManager.NetworkCallback() {
|
||||||
override fun onAvailable(network: Network) {
|
override fun onAvailable(network: Network) {
|
||||||
_networkStatus.postValue(true)
|
_networkStatus.postValue(true)
|
||||||
|
globalNetworkStatus = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLost(network: Network) {
|
override fun onLost(network: Network) {
|
||||||
_networkStatus.postValue(false)
|
_networkStatus.postValue(false)
|
||||||
|
globalNetworkStatus = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,7 +73,7 @@ class GeneralViewModel(application: Application) : AndroidViewModel(application)
|
||||||
_agreementStatus.value = PreferenceUtil.getAgreement()
|
_agreementStatus.value = PreferenceUtil.getAgreement()
|
||||||
|
|
||||||
// 初始化微信API
|
// 初始化微信API
|
||||||
initWXApi(application)
|
HeadParamUtils.applicationContext?.let { initWXApi(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isNetworkAvailable(): Boolean {
|
private fun isNetworkAvailable(): Boolean {
|
||||||
|
|
@ -138,10 +135,7 @@ class GeneralViewModel(application: Application) : AndroidViewModel(application)
|
||||||
|
|
||||||
@OptIn(DelicateCoroutinesApi::class)
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
fun getServerTime() {
|
fun getServerTime() {
|
||||||
if (networkStatus.value != true) {
|
mLaunch {
|
||||||
return
|
|
||||||
}
|
|
||||||
GlobalScope.launch {
|
|
||||||
val response = ApiManager.serviceVo.getServerTime()
|
val response = ApiManager.serviceVo.getServerTime()
|
||||||
if (response.status) {
|
if (response.status) {
|
||||||
_serverTime.value = response.data
|
_serverTime.value = response.data
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 881 KiB |
Loading…
Reference in New Issue