Skip to content

Commit

Permalink
refactor: Account Module
Browse files Browse the repository at this point in the history
  • Loading branch information
akashmeruva9 committed Jul 5, 2024
1 parent ec8d6b8 commit fa6ba72
Show file tree
Hide file tree
Showing 28 changed files with 425 additions and 212 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ dependencies {
implementation(projects.feature.savings)
implementation(projects.feature.qr)
implementation(projects.feature.transferProcess)
implementation(projects.feature.account)



Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.mifos.mobile.ui.client_accounts


import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -16,6 +15,7 @@ import org.mifos.mobile.ui.activities.base.BaseActivity
import org.mifos.mobile.core.model.enums.AccountType
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.core.common.Constants
import org.mifos.mobile.feature.account.client_account.screens.ClientAccountsScreen

/*
~This project is licensed under the open source MPL V2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import org.mifos.mobile.ui.enums.AccountType
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.core.common.Constants
import org.mifos.mobile.core.common.utils.ParcelableAndSerializableUtils.getCheckedSerializable
import org.mifos.mobile.utils.StatusUtils
import org.mifos.mobile.feature.account.utils.StatusUtils
import javax.inject.Inject
/*
Expand Down
114 changes: 0 additions & 114 deletions app/src/main/java/org/mifos/mobile/utils/StatusUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,120 +11,6 @@ import org.mifos.mobile.ui.getThemeAttributeColor
*/
object StatusUtils {

fun getSavingsAccountStatusList(context: Context?): List<CheckboxStatus> {
val arrayList = ArrayList<CheckboxStatus>()
arrayList.add(
CheckboxStatus(
context?.getString(R.string.active),
ContextCompat.getColor(context!!, R.color.deposit_green),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.approved),
ContextCompat.getColor(context, R.color.light_green),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.approval_pending),
ContextCompat
.getColor(context, R.color.light_yellow),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.matured),
ContextCompat.getColor(context, R.color.red_light),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.closed),
context.getThemeAttributeColor(R.attr.colorOnSurface),
),
)
return arrayList
}

fun getLoanAccountStatusList(context: Context?): List<CheckboxStatus> {
val arrayList = ArrayList<CheckboxStatus>()
arrayList.add(
CheckboxStatus(
context?.getString(R.string.in_arrears),
ContextCompat.getColor(context!!, R.color.red),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.active),
ContextCompat.getColor(context, R.color.deposit_green),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.waiting_for_disburse),
ContextCompat.getColor(context, R.color.blue),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.approval_pending),
ContextCompat
.getColor(context, R.color.light_yellow),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.overpaid),
ContextCompat.getColor(context, R.color.purple),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.closed),
context.getThemeAttributeColor(R.attr.colorOnSurface),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.withdrawn),
context.getThemeAttributeColor(R.attr.colorOnSurfaceVariant),
),
)
return arrayList
}

fun getShareAccountStatusList(context: Context?): List<CheckboxStatus> {
val arrayList = ArrayList<CheckboxStatus>()
arrayList.add(
CheckboxStatus(
context?.getString(R.string.active),
ContextCompat.getColor(context!!, R.color.deposit_green),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.approved),
ContextCompat.getColor(context, R.color.light_green),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.approval_pending),
ContextCompat
.getColor(context, R.color.light_yellow),
),
)
arrayList.add(
CheckboxStatus(
context.getString(R.string.closed),
ContextCompat.getColor(context, R.color.light_blue),
),
)
return arrayList
}

