Skip to content

Commit

Permalink
fix #2431 Progessbar Correct state transition logic
Browse files Browse the repository at this point in the history
  • Loading branch information
SaiThanushreddy committed Nov 17, 2023
1 parent ecbf4b6 commit b9d9775
Showing 1 changed file with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,40 @@ class RecentTransactionViewModel @Inject constructor(private val recentTransacti
private val _recentTransactionUiState = MutableLiveData<RecentTransactionUiState>()
val recentTransactionUiState: LiveData<RecentTransactionUiState> = _recentTransactionUiState

fun loadRecentTransactions(loadmore: Boolean, offset: Int) {
this.loadmore = loadmore
fun loadRecentTransactions(loadMore: Boolean, offset: Int) {
this.loadmore = loadMore
loadRecentTransactions(offset, limit)
}

private fun loadRecentTransactions(offset: Int, limit: Int) {
viewModelScope.launch {
_recentTransactionUiState.value = RecentTransactionUiState.Loading


val response = recentTransactionRepositoryImp.recentTransactions(offset, limit)


if (response?.isSuccessful == true) {
if (response.body()?.totalFilteredRecords == 0) {
_recentTransactionUiState.value = RecentTransactionUiState.EmptyTransaction
} else if (loadmore && response.body()?.pageItems?.isNotEmpty() == true) {
_recentTransactionUiState.value =
RecentTransactionUiState.LoadMoreRecentTransactions(
response.body()!!.pageItems
)
} else if (response.body()?.pageItems?.isNotEmpty() == true) {
_recentTransactionUiState.value = RecentTransactionUiState.RecentTransactions(
response.body()?.pageItems!!
)
when {
response.body()?.totalFilteredRecords == 0 -> {
_recentTransactionUiState.value = RecentTransactionUiState.EmptyTransaction
}
loadmore && response.body()?.pageItems?.isNotEmpty() == true -> {
_recentTransactionUiState.value =
RecentTransactionUiState.LoadMoreRecentTransactions(response.body()!!.pageItems)
}
response.body()?.pageItems?.isNotEmpty() == true -> {
_recentTransactionUiState.value =
RecentTransactionUiState.RecentTransactions(response.body()!!.pageItems)
}
else -> {
_recentTransactionUiState.value =
RecentTransactionUiState.Error(R.string.recent_transactions)
}
}
} else {
_recentTransactionUiState.value =
RecentTransactionUiState.Error(R.string.recent_transactions)
_recentTransactionUiState.value = RecentTransactionUiState.Error(R.string.recent_transactions)
}
}
}

}

0 comments on commit b9d9775

Please sign in to comment.