Skip to content

Commit

Permalink
Implement changes to Settings Appearance page
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed May 30, 2024
1 parent a9d32aa commit b8d199b
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum class LaunchPage(@StringRes val titleRes: Int, @DrawableRes val iconRes: In
get() = TranslatableString.ResString(titleRes)

companion object {
private val map = values().associateBy(LaunchPage::name)
private val map = entries.associateBy(LaunchPage::name)

fun fromString(type: String?): LaunchPage? = map[type]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ package io.horizontalsystems.bankwallet.modules.balance
import androidx.annotation.StringRes
import com.google.gson.annotations.SerializedName
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.ui.compose.TranslatableString
import io.horizontalsystems.bankwallet.ui.compose.WithTranslatableTitle

enum class BalanceViewType(@StringRes val titleResId: Int, @StringRes val subtitleResId: Int) {
enum class BalanceViewType(@StringRes val titleResId: Int, @StringRes val subtitleResId: Int) :
WithTranslatableTitle {
@SerializedName("coin")
CoinThenFiat(R.string.BalanceViewType_CoinValue, R.string.BalanceViewType_FiatValue),

@SerializedName("currency")
FiatThenCoin(R.string.BalanceViewType_FiatValue, R.string.BalanceViewType_CoinValue);

override val title: TranslatableString
get() = TranslatableString.ResString(titleResId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update

class BalanceViewTypeManager(private val localStorage: ILocalStorage) {
val viewTypes = BalanceViewType.values().asList()
val viewTypes = BalanceViewType.entries

val balanceViewType: BalanceViewType
get() = localStorage.balanceViewType ?: BalanceViewType.CoinThenFiat

private val _balanceViewTypeFlow = MutableStateFlow(balanceViewType)

private val _balanceViewTypeFlow = MutableStateFlow(
localStorage.balanceViewType ?: BalanceViewType.CoinThenFiat
)
val balanceViewTypeFlow = _balanceViewTypeFlow.asStateFlow()

fun setViewType(viewType: BalanceViewType) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ class AppearanceViewModel(
baseTokenOptions = baseTokenOptions,
balanceViewTypeOptions = balanceViewTypeOptions,
marketsTabHidden = marketsTabHidden,
balanceTabButtonsHidden = balanceTabButtonsHidden
balanceTabButtonsHidden = balanceTabButtonsHidden,
selectedTheme = themeService.selectedTheme,
selectedLaunchScreen = launchScreenService.selectedLaunchScreen,
selectedBalanceViewType = balanceViewTypeManager.balanceViewType,
)

private fun buildBaseTokenSelect(token: Token?): SelectOptional<Token> {
Expand Down Expand Up @@ -155,4 +158,7 @@ data class AppearanceUIState(
val balanceViewTypeOptions: Select<BalanceViewType>,
val marketsTabHidden: Boolean,
val balanceTabButtonsHidden: Boolean,
val selectedTheme: ThemeType,
val selectedLaunchScreen: LaunchPage,
val selectedBalanceViewType: BalanceViewType,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update

class LaunchScreenService(private val localStorage: ILocalStorage) {
private val screens by lazy { LaunchPage.values().asList() }
private val screens by lazy { LaunchPage.entries }

val selectedLaunchScreen: LaunchPage
get() = localStorage.launchPage ?: LaunchPage.Auto

private val _optionsFlow = MutableStateFlow(
Select(localStorage.launchPage ?: LaunchPage.Auto, screens)
Select(selectedLaunchScreen, screens)
)
val optionsFlow = _optionsFlow.asStateFlow()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update

class ThemeService(private val localStorage: ILocalStorage) {
private val themes by lazy { ThemeType.values().toList() }
private val themes by lazy { ThemeType.entries }

val selectedTheme: ThemeType
get() = localStorage.currentTheme

private val _optionsFlow = MutableStateFlow(
Select(localStorage.currentTheme, themes)
Select(selectedTheme, themes)
)
val optionsFlow = _optionsFlow.asStateFlow()

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1004,11 +1004,12 @@

<string name="Appearance_Theme">THEME</string>
<string name="Appearance_Tab">TAB SETTINGS</string>
<string name="Appearance_MarketsTab">MARKETS TAB</string>
<string name="Appearance_BalanceTab">BALANCE TAB</string>
<string name="Appearance_LaunchScreen">LAUNCH SCREEN</string>
<string name="Appearance_AppIcon">APP ICON</string>
<string name="Appearance_BalanceConversion">BALANCE CONVERSION</string>
<string name="Appearance_BalanceValue">BALANCE VALUE</string>
<string name="Appearance_BalanceConversion">Balance Conversion</string>
<string name="Appearance_BalanceValue">Balance Value</string>
<string name="Appearance_Warning_CloseApplication">Changing icon will close application</string>
<string name="Appearance_HideMarketsTab">Hide Markets</string>
<string name="Appearance_HideBalanceTabButtons">Hide Buttons</string>
Expand Down

0 comments on commit b8d199b

Please sign in to comment.