Skip to content

Commit

Permalink
small ui change
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 20, 2025
1 parent 220c1b0 commit b03ff6b
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 103 deletions.
111 changes: 53 additions & 58 deletions app/src/main/java/com/geode/launcher/AltMainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
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.safeDrawingPadding
import androidx.compose.foundation.layout.size
Expand All @@ -24,13 +23,12 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.FilledTonalIconButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LinearProgressIndicator
Expand Down Expand Up @@ -60,6 +58,7 @@ import com.geode.launcher.main.*
import com.geode.launcher.ui.theme.GeodeLauncherTheme
import com.geode.launcher.ui.theme.LocalTheme
import com.geode.launcher.ui.theme.Theme
import com.geode.launcher.utils.Constants
import com.geode.launcher.utils.GamePackageUtils
import com.geode.launcher.utils.LaunchUtils
import com.geode.launcher.utils.PreferenceUtils
Expand Down Expand Up @@ -123,7 +122,7 @@ class AltMainActivity : ComponentActivity() {
}

data class LaunchStatusInfo(
val title: String,
val title: String?,
val details: String? = null,
val progress: (() -> Float)? = null
)
Expand Down Expand Up @@ -156,8 +155,9 @@ fun mapCancelReasonToInfo(cancelReason: LaunchViewModel.LaunchCancelReason): Lau
title = stringResource(R.string.launcher_cancelled_error),
details = stringResource(R.string.launcher_cancelled_outdated)
)
LaunchViewModel.LaunchCancelReason.AUTOMATIC -> LaunchStatusInfo(
title = stringResource(R.string.launcher_cancelled_navigated_away)
LaunchViewModel.LaunchCancelReason.AUTOMATIC,
LaunchViewModel.LaunchCancelReason.MANUAL-> LaunchStatusInfo(
title = null
)
else -> LaunchStatusInfo(
title = stringResource(R.string.launcher_cancelled_manual)
Expand Down Expand Up @@ -185,7 +185,7 @@ fun mapLaunchStatusToInfo(state: LaunchViewModel.LaunchUIState, inSafeMode: Bool
}

val outOf = remember(state.outOf) {
state.outOf?.apply {
state.outOf?.run {
Formatter.formatShortFileSize(context, this)
}
}
Expand All @@ -207,16 +207,22 @@ fun mapLaunchStatusToInfo(state: LaunchViewModel.LaunchUIState, inSafeMode: Bool

@Composable
fun LaunchCancelledBody(statusInfo: LaunchStatusInfo, icon: @Composable () -> Unit, inProgress: Boolean, modifier: Modifier = Modifier) {
if (statusInfo.title == null && statusInfo.details == null && !inProgress) {
return
}

Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.Start,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = modifier.width(300.dp)
) {
Row(verticalAlignment = Alignment.CenterVertically) {
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyLarge) {
icon()
Spacer(Modifier.size(8.dp))
Text(statusInfo.title)
if (statusInfo.title != null) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center) {
CompositionLocalProvider(LocalTextStyle provides MaterialTheme.typography.bodyLarge) {
icon()
Spacer(Modifier.size(8.dp))
Text(statusInfo.title)
}
}
}

Expand All @@ -227,7 +233,8 @@ fun LaunchCancelledBody(statusInfo: LaunchStatusInfo, icon: @Composable () -> Un
if (statusInfo.details != null) {
Text(
statusInfo.details,
style = MaterialTheme.typography.bodyMedium
style = MaterialTheme.typography.bodyMedium,
textAlign = TextAlign.Center
)
}
}
Expand All @@ -241,7 +248,9 @@ fun LaunchProgressBody(statusInfo: LaunchStatusInfo, modifier: Modifier = Modifi
horizontalAlignment = Alignment.Start,
modifier = modifier.width(300.dp)
) {
Text(statusInfo.title, style = MaterialTheme.typography.bodyLarge)
if (statusInfo.title != null) {
Text(statusInfo.title, style = MaterialTheme.typography.bodyLarge)
}

if (statusInfo.progress != null) {
LinearProgressIndicator(
Expand All @@ -261,22 +270,22 @@ fun LaunchProgressBody(statusInfo: LaunchStatusInfo, modifier: Modifier = Modifi
@Composable
fun RetryButtonContents(reason: LaunchViewModel.LaunchCancelReason) {
when (reason) {
LaunchViewModel.LaunchCancelReason.MANUAL -> {
LaunchViewModel.LaunchCancelReason.LAST_LAUNCH_CRASHED -> {
Icon(
Icons.Filled.Refresh,
painterResource(R.drawable.icon_resume),
contentDescription = null
)
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
Text(stringResource(R.string.launcher_cancelled_restart))
Text(stringResource(R.string.launcher_cancelled_resume))
}
LaunchViewModel.LaunchCancelReason.LAST_LAUNCH_CRASHED,
LaunchViewModel.LaunchCancelReason.MANUAL,
LaunchViewModel.LaunchCancelReason.AUTOMATIC -> {
Icon(
painterResource(R.drawable.icon_resume),
Icons.Filled.PlayArrow,
contentDescription = null
)
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
Text(stringResource(R.string.launcher_cancelled_resume))
Text(stringResource(R.string.launcher_launch))
}
LaunchViewModel.LaunchCancelReason.GEODE_NOT_FOUND -> {
Icon(
Expand Down Expand Up @@ -307,22 +316,18 @@ fun LaunchProgressCard(
var showSafeModeDialog by remember { mutableStateOf(false) }
val status = mapLaunchStatusToInfo(uiState, safeModeEnabled)

Card(modifier = modifier.width(300.dp)) {
Column(verticalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.padding(16.dp)) {
Box(modifier = modifier) {
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
if (uiState is LaunchViewModel.LaunchUIState.Cancelled) {
LaunchCancelledBody(
statusInfo = status,
icon = { LaunchCancelledIcon(uiState.reason, Modifier.size(32.dp)) },
inProgress = uiState.inProgress
)

if (uiState.reason == LaunchViewModel.LaunchCancelReason.GAME_OUTDATED) {
if (uiState.reason.isGameInstallIssue()) {
val context = LocalContext.current

// game should be downloaded if this message is showing
val showDownload = remember {
!GamePackageUtils.identifyGameLegitimacy(context.packageManager)
}
val showDownload = remember { GamePackageUtils.showDownloadBadge(context.packageManager) }

if (showDownload) {
GooglePlayBadge(modifier = Modifier.align(Alignment.CenterHorizontally))
Expand All @@ -331,31 +336,31 @@ fun LaunchProgressCard(

if (uiState.reason.allowsRetry()) {
FlowRow(
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.width(300.dp)
horizontalArrangement = Arrangement.spacedBy(8.dp, alignment = Alignment.CenterHorizontally),
modifier = Modifier.align(Alignment.CenterHorizontally)
) {
LongPressButton(onClick = { onResume(false) }, onLongPress = {
showSafeModeDialog = true
}) {
RetryButtonContents(uiState.reason)
}

Spacer(Modifier.weight(1.0f))

if (crashInfo != null) {
IconButton(onClick = onMore) {
FilledTonalButton(onClick = onMore) {
Icon(
painterResource(R.drawable.icon_question_mark),
contentDescription = stringResource(R.string.launcher_cancelled_help_alt)
contentDescription = null
)
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
Text(stringResource(R.string.launcher_cancelled_help_alt))
}
}

extraOptions()
}
}
} else {
LaunchProgressBody(statusInfo = status)
LaunchProgressBody(statusInfo = status, modifier = Modifier.padding(top = 16.dp))

Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.width(300.dp)) {
TextButton(onClick = onCancel) {
Expand Down Expand Up @@ -438,10 +443,9 @@ fun AltMainScreen(
contentAlignment = Alignment.Center
) {
Column(
verticalArrangement = Arrangement.spacedBy(32.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.height(350.dp)
.padding(8.dp)
.verticalScroll(rememberScrollState())
) {
Expand Down Expand Up @@ -485,27 +489,18 @@ fun AltMainScreen(
safeModeEnabled = launchInSafeMode
)

val nextLauncherUpdate by launchViewModel.nextLauncherUpdate.collectAsState()

// only show launcher update in a case where a user won't see it ingame
if (nextLauncherUpdate != null && launchUIState is LaunchViewModel.LaunchUIState.Cancelled) {
StatusIndicator(
icon = {
Icon(
Icons.Default.Info,
contentDescription = null
)
},
onClick = {
installLauncherUpdate(context)
},
text = {
Text(
stringResource(R.string.launcher_update_available),
textAlign = TextAlign.Center
)
}
)
if (launchUIState is LaunchViewModel.LaunchUIState.Cancelled) {
val gameVersion = remember { GamePackageUtils.getGameVersionCodeOrNull(context.packageManager) }

if (gameVersion != null && gameVersion < Constants.SUPPORTED_VERSION_CODE_MIN_WARNING) {
UnsupportedVersionWarning()
}

val nextLauncherUpdate by launchViewModel.nextLauncherUpdate.collectAsState()
if (nextLauncherUpdate != null) {
LauncherUpdateIndicator()
}
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/com/geode/launcher/GeometryDashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.core.view.WindowInsetsControllerCompat
import com.customRobTop.BaseRobTopActivity
import com.customRobTop.JniToCpp
import com.geode.launcher.main.LaunchNotification
import com.geode.launcher.main.determineDisplayedCards
import com.geode.launcher.utils.Constants
import com.geode.launcher.utils.ConstrainedFrameLayout
import com.geode.launcher.utils.DownloadUtils
Expand Down Expand Up @@ -406,11 +407,14 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL

val showNotification = PreferenceUtils.get(this).getBoolean(PreferenceUtils.Key.ENABLE_REDESIGN)
if (showNotification) {
val notificationView = ComposeView(this)
frameLayout.addView(notificationView)
val hasCards = determineDisplayedCards(this)
if (hasCards.isNotEmpty()) {
val notificationView = ComposeView(this)
frameLayout.addView(notificationView)

notificationView.setContent {
LaunchNotification()
notificationView.setContent {
LaunchNotification()
}
}
}

Expand Down
25 changes: 2 additions & 23 deletions app/src/main/java/com/geode/launcher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class MainActivity : ComponentActivity() {
LoadFailureInfo(LaunchUtils.LauncherError.CRASHED)
} else { null }

/*
val redirectToAlt = PreferenceUtils.get(this).getBoolean(PreferenceUtils.Key.ENABLE_REDESIGN)
if (redirectToAlt) {
val launchIntent = Intent(this, AltMainActivity::class.java)
Expand All @@ -72,7 +71,6 @@ class MainActivity : ComponentActivity() {

return
}
*/

setContent {
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
Expand Down Expand Up @@ -114,7 +112,7 @@ fun MainScreen(
val autoUpdateState by releaseViewModel.uiState.collectAsState()

val geodeJustInstalled = (autoUpdateState as? ReleaseViewModel.ReleaseUIState.Finished)
?.hasUpdated ?: false
?.hasUpdated == true
val geodeInstalled = geodePreinstalled || geodeJustInstalled

var beginLaunch by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -194,26 +192,7 @@ fun MainScreen(
)

if (gdVersion < Constants.SUPPORTED_VERSION_CODE_MIN_WARNING) {
InlineDialog(
headline = {
Icon(
Icons.Default.Warning,
contentDescription = null,
modifier = Modifier.size(28.dp)
)

Text(
stringResource(R.string.launcher_unsupported_version_title),
style = MaterialTheme.typography.titleMedium,
)
},
body = {
Text(
stringResource(R.string.launcher_game_update_required),
)
},
modifier = Modifier.padding(8.dp)
)
UnsupportedVersionWarning()
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/com/geode/launcher/main/ErrorComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,7 @@ fun DownloadRecommendation(needsUniversal: Boolean, modifier: Modifier = Modifie
val context = LocalContext.current
val version = BuildConfig.VERSION_NAME

val showDownload = remember {
!GamePackageUtils.isGameInstalled(context.packageManager) ||
!GamePackageUtils.identifyGameLegitimacy(context.packageManager)
}
val showDownload = remember { GamePackageUtils.showDownloadBadge(context.packageManager) }

val downloadBase = "https://github.com/geode-sdk/android-launcher/releases/download/$version"
val legacyDownloadUrl = "$downloadBase/geode-launcher-v$version-android32.apk"
Expand Down
29 changes: 25 additions & 4 deletions app/src/main/java/com/geode/launcher/main/LaunchComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,7 @@ fun PlayButton(
fun LaunchBlockedLabel(text: String) {
val context = LocalContext.current

val showDownload = remember {
!GamePackageUtils.isGameInstalled(context.packageManager) ||
!GamePackageUtils.identifyGameLegitimacy(context.packageManager)
}
val showDownload = remember { GamePackageUtils.showDownloadBadge(context.packageManager) }

Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text, textAlign = TextAlign.Center, modifier = Modifier.padding(12.dp))
Expand All @@ -292,3 +289,27 @@ fun LaunchBlockedLabel(text: String) {
}
}
}

@Composable
fun UnsupportedVersionWarning(modifier: Modifier = Modifier) {
InlineDialog(
headline = {
Icon(
Icons.Default.Warning,
contentDescription = null,
modifier = Modifier.size(28.dp)
)

Text(
stringResource(R.string.launcher_unsupported_version_title),
style = MaterialTheme.typography.titleMedium,
)
},
body = {
Text(
stringResource(R.string.launcher_game_update_required),
)
},
modifier = modifier.padding(8.dp)
)
}
Loading

0 comments on commit b03ff6b

Please sign in to comment.