Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Removed old loan UI related code and files (#3542)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamim-emon authored Sep 18, 2024
1 parent 04b9fd1 commit 8ebb5c0
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ val FAB_BUTTON_SIZE = 56.dp
const val ZINDEX = 200f

@Composable
internal fun BoxWithConstraintsScope.TabularLoanBottomBar(
internal fun BoxWithConstraintsScope.LoanBottomBar(
tab: LoanTab,
selectTab: (LoanTab) -> Unit,
onAdd: () -> Unit
Expand Down Expand Up @@ -158,7 +158,7 @@ private fun PreviewTabularBottomBar() {
) {
}

TabularLoanBottomBar(
LoanBottomBar(
tab = LoanTab.PENDING,
selectTab = {},
onAdd = {}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import java.time.Instant

data class LoanScreenState(
val baseCurrency: String,
val loans: ImmutableList<DisplayLoan>,
val completedLoans: ImmutableList<DisplayLoan>,
val pendingLoans: ImmutableList<DisplayLoan>,
val accounts: ImmutableList<Account>,
Expand All @@ -18,7 +17,6 @@ data class LoanScreenState(
val totalOweAmount: String,
val totalOwedAmount: String,
val paidOffLoanVisibility: Boolean,
val screenMode: LoanScreenMode,
val dateTime: Instant,
val selectedTab: LoanTab
)
30 changes: 1 addition & 29 deletions screen/loans/src/main/java/com/ivy/loans/loan/LoanViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.ivy.data.db.dao.read.LoanRecordDao
import com.ivy.data.db.dao.read.SettingsDao
import com.ivy.data.db.dao.write.WriteLoanDao
import com.ivy.data.model.LoanType
import com.ivy.domain.features.Features
import com.ivy.frp.test.TestIdlingResource
import com.ivy.legacy.datamodel.Account
import com.ivy.legacy.datamodel.Loan
Expand Down Expand Up @@ -58,12 +57,10 @@ class LoanViewModel @Inject constructor(
private val loanWriter: WriteLoanDao,
private val timeConverter: TimeConverter,
private val timeProvider: TimeProvider,
private val dateTimePicker: DateTimePicker,
private val features: Features
private val dateTimePicker: DateTimePicker
) : ComposeViewModel<LoanScreenState, LoanScreenEvent>() {

private var baseCurrencyCode by mutableStateOf(getDefaultFIATCurrency().currencyCode)
private var loans by mutableStateOf<ImmutableList<DisplayLoan>>(persistentListOf())
private var completedLoans by mutableStateOf<ImmutableList<DisplayLoan>>(persistentListOf())
private var pendingLoans by mutableStateOf<ImmutableList<DisplayLoan>>(persistentListOf())
private var accounts by mutableStateOf<ImmutableList<Account>>(persistentListOf())
Expand All @@ -90,15 +87,13 @@ class LoanViewModel @Inject constructor(

return LoanScreenState(
baseCurrency = getBaseCurrencyCode(),
loans = getLoans(),
accounts = getAccounts(),
selectedAccount = getSelectedAccount(),
loanModalData = getLoanModalData(),
reorderModalVisible = getReorderModalVisible(),
totalOweAmount = getTotalOweAmount(totalOweAmount, defaultCurrencyCode),
totalOwedAmount = getTotalOwedAmount(totalOwedAmount, defaultCurrencyCode),
paidOffLoanVisibility = getPaidOffLoanVisibility(),
screenMode = getScreenMode(),
dateTime = dateTime,
selectedTab = getSelectedTab(),
completedLoans = getCompletedLoans(),
Expand All @@ -125,25 +120,12 @@ class LoanViewModel @Inject constructor(
return pendingLoans
}

@Composable
private fun getScreenMode(): LoanScreenMode {
return when (features.tabularLoanMode.asEnabledState()) {
true -> LoanScreenMode.TabularMode
else -> LoanScreenMode.NonTabularMode
}
}

@Composable
private fun getReorderModalVisible() = reorderModalVisible

@Composable
private fun getLoanModalData() = loanModalData

@Composable
private fun getLoans(): ImmutableList<DisplayLoan> {
return loans
}

@Composable
private fun getBaseCurrencyCode(): String {
return baseCurrencyCode
Expand Down Expand Up @@ -258,7 +240,6 @@ class LoanViewModel @Inject constructor(
)
}.toImmutableList()
}
filterLoans()
loadPendingLoans()
loadCompletedLoans()

Expand Down Expand Up @@ -367,14 +348,6 @@ class LoanViewModel @Inject constructor(
}
}

/** It filters [allLoans] and updates [loans] based on weather to show paid off loans or not */
private fun filterLoans() {
loans = when (paidOffLoanVisibility) {
true -> allLoans
false -> allLoans.filter { loan -> loan.percentPaid < 1.0 }.toImmutableList()
}
}

private fun loadCompletedLoans() {
completedLoans = allLoans.filter { loan -> loan.percentPaid == 1.0 }.toImmutableList()
}
Expand Down Expand Up @@ -437,6 +410,5 @@ class LoanViewModel @Inject constructor(

private fun updatePaidOffLoanVisibility() {
paidOffLoanVisibility = paidOffLoanVisibility.not()
filterLoans()
}
}
Loading

0 comments on commit 8ebb5c0

Please sign in to comment.