From 9ce633ec2447f7594d58fbde8eee642ceeeb313d Mon Sep 17 00:00:00 2001 From: Alexandre G Pereira Date: Mon, 19 Aug 2024 22:15:10 -0300 Subject: [PATCH] Add GitHub project link on the menu screen (#330) * Add GitHub project link on the menu screen * Change settings title to language --- .../hunter/settings/SettingsAnalytics.kt | 24 +++++++++++++++++++ .../hunter/settings/SettingsFeature.kt | 13 ++++++++++ .../hunter/settings/SettingsStateHolder.kt | 14 ++++++++++- .../hunter/settings/SettingsStrings.kt | 8 +++++-- .../hunter/settings/SettingsViewAction.kt | 5 ++++ .../hunter/settings/SettingsViewIntent.kt | 2 ++ .../hunter/settings/ui/MenuScreen.kt | 7 ++++++ 7 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsViewAction.kt diff --git a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsAnalytics.kt b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsAnalytics.kt index 502695a3b..4d7000ee8 100644 --- a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsAnalytics.kt +++ b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsAnalytics.kt @@ -65,4 +65,28 @@ internal class SettingsAnalytics( ) ) } + + fun trackOpenGitHubProjectClick() { + analytics.track( + eventName = "Settings - open GitHub project click", + ) + } + + fun trackImportContentClick() { + analytics.track( + eventName = "Settings - import content click", + ) + } + + fun trackAppearanceSettingsSaveClick() { + analytics.track( + eventName = "Settings - appearance settings save click", + ) + } + + fun trackAppearanceSettingsClick() { + analytics.track( + eventName = "Settings - appearance settings click", + ) + } } \ No newline at end of file diff --git a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsFeature.kt b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsFeature.kt index b3abd91e7..b2f2c2fa3 100644 --- a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsFeature.kt +++ b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsFeature.kt @@ -18,8 +18,11 @@ package br.alexandregpereira.hunter.settings import androidx.compose.foundation.layout.PaddingValues import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState +import androidx.compose.ui.platform.LocalUriHandler import br.alexandregpereira.hunter.settings.ui.MenuScreen +import kotlinx.coroutines.flow.collectLatest import org.koin.compose.koinInject @Composable @@ -28,6 +31,16 @@ fun SettingsFeature( contentPadding: PaddingValues, ) { val viewModel: SettingsStateHolder = koinInject() + + val uriHandler = LocalUriHandler.current + LaunchedEffect(viewModel, uriHandler) { + viewModel.action.collectLatest { action -> + when (action) { + is SettingsViewAction.GoToExternalUrl -> uriHandler.openUri(action.url) + } + } + } + MenuScreen( state = viewModel.state.collectAsState().value, versionName = versionName, diff --git a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsStateHolder.kt b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsStateHolder.kt index 446f6d56c..f328ffd41 100644 --- a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsStateHolder.kt +++ b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsStateHolder.kt @@ -32,6 +32,7 @@ import br.alexandregpereira.hunter.monster.event.MonsterEvent import br.alexandregpereira.hunter.monster.event.MonsterEventDispatcher import br.alexandregpereira.hunter.settings.domain.ApplyAppearanceSettings import br.alexandregpereira.hunter.settings.domain.GetAppearanceSettingsFromMonsters +import br.alexandregpereira.hunter.state.MutableActionHandler import br.alexandregpereira.hunter.state.UiModel import br.alexandregpereira.hunter.sync.event.SyncEventDispatcher import br.alexandregpereira.hunter.ui.compose.AppImageContentScale @@ -60,7 +61,8 @@ internal class SettingsStateHolder( private val saveLanguage: SaveLanguageUseCase, private val getAppearanceSettings: GetAppearanceSettingsFromMonsters, private val applyAppearanceSettings: ApplyAppearanceSettings, -) : UiModel(SettingsViewState()), SettingsViewIntent { +) : UiModel(SettingsViewState()), SettingsViewIntent, + MutableActionHandler by MutableActionHandler() { private val strings: SettingsStrings get() = getSettingsStrings(appLocalization.getLanguage()) @@ -140,6 +142,7 @@ internal class SettingsStateHolder( } override fun onAppearanceSettingsClick() { + analytics.trackAppearanceSettingsClick() fillAppearanceSettingsState() setState { copy(appearanceSettingsOpened = true) } } @@ -149,6 +152,7 @@ internal class SettingsStateHolder( } override fun onAppearanceSettingsSaveClick() { + analytics.trackAppearanceSettingsSaveClick() onAppearanceSettingsCloseClick() val appearanceState = state.value.appearanceState flow { @@ -177,9 +181,17 @@ internal class SettingsStateHolder( } override fun onImport() { + analytics.trackImportContentClick() shareContentEventDispatcher.dispatchEvent(ShareContentEvent.Import.OnStart) } + override fun onOpenGitHubProjectClick() { + analytics.trackOpenGitHubProjectClick() + SettingsViewAction.GoToExternalUrl( + url = "https://github.com/alexandregpereira/Monster-Compendium" + ).also { sendAction(it) } + } + private fun load() { getMonsterImageJsonUrl() .zip(getAlternativeSourceJsonUrl()) { imageBaseUrl, alternativeSourceBaseUrl -> diff --git a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsStrings.kt b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsStrings.kt index ab45e9fd1..da359bf4b 100644 --- a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsStrings.kt +++ b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsStrings.kt @@ -20,6 +20,7 @@ interface SettingsStrings { val monsterImageContentScale: String val imageContentScaleFit: String val imageContentScaleCrop: String + val openGitHubProject: String } internal data class SettingsEnStrings( @@ -29,7 +30,7 @@ internal data class SettingsEnStrings( override val manageMonsterContent: String = "Manage Monsters Content", override val sync: String = "Sync", override val manageAdvancedSettings: String = "Advanced Settings", - override val settingsTitle: String = "Settings", + override val settingsTitle: String = "Language", override val languageLabel: String = "Language", override val save: String = "Save", override val appearanceSettingsTitle: String = "Appearance", @@ -40,6 +41,7 @@ internal data class SettingsEnStrings( override val monsterImageContentScale: String = "Monster Image Content Scale", override val imageContentScaleFit: String = "Show entire image", override val imageContentScaleCrop: String = "Expand the image", + override val openGitHubProject: String = "Open GitHub Project", ) : SettingsStrings internal data class SettingsPtStrings( @@ -49,7 +51,7 @@ internal data class SettingsPtStrings( override val manageMonsterContent: String = "Gerenciar Conteúdo de Monstros", override val sync: String = "Sincronizar", override val manageAdvancedSettings: String = "Configurações Avançadas", - override val settingsTitle: String = "Configurações", + override val settingsTitle: String = "Idioma", override val languageLabel: String = "Idioma", override val save: String = "Salvar", override val appearanceSettingsTitle: String = "Aparência", @@ -60,6 +62,7 @@ internal data class SettingsPtStrings( override val monsterImageContentScale: String = "Escala de Conteúdo de Imagem de Monstro", override val imageContentScaleFit: String = "Mostrar imagem inteira", override val imageContentScaleCrop: String = "Expandir a imagem", + override val openGitHubProject: String = "Abrir Projeto no GitHub", ) : SettingsStrings internal data class SettingsEmptyStrings( @@ -80,6 +83,7 @@ internal data class SettingsEmptyStrings( override val monsterImageContentScale: String = "", override val imageContentScaleFit: String = "", override val imageContentScaleCrop: String = "", + override val openGitHubProject: String = "", ) : SettingsStrings internal fun getSettingsStrings(lang: Language): SettingsStrings { diff --git a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsViewAction.kt b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsViewAction.kt new file mode 100644 index 000000000..b170efb19 --- /dev/null +++ b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsViewAction.kt @@ -0,0 +1,5 @@ +package br.alexandregpereira.hunter.settings + +internal sealed class SettingsViewAction { + data class GoToExternalUrl(val url: String) : SettingsViewAction() +} diff --git a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsViewIntent.kt b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsViewIntent.kt index 2b7db132f..5805265fe 100644 --- a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsViewIntent.kt +++ b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/SettingsViewIntent.kt @@ -30,4 +30,6 @@ internal interface SettingsViewIntent { fun onAppearanceChange(appearance: AppearanceSettingsState) fun onImport() + + fun onOpenGitHubProjectClick() } diff --git a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/ui/MenuScreen.kt b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/ui/MenuScreen.kt index 835a838a5..a2e198ad2 100644 --- a/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/ui/MenuScreen.kt +++ b/feature/settings/compose/src/commonMain/kotlin/br/alexandregpereira/hunter/settings/ui/MenuScreen.kt @@ -79,6 +79,13 @@ internal fun MenuScreen( text = state.strings.manageMonsterContent, onClick = viewIntent::onManageMonsterContentClick ) + + Divider() + + MenuItem( + text = state.strings.openGitHubProject, + onClick = viewIntent::onOpenGitHubProjectClick + ) } if (versionName.isNotBlank()) {