Skip to content

Commit

Permalink
Add setting to hide balance tab buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrasulov committed May 20, 2024
1 parent 6a2f2ae commit 22dfefc
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ interface ILocalStorage {
var relaunchBySettingChange: Boolean
var marketsTabEnabled: Boolean
val marketsTabEnabledFlow: StateFlow<Boolean>
var balanceTabButtonsEnabled: Boolean
val balanceTabButtonsEnabledFlow: StateFlow<Boolean>
var nonRecommendedAccountAlertDismissedAccounts: Set<String>
var personalSupportEnabled: Boolean
var hideSuspiciousTransactions: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,15 @@ class LocalStorageManager(
}
}

override var balanceTabButtonsEnabled: Boolean
get() = preferences.getBoolean("balanceTabButtonsEnabled", true)
set(value) {
preferences.edit().putBoolean("balanceTabButtonsEnabled", value).apply()
balanceTabButtonsEnabledFlow.update { value }
}

override val balanceTabButtonsEnabledFlow = MutableStateFlow(balanceTabButtonsEnabled)

override var personalSupportEnabled: Boolean
get() = preferences.getBoolean(PERSONAL_SUPPORT_ENABLED, false)
set(enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BalanceViewModel(
private var isRefreshing = false
private var openSendTokenSelect: OpenSendTokenSelect? = null
private var errorMessage: String? = null
private var balanceTabButtonsEnabled = localStorage.balanceTabButtonsEnabled

val sortTypes =
listOf(BalanceSortType.Value, BalanceSortType.Name, BalanceSortType.PercentGrowth)
Expand Down Expand Up @@ -90,18 +91,26 @@ class BalanceViewModel(
}
}

viewModelScope.launch {
localStorage.balanceTabButtonsEnabledFlow.collect {
balanceTabButtonsEnabled = it
emitState()
}
}

service.start()

totalBalance.start(viewModelScope)
}

override fun createState()= BalanceUiState(
override fun createState() = BalanceUiState(
balanceViewItems = balanceViewItems,
viewState = viewState,
isRefreshing = isRefreshing,
headerNote = headerNote(),
errorMessage = errorMessage,
openSend = openSendTokenSelect
openSend = openSendTokenSelect,
balanceTabButtonsEnabled = balanceTabButtonsEnabled
)

private suspend fun handleUpdatedBalanceViewType(balanceViewType: BalanceViewType) {
Expand Down Expand Up @@ -329,6 +338,7 @@ data class BalanceUiState(
val headerNote: HeaderNote,
val errorMessage: String?,
val openSend: OpenSendTokenSelect? = null,
val balanceTabButtonsEnabled: Boolean,
)

data class OpenSendTokenSelect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ fun BalanceItems(
)
}

if (!accountViewItem.isWatchAccount) {
if (uiState.balanceTabButtonsEnabled && !accountViewItem.isWatchAccount) {
item {
Row(
modifier = Modifier.padding(horizontal = 24.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fun AppearanceScreen(navController: NavController) {

HeaderText(text = stringResource(id = R.string.Appearance_Tab))
CellUniversalLawrenceSection(
listOf {
listOf({
RowUniversal(
modifier = Modifier.padding(horizontal = 16.dp),
) {
Expand All @@ -185,8 +185,33 @@ fun AppearanceScreen(navController: NavController) {
)

}
}, {
RowUniversal(
modifier = Modifier.padding(horizontal = 16.dp),
) {
Image(
modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.ic_more_24),
contentDescription = null,
colorFilter = ColorFilter.tint(ComposeAppTheme.colors.grey)
)

}
body_leah(
text = stringResource(id = R.string.Appearance_BalanceTabButtons),
modifier = Modifier
.weight(1f)
.padding(horizontal = 16.dp)
)

HsSwitch(
checked = uiState.balanceTabButtonsEnabled,
onCheckedChange = {
viewModel.onSetBalanceTabButtons(it)
}
)

}
})
)
Spacer(modifier = Modifier.height(24.dp))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AppearanceViewModel(
private var themeOptions = themeService.optionsFlow.value
private var baseTokenOptions = buildBaseTokenSelect(baseTokenManager.baseTokenFlow.value)
private var marketsTabEnabled = localStorage.marketsTabEnabled
private var balanceTabButtonsEnabled = localStorage.balanceTabButtonsEnabled
private var balanceViewTypeOptions =
buildBalanceViewTypeSelect(balanceViewTypeManager.balanceViewTypeFlow.value)
private val currentLanguageDisplayName: String
Expand Down Expand Up @@ -87,7 +88,8 @@ class AppearanceViewModel(
balanceViewTypeOptions = balanceViewTypeOptions,
marketsTabEnabled = marketsTabEnabled,
currentLanguage = currentLanguageDisplayName,
baseCurrencyCode = baseCurrencyCode
baseCurrencyCode = baseCurrencyCode,
balanceTabButtonsEnabled = balanceTabButtonsEnabled
)

private fun buildBaseTokenSelect(token: Token?): SelectOptional<Token> {
Expand Down Expand Up @@ -153,6 +155,13 @@ class AppearanceViewModel(
emitState()
}

fun onSetBalanceTabButtons(enabled: Boolean) {
localStorage.balanceTabButtonsEnabled = enabled

balanceTabButtonsEnabled = enabled
emitState()
}

}

data class AppearanceUIState(
Expand All @@ -164,4 +173,5 @@ data class AppearanceUIState(
val marketsTabEnabled: Boolean,
val currentLanguage: String,
val baseCurrencyCode: String,
val balanceTabButtonsEnabled: Boolean,
)
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@
<string name="Appearance_BalanceValue">BALANCE VALUE</string>
<string name="Appearance_Warning_CloseApplication">Changing icon will close application</string>
<string name="Appearance_MarketsTab">Markets Tab</string>
<string name="Appearance_BalanceTabButtons">Balance Tab Buttons</string>
<string name="Appearance_BalanceAutoHide">Balance Auto Hide</string>
<string name="Appearance_BalanceAutoHide_Description">Automatically hides balance each time the app is opened, regardless of previous preferences.</string>

Expand Down

0 comments on commit 22dfefc

Please sign in to comment.