fun getSavingsAccountTransactionList(context: Context?): List<CheckboxStatus> {
val arrayList = ArrayList<CheckboxStatus>()
arrayList.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mifos.mobile.models.client.ClientAccounts
import org.mifos.mobile.repositories.AccountsRepository
import org.mifos.mobile.repositories.HomeRepositoryImp
import org.mifos.mobile.ui.account.AccountsViewModel
import org.mifos.mobile.core.data.repositories.AccountsRepository
import org.mifos.mobile.core.data.repositories.HomeRepositoryImp
import org.mifos.mobile.core.model.entity.client.ClientAccounts
import org.mifos.mobile.feature.account.utils.AccountState
import org.mifos.mobile.feature.account.viewmodel.AccountsViewModel
import org.mifos.mobile.util.RxSchedulersOverrideRule
import org.mifos.mobile.utils.AccountsUiState
import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mock
import org.mockito.Mockito
Expand Down Expand Up @@ -51,7 +51,10 @@ class AccountsViewModelTest {
@Before
fun setUp() {
MockitoAnnotations.openMocks(this)
accountsViewModel = AccountsViewModel(accountsRepositoryImp, homeRepositoryImp)
accountsViewModel = org.mifos.mobile.feature.account.viewmodel.AccountsViewModel(
accountsRepositoryImp,
homeRepositoryImp
)
mockClientAccounts = Mockito.mock(ClientAccounts::class.java)
}

Expand All @@ -61,15 +64,15 @@ class AccountsViewModelTest {
`when`(homeRepositoryImp.clientAccounts()).thenReturn(flowOf(mockClientAccounts))
accountsViewModel.accountsUiState.test {
accountsViewModel.loadClientAccounts()
assertEquals(AccountsUiState.Loading, awaitItem())
assertEquals(AccountState.Loading, awaitItem())
assertEquals(
AccountsUiState.ShowSavingsAccounts(mockClientAccounts.savingsAccounts), awaitItem()
AccountState.ShowSavingsAccounts(mockClientAccounts.savingsAccounts), awaitItem()
)
assertEquals(
AccountsUiState.ShowLoanAccounts(mockClientAccounts.loanAccounts), awaitItem()
AccountState.ShowLoanAccounts(mockClientAccounts.loanAccounts), awaitItem()
)
assertEquals(
AccountsUiState.ShowShareAccounts(mockClientAccounts.shareAccounts), awaitItem()
AccountState.ShowShareAccounts(mockClientAccounts.shareAccounts), awaitItem()
)
cancelAndIgnoreRemainingEvents()
}
Expand All @@ -86,9 +89,9 @@ class AccountsViewModelTest {
)
accountsViewModel.accountsUiState.test {
accountsViewModel.loadAccounts(mockAccountType)
assertEquals(AccountsUiState.Loading, awaitItem())
assertEquals(AccountState.Loading, awaitItem())
assertEquals(
AccountsUiState.ShowSavingsAccounts(mockClientAccounts.savingsAccounts), awaitItem()
AccountState.ShowSavingsAccounts(mockClientAccounts.savingsAccounts), awaitItem()
)
cancelAndIgnoreRemainingEvents()
}
Expand All @@ -101,9 +104,9 @@ class AccountsViewModelTest {
accountsViewModel.accountsUiState.test {
try {
accountsViewModel.loadAccounts(mockAccountType)
assertEquals(AccountsUiState.Loading, awaitItem())
assertEquals(AccountState.Loading, awaitItem())
} catch (e: RuntimeException) {
assertEquals(AccountsUiState.Error, awaitItem())
assertEquals(AccountState.Error, awaitItem())
}
cancelAndIgnoreRemainingEvents()
}
Expand Down
1 change: 1 addition & 0 deletions feature/account/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
22 changes: 22 additions & 0 deletions feature/account/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
}

android {
namespace = "org.mifos.mobile.feature.account"
}

dependencies {
implementation(projects.ui)
implementation(projects.core.common)
implementation(projects.core.model)
implementation(projects.core.data)
implementation(libs.reactivex.rxjava2.android)
implementation(libs.reactivex.rxjava2)
api(libs.androidx.compose.material)
implementation("com.github.rahul-gill.mifos-ui-library:uihouse:alpha-2.1")
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
}
Empty file.
21 changes: 21 additions & 0 deletions feature/account/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
4 changes: 4 additions & 0 deletions feature/account/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mifos.mobile.ui.account
package org.mifos.mobile.feature.account.account.screens

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand All @@ -16,7 +16,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.mifos.mobile.R
import org.mifos.mobile.feature.account.R
import org.mifos.mobile.core.ui.component.MifosErrorComponent
import org.mifos.mobile.core.ui.component.MifosProgressIndicatorOverlay
import org.mifos.mobile.core.common.Network
Expand All @@ -28,6 +28,8 @@ import org.mifos.mobile.core.model.entity.accounts.savings.SavingAccount
import org.mifos.mobile.core.model.entity.accounts.share.ShareAccount
import org.mifos.mobile.core.ui.component.EmptyDataView
import org.mifos.mobile.core.ui.theme.MifosMobileTheme
import org.mifos.mobile.feature.account.utils.AccountState
import org.mifos.mobile.feature.account.viewmodel.AccountsViewModel


@Composable
Expand Down Expand Up @@ -101,7 +103,7 @@ fun AccountsScreen(
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun AccountsScreen(
uiState: AccountsUiState,
uiState: AccountState,
onRetry: () -> Unit,
isRefreshing: Boolean,
onRefresh: () -> Unit,
Expand Down Expand Up @@ -129,19 +131,19 @@ fun AccountsScreen(
Box(modifier = Modifier.pullRefresh(pullRefreshState))
{
when (uiState) {
is AccountsUiState.Error -> {
is AccountState.Error -> {
MifosErrorComponent(
isNetworkConnected = Network.isConnected(context),
isRetryEnabled = true,
onRetry = onRetry
)
}

is AccountsUiState.Loading -> {
is AccountState.Loading -> {
MifosProgressIndicatorOverlay()
}

is AccountsUiState.ShowSavingsAccounts -> {
is AccountState.ShowSavingsAccounts -> {
if ((uiState.savingAccounts.isNullOrEmpty())) {
EmptyDataView(
icon = R.drawable.ic_error_black_24dp,
Expand All @@ -160,7 +162,7 @@ fun AccountsScreen(
}
}

is AccountsUiState.ShowLoanAccounts -> {
is AccountState.ShowLoanAccounts -> {
if ((uiState.loanAccounts.isNullOrEmpty())) {
EmptyDataView(
icon = R.drawable.ic_error_black_24dp,
Expand All @@ -179,7 +181,7 @@ fun AccountsScreen(
}
}

is AccountsUiState.ShowShareAccounts -> {
is AccountState.ShowShareAccounts -> {
if ((uiState.shareAccounts.isNullOrEmpty())) {
EmptyDataView(
icon = R.drawable.ic_error_black_24dp,
Expand Down Expand Up @@ -207,22 +209,22 @@ fun AccountsScreen(
}
}

class AccountsScreenPreviewProvider : PreviewParameterProvider<AccountsUiState> {
class AccountsScreenPreviewProvider : PreviewParameterProvider<AccountState> {

override val values: Sequence<AccountsUiState>
override val values: Sequence<AccountState>
get() = sequenceOf(
AccountsUiState.Loading,
AccountsUiState.Error,
AccountsUiState.ShowLoanAccounts(listOf()),
AccountsUiState.ShowShareAccounts(listOf()),
AccountsUiState.ShowSavingsAccounts(listOf()),
AccountState.Loading,
AccountState.Error,
AccountState.ShowLoanAccounts(listOf()),
AccountState.ShowShareAccounts(listOf()),
AccountState.ShowSavingsAccounts(listOf()),
)
}

@Preview(showSystemUi = true)
@Composable
private fun AccountSavingsScreenPreview(
@PreviewParameter(AccountsScreenPreviewProvider::class) accountUiState: AccountsUiState
@PreviewParameter(AccountsScreenPreviewProvider::class) accountUiState: AccountState
) {
MifosMobileTheme {
AccountsScreen(
Expand Down
Loading

0 comments on commit fa6ba72

Please sign in to comment.