forked from geode-sdk/android-launcher
reorganization
This commit is contained in:
1 file changed
+109
-81
@@ -1,6 +1,5 @@
|
|||||||
package com.geode.launcher
|
package com.geode.launcher
|
||||||
|
|
||||||
import android.content.pm.ActivityInfo
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.format.Formatter
|
import android.text.format.Formatter
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
@@ -12,23 +11,25 @@ import androidx.compose.foundation.layout.Box
|
|||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.defaultMinSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.offset
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.safeDrawingPadding
|
import androidx.compose.foundation.layout.safeDrawingPadding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
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.Refresh
|
import androidx.compose.material.icons.filled.Refresh
|
||||||
import androidx.compose.material.icons.filled.Settings
|
import androidx.compose.material.icons.filled.Settings
|
||||||
import androidx.compose.material.icons.filled.Warning
|
import androidx.compose.material.icons.filled.Warning
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.FilledTonalButton
|
import androidx.compose.material3.FilledTonalButton
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.LinearProgressIndicator
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
import androidx.compose.material3.LocalTextStyle
|
import androidx.compose.material3.LocalTextStyle
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -49,6 +50,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.geode.launcher.main.*
|
import com.geode.launcher.main.*
|
||||||
@@ -64,7 +66,6 @@ class AltMainActivity : ComponentActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
|
||||||
val gdInstalled = GamePackageUtils.isGameInstalled(packageManager)
|
val gdInstalled = GamePackageUtils.isGameInstalled(packageManager)
|
||||||
@@ -203,10 +204,10 @@ fun LaunchCancelledBody(statusInfo: LaunchStatusInfo, icon: @Composable () -> Un
|
|||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = modifier
|
modifier = modifier.width(300.dp)
|
||||||
) {
|
) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.titleLarge) {
|
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyLarge) {
|
||||||
icon()
|
icon()
|
||||||
Spacer(Modifier.size(8.dp))
|
Spacer(Modifier.size(8.dp))
|
||||||
Text(statusInfo.title)
|
Text(statusInfo.title)
|
||||||
@@ -214,11 +215,14 @@ fun LaunchCancelledBody(statusInfo: LaunchStatusInfo, icon: @Composable () -> Un
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (inProgress) {
|
if (inProgress) {
|
||||||
LinearProgressIndicator()
|
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statusInfo.details != null) {
|
if (statusInfo.details != null) {
|
||||||
Text(statusInfo.details)
|
Text(
|
||||||
|
statusInfo.details,
|
||||||
|
style = MaterialTheme.typography.bodyMedium
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,10 +232,10 @@ fun LaunchCancelledBody(statusInfo: LaunchStatusInfo, icon: @Composable () -> Un
|
|||||||
fun LaunchProgressBody(statusInfo: LaunchStatusInfo, modifier: Modifier = Modifier) {
|
fun LaunchProgressBody(statusInfo: LaunchStatusInfo, modifier: Modifier = Modifier) {
|
||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
horizontalAlignment = Alignment.Start,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = modifier.defaultMinSize(minWidth = 300.dp)
|
modifier = modifier.width(300.dp)
|
||||||
) {
|
) {
|
||||||
Text(statusInfo.title, style = MaterialTheme.typography.titleLarge)
|
Text(statusInfo.title, style = MaterialTheme.typography.bodyLarge)
|
||||||
|
|
||||||
if (statusInfo.progress != null) {
|
if (statusInfo.progress != null) {
|
||||||
LinearProgressIndicator(
|
LinearProgressIndicator(
|
||||||
@@ -249,7 +253,7 @@ fun LaunchProgressBody(statusInfo: LaunchStatusInfo, modifier: Modifier = Modifi
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (statusInfo.details != null) {
|
if (statusInfo.details != null) {
|
||||||
Text(statusInfo.details)
|
Text(statusInfo.details, style = MaterialTheme.typography.bodyMedium)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,14 +299,15 @@ fun LaunchProgressCard(
|
|||||||
onCancel: () -> Unit,
|
onCancel: () -> Unit,
|
||||||
onResume: (safeMode: Boolean) -> Unit,
|
onResume: (safeMode: Boolean) -> Unit,
|
||||||
onMore: () -> Unit,
|
onMore: () -> Unit,
|
||||||
|
extraOptions: @Composable () -> Unit,
|
||||||
safeModeEnabled: Boolean,
|
safeModeEnabled: Boolean,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
var showSafeModeDialog by remember { mutableStateOf(false) }
|
var showSafeModeDialog by remember { mutableStateOf(false) }
|
||||||
val status = mapLaunchStatusToInfo(uiState, safeModeEnabled)
|
val status = mapLaunchStatusToInfo(uiState, safeModeEnabled)
|
||||||
|
|
||||||
Card(modifier = modifier) {
|
Card(modifier = modifier.width(300.dp)) {
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(16.dp), modifier = Modifier.padding(16.dp)) {
|
Column(verticalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.padding(16.dp)) {
|
||||||
if (uiState is LaunchViewModel.LaunchUIState.Cancelled) {
|
if (uiState is LaunchViewModel.LaunchUIState.Cancelled) {
|
||||||
LaunchCancelledBody(
|
LaunchCancelledBody(
|
||||||
statusInfo = status,
|
statusInfo = status,
|
||||||
@@ -324,7 +329,10 @@ fun LaunchProgressCard(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (uiState.reason.allowsRetry()) {
|
if (uiState.reason.allowsRetry()) {
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
modifier = Modifier.width(300.dp)
|
||||||
|
) {
|
||||||
LongPressButton(onClick = { onResume(false) }, onLongPress = {
|
LongPressButton(onClick = { onResume(false) }, onLongPress = {
|
||||||
showSafeModeDialog = true
|
showSafeModeDialog = true
|
||||||
}) {
|
}) {
|
||||||
@@ -341,13 +349,23 @@ fun LaunchProgressCard(
|
|||||||
Text(stringResource(R.string.launcher_error_more))
|
Text(stringResource(R.string.launcher_error_more))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer(Modifier.weight(1.0f))
|
||||||
|
|
||||||
|
extraOptions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LaunchProgressBody(statusInfo = status)
|
LaunchProgressBody(statusInfo = status)
|
||||||
|
|
||||||
TextButton(onClick = onCancel) {
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.width(300.dp)) {
|
||||||
Text(stringResource(R.string.release_fetch_button_cancel))
|
TextButton(onClick = onCancel) {
|
||||||
|
Text(stringResource(R.string.release_fetch_button_cancel))
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(Modifier.weight(1.0f))
|
||||||
|
|
||||||
|
extraOptions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -366,6 +384,18 @@ fun LaunchProgressCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ExtraOptions(onSettings: () -> Unit) {
|
||||||
|
IconButton(
|
||||||
|
onClick = onSettings,
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Filled.Settings,
|
||||||
|
contentDescription = stringResource(R.string.launcher_settings_icon_alt)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun GeodeLogo(modifier: Modifier = Modifier) {
|
fun GeodeLogo(modifier: Modifier = Modifier) {
|
||||||
Row(
|
Row(
|
||||||
@@ -408,80 +438,78 @@ fun AltMainScreen(
|
|||||||
.safeDrawingPadding(),
|
.safeDrawingPadding(),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
GeodeLogo(modifier = Modifier.offset(y = (-90).dp))
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
verticalArrangement = Arrangement.spacedBy(32.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = Modifier.offset(y = 90.dp)
|
modifier = Modifier
|
||||||
|
.height(350.dp)
|
||||||
|
.padding(8.dp)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
) {
|
) {
|
||||||
LaunchProgressCard(
|
GeodeLogo()
|
||||||
launchUIState,
|
|
||||||
crashInfo = launchViewModel.currentCrashInfo(),
|
|
||||||
onCancel = {
|
|
||||||
launchInSafeMode = false
|
|
||||||
coroutineScope.launch {
|
|
||||||
launchViewModel.cancelLaunch()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onResume = { safeMode ->
|
|
||||||
launchInSafeMode = safeMode
|
|
||||||
|
|
||||||
launchViewModel.clearCrashInfo()
|
Column(
|
||||||
coroutineScope.launch {
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
launchViewModel.beginLaunchFlow()
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
}
|
) {
|
||||||
},
|
LaunchProgressCard(
|
||||||
onMore = {
|
launchUIState,
|
||||||
showErrorInfo = true
|
crashInfo = launchViewModel.currentCrashInfo(),
|
||||||
},
|
onCancel = {
|
||||||
safeModeEnabled = launchInSafeMode
|
launchInSafeMode = false
|
||||||
)
|
coroutineScope.launch {
|
||||||
|
launchViewModel.cancelLaunch()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onResume = { safeMode ->
|
||||||
|
launchInSafeMode = safeMode
|
||||||
|
|
||||||
val nextLauncherUpdate by launchViewModel.nextLauncherUpdate.collectAsState()
|
launchViewModel.clearCrashInfo()
|
||||||
val launcherDownloadUrl = nextLauncherUpdate?.getLauncherDownload()?.browserDownloadUrl
|
coroutineScope.launch {
|
||||||
|
launchViewModel.beginLaunchFlow()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onMore = {
|
||||||
|
showErrorInfo = true
|
||||||
|
},
|
||||||
|
extraOptions = {
|
||||||
|
ExtraOptions(
|
||||||
|
onSettings = {
|
||||||
|
coroutineScope.launch {
|
||||||
|
launchViewModel.cancelLaunch(true)
|
||||||
|
}
|
||||||
|
|
||||||
// only show launcher update in a case where a user won't see it ingame
|
onSettings(context)
|
||||||
if (launcherDownloadUrl != null && launchUIState is LaunchViewModel.LaunchUIState.Cancelled) {
|
}
|
||||||
StatusIndicator(
|
|
||||||
icon = {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Info,
|
|
||||||
contentDescription = null
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onClick = {
|
safeModeEnabled = launchInSafeMode
|
||||||
downloadUrl(context, launcherDownloadUrl)
|
|
||||||
},
|
|
||||||
text = {
|
|
||||||
Text(stringResource(R.string.launcher_update_available))
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
val nextLauncherUpdate by launchViewModel.nextLauncherUpdate.collectAsState()
|
||||||
modifier = Modifier
|
val launcherDownloadUrl =
|
||||||
.fillMaxSize()
|
nextLauncherUpdate?.getLauncherDownload()?.browserDownloadUrl
|
||||||
.padding(16.dp),
|
|
||||||
horizontalArrangement = Arrangement.End,
|
|
||||||
verticalAlignment = Alignment.Bottom
|
|
||||||
) {
|
|
||||||
Button(
|
|
||||||
onClick = {
|
|
||||||
coroutineScope.launch {
|
|
||||||
launchViewModel.cancelLaunch(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
onSettings(context)
|
// 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.Filled.Settings,
|
Icon(
|
||||||
contentDescription = null
|
Icons.Default.Info,
|
||||||
)
|
contentDescription = null
|
||||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
)
|
||||||
Text(context.getString(R.string.launcher_settings))
|
},
|
||||||
|
onClick = {
|
||||||
|
downloadUrl(context, launcherDownloadUrl)
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.launcher_update_available),
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user