Skip to content

Commit

Permalink
Move currency and language to Main Settings
Browse files Browse the repository at this point in the history
- Refactor MainSettings ViewModel
  • Loading branch information
rafaelekol committed May 30, 2024
1 parent d60519b commit a9d32aa
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,6 @@ fun AppearanceScreen(navController: NavController) {
.fillMaxSize()
.verticalScroll(rememberScrollState()),
) {
CellUniversalLawrenceSection(
listOf({
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)
}
)
})
)
VSpacer(height = 12.dp)
HeaderText(text = stringResource(id = R.string.Appearance_Theme))
CellUniversalLawrenceSection(uiState.themeOptions.options) { option: ThemeType ->
Expand Down
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,8 +72,6 @@ class AppearanceViewModel(
baseTokenOptions = baseTokenOptions,
balanceViewTypeOptions = balanceViewTypeOptions,
marketsTabHidden = marketsTabHidden,
currentLanguage = currentLanguageDisplayName,
baseCurrencyCode = baseCurrencyCode,
balanceTabButtonsHidden = balanceTabButtonsHidden
)

Expand Down Expand Up @@ -171,7 +154,5 @@ data class AppearanceUIState(
val baseTokenOptions: SelectOptional<Token>,
val balanceViewTypeOptions: Select<BalanceViewType>,
val marketsTabHidden: Boolean,
val currentLanguage: String,
val baseCurrencyCode: String,
val balanceTabButtonsHidden: Boolean,
)
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

This file was deleted.

Loading

0 comments on commit a9d32aa

Please sign in to comment.