show update if necessary

This commit is contained in:
qimiko committed 2024-06-16 04:34:06 -07:00
1 parent 4d189f44a9
commit 0c551c8276
5 files changed
+83 -30

No files matched your search

@@ -397,31 +397,55 @@ fun AltMainScreen(
) {
GeodeLogo(modifier = Modifier.offset(y = (-90).dp))
LaunchProgressCard(
launchUIState,
crashInfo = launchViewModel.currentCrashInfo(),
onCancel = {
launchInSafeMode = false
coroutineScope.launch {
launchViewModel.cancelLaunch()
}
},
onResume = { safeMode ->
launchInSafeMode = safeMode
Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.offset(y = 90.dp)
) {
LaunchProgressCard(
launchUIState,
crashInfo = launchViewModel.currentCrashInfo(),
onCancel = {
launchInSafeMode = false
coroutineScope.launch {
launchViewModel.cancelLaunch()
}
},
onResume = { safeMode ->
launchInSafeMode = safeMode
launchViewModel.clearCrashInfo()
coroutineScope.launch {
launchViewModel.beginLaunchFlow()
}
},
onMore = {
showErrorInfo = true
},
safeModeEnabled = launchInSafeMode,
modifier = Modifier
.padding(16.dp)
.offset(y = 90.dp)
)
launchViewModel.clearCrashInfo()
coroutineScope.launch {
launchViewModel.beginLaunchFlow()
}
},
onMore = {
showErrorInfo = true
},
safeModeEnabled = launchInSafeMode
)
val nextLauncherUpdate by launchViewModel.nextLauncherUpdate.collectAsState()
val launcherDownloadUrl = nextLauncherUpdate?.getLauncherDownload()?.browserDownloadUrl
// only show launcher update in a case where a user won't see it ingame
if (launcherDownloadUrl != null && launchUIState is LaunchViewModel.LaunchUIState.Cancelled) {
StatusIndicator(
icon = {
Icon(
Icons.Default.Info,
contentDescription = null
)
},
onClick = {
downloadUrl(context, launcherDownloadUrl)
},
text = {
Text(stringResource(R.string.launcher_update_available))
}
)
}
}
Row(
modifier = Modifier
@@ -7,8 +7,13 @@ import android.net.Uri
import android.widget.Toast
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.AbsoluteRoundedCornerShape
import androidx.compose.material3.ElevatedCard
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@@ -44,4 +49,20 @@ fun GooglePlayBadge(modifier: Modifier = Modifier) {
.clip(AbsoluteRoundedCornerShape(4.dp))
.clickable { onDownloadGame(context) }
)
}
@Composable
fun StatusIndicator(
icon: @Composable () -> Unit,
text: @Composable () -> Unit,
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
ElevatedCard(modifier = modifier, onClick = onClick) {
Row(modifier = Modifier.padding(8.dp)) {
icon()
Spacer(Modifier.size(8.dp))
text()
}
}
}
@@ -16,7 +16,6 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
@@ -76,11 +75,7 @@ fun NotificationCardFromType(type: LaunchNotificationType) {
LaunchNotificationType.LAUNCHER_UPDATE_AVAILABLE -> {
AnimatedNotificationCard(
onClick = {
val nextUpdate = ReleaseManager.get(context).availableLauncherUpdate.value
val launcherUrl = nextUpdate?.getLauncherDownload()?.browserDownloadUrl
if (launcherUrl != null) {
downloadUrl(context, launcherUrl)
}
downloadLauncherUpdate(context)
}
) {
LauncherUpdateContent()
@@ -79,6 +79,8 @@ class LaunchViewModel(private val application: Application): ViewModel() {
private val _uiState = MutableStateFlow<LaunchUIState>(LaunchUIState.Initial)
val uiState = _uiState.asStateFlow()
val nextLauncherUpdate = ReleaseManager.get(application).availableLauncherUpdate
var loadFailure: LoadFailureInfo? = null
private var hasCheckedForUpdates = false
private var isCancelling = false
@@ -49,6 +49,17 @@ fun downloadUrl(context: Context, url: String) {
}
}
fun downloadLauncherUpdate(context: Context) {
val nextUpdate = ReleaseManager.get(context).availableLauncherUpdate.value
val launcherUrl = nextUpdate?.getLauncherDownload()?.browserDownloadUrl
if (launcherUrl != null) {
downloadUrl(context, launcherUrl)
} else {
Toast.makeText(context, context.getString(R.string.release_fetch_no_releases), Toast.LENGTH_SHORT).show()
}
}
@Composable
fun LauncherUpdateIndicator(modifier: Modifier = Modifier, openTo: String, onDismiss: () -> Unit) {
val context = LocalContext.current