Skip to content

Commit

Permalink
show download button if geode not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 8, 2024
1 parent 4c44b30 commit f8d7f7f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
29 changes: 21 additions & 8 deletions app/src/main/java/com/geode/launcher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,31 @@ fun MainScreen(
)
}
}
} else if (gdInstalled && !geodeInstalled) {
} else if (gdInstalled) {
Text(
context.getString(R.string.geode_download_title),
modifier = Modifier.padding(12.dp)
)
OutlinedButton(onClick = { onSettings(context) }) {
Icon(
Icons.Filled.Settings,
contentDescription = context.getString(R.string.launcher_settings_icon_alt)
)
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
Text(context.getString(R.string.launcher_settings))

Row {
Button(
onClick = { releaseViewModel.runReleaseCheck() },
enabled = !releaseViewModel.isInUpdate
) {
Icon(
painterResource(R.drawable.icon_download),
contentDescription = context.getString(R.string.launcher_download_icon_alt)
)
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
Text(context.getString(R.string.launcher_download))
}
Spacer(Modifier.size(2.dp))
IconButton(onClick = { onSettings(context) }) {
Icon(
Icons.Filled.Settings,
contentDescription = context.getString(R.string.launcher_settings_icon_alt)
)
}
}
} else {
Text(
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/com/geode/launcher/utils/ReleaseManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ class ReleaseManager private constructor(
_uiState.value = ReleaseManagerState.InDownload(progress, outOf)
}

val geodeName = LaunchUtils.getGeodeFilename()
val geodeFile = getGeodeOutputPath(geodeName)
val geodeFile = getGeodeOutputPath()

// work around a permission issue from adb push
if (geodeFile.exists()) {
Expand All @@ -117,7 +116,7 @@ class ReleaseManager private constructor(
DownloadUtils.extractFileFromZipStream(
fileStream,
geodeFile.outputStream(),
geodeName
geodeFile.name
)
} catch (e: Exception) {
sendError(e)
Expand Down Expand Up @@ -147,8 +146,11 @@ class ReleaseManager private constructor(
val currentVersion = sharedPreferences.getLong(PreferenceUtils.Key.CURRENT_VERSION_TIMESTAMP)
val latestVersion = release.getDescriptor()

// make sure geode is still here. just in case
val geodeFile = getGeodeOutputPath()

// check if an update is needed
if (latestVersion <= currentVersion) {
if (latestVersion <= currentVersion && geodeFile.exists()) {
_uiState.value = ReleaseManagerState.Finished()
return
}
Expand All @@ -172,7 +174,9 @@ class ReleaseManager private constructor(
}
}

private fun getGeodeOutputPath(geodeName: String): File {
private fun getGeodeOutputPath(): File {
val geodeName = LaunchUtils.getGeodeFilename()

val fallbackPath = File(applicationContext.filesDir, "launcher")
val geodeDirectory = applicationContext.getExternalFilesDir("") ?: fallbackPath

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/icon_download.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Using the download icon from Google's Material Icons. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,640L280,440L336,382L440,486L440,160L520,160L520,486L624,382L680,440L480,640ZM240,800Q207,800 183.5,776.5Q160,753 160,720L160,600L240,600L240,720Q240,720 240,720Q240,720 240,720L720,720Q720,720 720,720Q720,720 720,720L720,600L800,600L800,720Q800,753 776.5,776.5Q753,800 720,800L240,800Z"/>
</vector>
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
<string name="game_not_found">Geometry Dash was not found.</string>
<string name="launcher_launch">Launch</string>
<string name="launcher_settings">Settings</string>
<string name="launcher_download">Download</string>
<string name="launcher_title">Geode</string>
<string name="launcher_logo_alt">geode logo</string>
<string name="launcher_launch_icon_alt">play icon</string>
<string name="launcher_download_icon_alt">download icon</string>
<string name="launcher_settings_icon_alt">settings icon</string>
<string name="geode_download_title">Geode is not installed</string>
<string name="geode_download_title">Geode is not installed.</string>
<string name="geode_download_description">Geode is downloading. Please wait.</string>
<plurals name="automatically_load_countdown">
<item quantity="one">Automatically launching game in %1$d second.</item>
Expand Down

0 comments on commit f8d7f7f

Please sign in to comment.