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 all commits
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 @@ -20,6 +20,7 @@ class AccountViewModel @Inject constructor() : ViewModel() {
val accountsUiState: StateFlow<AccountsUiState> = _accountUiState

private val mRandom = Random()
val isRefreshing = MutableStateFlow(false)

init {
fetchLinkedAccount()
Expand Down Expand Up @@ -82,6 +83,11 @@ class AccountViewModel @Inject constructor() : ViewModel() {
)
return bankAccountDetailsList
}
fun refreshAccountList(){
isRefreshing.value = true
fetchLinkedAccount()
isRefreshing.value = false
}

}

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,18 @@ fun AccountsScreen(
) {
val accountsUiState by viewModel.accountsUiState.collectAsStateWithLifecycle()
val sampleList = viewModel.bankAccountDetailsList
AccountScreen(
accountsUiState = accountsUiState,
onAddAccount = onAddAccount,
sampleList = sampleList,
)
val isRefreshing by viewModel.isRefreshing.collectAsStateWithLifecycle()
val swipeRefreshState = rememberSwipeRefreshState(isRefreshing = isRefreshing)
SwipeRefresh(
state = swipeRefreshState,
onRefresh = viewModel::refreshAccountList
){
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 @@ -23,12 +21,13 @@ class KYCDescriptionViewModel @Inject constructor(
MutableStateFlow<KYCDescriptionUiState>(KYCDescriptionUiState.Loading)

val kycdescriptionState: StateFlow<KYCDescriptionUiState> = _kycdescriptionState
val isRefreshing = MutableStateFlow(false)

init {
fetchCurrentLevel()
}

private fun fetchCurrentLevel() {
fun fetchCurrentLevel() {
fetchKYCLevel1DetailsUseCase.walletRequestValues =
FetchKYCLevel1Details.RequestValues(mLocalRepository.clientDetails.clientId.toInt())
val requestValues = fetchKYCLevel1DetailsUseCase.walletRequestValues
Expand All @@ -49,6 +48,11 @@ class KYCDescriptionViewModel @Inject constructor(
}
})
}
fun refreshKYCLevel(){
isRefreshing.value = true
fetchCurrentLevel()
isRefreshing.value = false
}

}

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,9 @@ 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 androidx.lifecycle.compose.collectAsStateWithLifecycle
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 @@ -53,31 +60,45 @@ fun KYCDescriptionScreen(
onLevel3Clicked: () -> Unit
) {
val kUiState by viewModel.kycdescriptionState.collectAsState()
val isRefreshing by viewModel.isRefreshing.collectAsStateWithLifecycle()
val swipeRefreshState = rememberSwipeRefreshState(isRefreshing = isRefreshing)

when (val state = kUiState) {
KYCDescriptionUiState.Loading -> {
MifosOverlayLoadingWheel(contentDesc = stringResource(R.string.loading))
}
SwipeRefresh(
state = swipeRefreshState,
onRefresh = viewModel::refreshKYCLevel
){
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.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 @@ -36,6 +36,8 @@ class MerchantViewModel @Inject constructor(
private val _merchantUiState = MutableStateFlow<MerchantUiState>(MerchantUiState.Loading)
val merchantUiState: StateFlow<MerchantUiState> = _merchantUiState

val isRefreshing = MutableStateFlow(false)

init {
fetchMerchants()
}
Expand Down Expand Up @@ -120,6 +122,12 @@ class MerchantViewModel @Inject constructor(
}
})
}

fun refreshMerchantsList(){
isRefreshing.value = true
fetchMerchants()
isRefreshing.value = false
}
}

sealed class MerchantUiState {
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 @@ -17,9 +19,11 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.SearchBar
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.graphics.Color
Expand All @@ -29,6 +33,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,11 +50,19 @@ fun MerchantScreen(
) {
val merchantUiState by viewModel.merchantUiState.collectAsStateWithLifecycle()
val merchantsListUiState by viewModel.merchantsListUiState.collectAsStateWithLifecycle()
MerchantScreen(
merchantUiState = merchantUiState,
merchantListUiState = merchantsListUiState,
updateQuery = { viewModel.updateSearchQuery(it) }
)
val isRefreshing by viewModel.isRefreshing.collectAsStateWithLifecycle()
val swipeRefreshState = rememberSwipeRefreshState(isRefreshing = isRefreshing)

SwipeRefresh(
state = swipeRefreshState,
onRefresh = viewModel::refreshMerchantsList
){
MerchantScreen(
merchantUiState = merchantUiState,
merchantListUiState = merchantsListUiState,
updateQuery = { viewModel.updateSearchQuery(it) }
)
}
}

@Composable
Expand All @@ -59,7 +73,8 @@ fun MerchantScreen(
) {
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 @@ -38,6 +38,8 @@ class CardsScreenViewModel @Inject constructor(
private val _cardState = MutableStateFlow<CardsUiState>(CardsUiState.Loading)
val cardState: StateFlow<CardsUiState> = _cardState.asStateFlow()

val isRefreshing = MutableStateFlow(false)

init {
fetchSavedCards()
}
Expand Down Expand Up @@ -163,6 +165,11 @@ class CardsScreenViewModel @Inject constructor(
}
})
}
fun refreshSavedCards(){
isRefreshing.value = true
fetchSavedCards()
isRefreshing.value = false
}
}


Expand Down
Loading
Loading