Feat: Disable install button when downgrading
This commit is contained in:
parent
f5e3eef0d6
commit
b3349f07ff
3 changed files with 12 additions and 4 deletions
|
@ -54,6 +54,7 @@ import dev.beefers.vendetta.manager.ui.screen.about.AboutScreen
|
||||||
import dev.beefers.vendetta.manager.ui.screen.installer.InstallerScreen
|
import dev.beefers.vendetta.manager.ui.screen.installer.InstallerScreen
|
||||||
import dev.beefers.vendetta.manager.ui.viewmodel.home.HomeViewModel
|
import dev.beefers.vendetta.manager.ui.viewmodel.home.HomeViewModel
|
||||||
import dev.beefers.vendetta.manager.ui.widgets.home.Commit
|
import dev.beefers.vendetta.manager.ui.widgets.home.Commit
|
||||||
|
import dev.beefers.vendetta.manager.utils.Constants
|
||||||
import dev.beefers.vendetta.manager.utils.DiscordVersion
|
import dev.beefers.vendetta.manager.utils.DiscordVersion
|
||||||
import dev.beefers.vendetta.manager.utils.ManagerTab
|
import dev.beefers.vendetta.manager.utils.ManagerTab
|
||||||
import dev.beefers.vendetta.manager.utils.TabOptions
|
import dev.beefers.vendetta.manager.utils.TabOptions
|
||||||
|
@ -73,6 +74,7 @@ class HomeScreen : ManagerTab {
|
||||||
val nav = LocalNavigator.currentOrThrow
|
val nav = LocalNavigator.currentOrThrow
|
||||||
val prefs: PreferenceManager = get()
|
val prefs: PreferenceManager = get()
|
||||||
val viewModel: HomeViewModel = getScreenModel()
|
val viewModel: HomeViewModel = getScreenModel()
|
||||||
|
val currentVersion = DiscordVersion.fromVersionCode(viewModel.installManager.current?.versionCode.toString())
|
||||||
val latestVersion = when {
|
val latestVersion = when {
|
||||||
prefs.discordVersion.isBlank() -> viewModel.discordVersions?.get(prefs.channel)
|
prefs.discordVersion.isBlank() -> viewModel.discordVersions?.get(prefs.channel)
|
||||||
else -> DiscordVersion.fromVersionCode(prefs.discordVersion)
|
else -> DiscordVersion.fromVersionCode(prefs.discordVersion)
|
||||||
|
@ -132,13 +134,15 @@ class HomeScreen : ManagerTab {
|
||||||
val version = viewModel.discordVersions!![prefs.channel]!!
|
val version = viewModel.discordVersions!![prefs.channel]!!
|
||||||
nav.navigate(InstallerScreen(version))
|
nav.navigate(InstallerScreen(version))
|
||||||
},
|
},
|
||||||
enabled = viewModel.discordVersions != null,
|
enabled = latestVersion != null && latestVersion >= (currentVersion ?: Constants.DUMMY_VERSION),
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
val label = when {
|
val label = when {
|
||||||
viewModel.installManager.current == null -> R.string.action_install
|
latestVersion == null -> R.string.msg_loading
|
||||||
viewModel.installManager.current?.versionName == latestVersion.toString() -> R.string.action_reinstall
|
currentVersion == null -> R.string.action_install
|
||||||
else -> R.string.action_update
|
currentVersion == latestVersion -> R.string.action_reinstall
|
||||||
|
latestVersion > currentVersion -> R.string.action_update
|
||||||
|
else -> R.string.msg_downgrade
|
||||||
}
|
}
|
||||||
Text(stringResource(label))
|
Text(stringResource(label))
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ object Constants {
|
||||||
|
|
||||||
val VENDETTA_DIR = Environment.getExternalStorageDirectory().resolve("Vendetta")
|
val VENDETTA_DIR = Environment.getExternalStorageDirectory().resolve("Vendetta")
|
||||||
|
|
||||||
|
val DUMMY_VERSION = DiscordVersion(1,0, DiscordVersion.Type.STABLE)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class TeamMember(
|
data class TeamMember(
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
<string name="msg_seven_left">7 more taps</string>
|
<string name="msg_seven_left">7 more taps</string>
|
||||||
<string name="msg_five_left">5 more taps</string>
|
<string name="msg_five_left">5 more taps</string>
|
||||||
<string name="msg_two_left">2 more taps</string>
|
<string name="msg_two_left">2 more taps</string>
|
||||||
|
<string name="msg_loading">Loading…</string>
|
||||||
|
<string name="msg_downgrade">Cannot downgrade, try uninstalling first</string>
|
||||||
<string name="msg_unlocked">You are now a developer</string>
|
<string name="msg_unlocked">You are now a developer</string>
|
||||||
<string name="msg_permission_grant">In order for Vendetta Manager to function, file permissions are required. Since shared data is stored in ~/Vendetta, permissions are required in order to access it.</string>
|
<string name="msg_permission_grant">In order for Vendetta Manager to function, file permissions are required. Since shared data is stored in ~/Vendetta, permissions are required in order to access it.</string>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue