Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add swipe refresh in finance screens #1593

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mifospay/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ dependencies {
implementation("de.hdodenhof:circleimageview:3.1.0")
implementation("com.github.yalantis:ucrop:2.2.2")

implementation("com.google.accompanist:accompanist-swiperefresh:0.27.0")

kspTest(libs.hilt.compiler)

testImplementation(libs.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -26,6 +29,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.mifos.mobilewallet.model.domain.BankAccountDetails
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.bank.presenter.AccountViewModel
Expand All @@ -42,11 +47,26 @@ fun AccountsScreen(
) {
val accountsUiState by viewModel.accountsUiState.collectAsStateWithLifecycle()
val sampleList = viewModel.bankAccountDetailsList
AccountScreen(
accountsUiState = accountsUiState,
onAddAccount = onAddAccount,
sampleList = sampleList,
)
var isRefreshing by rememberSaveable {
mutableStateOf(false)
Akshay2004-701 marked this conversation as resolved.
Show resolved Hide resolved
}
val swipeRefreshState = rememberSwipeRefreshState(
isRefreshing = isRefreshing
)
SwipeRefresh(
state = swipeRefreshState,
onRefresh = {
isRefreshing = true
viewModel.fetchLinkedAccount()
isRefreshing = false
}
Akshay2004-701 marked this conversation as resolved.
Show resolved Hide resolved
){
AccountScreen(
accountsUiState = accountsUiState,
onAddAccount = onAddAccount,
sampleList = sampleList,
)
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import kotlinx.coroutines.flow.StateFlow
import org.mifos.mobilewallet.core.base.UseCase
import org.mifos.mobilewallet.core.base.UseCaseHandler
import org.mifos.mobilewallet.core.domain.usecase.kyc.FetchKYCLevel1Details
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.data.local.LocalRepository
import org.mifos.mobilewallet.mifospay.kyc.KYCContract
import javax.inject.Inject

@HiltViewModel
Expand All @@ -28,7 +26,7 @@ class KYCDescriptionViewModel @Inject constructor(
fetchCurrentLevel()
}

private fun fetchCurrentLevel() {
fun fetchCurrentLevel() {
fetchKYCLevel1DetailsUseCase.walletRequestValues =
FetchKYCLevel1Details.RequestValues(mLocalRepository.clientDetails.clientId.toInt())
val requestValues = fetchKYCLevel1DetailsUseCase.walletRequestValues
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.mifos.mobilewallet.mifospay.kyc.ui

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -15,7 +14,9 @@ import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.Button
Expand All @@ -26,6 +27,9 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
Expand All @@ -39,6 +43,8 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.mifos.mobilewallet.model.entity.kyc.KYCLevel1Details
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.designsystem.component.MifosOverlayLoadingWheel
Expand All @@ -54,30 +60,54 @@ fun KYCDescriptionScreen(
) {
val kUiState by viewModel.kycdescriptionState.collectAsState()

when (val state = kUiState) {
KYCDescriptionUiState.Loading -> {
MifosOverlayLoadingWheel(contentDesc = stringResource(R.string.loading))
}
var isRefreshing by rememberSaveable {
mutableStateOf(false)
}
val swipeRefreshState =
rememberSwipeRefreshState(
isRefreshing = isRefreshing
)
Akshay2004-701 marked this conversation as resolved.
Show resolved Hide resolved

is KYCDescriptionUiState.Error -> {
PlaceholderScreen()
}
SwipeRefresh(
state = swipeRefreshState,
onRefresh = {
isRefreshing = true
viewModel.fetchCurrentLevel()
isRefreshing = false
Akshay2004-701 marked this conversation as resolved.
Show resolved Hide resolved
}
){
Box(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState()),
contentAlignment = Alignment.Center
) {
when (val state = kUiState) {
KYCDescriptionUiState.Loading -> {
MifosOverlayLoadingWheel(contentDesc = stringResource(R.string.loading))
}

is KYCDescriptionUiState.Error -> {
PlaceholderScreen()
}

is KYCDescriptionUiState.KYCDescription -> {
val kyc = state.kycLevel1Details
if (kyc != null) {
KYCDescriptionScreen(
kUiState = state,
kyc,
onLevel1Clicked,
onLevel2Clicked,
onLevel3Clicked
)
}
}

is KYCDescriptionUiState.KYCDescription -> {
val kyc = state.kycLevel1Details
if (kyc != null) {
KYCDescriptionScreen(
kUiState = state,
kyc,
onLevel1Clicked,
onLevel2Clicked,
onLevel3Clicked
)
else -> {}
}
}
}

else -> {}
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Search
Expand All @@ -20,6 +22,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -29,6 +32,8 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.mifos.mobilewallet.model.entity.accounts.savings.SavingsWithAssociations
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.common.Constants
Expand All @@ -44,22 +49,40 @@ fun MerchantScreen(
) {
val merchantUiState by viewModel.merchantUiState.collectAsStateWithLifecycle()
val merchantsListUiState by viewModel.merchantsListUiState.collectAsStateWithLifecycle()
MerchantScreen(
merchantUiState = merchantUiState,
merchantListUiState = merchantsListUiState,
updateQuery = { viewModel.updateSearchQuery(it) }
)
var isRefreshing by rememberSaveable {
mutableStateOf(false)
}
val swipeRefreshState =
rememberSwipeRefreshState(
isRefreshing = isRefreshing
)

SwipeRefresh(
state = swipeRefreshState,
onRefresh = {
isRefreshing = true
viewModel.fetchMerchants()
isRefreshing = false
}
){
MerchantScreen(
merchantUiState = merchantUiState,
merchantListUiState = merchantsListUiState,
updateQuery = { viewModel.updateSearchQuery(it) }
)
}
}

@Composable
fun MerchantScreen(
merchantUiState: MerchantUiState,
merchantListUiState: MerchantUiState,
updateQuery: (String) -> Unit
updateQuery: (String) -> Unit,
Akshay2004-701 marked this conversation as resolved.
Show resolved Hide resolved
) {
Box(
modifier = Modifier
.fillMaxSize(),
.fillMaxSize()
.verticalScroll(rememberScrollState()),
contentAlignment = Alignment.Center,
) {
when (merchantUiState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.rounded.Info
import androidx.compose.material3.AssistChip
import androidx.compose.material3.AssistChipDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
Expand All @@ -39,11 +37,12 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import com.mifos.mobilewallet.model.entity.savedcards.Card
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.designsystem.component.MfLoadingWheel
Expand All @@ -65,19 +64,33 @@ fun CardsScreen(
) {
val cardState by viewModel.cardState.collectAsStateWithLifecycle()
val cardListUiState by viewModel.cardListUiState.collectAsStateWithLifecycle()
CardsScreen(
cardState = cardState,
cardListUiState = cardListUiState,
onEditCard = onEditCard,
onDeleteCard = {
// TODO implement Delete card by implementing a delete confirm dialog and call
// TODO viewModel.deleteCard
},
onAddBtn = onAddBtn,
updateQuery = {
viewModel.updateSearchQuery(it)
var isRefreshing by rememberSaveable {
mutableStateOf(false)
}
val swipeRefreshState = rememberSwipeRefreshState(isRefreshing = isRefreshing)

SwipeRefresh(
state = swipeRefreshState,
onRefresh = {
isRefreshing = true
viewModel.fetchSavedCards()
isRefreshing = false
}
)
){
CardsScreen(
cardState = cardState,
cardListUiState = cardListUiState,
onEditCard = onEditCard,
onDeleteCard = {
// TODO implement Delete card by implementing a delete confirm dialog and call
// TODO viewModel.deleteCard
},
onAddBtn = onAddBtn,
updateQuery = {
viewModel.updateSearchQuery(it)
}
)
}
}

@Composable
Expand All @@ -87,11 +100,12 @@ fun CardsScreen(
onEditCard: (Card) -> Unit,
onDeleteCard: (Card) -> Unit,
onAddBtn: () -> Unit,
updateQuery: (String) -> Unit
updateQuery: (String) -> Unit,
) {
Box(
modifier = Modifier
.fillMaxSize(),
.fillMaxSize()
.verticalScroll(rememberScrollState()),
contentAlignment = Alignment.Center,
) {
when (cardState) {
Expand Down Expand Up @@ -223,7 +237,9 @@ fun CardsList(
onMenuItemClick: (Card, CardMenuAction) -> Unit
) {
LazyColumn(
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp)
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
items(cards) { card ->
CardItem(card = card) { clickedCard, menuItem ->
Expand Down
Loading