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

Commit

Permalink
Merge branch 'main' into fix-issue-3535
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsin363 authored Sep 18, 2024
2 parents f02fdc9 + b75a0b8 commit 5078d10
Show file tree
Hide file tree
Showing 21 changed files with 510 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @ILIYANGERMANOV
* @ILIYANGERMANOV
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private fun SearchField(
searchQueryTextFieldValue = searchQueryTextFieldValue,
hint = "Search currency",
focus = false,
showClearIcon = searchQueryTextFieldValue.text.isNotEmpty(),
onSetSearchQueryTextField = {
searchQueryTextFieldValue = it
onSearch(it.text)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 5078d10

Please sign in to comment.