Skip to content

Commit

Permalink
AccountsViewModel: using by delegation for mutable states (#3525)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamim-emon committed Sep 16, 2024
1 parent 55103ff commit 7fbb143
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions screen/accounts/src/main/java/com/ivy/accounts/AccountsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.viewModelScope
import com.ivy.base.legacy.SharedPrefs
import com.ivy.base.time.TimeConverter
Expand Down Expand Up @@ -50,13 +52,13 @@ class AccountsViewModel @Inject constructor(
private val timeProvider: TimeProvider,
private val timeConverter: TimeConverter,
) : ComposeViewModel<AccountsState, AccountsEvent>() {
private val baseCurrency = mutableStateOf("")
private val accountsData = mutableStateOf(listOf<AccountData>())
private val totalBalanceWithExcluded = mutableStateOf("")
private val totalBalanceWithExcludedText = mutableStateOf("")
private val totalBalanceWithoutExcluded = mutableStateOf("")
private val totalBalanceWithoutExcludedText = mutableStateOf("")
private val reorderVisible = mutableStateOf(false)
private var baseCurrency by mutableStateOf("")
private var accountsData by mutableStateOf(listOf<AccountData>())
private var totalBalanceWithExcluded by mutableStateOf("")
private var totalBalanceWithExcludedText by mutableStateOf("")
private var totalBalanceWithoutExcluded by mutableStateOf("")
private var totalBalanceWithoutExcludedText by mutableStateOf("")
private var reorderVisible by mutableStateOf(false)

init {
viewModelScope.launch {
Expand Down Expand Up @@ -100,37 +102,37 @@ class AccountsViewModel @Inject constructor(

@Composable
private fun getBaseCurrency(): String {
return baseCurrency.value
return baseCurrency
}

@Composable
private fun getAccountsData(): ImmutableList<AccountData> {
return accountsData.value.toImmutableList()
return accountsData.toImmutableList()
}

@Composable
private fun getTotalBalanceWithExcluded(): String {
return totalBalanceWithExcluded.value
return totalBalanceWithExcluded
}

@Composable
private fun getTotalBalanceWithExcludedText(): String {
return totalBalanceWithExcludedText.value
return totalBalanceWithExcludedText
}

@Composable
private fun getTotalBalanceWithoutExcluded(): String {
return totalBalanceWithoutExcluded.value
return totalBalanceWithoutExcluded
}

@Composable
private fun getTotalBalanceWithoutExcludedText(): String {
return totalBalanceWithoutExcludedText.value
return totalBalanceWithoutExcludedText
}

@Composable
private fun getReorderVisible(): Boolean {
return reorderVisible.value
return reorderVisible
}

@Composable
Expand Down Expand Up @@ -197,18 +199,18 @@ class AccountsViewModel @Inject constructor(
)
).toDouble()

baseCurrency.value = baseCurrencyCode
accountsData.value = accountsDataList
totalBalanceWithExcluded.value = totalBalanceWithExcludedAccounts.toString()
totalBalanceWithExcludedText.value = context.getString(
baseCurrency = baseCurrencyCode
accountsData = accountsDataList
totalBalanceWithExcluded = totalBalanceWithExcludedAccounts.toString()
totalBalanceWithExcludedText = context.getString(
R.string.total,
baseCurrencyCode,
totalBalanceWithExcludedAccounts.format(
baseCurrencyCode
)
)
totalBalanceWithoutExcluded.value = totalBalanceWithoutExcludedAccounts.toString()
totalBalanceWithoutExcludedText.value = context.getString(
totalBalanceWithoutExcluded = totalBalanceWithoutExcludedAccounts.toString()
totalBalanceWithoutExcludedText = context.getString(
R.string.total_exclusive,
baseCurrencyCode,
totalBalanceWithoutExcludedAccounts.format(
Expand All @@ -218,6 +220,6 @@ class AccountsViewModel @Inject constructor(
}

private fun reorderModalVisible(visible: Boolean) {
reorderVisible.value = visible
reorderVisible = visible
}
}

0 comments on commit 7fbb143

Please sign in to comment.