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

Commit

Permalink
Tabular Loan UI added (#3539)
Browse files Browse the repository at this point in the history
* Tabular Loan UI added

* Fixed detekt errors

* Fixed detekt errors

* Fixed detekt errors

* Fixed detekt errors

* TabularLoanBottomBar Fab Button Color Update

* TabularLoanBottomBar Fab Button Color Update

* TabularLoanBottomBar Tab Selection Color Update

* Detekt error fixed

* Reviews resolved

* Detekt errors fixed

* compose-stability errors fixed

* compose-stability errors fixed

* compose-stability errors fixed

* Removed un-used import
  • Loading branch information
shamim-emon authored Sep 18, 2024
1 parent 1a9fe27 commit b75a0b8
Show file tree
Hide file tree
Showing 17 changed files with 508 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sealed interface LoanScreenEvent {
data class OnReordered(val reorderedList: List<DisplayLoan>) : LoanScreenEvent
data class OnCreateAccount(val accountData: CreateAccountData) : LoanScreenEvent
data class OnReOrderModalShow(val show: Boolean) : LoanScreenEvent
data class OnTabChanged(val tab: LoanTab) : LoanScreenEvent
data object OnAddLoan : LoanScreenEvent
data object OnLoanModalDismiss : LoanScreenEvent
data object OnChangeDate : LoanScreenEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ivy.loans.loan

sealed interface LoanScreenMode {
data object TabularMode : LoanScreenMode
data object NonTabularMode : LoanScreenMode
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ 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>,
val selectedAccount: Account?,
val loanModalData: LoanModalData?,
val reorderModalVisible: Boolean,
val totalOweAmount: String,
val totalOwedAmount: String,
val paidOffLoanVisibility: Boolean,
val dateTime: Instant
)
val screenMode: LoanScreenMode,
val dateTime: Instant,
val selectedTab: LoanTab
)
8 changes: 8 additions & 0 deletions screen/loans/src/main/java/com/ivy/loans/loan/LoanTab.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.ivy.loans.loan

import androidx.compose.runtime.Immutable

@Immutable
enum class LoanTab {
PENDING, COMPLETED
}
53 changes: 52 additions & 1 deletion screen/loans/src/main/java/com/ivy/loans/loan/LoanViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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,15 +59,19 @@ class LoanViewModel @Inject constructor(
private val timeConverter: TimeConverter,
private val timeProvider: TimeProvider,
private val dateTimePicker: DateTimePicker,
private val features: Features
) : 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())
private var selectedAccount by mutableStateOf<Account?>(null)
private var loanModalData by mutableStateOf<LoanModalData?>(null)
private var reorderModalVisible by mutableStateOf(false)
private var dateTime by mutableStateOf<Instant>(timeProvider.utcNow())
private var selectedTab by mutableStateOf(LoanTab.PENDING)

/** If true paid off loans will be visible */
private var paidOffLoanVisibility by mutableStateOf(true)
Expand All @@ -93,10 +98,41 @@ class LoanViewModel @Inject constructor(
totalOweAmount = getTotalOweAmount(totalOweAmount, defaultCurrencyCode),
totalOwedAmount = getTotalOwedAmount(totalOwedAmount, defaultCurrencyCode),
paidOffLoanVisibility = getPaidOffLoanVisibility(),
dateTime = dateTime
screenMode = getScreenMode(),
dateTime = dateTime,
selectedTab = getSelectedTab(),
completedLoans = getCompletedLoans(),
pendingLoans = getPendingLoans()
)
}

fun setTab(tab: LoanTab) {
selectedTab = tab
}

@Composable
private fun getSelectedTab(): LoanTab {
return selectedTab
}

@Composable
private fun getCompletedLoans(): ImmutableList<DisplayLoan> {
return completedLoans
}

@Composable
private fun getPendingLoans(): ImmutableList<DisplayLoan> {
return pendingLoans
}

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

@Composable
private fun getReorderModalVisible() = reorderModalVisible

Expand Down Expand Up @@ -160,9 +196,14 @@ class LoanViewModel @Inject constructor(
is LoanScreenEvent.OnChangeDate -> {
handleChangeDate()
}

is LoanScreenEvent.OnChangeTime -> {
handleChangeTime()
}

is LoanScreenEvent.OnTabChanged -> {
setTab(event.tab)
}
}
}

Expand Down Expand Up @@ -218,6 +259,8 @@ class LoanViewModel @Inject constructor(
}.toImmutableList()
}
filterLoans()
loadPendingLoans()
loadCompletedLoans()

TestIdlingResource.decrement()
}
Expand Down Expand Up @@ -332,6 +375,14 @@ class LoanViewModel @Inject constructor(
}
}

private fun loadCompletedLoans() {
completedLoans = allLoans.filter { loan -> loan.percentPaid == 1.0 }.toImmutableList()
}

private fun loadPendingLoans() {
pendingLoans = allLoans.filter { loan -> loan.percentPaid < 1.0 }.toImmutableList()
}

private fun createAccount(data: CreateAccountData) {
viewModelScope.launch {
TestIdlingResource.increment()
Expand Down
Loading

0 comments on commit b75a0b8

Please sign in to comment.