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)) GeodeLogo(modifier = Modifier.offset(y = (-90).dp))
LaunchProgressCard( Column(
launchUIState, verticalArrangement = Arrangement.spacedBy(8.dp),
crashInfo = launchViewModel.currentCrashInfo(), horizontalAlignment = Alignment.CenterHorizontally,
onCancel = { modifier = Modifier.offset(y = 90.dp)
launchInSafeMode = false ) {
coroutineScope.launch { LaunchProgressCard(
launchViewModel.cancelLaunch() launchUIState,
} crashInfo = launchViewModel.currentCrashInfo(),
}, onCancel = {
onResume = { safeMode -> launchInSafeMode = false
launchInSafeMode = safeMode coroutineScope.launch {
launchViewModel.cancelLaunch()
}
},
onResume = { safeMode ->
launchInSafeMode = safeMode
launchViewModel.clearCrashInfo() launchViewModel.clearCrashInfo()
coroutineScope.launch { coroutineScope.launch {
launchViewModel.beginLaunchFlow() launchViewModel.beginLaunchFlow()
} }
}, },
onMore = { onMore = {
showErrorInfo = true showErrorInfo = true
}, },
safeModeEnabled = launchInSafeMode, safeModeEnabled = launchInSafeMode
modifier = Modifier )
.padding(16.dp)
.offset(y = 90.dp) 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( Row(
modifier = Modifier modifier = Modifier
@@ -7,8 +7,13 @@ import android.net.Uri
import android.widget.Toast import android.widget.Toast
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable 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.layout.width
import androidx.compose.foundation.shape.AbsoluteRoundedCornerShape import androidx.compose.foundation.shape.AbsoluteRoundedCornerShape
import androidx.compose.material3.ElevatedCard
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
@@ -44,4 +49,20 @@ fun GooglePlayBadge(modifier: Modifier = Modifier) {
.clip(AbsoluteRoundedCornerShape(4.dp)) .clip(AbsoluteRoundedCornerShape(4.dp))
.clickable { onDownloadGame(context) } .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.Icons
import androidx.compose.material.icons.filled.Info import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.Warning import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
@@ -76,11 +75,7 @@ fun NotificationCardFromType(type: LaunchNotificationType) {
LaunchNotificationType.LAUNCHER_UPDATE_AVAILABLE -> { LaunchNotificationType.LAUNCHER_UPDATE_AVAILABLE -> {
AnimatedNotificationCard( AnimatedNotificationCard(
onClick = { onClick = {
val nextUpdate = ReleaseManager.get(context).availableLauncherUpdate.value downloadLauncherUpdate(context)
val launcherUrl = nextUpdate?.getLauncherDownload()?.browserDownloadUrl
if (launcherUrl != null) {
downloadUrl(context, launcherUrl)
}
} }
) { ) {
LauncherUpdateContent() LauncherUpdateContent()
@@ -79,6 +79,8 @@ class LaunchViewModel(private val application: Application): ViewModel() {
private val _uiState = MutableStateFlow<LaunchUIState>(LaunchUIState.Initial) private val _uiState = MutableStateFlow<LaunchUIState>(LaunchUIState.Initial)
val uiState = _uiState.asStateFlow() val uiState = _uiState.asStateFlow()
val nextLauncherUpdate = ReleaseManager.get(application).availableLauncherUpdate
var loadFailure: LoadFailureInfo? = null var loadFailure: LoadFailureInfo? = null
private var hasCheckedForUpdates = false private var hasCheckedForUpdates = false
private var isCancelling = 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 @Composable
fun LauncherUpdateIndicator(modifier: Modifier = Modifier, openTo: String, onDismiss: () -> Unit) { fun LauncherUpdateIndicator(modifier: Modifier = Modifier, openTo: String, onDismiss: () -> Unit) {
val context = LocalContext.current val context = LocalContext.current