Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement changes to Appearance Settings page #7501

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -23,8 +23,6 @@ object AppearanceModule {
App.baseTokenManager,
App.balanceViewTypeManager,
App.localStorage,
App.languageManager,
App.currencyManager,
) as T
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import androidx.lifecycle.viewModelScope
import io.horizontalsystems.bankwallet.core.ILocalStorage
import io.horizontalsystems.bankwallet.core.ViewModelUiState
import io.horizontalsystems.bankwallet.core.managers.BaseTokenManager
import io.horizontalsystems.bankwallet.core.managers.CurrencyManager
import io.horizontalsystems.bankwallet.core.managers.LanguageManager
import io.horizontalsystems.bankwallet.entities.LaunchPage
import io.horizontalsystems.bankwallet.modules.balance.BalanceViewType
import io.horizontalsystems.bankwallet.modules.balance.BalanceViewTypeManager
Expand All @@ -15,7 +13,6 @@ import io.horizontalsystems.bankwallet.ui.compose.Select
import io.horizontalsystems.bankwallet.ui.compose.SelectOptional
import io.horizontalsystems.marketkit.models.Token
import kotlinx.coroutines.launch
import kotlinx.coroutines.rx2.asFlow


class AppearanceViewModel(
Expand All @@ -25,8 +22,6 @@ class AppearanceViewModel(
private val baseTokenManager: BaseTokenManager,
private val balanceViewTypeManager: BalanceViewTypeManager,
private val localStorage: ILocalStorage,
private val languageManager: LanguageManager,
private val currencyManager: CurrencyManager,
) : ViewModelUiState<AppearanceUIState>() {
private var launchScreenOptions = launchScreenService.optionsFlow.value
private var appIconOptions = appIconService.optionsFlow.value
Expand All @@ -36,11 +31,6 @@ class AppearanceViewModel(
private var balanceTabButtonsHidden = !localStorage.balanceTabButtonsEnabled
private var balanceViewTypeOptions =
buildBalanceViewTypeSelect(balanceViewTypeManager.balanceViewTypeFlow.value)
private val currentLanguageDisplayName: String
get() = languageManager.currentLanguageName

private val baseCurrencyCode: String
get() = currencyManager.baseCurrency.code

init {
viewModelScope.launch {
Expand Down Expand Up @@ -73,11 +63,6 @@ class AppearanceViewModel(
handleUpdatedBalanceViewType(buildBalanceViewTypeSelect(it))
}
}
viewModelScope.launch {
currencyManager.baseCurrencyUpdatedSignal.asFlow().collect {
emitState()
}
}
}

override fun createState() = AppearanceUIState(
Expand All @@ -87,9 +72,10 @@ class AppearanceViewModel(
baseTokenOptions = baseTokenOptions,
balanceViewTypeOptions = balanceViewTypeOptions,
marketsTabHidden = marketsTabHidden,
currentLanguage = currentLanguageDisplayName,
baseCurrencyCode = baseCurrencyCode,
balanceTabButtonsHidden = balanceTabButtonsHidden
balanceTabButtonsHidden = balanceTabButtonsHidden,
selectedTheme = themeService.selectedTheme,
selectedLaunchScreen = launchScreenService.selectedLaunchScreen,
selectedBalanceViewType = balanceViewTypeManager.balanceViewType,
)

private fun buildBaseTokenSelect(token: Token?): SelectOptional<Token> {
Expand Down Expand Up @@ -171,7 +157,8 @@ data class AppearanceUIState(
val baseTokenOptions: SelectOptional<Token>,
val balanceViewTypeOptions: Select<BalanceViewType>,
val marketsTabHidden: Boolean,
val currentLanguage: String,
val baseCurrencyCode: String,
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 @@ -9,7 +9,7 @@ object MainSettingsModule {
class Factory : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
val service = MainSettingsService(
val viewModel = MainSettingsViewModel(
App.backupManager,
App.systemInfoManager,
App.termsManager,
Expand All @@ -18,10 +18,8 @@ object MainSettingsModule {
App.wcManager,
App.accountManager,
App.appConfigProvider,
)
val viewModel = MainSettingsViewModel(
service,
App.appConfigProvider.companyWebPageLink,
App.languageManager,
App.currencyManager,
)

return viewModel as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import androidx.compose.material.Icon
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -88,11 +86,7 @@ private fun SettingSections(
viewModel: MainSettingsViewModel,
navController: NavController
) {

val showAlertManageWallet by viewModel.manageWalletShowAlertLiveData.observeAsState(false)
val showAlertSecurityCenter by viewModel.securityCenterShowAlertLiveData.observeAsState(false)
val showAlertAboutApp by viewModel.aboutAppShowAlertLiveData.observeAsState(false)
val wcCounter by viewModel.wcCounterLiveData.observeAsState()
val uiState = viewModel.uiState
val context = LocalContext.current

CellUniversalLawrenceSection(
Expand All @@ -117,7 +111,7 @@ private fun SettingSections(
HsSettingCell(
R.string.SettingsSecurity_ManageKeys,
R.drawable.ic_wallet_20,
showAlert = showAlertManageWallet,
showAlert = uiState.manageWalletShowAlert,
onClick = {
navController.slideFromRight(
R.id.manageAccountsFragment,
Expand All @@ -134,21 +128,27 @@ private fun SettingSections(
onClick = {
navController.slideFromRight(R.id.blockchainSettingsFragment)

stat(page = StatPage.Settings, event = StatEvent.Open(StatPage.BlockchainSettings))
stat(
page = StatPage.Settings,
event = StatEvent.Open(StatPage.BlockchainSettings)
)
}
)
}, {
HsSettingCell(
R.string.Settings_WalletConnect,
R.drawable.ic_wallet_connect_20,
value = (wcCounter as? MainSettingsModule.CounterType.SessionCounter)?.number?.toString(),
counterBadge = (wcCounter as? MainSettingsModule.CounterType.PendingRequestCounter)?.number?.toString(),
value = (uiState.wcCounterType as? MainSettingsModule.CounterType.SessionCounter)?.number?.toString(),
counterBadge = (uiState.wcCounterType as? MainSettingsModule.CounterType.PendingRequestCounter)?.number?.toString(),
onClick = {
when (val state = viewModel.getWalletConnectSupportState()) {
when (val state = viewModel.walletConnectSupportState) {
WCManager.SupportState.Supported -> {
navController.slideFromRight(R.id.wcListFragment)

stat(page = StatPage.Settings, event = StatEvent.Open(StatPage.WalletConnect))
stat(
page = StatPage.Settings,
event = StatEvent.Open(StatPage.WalletConnect)
)
}

WCManager.SupportState.NotSupportedDueToNoActiveAccount -> {
Expand All @@ -162,7 +162,10 @@ private fun SettingSections(
BackupRequiredDialog.Input(state.account, text)
)

stat(page = StatPage.Settings, event = StatEvent.Open(StatPage.BackupRequired))
stat(
page = StatPage.Settings,
event = StatEvent.Open(StatPage.BackupRequired)
)
}

is WCManager.SupportState.NotSupported -> {
Expand Down Expand Up @@ -196,7 +199,7 @@ private fun SettingSections(
HsSettingCell(
R.string.Settings_SecurityCenter,
R.drawable.ic_security,
showAlert = showAlertSecurityCenter,
showAlert = uiState.securityCenterShowAlert,
onClick = {
navController.slideFromRight(R.id.securitySettingsFragment)

Expand Down Expand Up @@ -229,6 +232,26 @@ private fun SettingSections(
}
)
},
{
HsSettingCell(
R.string.Settings_BaseCurrency,
R.drawable.ic_currency,
value = uiState.baseCurrencyCode,
onClick = {
navController.slideFromRight(R.id.baseCurrencySettingsFragment)
}
)
},
{
HsSettingCell(
R.string.Settings_Language,
R.drawable.ic_language,
value = uiState.currentLanguage,
onClick = {
navController.slideFromRight(R.id.languageSettingsFragment)
}
)
}
)
)

Expand All @@ -252,7 +275,10 @@ private fun SettingSections(
onClick = {
LinkHelper.openLinkInAppBrowser(context, App.appConfigProvider.appTelegramLink)

stat(page = StatPage.Settings, event = StatEvent.Open(StatPage.ExternalTelegram))
stat(
page = StatPage.Settings,
event = StatEvent.Open(StatPage.ExternalTelegram)
)
}
)
}, {
Expand Down Expand Up @@ -305,7 +331,7 @@ private fun SettingSections(
HsSettingCell(
R.string.SettingsAboutApp_Title,
R.drawable.ic_about_app_20,
showAlert = showAlertAboutApp,
showAlert = uiState.aboutAppShowAlert,
onClick = {
navController.slideFromRight(R.id.aboutAppFragment)

Expand All @@ -327,7 +353,7 @@ private fun SettingSections(
R.string.Settings_ShareThisWallet,
R.drawable.ic_share_20,
onClick = {
shareAppLink(viewModel.appWebPageLink, context)
shareAppLink(uiState.appWebPageLink, context)

stat(page = StatPage.Settings, event = StatEvent.Open(StatPage.TellFriends))
}
Expand Down
Loading
Loading