From fa6ba72e5dd2074b5829ee2cb4511d4b352da7c5 Mon Sep 17 00:00:00 2001 From: akashmeruva9 Date: Fri, 5 Jul 2024 18:23:12 +0530 Subject: [PATCH] refactor: Account Module --- app/build.gradle.kts | 1 + .../ClientAccountsComposeFragment.kt | 2 +- .../client_accounts/ClientAccountsFragment.kt | 2 +- .../org/mifos/mobile/utils/StatusUtils.kt | 114 ---------------- .../viewModels/AccountsViewModelTest.kt | 31 +++-- feature/account/.gitignore | 1 + feature/account/build.gradle.kts | 22 +++ feature/account/consumer-rules.pro | 0 feature/account/proguard-rules.pro | 21 +++ feature/account/src/main/AndroidManifest.xml | 4 + .../account/screens}/AccountsScreen.kt | 34 ++--- .../account/screens}/LoanAccountContent.kt | 7 +- .../account/screens}/SavingsAccountContent.kt | 6 +- .../account/screens}/ShareAccountContent.kt | 7 +- .../utils/AccountTypeItemIndicator.kt | 2 +- .../account}/utils/AccountsFilterUtil.kt | 4 +- .../screens}/ClientAccountsScreen.kt | 19 +-- .../utils}/ClientAccountFilterDialog.kt | 4 +- .../utils}/ClientAccountScreenTopBar.kt | 5 +- .../feature/account/utils/AccountState.kt | 14 ++ .../feature/account/utils/StatusUtils.kt | 127 ++++++++++++++++++ .../account/viewmodel}/AccountsViewModel.kt | 54 ++++---- .../main/res/drawable/ic_error_black_24dp.xml | 9 ++ .../account/src/main/res/values/colors.xml | 74 ++++++++++ .../account/src/main/res/values/strings.xml | 37 +++++ .../screens/RegistrationScreen.kt | 31 ++++- .../SavingAccountsTransactionViewModel.kt | 4 +- settings.gradle.kts | 1 + 28 files changed, 425 insertions(+), 212 deletions(-) create mode 100644 feature/account/.gitignore create mode 100644 feature/account/build.gradle.kts create mode 100644 feature/account/consumer-rules.pro create mode 100644 feature/account/proguard-rules.pro create mode 100644 feature/account/src/main/AndroidManifest.xml rename {app/src/main/java/org/mifos/mobile/ui/account => feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens}/AccountsScreen.kt (91%) rename {app/src/main/java/org/mifos/mobile/ui/account => feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens}/LoanAccountContent.kt (97%) rename {app/src/main/java/org/mifos/mobile/ui/account => feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens}/SavingsAccountContent.kt (96%) rename {app/src/main/java/org/mifos/mobile/ui/account => feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens}/ShareAccountContent.kt (96%) rename {app/src/main/java/org/mifos/mobile => feature/account/src/main/java/org/mifos/mobile/feature/account/account}/utils/AccountTypeItemIndicator.kt (97%) rename {app/src/main/java/org/mifos/mobile => feature/account/src/main/java/org/mifos/mobile/feature/account/account}/utils/AccountsFilterUtil.kt (92%) rename {app/src/main/java/org/mifos/mobile/ui/client_accounts => feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/screens}/ClientAccountsScreen.kt (91%) rename {app/src/main/java/org/mifos/mobile/ui/client_accounts => feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/utils}/ClientAccountFilterDialog.kt (98%) rename {app/src/main/java/org/mifos/mobile/ui/client_accounts => feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/utils}/ClientAccountScreenTopBar.kt (94%) create mode 100644 feature/account/src/main/java/org/mifos/mobile/feature/account/utils/AccountState.kt create mode 100644 feature/account/src/main/java/org/mifos/mobile/feature/account/utils/StatusUtils.kt rename {app/src/main/java/org/mifos/mobile/ui/account => feature/account/src/main/java/org/mifos/mobile/feature/account/viewmodel}/AccountsViewModel.kt (89%) create mode 100644 feature/account/src/main/res/drawable/ic_error_black_24dp.xml create mode 100644 feature/account/src/main/res/values/colors.xml create mode 100644 feature/account/src/main/res/values/strings.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 247294d2a..312465d12 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -84,6 +84,7 @@ dependencies { implementation(projects.feature.savings) implementation(projects.feature.qr) implementation(projects.feature.transferProcess) + implementation(projects.feature.account) diff --git a/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountsComposeFragment.kt b/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountsComposeFragment.kt index 65ce2c070..1af99ce4f 100644 --- a/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountsComposeFragment.kt +++ b/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountsComposeFragment.kt @@ -1,6 +1,5 @@ package org.mifos.mobile.ui.client_accounts - import android.content.Intent import android.os.Bundle import android.view.LayoutInflater @@ -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. diff --git a/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountsFragment.kt b/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountsFragment.kt index 897c09430..1b39f5917 100644 --- a/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountsFragment.kt +++ b/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountsFragment.kt @@ -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 /* diff --git a/app/src/main/java/org/mifos/mobile/utils/StatusUtils.kt b/app/src/main/java/org/mifos/mobile/utils/StatusUtils.kt index 355ea14e8..93581dd9c 100644 --- a/app/src/main/java/org/mifos/mobile/utils/StatusUtils.kt +++ b/app/src/main/java/org/mifos/mobile/utils/StatusUtils.kt @@ -11,120 +11,6 @@ import org.mifos.mobile.ui.getThemeAttributeColor */ object StatusUtils { - fun getSavingsAccountStatusList(context: Context?): List { - val arrayList = ArrayList() - 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 { - val arrayList = ArrayList() - 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 { - val arrayList = ArrayList() - 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 { val arrayList = ArrayList() arrayList.add( diff --git a/app/src/test/java/org/mifos/mobile/viewModels/AccountsViewModelTest.kt b/app/src/test/java/org/mifos/mobile/viewModels/AccountsViewModelTest.kt index 7831dee80..a403b66fc 100644 --- a/app/src/test/java/org/mifos/mobile/viewModels/AccountsViewModelTest.kt +++ b/app/src/test/java/org/mifos/mobile/viewModels/AccountsViewModelTest.kt @@ -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 @@ -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) } @@ -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() } @@ -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() } @@ -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() } diff --git a/feature/account/.gitignore b/feature/account/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/feature/account/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/feature/account/build.gradle.kts b/feature/account/build.gradle.kts new file mode 100644 index 000000000..8358bc803 --- /dev/null +++ b/feature/account/build.gradle.kts @@ -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) +} \ No newline at end of file diff --git a/feature/account/consumer-rules.pro b/feature/account/consumer-rules.pro new file mode 100644 index 000000000..e69de29bb diff --git a/feature/account/proguard-rules.pro b/feature/account/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/feature/account/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/feature/account/src/main/AndroidManifest.xml b/feature/account/src/main/AndroidManifest.xml new file mode 100644 index 000000000..a5918e68a --- /dev/null +++ b/feature/account/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/org/mifos/mobile/ui/account/AccountsScreen.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/AccountsScreen.kt similarity index 91% rename from app/src/main/java/org/mifos/mobile/ui/account/AccountsScreen.kt rename to feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/AccountsScreen.kt index c2538be2f..19a993684 100644 --- a/app/src/main/java/org/mifos/mobile/ui/account/AccountsScreen.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/AccountsScreen.kt @@ -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 @@ -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 @@ -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 @@ -101,7 +103,7 @@ fun AccountsScreen( @OptIn(ExperimentalMaterialApi::class) @Composable fun AccountsScreen( - uiState: AccountsUiState, + uiState: AccountState, onRetry: () -> Unit, isRefreshing: Boolean, onRefresh: () -> Unit, @@ -129,7 +131,7 @@ fun AccountsScreen( Box(modifier = Modifier.pullRefresh(pullRefreshState)) { when (uiState) { - is AccountsUiState.Error -> { + is AccountState.Error -> { MifosErrorComponent( isNetworkConnected = Network.isConnected(context), isRetryEnabled = true, @@ -137,11 +139,11 @@ fun AccountsScreen( ) } - 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, @@ -160,7 +162,7 @@ fun AccountsScreen( } } - is AccountsUiState.ShowLoanAccounts -> { + is AccountState.ShowLoanAccounts -> { if ((uiState.loanAccounts.isNullOrEmpty())) { EmptyDataView( icon = R.drawable.ic_error_black_24dp, @@ -179,7 +181,7 @@ fun AccountsScreen( } } - is AccountsUiState.ShowShareAccounts -> { + is AccountState.ShowShareAccounts -> { if ((uiState.shareAccounts.isNullOrEmpty())) { EmptyDataView( icon = R.drawable.ic_error_black_24dp, @@ -207,22 +209,22 @@ fun AccountsScreen( } } -class AccountsScreenPreviewProvider : PreviewParameterProvider { +class AccountsScreenPreviewProvider : PreviewParameterProvider { - override val values: Sequence + override val values: Sequence 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( diff --git a/app/src/main/java/org/mifos/mobile/ui/account/LoanAccountContent.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/LoanAccountContent.kt similarity index 97% rename from app/src/main/java/org/mifos/mobile/ui/account/LoanAccountContent.kt rename to feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/LoanAccountContent.kt index f1be20ad0..a333988d1 100644 --- a/app/src/main/java/org/mifos/mobile/ui/account/LoanAccountContent.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/LoanAccountContent.kt @@ -1,4 +1,4 @@ -package org.mifos.mobile.ui.account +package org.mifos.mobile.feature.account.account.screens import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column @@ -22,11 +22,12 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import org.mifos.mobile.R -import org.mifos.mobile.utils.AccountTypeItemIndicator +import org.mifos.mobile.feature.account.R +import org.mifos.mobile.feature.account.account.utils.AccountTypeItemIndicator import org.mifos.mobile.core.model.entity.accounts.loan.LoanAccount import org.mifos.mobile.core.common.utils.CurrencyUtil import org.mifos.mobile.core.common.utils.DateHelper + @Composable fun LoanAccountContent( accountsList: List, diff --git a/app/src/main/java/org/mifos/mobile/ui/account/SavingsAccountContent.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/SavingsAccountContent.kt similarity index 96% rename from app/src/main/java/org/mifos/mobile/ui/account/SavingsAccountContent.kt rename to feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/SavingsAccountContent.kt index 182748682..dd1302839 100644 --- a/app/src/main/java/org/mifos/mobile/ui/account/SavingsAccountContent.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/SavingsAccountContent.kt @@ -1,4 +1,4 @@ -package org.mifos.mobile.ui.account +package org.mifos.mobile.feature.account.account.screens import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column @@ -22,8 +22,8 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import org.mifos.mobile.R -import org.mifos.mobile.utils.AccountTypeItemIndicator +import org.mifos.mobile.feature.account.R +import org.mifos.mobile.feature.account.account.utils.AccountTypeItemIndicator import org.mifos.mobile.core.model.entity.accounts.savings.SavingAccount import org.mifos.mobile.core.common.utils.CurrencyUtil import org.mifos.mobile.core.common.utils.DateHelper diff --git a/app/src/main/java/org/mifos/mobile/ui/account/ShareAccountContent.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/ShareAccountContent.kt similarity index 96% rename from app/src/main/java/org/mifos/mobile/ui/account/ShareAccountContent.kt rename to feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/ShareAccountContent.kt index a1902216b..5586f19cf 100644 --- a/app/src/main/java/org/mifos/mobile/ui/account/ShareAccountContent.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/screens/ShareAccountContent.kt @@ -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.Column @@ -19,13 +19,12 @@ 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 import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import org.mifos.mobile.R +import org.mifos.mobile.feature.account.R import org.mifos.mobile.core.model.entity.accounts.share.ShareAccount -import org.mifos.mobile.utils.AccountTypeItemIndicator +import org.mifos.mobile.feature.account.account.utils.AccountTypeItemIndicator @Composable fun AccountScreenShareContent( diff --git a/app/src/main/java/org/mifos/mobile/utils/AccountTypeItemIndicator.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/utils/AccountTypeItemIndicator.kt similarity index 97% rename from app/src/main/java/org/mifos/mobile/utils/AccountTypeItemIndicator.kt rename to feature/account/src/main/java/org/mifos/mobile/feature/account/account/utils/AccountTypeItemIndicator.kt index a457b1cf5..dc398e899 100644 --- a/app/src/main/java/org/mifos/mobile/utils/AccountTypeItemIndicator.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/utils/AccountTypeItemIndicator.kt @@ -1,4 +1,4 @@ -package org.mifos.mobile.utils +package org.mifos.mobile.feature.account.account.utils import androidx.compose.foundation.Canvas import androidx.compose.foundation.background diff --git a/app/src/main/java/org/mifos/mobile/utils/AccountsFilterUtil.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/utils/AccountsFilterUtil.kt similarity index 92% rename from app/src/main/java/org/mifos/mobile/utils/AccountsFilterUtil.kt rename to feature/account/src/main/java/org/mifos/mobile/feature/account/account/utils/AccountsFilterUtil.kt index 2a88c6617..bc40f2f96 100644 --- a/app/src/main/java/org/mifos/mobile/utils/AccountsFilterUtil.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/account/utils/AccountsFilterUtil.kt @@ -1,7 +1,7 @@ -package org.mifos.mobile.utils +package org.mifos.mobile.feature.account.account.utils import android.content.Context -import org.mifos.mobile.R +import org.mifos.mobile.feature.account.R data class AccountsFilterUtil( var activeString: String? = null, diff --git a/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountsScreen.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/screens/ClientAccountsScreen.kt similarity index 91% rename from app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountsScreen.kt rename to feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/screens/ClientAccountsScreen.kt index 5bf3494f1..3562a7ffb 100644 --- a/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountsScreen.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/screens/ClientAccountsScreen.kt @@ -1,4 +1,4 @@ -package org.mifos.mobile.ui.client_accounts +package org.mifos.mobile.feature.account.client_account.screens import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.isSystemInDarkTheme @@ -21,15 +21,18 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview 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.common.Constants import org.mifos.mobile.core.ui.component.FloatingActionButtonContent import org.mifos.mobile.core.ui.component.MFScaffold import org.mifos.mobile.core.ui.component.MifosIcons import org.mifos.mobile.core.ui.component.MifosTabPager import org.mifos.mobile.core.ui.theme.MifosMobileTheme -import org.mifos.mobile.ui.account.AccountsScreen -import org.mifos.mobile.ui.account.AccountsViewModel +import org.mifos.mobile.feature.account.account.screens.AccountsScreen import org.mifos.mobile.core.model.entity.CheckboxStatus +import org.mifos.mobile.feature.account.client_account.utils.ClientAccountFilterDialog +import org.mifos.mobile.feature.account.client_account.utils.ClientAccountsScreenTopBar +import org.mifos.mobile.feature.account.viewmodel.AccountsViewModel @Composable fun ClientAccountsScreen( @@ -133,7 +136,7 @@ fun ClientAccountsScreen( Icon( imageVector = MifosIcons.Add, contentDescription = "Create Account", - tint = MaterialTheme.colorScheme.onSurface + tint = if (isSystemInDarkTheme()) Color.Black else Color.White ) } ), @@ -193,7 +196,7 @@ fun ClientAccountsTabRow( ) { when (currentPage) { 0 -> AccountsScreen( - accountType = org.mifos.mobile.core.common.Constants.SAVINGS_ACCOUNTS, + accountType = Constants.SAVINGS_ACCOUNTS, onItemClick = { accType, accountId -> onItemClick.invoke( accType, @@ -203,7 +206,7 @@ fun ClientAccountsTabRow( ) 1 -> AccountsScreen( - accountType = org.mifos.mobile.core.common.Constants.LOAN_ACCOUNTS, + accountType = Constants.LOAN_ACCOUNTS, onItemClick = { accType, accountId -> onItemClick.invoke( accType, @@ -213,7 +216,7 @@ fun ClientAccountsTabRow( ) 2 -> AccountsScreen( - accountType = org.mifos.mobile.core.common.Constants.SHARE_ACCOUNTS, + accountType = Constants.SHARE_ACCOUNTS, onItemClick = { accType, accountId -> onItemClick.invoke( accType, diff --git a/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountFilterDialog.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/utils/ClientAccountFilterDialog.kt similarity index 98% rename from app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountFilterDialog.kt rename to feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/utils/ClientAccountFilterDialog.kt index 20485eef6..8d3cfd034 100644 --- a/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountFilterDialog.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/utils/ClientAccountFilterDialog.kt @@ -1,4 +1,4 @@ -package org.mifos.mobile.ui.client_accounts +package org.mifos.mobile.feature.account.client_account.utils import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Arrangement @@ -25,7 +25,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import org.mifos.mobile.R +import org.mifos.mobile.feature.account.R import org.mifos.mobile.core.model.entity.CheckboxStatus @Composable diff --git a/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountScreenTopBar.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/utils/ClientAccountScreenTopBar.kt similarity index 94% rename from app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountScreenTopBar.kt rename to feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/utils/ClientAccountScreenTopBar.kt index 5706ab76b..635fade63 100644 --- a/app/src/main/java/org/mifos/mobile/ui/client_accounts/ClientAccountScreenTopBar.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/client_account/utils/ClientAccountScreenTopBar.kt @@ -1,4 +1,4 @@ -package org.mifos.mobile.ui.client_accounts +package org.mifos.mobile.feature.account.client_account.utils import androidx.compose.foundation.Image import androidx.compose.foundation.background @@ -94,7 +94,8 @@ fun ClientAccountsScreenTopBar( ) { Image( imageVector = MifosIcons.FilterList, - contentDescription = "Add account" + contentDescription = "Add account", + colorFilter = ColorFilter.tint(if (isSystemInDarkTheme()) Color.White else Color.Black) ) } } diff --git a/feature/account/src/main/java/org/mifos/mobile/feature/account/utils/AccountState.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/utils/AccountState.kt new file mode 100644 index 000000000..c02058197 --- /dev/null +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/utils/AccountState.kt @@ -0,0 +1,14 @@ +package org.mifos.mobile.feature.account.utils + +import org.mifos.mobile.core.model.entity.accounts.loan.LoanAccount +import org.mifos.mobile.core.model.entity.accounts.savings.SavingAccount +import org.mifos.mobile.core.model.entity.accounts.share.ShareAccount + + +sealed class AccountState { + data object Error : AccountState() + data object Loading : AccountState() + data class ShowSavingsAccounts(val savingAccounts: List?) : AccountState() + data class ShowLoanAccounts(val loanAccounts: List?) : AccountState() + data class ShowShareAccounts(val shareAccounts: List?) : AccountState() +} \ No newline at end of file diff --git a/feature/account/src/main/java/org/mifos/mobile/feature/account/utils/StatusUtils.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/utils/StatusUtils.kt new file mode 100644 index 000000000..8fadffdb2 --- /dev/null +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/utils/StatusUtils.kt @@ -0,0 +1,127 @@ +package org.mifos.mobile.feature.account.utils + +import android.content.Context +import androidx.core.content.ContextCompat +import org.mifos.mobile.feature.account.R +import org.mifos.mobile.core.model.entity.CheckboxStatus +import org.mifos.mobile.ui.getThemeAttributeColor + +/** + * Created by dilpreet on 3/7/17. + */ +object StatusUtils { + + fun getSavingsAccountStatusList(context: Context?): List { + val arrayList = ArrayList() + 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), + ), + )or + return arrayList + } + + fun getLoanAccountStatusList(context: Context?): List { + val arrayList = ArrayList() + 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 { + val arrayList = ArrayList() + 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 + } +} diff --git a/app/src/main/java/org/mifos/mobile/ui/account/AccountsViewModel.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/viewmodel/AccountsViewModel.kt similarity index 89% rename from app/src/main/java/org/mifos/mobile/ui/account/AccountsViewModel.kt rename to feature/account/src/main/java/org/mifos/mobile/feature/account/viewmodel/AccountsViewModel.kt index d07f90e37..ef31d42c3 100644 --- a/app/src/main/java/org/mifos/mobile/ui/account/AccountsViewModel.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/viewmodel/AccountsViewModel.kt @@ -1,10 +1,9 @@ -package org.mifos.mobile.ui.account +package org.mifos.mobile.feature.account.viewmodel import android.content.Context import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel -import io.reactivex.Observable import io.reactivex.functions.Predicate import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -13,14 +12,15 @@ import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import org.mifos.mobile.core.common.Constants -import org.mifos.mobile.utils.AccountsFilterUtil +import org.mifos.mobile.feature.account.account.utils.AccountsFilterUtil import org.mifos.mobile.core.data.repositories.AccountsRepository import org.mifos.mobile.core.data.repositories.HomeRepository import org.mifos.mobile.core.model.entity.CheckboxStatus import org.mifos.mobile.core.model.entity.accounts.loan.LoanAccount import org.mifos.mobile.core.model.entity.accounts.savings.SavingAccount import org.mifos.mobile.core.model.entity.accounts.share.ShareAccount -import org.mifos.mobile.utils.StatusUtils +import org.mifos.mobile.feature.account.utils.AccountState +import org.mifos.mobile.feature.account.utils.StatusUtils import java.util.* import javax.inject.Inject @@ -30,8 +30,8 @@ class AccountsViewModel @Inject constructor( private val homeRepositoryImp: HomeRepository ) : ViewModel() { - private val _accountsUiState = MutableStateFlow(AccountsUiState.Loading) - val accountsUiState: StateFlow = _accountsUiState + private val _accountsUiState = MutableStateFlow(AccountState.Loading) + val accountsUiState: StateFlow = _accountsUiState private val _isRefreshing = MutableStateFlow(false) val isRefreshing: StateFlow get() = _isRefreshing.asStateFlow() @@ -174,16 +174,16 @@ class AccountsViewModel @Inject constructor( */ fun loadClientAccounts() { viewModelScope.launch { - _accountsUiState.value = AccountsUiState.Loading + _accountsUiState.value = AccountState.Loading homeRepositoryImp.clientAccounts().catch { - _accountsUiState.value = AccountsUiState.Error + _accountsUiState.value = AccountState.Error }.collect { clientAccounts -> _accountsUiState.value = - AccountsUiState.ShowSavingsAccounts(clientAccounts.savingsAccounts) + AccountState.ShowSavingsAccounts(clientAccounts.savingsAccounts) _accountsUiState.value = - AccountsUiState.ShowLoanAccounts(clientAccounts.loanAccounts) + AccountState.ShowLoanAccounts(clientAccounts.loanAccounts) _accountsUiState.value = - AccountsUiState.ShowShareAccounts(clientAccounts.shareAccounts) + AccountState.ShowShareAccounts(clientAccounts.shareAccounts) } } } @@ -196,17 +196,17 @@ class AccountsViewModel @Inject constructor( */ fun loadAccounts(accountType: String?) { viewModelScope.launch { - _accountsUiState.value = AccountsUiState.Loading + _accountsUiState.value = AccountState.Loading accountsRepositoryImp.loadAccounts(accountType).catch { - _accountsUiState.value = AccountsUiState.Error + _accountsUiState.value = AccountState.Error }.collect { clientAccounts -> when (accountType) { Constants.SAVINGS_ACCOUNTS -> _accountsUiState.value = - AccountsUiState.ShowSavingsAccounts(clientAccounts.savingsAccounts) + AccountState.ShowSavingsAccounts(clientAccounts.savingsAccounts) Constants.LOAN_ACCOUNTS -> _accountsUiState.value = - AccountsUiState.ShowLoanAccounts(clientAccounts.loanAccounts) + AccountState.ShowLoanAccounts(clientAccounts.loanAccounts) Constants.SHARE_ACCOUNTS -> _accountsUiState.value = - AccountsUiState.ShowShareAccounts(clientAccounts.shareAccounts) + AccountState.ShowShareAccounts(clientAccounts.shareAccounts) } _isRefreshing.emit(false) } @@ -225,7 +225,7 @@ class AccountsViewModel @Inject constructor( accounts: List?, input: String?, ): List { - return Observable.fromIterable(accounts) + return io.reactivex.Observable.fromIterable(accounts) .filter { (accountNo, productName) -> input?.lowercase(Locale.ROOT) ?.let { productName?.lowercase(Locale.ROOT)?.contains(it) } == true || @@ -247,7 +247,7 @@ class AccountsViewModel @Inject constructor( accounts: List?, input: String?, ): List { - return Observable.fromIterable(accounts) + return io.reactivex.Observable.fromIterable(accounts) .filter { (_, _, _, accountNo, productName) -> input?.lowercase(Locale.ROOT) ?.let { productName?.lowercase(Locale.ROOT)?.contains(it) } == true || @@ -269,7 +269,7 @@ class AccountsViewModel @Inject constructor( accounts: Collection?, input: String?, ): List { - return Observable.fromIterable(accounts) + return io.reactivex.Observable.fromIterable(accounts) .filter { (accountNo, _, _, _, productName) -> input?.lowercase(Locale.ROOT) ?.let { productName?.lowercase(Locale.ROOT)?.contains(it) } == true || @@ -287,7 +287,7 @@ class AccountsViewModel @Inject constructor( * `checkboxStatus.isChecked()` as true. */ fun getCheckedStatus(statusModelList: List?): List? { - return Observable.fromIterable(statusModelList) + return io.reactivex.Observable.fromIterable(statusModelList) .filter { (_, _, isChecked) -> isChecked }.toList().blockingGet() } @@ -303,7 +303,7 @@ class AccountsViewModel @Inject constructor( status: CheckboxStatus?, accountsFilterUtil: AccountsFilterUtil ): Collection { - return Observable.fromIterable(accounts) + return io.reactivex.Observable.fromIterable(accounts) .filter( Predicate { (_, _, _, _, _, _, _, _, _, _, _, status1) -> if (accountsFilterUtil.activeString @@ -344,7 +344,7 @@ class AccountsViewModel @Inject constructor( status: CheckboxStatus?, accountsFilterUtil: AccountsFilterUtil ): Collection { - return Observable.fromIterable(accounts) + return io.reactivex.Observable.fromIterable(accounts) .filter( Predicate { (_, _, _, _, _, _, _, _, _, _, _, status1, _, _, _, _, _, inArrears) -> if (accountsFilterUtil.inArrearsString?.let { status?.status?.compareTo(it) } @@ -393,7 +393,7 @@ class AccountsViewModel @Inject constructor( status: CheckboxStatus?, accountsFilterUtil: AccountsFilterUtil ): Collection { - return Observable.fromIterable(accounts) + return io.reactivex.Observable.fromIterable(accounts) .filter( Predicate { (_, _, _, _, _, _, status1) -> if (accountsFilterUtil.activeString @@ -419,12 +419,4 @@ class AccountsViewModel @Inject constructor( ).toList().blockingGet().filterNotNull() } -} - -sealed class AccountsUiState { - data object Error : AccountsUiState() - data object Loading : AccountsUiState() - data class ShowSavingsAccounts(val savingAccounts: List?) : AccountsUiState() - data class ShowLoanAccounts(val loanAccounts: List?) : AccountsUiState() - data class ShowShareAccounts(val shareAccounts: List?) : AccountsUiState() } \ No newline at end of file diff --git a/feature/account/src/main/res/drawable/ic_error_black_24dp.xml b/feature/account/src/main/res/drawable/ic_error_black_24dp.xml new file mode 100644 index 000000000..b666c1818 --- /dev/null +++ b/feature/account/src/main/res/drawable/ic_error_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/feature/account/src/main/res/values/colors.xml b/feature/account/src/main/res/values/colors.xml new file mode 100644 index 000000000..324b9cd91 --- /dev/null +++ b/feature/account/src/main/res/values/colors.xml @@ -0,0 +1,74 @@ + + + #ffffffff + #000000 + #eaeaea + #ff14c416 + #ff8bf98a + #fff9ac06 + #FF87DBF9 + #fff9393c + #ffd1d1d1 + #8ad3da44 + #8ada6134 + #ff003fff + #FF0000 + #1C1C1C + + #B2C1C8 + + + #ff33b5e5 + + #33999999 + + #BB666666 + + #ff99cc00 + + #ffff4444 + + #ff0099cc + + #ff669900 + + #ffcc0000 + + #ffaa66cc + + #ffffbb33 + + #ffff8800 + + #ff00ddff + + #33CCCCCC + + + + + + + + #03A9F4 + #0288D1 + #B3E5FC + #FF4081 + #212121 + #757575 + #FFFFFF + #BDBDBD + #ffffff + @color/blue_light + #EEEEEE + #00000000 + + + + @color/blue_light + @color/green_light + @color/red_light + @color/orange_light + + + \ No newline at end of file diff --git a/feature/account/src/main/res/values/strings.xml b/feature/account/src/main/res/values/strings.xml new file mode 100644 index 000000000..412bde354 --- /dev/null +++ b/feature/account/src/main/res/values/strings.xml @@ -0,0 +1,37 @@ + + + Active + Approved + Approval Pending + Matured + Waiting for Disburse + Overpaid + Closed + Withdrawn + In Arrears + There is no SavingsAccount associated with you + There is no LoanAccount associated with you + There is no ShareAccount associated with you + Disbursement + Submitted + %1$s %2$s + Pending + Savings Account + Share Account + Loan Account + Saving + Loan + Share + Select all filters you want to apply + Clear Filters + Cancel + Filter + Deposit + Dividend Payout + Withdrawal + Interest Posting + Fee Deduction + Withdrawal Transfer + Rejected Transfer + Overdraft Fee + \ No newline at end of file diff --git a/feature/registration/src/main/java/org/mifos/mobile/feature/registration/screens/RegistrationScreen.kt b/feature/registration/src/main/java/org/mifos/mobile/feature/registration/screens/RegistrationScreen.kt index daa892202..1d77e8cd5 100644 --- a/feature/registration/src/main/java/org/mifos/mobile/feature/registration/screens/RegistrationScreen.kt +++ b/feature/registration/src/main/java/org/mifos/mobile/feature/registration/screens/RegistrationScreen.kt @@ -1,9 +1,12 @@ package org.mifos.mobile.feature.registration.screens +import android.app.Activity import android.content.Context import android.content.res.Configuration +import android.view.WindowInsets import android.widget.Toast import androidx.compose.foundation.border +import androidx.compose.foundation.gestures.detectDragGestures import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Arrangement @@ -11,8 +14,10 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape @@ -32,12 +37,15 @@ import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier @@ -45,6 +53,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalSoftwareKeyboardController +import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.PasswordVisualTransformation @@ -57,6 +66,7 @@ import androidx.compose.ui.unit.dp import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat.getString import androidx.core.util.PatternsCompat +import androidx.core.view.WindowCompat import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.owlbuddy.www.countrycodechooser.CountryCodeChooser @@ -107,7 +117,7 @@ fun RegistrationScreen( ) } -@OptIn(ExperimentalComposeUiApi::class) + @Composable fun RegistrationScreen( uiState: RegistrationState, @@ -124,6 +134,7 @@ fun RegistrationScreen( MFScaffold( topBarTitleResId = R.string.register, navigateBack = navigateBack, + snackbarHost = { SnackbarHost(hostState = snackBarHostState) }, scaffoldContent = { contentPadding -> Box( @@ -155,7 +166,7 @@ fun RegistrationScreen( } } } - }, snackbarHost = { SnackbarHost(hostState = snackBarHostState) } + } ) } @@ -166,7 +177,6 @@ fun RegistrationContent( snackBarHostState: SnackbarHostState, ) { val context = LocalContext.current - val keyboardController = LocalSoftwareKeyboardController.current var accountNumber by rememberSaveable(stateSaver = TextFieldValue.Saver) { @@ -199,8 +209,8 @@ fun RegistrationContent( var countryCode by rememberSaveable { mutableStateOf("") } - val radioOptions = - listOf(stringResource(id = R.string.rb_email), stringResource(id = R.string.rb_mobile)) + val radioOptions = listOf(stringResource(id = R.string.rb_email), stringResource(id = R.string.rb_mobile)) + var authenticationMode by remember { mutableStateOf(radioOptions[0]) } val progressIndicator = progress(password.text) @@ -209,6 +219,10 @@ fun RegistrationContent( val scrollState = rememberScrollState() val coroutineScope = rememberCoroutineScope() + LaunchedEffect(scrollState.canScrollForward){ + if (scrollState.canScrollForward) scrollState.scrollTo(scrollState.maxValue) + } + Column( modifier = Modifier .fillMaxSize() @@ -221,7 +235,8 @@ fun RegistrationContent( .verticalScroll( state = scrollState, enabled = true - )) { + ) + ) { MifosMobileIcon(id = R.drawable.mifos_logo) @@ -405,6 +420,8 @@ fun RegistrationContent( ) { Text(text = stringResource(id = R.string.register)) } + + Spacer(modifier = Modifier.imePadding()) } } @@ -567,7 +584,7 @@ class RegistrationScreenPreviewProvider : PreviewParameterProvider