Skip to content

Commit

Permalink
Add GitHub project link on the menu screen (#330)
Browse files Browse the repository at this point in the history
* Add GitHub project link on the menu screen

* Change settings title to language
  • Loading branch information
alexandregpereira authored Aug 20, 2024
1 parent 9a54412 commit 9ce633e
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,7 +61,8 @@ internal class SettingsStateHolder(
private val saveLanguage: SaveLanguageUseCase,
private val getAppearanceSettings: GetAppearanceSettingsFromMonsters,
private val applyAppearanceSettings: ApplyAppearanceSettings,
) : UiModel<SettingsViewState>(SettingsViewState()), SettingsViewIntent {
) : UiModel<SettingsViewState>(SettingsViewState()), SettingsViewIntent,
MutableActionHandler<SettingsViewAction> by MutableActionHandler() {

private val strings: SettingsStrings
get() = getSettingsStrings(appLocalization.getLanguage())
Expand Down Expand Up @@ -140,6 +142,7 @@ internal class SettingsStateHolder(
}

override fun onAppearanceSettingsClick() {
analytics.trackAppearanceSettingsClick()
fillAppearanceSettingsState()
setState { copy(appearanceSettingsOpened = true) }
}
Expand All @@ -149,6 +152,7 @@ internal class SettingsStateHolder(
}

override fun onAppearanceSettingsSaveClick() {
analytics.trackAppearanceSettingsSaveClick()
onAppearanceSettingsCloseClick()
val appearanceState = state.value.appearanceState
flow {
Expand Down Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface SettingsStrings {
val monsterImageContentScale: String
val imageContentScaleFit: String
val imageContentScaleCrop: String
val openGitHubProject: String
}

internal data class SettingsEnStrings(
Expand All @@ -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",
Expand All @@ -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(
Expand All @@ -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",
Expand All @@ -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(
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package br.alexandregpereira.hunter.settings

internal sealed class SettingsViewAction {
data class GoToExternalUrl(val url: String) : SettingsViewAction()
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ internal interface SettingsViewIntent {
fun onAppearanceChange(appearance: AppearanceSettingsState)

fun onImport()

fun onOpenGitHubProjectClick()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 9ce633e

Please sign in to comment.