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

Commit

Permalink
Reviews resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
shamim-emon committed Sep 18, 2024
1 parent 38a9ca0 commit bbcb263
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 76 deletions.
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 @@ -18,7 +18,7 @@ data class LoanScreenState(
val totalOweAmount: String,
val totalOwedAmount: String,
val paidOffLoanVisibility: Boolean,
val tabularLoanMode: Boolean,
val screenMode: LoanScreenMode,
val dateTime: Instant,
val selectedTab: LoanTab
)
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class LoanViewModel @Inject constructor(
totalOweAmount = getTotalOweAmount(totalOweAmount, defaultCurrencyCode),
totalOwedAmount = getTotalOwedAmount(totalOwedAmount, defaultCurrencyCode),
paidOffLoanVisibility = getPaidOffLoanVisibility(),
tabularLoanMode = getTabularLoanMode(),
screenMode = getScreenMode(),
dateTime = dateTime,
selectedTab = getSelectedTab(),
completedLoans = getCompletedLoans(),
Expand Down Expand Up @@ -126,8 +126,11 @@ class LoanViewModel @Inject constructor(
}

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

@Composable
Expand Down
151 changes: 81 additions & 70 deletions screen/loans/src/main/java/com/ivy/loans/loan/LoansScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -45,6 +47,7 @@ import com.ivy.navigation.LoanDetailsScreen
import com.ivy.navigation.LoansScreen
import com.ivy.navigation.navigation
import com.ivy.ui.R
import com.ivy.ui.rememberScrollPositionListState
import com.ivy.wallet.ui.theme.Blue
import com.ivy.wallet.ui.theme.Gray
import com.ivy.wallet.ui.theme.Red
Expand Down Expand Up @@ -80,17 +83,15 @@ private fun BoxWithConstraintsScope.UI(
onEventHandler: (LoanScreenEvent) -> Unit = {}
) {
val nav = navigation()
val scrollState = ivyWalletCtx().loansScrollState
Column(
modifier = Modifier
.fillMaxSize()
.systemBarsPadding()
.verticalScroll(scrollState),
) {
Spacer(Modifier.height(32.dp))

Toolbar(
isTabularModeOn = state.tabularLoanMode,
isTabularModeOn = state.screenMode == LoanScreenMode.TabularMode,
onDismiss = {
nav.back()
},
Expand All @@ -103,24 +104,41 @@ private fun BoxWithConstraintsScope.UI(

Spacer(Modifier.height(8.dp))

if (state.tabularLoanMode) {
if (state.screenMode == LoanScreenMode.TabularMode) {
val scrollState: LazyListState
val loans = if (state.selectedTab == LoanTab.PENDING) {
rememberScrollPositionListState(
key = "loans_pending_lazy_column",
initialFirstVisibleItemIndex = ivyWalletCtx().loansPendingListState?.firstVisibleItemIndex
?: 0,
initialFirstVisibleItemScrollOffset = ivyWalletCtx().loansPendingListState?.firstVisibleItemScrollOffset
?: 0
).also { scrollState = it }
state.pendingLoans
} else {
scrollState = rememberScrollPositionListState(
key = "loans_completed_lazy_column",
initialFirstVisibleItemIndex = ivyWalletCtx().loansCompletedListState?.firstVisibleItemIndex
?: 0,
initialFirstVisibleItemScrollOffset = ivyWalletCtx().loansCompletedListState?.firstVisibleItemScrollOffset
?: 0
)
state.completedLoans
}

for (item in loans) {
Spacer(Modifier.height(16.dp))

LoanItem(
displayLoan = item
) {
nav.navigateTo(
screen = LoanDetailsScreen(
loanId = item.loan.id
LazyColumn(state = scrollState) {
items(loans) { item ->
Spacer(Modifier.height(16.dp))

LoanItem(
displayLoan = item
) {
nav.navigateTo(
screen = LoanDetailsScreen(
loanId = item.loan.id
)
)
)
}
}
}

Expand All @@ -135,20 +153,28 @@ private fun BoxWithConstraintsScope.UI(
Spacer(Modifier.weight(1f))
}
} else {
for (item in state.loans) {
Spacer(Modifier.height(16.dp))

LoanItem(
displayLoan = item
) {
nav.navigateTo(
screen = LoanDetailsScreen(
loanId = item.loan.id
val scrollState = rememberScrollPositionListState(
key = "loans_all_lazy_column",
initialFirstVisibleItemIndex = ivyWalletCtx().loansAllListState?.firstVisibleItemIndex
?: 0,
initialFirstVisibleItemScrollOffset = ivyWalletCtx().loansAllListState?.firstVisibleItemScrollOffset
?: 0
)
LazyColumn(state = scrollState) {
items(state.loans) { item ->
Spacer(Modifier.height(16.dp))

LoanItem(
displayLoan = item
) {
nav.navigateTo(
screen = LoanDetailsScreen(
loanId = item.loan.id
)
)
)
}
}
}

if (state.loans.isEmpty()) {
Spacer(Modifier.weight(1f))

Expand All @@ -163,7 +189,7 @@ private fun BoxWithConstraintsScope.UI(
Spacer(Modifier.height(150.dp)) // scroll hack
}

if (state.tabularLoanMode) {
if (state.screenMode == LoanScreenMode.TabularMode) {
TabularLoanBottomBar(
tab = state.selectedTab,
selectTab = { onEventHandler.invoke(LoanScreenEvent.OnTabChanged(it)) },
Expand Down Expand Up @@ -209,27 +235,30 @@ private fun BoxWithConstraintsScope.UI(
)
}

LoanModal(
accounts = state.accounts,
onCreateAccount = {
onEventHandler.invoke(LoanScreenEvent.OnCreateAccount(accountData = it))
},
modal = state.loanModalData,
onCreateLoan = {
onEventHandler.invoke(LoanScreenEvent.OnLoanCreate(createLoanData = it))
},
onEditLoan = { _, _ -> },
dismiss = {
onEventHandler.invoke(LoanScreenEvent.OnLoanModalDismiss)
},
dateTime = state.dateTime,
onSetDate = {
onEventHandler.invoke(LoanScreenEvent.OnChangeDate)
},
onSetTime = {
onEventHandler.invoke(LoanScreenEvent.OnChangeTime)
}
)
if(state.loanModalData!= null) {
LoanModal(
accounts = state.accounts,
onCreateAccount = {
onEventHandler.invoke(LoanScreenEvent.OnCreateAccount(accountData = it))
},
modal = state.loanModalData,
onCreateLoan = {
onEventHandler.invoke(LoanScreenEvent.OnLoanCreate(createLoanData = it))
},
onEditLoan = { _, _ -> },
dismiss = {
onEventHandler.invoke(LoanScreenEvent.OnLoanModalDismiss)
},
dateTime = state.dateTime,
onSetDate = {
onEventHandler.invoke(LoanScreenEvent.OnChangeDate)
},
onSetTime = {
onEventHandler.invoke(LoanScreenEvent.OnChangeTime)
}
)
}

}

@Composable
Expand Down Expand Up @@ -516,20 +545,11 @@ private fun PreviewInTabularMode(theme: Theme = Theme.LIGHT) {
accounts = persistentListOf(),
totalOweAmount = "1000.00 INR",
totalOwedAmount = "1500.0 INR",
loanModalData = LoanModalData(
loan = Loan(
name = "",
color = Blue.toArgb(),
amount = 0.0,
type = LoanType.LEND,
dateTime = testDateTime
),
baseCurrency = "INR"
),
loanModalData = null,
reorderModalVisible = false,
selectedAccount = null,
paidOffLoanVisibility = true,
tabularLoanMode = true,
screenMode = LoanScreenMode.TabularMode,
dateTime = Instant.now()
)
IvyWalletPreview(theme) {
Expand Down Expand Up @@ -593,20 +613,11 @@ private fun PreviewInNonTabularMode(theme: Theme = Theme.LIGHT) {
accounts = persistentListOf(),
totalOweAmount = "1000.00 INR",
totalOwedAmount = "1500.0 INR",
loanModalData = LoanModalData(
loan = Loan(
name = "",
color = Blue.toArgb(),
amount = 0.0,
type = LoanType.LEND,
dateTime = testDateTime
),
baseCurrency = "INR"
),
loanModalData = null,
reorderModalVisible = false,
selectedAccount = null,
paidOffLoanVisibility = true,
tabularLoanMode = false,
screenMode = LoanScreenMode.NonTabularMode,
dateTime = Instant.now()
)
IvyWalletPreview(theme) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.ivy.loans

import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import com.ivy.loans.loan.LoanScreenNonTabularModeUiTest
import com.ivy.loans.loan.LoanScreenTabularModeUiTest
import com.ivy.ui.testing.PaparazziScreenshotTest
import com.ivy.ui.testing.PaparazziTheme
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(TestParameterInjector::class)
class LoanScreenPaparazziTest(
@TestParameter
private val theme: PaparazziTheme,
) : PaparazziScreenshotTest() {
@Test
fun `snapshot loanScreen tabular composable`() {
snapshot(theme) {
LoanScreenTabularModeUiTest(theme == PaparazziTheme.Dark)
}
}

@Test
fun `snapshot loanScreen non tabular composable`() {
snapshot(theme) {
LoanScreenNonTabularModeUiTest(theme == PaparazziTheme.Dark)
}
}
}
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.
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 @@ -85,7 +85,13 @@ class IvyWalletCtx @Inject constructor() : IvyContext() {
var accountsListState: LazyListState? = null

@Deprecated("Legacy code. Don't use it, please.")
var loansScrollState: ScrollState = ScrollState(0)
var loansPendingListState: LazyListState? = null

@Deprecated("Legacy code. Don't use it, please.")
var loansCompletedListState: LazyListState? = null

@Deprecated("Legacy code. Don't use it, please.")
var loansAllListState: LazyListState? = null

@Deprecated("Legacy code. Don't use it, please.")
var mainTab by mutableStateOf(com.ivy.legacy.data.model.MainTab.HOME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ val Transparent = Color(0x00000000)
@Deprecated("Old design system. Use `:ivy-design` and Material3")
val GradientRed = Gradient(Red, Color(0xFFFF99AB))

val GradientPurple = Gradient(Purple, Color(0xFFFF99AB))
val GradientPurple = Gradient(Purple, Color(0xFFED3EF7))

@Deprecated("Old design system. Use `:ivy-design` and Material3")
val GradientGreen = Gradient(Green, Color(0xFF49F2C8))
Expand Down

0 comments on commit bbcb263

Please sign in to comment.