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 502695a3..4d7000ee 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 b3abd91e..b2f2c2fa 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 446f6d56..f328ffd4 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 ab45e9fd..fd2cbfd1 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( @@ -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( @@ -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 00000000..b170efb1 --- /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 2b7db132..5805265f 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 835a838a..a2e198ad 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()) {