diff --git a/app/src/main/java/org/mifos/mobile/navigation/MifosNavGraph.kt b/app/src/main/java/org/mifos/mobile/navigation/MifosNavGraph.kt index 09c148622..be51a54d1 100644 --- a/app/src/main/java/org/mifos/mobile/navigation/MifosNavGraph.kt +++ b/app/src/main/java/org/mifos/mobile/navigation/MifosNavGraph.kt @@ -2,17 +2,18 @@ package org.mifos.mobile.navigation import android.content.Context import android.content.Intent +import android.os.Build +import androidx.annotation.RequiresApi import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalContext import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost -import org.mifos.mobile.feature.auth.navigation.AuthenticationNavigation import org.mifos.mobile.feature.auth.navigation.authenticationNavGraph -import org.mifos.mobile.feature.guarantor.navigation.GuarantorNavigation -import org.mifos.mobile.feature.guarantor.navigation.GuarantorRoute +import org.mifos.mobile.feature.beneficiary.navigation.beneficiaryNavGraph import org.mifos.mobile.feature.guarantor.navigation.guarantorNavGraph import org.mifos.mobile.ui.activities.PassCodeActivity +@RequiresApi(Build.VERSION_CODES.TIRAMISU) @Composable fun RootNavGraph( navController: NavHostController, @@ -40,6 +41,14 @@ fun RootNavGraph( navigateBack = navigateBack, loanId = loanId ) + + beneficiaryNavGraph( + navController = navController, + navigateBack = { navController.popBackStack() }, + startDestination = nestedStartDestination, + openQrImportScreen = {}, + openQrReaderScreen = {} + ) } } diff --git a/app/src/main/java/org/mifos/mobile/ui/beneficiary/presentation/BeneficiaryAddOptionsFragment.kt b/app/src/main/java/org/mifos/mobile/ui/beneficiary/presentation/BeneficiaryAddOptionsFragment.kt index 6fbe4ee82..bf8031856 100644 --- a/app/src/main/java/org/mifos/mobile/ui/beneficiary/presentation/BeneficiaryAddOptionsFragment.kt +++ b/app/src/main/java/org/mifos/mobile/ui/beneficiary/presentation/BeneficiaryAddOptionsFragment.kt @@ -30,6 +30,8 @@ import org.mifos.mobile.utils.Toaster /** * Created by dilpreet on 5/7/17. */ +// File Can be deleted After fully implementing compose navigation. +// Has Instances Left out in Add Beneficiary Activity and ThirdPartyTransfer Fragment @AndroidEntryPoint class BeneficiaryAddOptionsFragment : BaseFragment() { @@ -51,16 +53,15 @@ class BeneficiaryAddOptionsFragment : BaseFragment() { setContent { MifosMobileTheme { - BeneficiaryScreen( - topAppbarNavigateback = { - requireActivity().onBackPressedDispatcher.onBackPressed() - }, - addiconClicked = { addManually() }, - scaniconClicked = { addUsingQrCode() }, - uploadIconClicked = { addByImportingQrCode() }, - ) +// BeneficiaryScreen( +// topAppbarNavigateback = { +// requireActivity().onBackPressedDispatcher.onBackPressed() +// }, +// addiconClicked = { addManually() }, +// scaniconClicked = { addUsingQrCode() }, +// uploadIconClicked = { addByImportingQrCode() }, +// ) } - } } @@ -189,4 +190,4 @@ class BeneficiaryAddOptionsFragment : BaseFragment() { return fragment } } -} +} \ No newline at end of file diff --git a/app/src/main/java/org/mifos/mobile/ui/beneficiary_application/BeneficiaryApplicationComposeFragment.kt b/app/src/main/java/org/mifos/mobile/ui/beneficiary_application/BeneficiaryApplicationComposeFragment.kt index 2d0613d0a..98f136b55 100644 --- a/app/src/main/java/org/mifos/mobile/ui/beneficiary_application/BeneficiaryApplicationComposeFragment.kt +++ b/app/src/main/java/org/mifos/mobile/ui/beneficiary_application/BeneficiaryApplicationComposeFragment.kt @@ -20,6 +20,8 @@ import org.mifos.mobile.feature.beneficiary.beneficiary_application.BeneficiaryA /** * Created by dilpreet on 16/6/17. */ +// File Can be deleted After fully implementing compose navigation. +// Has Instances left out in Qr Code Import and Qr Code Reader Fragment @AndroidEntryPoint class BeneficiaryApplicationComposeFragment : BaseFragment() { @@ -41,9 +43,11 @@ class BeneficiaryApplicationComposeFragment : BaseFragment() { savedInstanceState: Bundle?, ): View { return mifosComposeView(requireContext()) { - BeneficiaryApplicationScreen( - navigateBack = { activity?.onBackPressed() } - ) +// BeneficiaryApplicationScreen( +// navigateBack = { activity?.onBackPressed() }, +// beneficiary = beneficiary, +// beneficiaryState = beneficiaryState +// ) } } diff --git a/app/src/main/java/org/mifos/mobile/ui/beneficiary_detail/BeneficiaryDetailFragment.kt b/app/src/main/java/org/mifos/mobile/ui/beneficiary_detail/BeneficiaryDetailFragment.kt index 4a71fa1fe..dc7e5475b 100644 --- a/app/src/main/java/org/mifos/mobile/ui/beneficiary_detail/BeneficiaryDetailFragment.kt +++ b/app/src/main/java/org/mifos/mobile/ui/beneficiary_detail/BeneficiaryDetailFragment.kt @@ -1,5 +1,6 @@ package org.mifos.mobile.ui.beneficiary_detail; +/* import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -75,6 +76,4 @@ class BeneficiaryDetailFragment : BaseFragment() { } } } - - - + */ \ No newline at end of file diff --git a/app/src/main/java/org/mifos/mobile/ui/beneficiary_list/BeneficiaryListComposeFragment.kt b/app/src/main/java/org/mifos/mobile/ui/beneficiary_list/BeneficiaryListComposeFragment.kt index af2107674..865d4dee3 100644 --- a/app/src/main/java/org/mifos/mobile/ui/beneficiary_list/BeneficiaryListComposeFragment.kt +++ b/app/src/main/java/org/mifos/mobile/ui/beneficiary_list/BeneficiaryListComposeFragment.kt @@ -1,54 +1,64 @@ package org.mifos.mobile.ui.beneficiary_list +import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.annotation.RequiresApi +import androidx.navigation.compose.rememberNavController import dagger.hilt.android.AndroidEntryPoint -import org.mifos.mobile.core.model.entity.beneficiary.Beneficiary import org.mifos.mobile.core.ui.component.mifosComposeView import org.mifos.mobile.ui.activities.base.BaseActivity -import org.mifos.mobile.ui.beneficiary.presentation.BeneficiaryAddOptionsFragment import org.mifos.mobile.ui.fragments.base.BaseFragment -import org.mifos.mobile.feature.beneficiary.beneficiary_list.BeneficiaryListScreen -import org.mifos.mobile.feature.guarantor.R +import org.mifos.mobile.feature.beneficiary.navigation.BeneficiaryNavigation +import org.mifos.mobile.feature.beneficiary.navigation.BeneficiaryRoute +import org.mifos.mobile.navigation.RootNavGraph @AndroidEntryPoint class BeneficiaryListComposeFragment : BaseFragment() { + @RequiresApi(Build.VERSION_CODES.TIRAMISU) override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, ): View { return mifosComposeView(requireContext()) { - BeneficiaryListScreen( - navigateBack = { activity?.supportFragmentManager?.popBackStack() }, - addBeneficiaryClicked = { addBeneficiary() }, - onBeneficiaryItemClick = { position, beneficiaryList -> - onItemClick( - position = position, - beneficiaryList = beneficiaryList - ) - }, - ) - } - } + val navController = rememberNavController() + RootNavGraph( + startDestination = BeneficiaryRoute.BENEFICIARY_NAVIGATION_ROUTE, + navController = navController, + nestedStartDestination = BeneficiaryNavigation.BeneficiaryList.route, + ) - private fun onItemClick(position: Int, beneficiaryList: List) { - (activity as? BaseActivity)?.replaceFragment( - org.mifos.mobile.ui.beneficiary_detail.BeneficiaryDetailFragment.newInstance(beneficiaryList[position]), - true, - R.id.container, - ) +// BeneficiaryListScreen( +// navigateBack = { activity?.supportFragmentManager?.popBackStack() }, +// addBeneficiaryClicked = { addBeneficiary() }, +// onBeneficiaryItemClick = { position, beneficiaryList -> +// onItemClick( +// position = position, +// beneficiaryList = beneficiaryList +// ) +// }, +// ) + } } - private fun addBeneficiary() { - (activity as? BaseActivity)?.replaceFragment( - BeneficiaryAddOptionsFragment.newInstance(), - true, - R.id.container, - ) - } +// private fun onItemClick(position: Int, beneficiaryList: List) { +// (activity as? BaseActivity)?.replaceFragment( +// org.mifos.mobile.ui.beneficiary_detail.BeneficiaryDetailFragment.newInstance(beneficiaryList[position]), +// true, +// R.id.container, +// ) +// } +// +// private fun addBeneficiary() { +// (activity as? BaseActivity)?.replaceFragment( +// BeneficiaryAddOptionsFragment.newInstance(), +// true, +// R.id.container, +// ) +// } override fun onResume() { super.onResume() diff --git a/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/beneficiary_application/BeneficiaryApplicationScreen.kt b/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/beneficiary_application/BeneficiaryApplicationScreen.kt index 4d0ee0d95..80c818acd 100644 --- a/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/beneficiary_application/BeneficiaryApplicationScreen.kt +++ b/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/beneficiary_application/BeneficiaryApplicationScreen.kt @@ -14,11 +14,14 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle +import org.mifos.mobile.core.common.Constants import org.mifos.mobile.core.ui.component.MFScaffold import org.mifos.mobile.core.ui.component.MifosErrorComponent import org.mifos.mobile.core.ui.component.MifosProgressIndicator import org.mifos.mobile.core.ui.theme.MifosMobileTheme import org.mifos.mobile.core.common.Network +import org.mifos.mobile.core.common.utils.ParcelableAndSerializableUtils.getCheckedParcelable +import org.mifos.mobile.core.common.utils.ParcelableAndSerializableUtils.getCheckedSerializable import org.mifos.mobile.core.model.entity.beneficiary.Beneficiary import org.mifos.mobile.core.model.entity.beneficiary.BeneficiaryPayload import org.mifos.mobile.core.model.entity.templates.beneficiary.BeneficiaryTemplate @@ -29,10 +32,19 @@ import org.mifos.mobile.feature.beneficiary.R @Composable fun BeneficiaryApplicationScreen( viewModel: BeneficiaryApplicationViewModel = hiltViewModel(), - navigateBack: () -> Unit + navigateBack: () -> Unit, + beneficiary: Beneficiary?, + beneficiaryState: BeneficiaryState? ) { - val beneficiaryState by viewModel.beneficiaryState.collectAsStateWithLifecycle() - val beneficiary by viewModel.beneficiary.collectAsStateWithLifecycle() + beneficiaryState?.let { + viewModel.initArgs( + beneficiaryState = beneficiaryState, + beneficiary = beneficiary + ) + } + + val newBeneficiaryState by viewModel.beneficiaryState.collectAsStateWithLifecycle() + val newBeneficiary by viewModel.beneficiary.collectAsStateWithLifecycle() val uiState by viewModel.beneficiaryUiState.collectAsStateWithLifecycle() LaunchedEffect(key1 = Unit) { @@ -42,8 +54,8 @@ fun BeneficiaryApplicationScreen( BeneficiaryApplicationScreen ( uiState = uiState, navigateBack = navigateBack, - beneficiaryState = beneficiaryState, - beneficiary = beneficiary, + beneficiaryState = newBeneficiaryState, + beneficiary = newBeneficiary, onRetry = { viewModel.loadBeneficiaryTemplate() }, onSubmit = { viewModel.submitBeneficiary(it) } ) diff --git a/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/beneficiary_detail/BeneficiaryDetailScreen.kt b/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/beneficiary_detail/BeneficiaryDetailScreen.kt index 765403d37..c0b162b18 100644 --- a/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/beneficiary_detail/BeneficiaryDetailScreen.kt +++ b/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/beneficiary_detail/BeneficiaryDetailScreen.kt @@ -31,7 +31,9 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle +import org.mifos.mobile.core.common.Constants import org.mifos.mobile.core.model.entity.beneficiary.Beneficiary +import org.mifos.mobile.core.model.enums.BeneficiaryState import org.mifos.mobile.core.ui.component.MifosAlertDialog import org.mifos.mobile.core.ui.component.MifosProgressIndicatorOverlay import org.mifos.mobile.core.ui.theme.MifosMobileTheme @@ -41,8 +43,12 @@ import org.mifos.mobile.feature.beneficiary.R fun BeneficiaryDetailScreen( viewModel: BeneficiaryDetailViewModel = hiltViewModel(), navigateBack: () -> Unit, - updateBeneficiary: () -> Unit, + updateBeneficiary: ( beneficiary : Beneficiary? ) -> Unit, + beneficiary: Beneficiary? ) { + beneficiary?.let { + viewModel.setBeneficiary(beneficiary) + } val uiState by viewModel.beneficiaryDetailsUiStates.collectAsStateWithLifecycle() val beneficiary by viewModel.beneficiary.collectAsStateWithLifecycle() @@ -50,7 +56,11 @@ fun BeneficiaryDetailScreen( beneficiary = beneficiary, uiState = uiState, navigateBack = navigateBack, - updateBeneficiary = updateBeneficiary, + updateBeneficiary = { + updateBeneficiary.invoke( + viewModel.getBeneficiary() + ) + }, deleteBeneficiary = { viewModel.deleteBeneficiary(it) } diff --git a/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/navigation/BeneficiaryNavGraph.kt b/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/navigation/BeneficiaryNavGraph.kt new file mode 100644 index 000000000..2107dc1e5 --- /dev/null +++ b/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/navigation/BeneficiaryNavGraph.kt @@ -0,0 +1,135 @@ +package org.mifos.mobile.feature.beneficiary.navigation + +import android.os.Build +import androidx.annotation.RequiresApi +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavHostController +import androidx.navigation.compose.composable +import androidx.navigation.compose.navigation +import org.mifos.mobile.core.model.entity.beneficiary.Beneficiary +import org.mifos.mobile.core.model.enums.BeneficiaryState +import org.mifos.mobile.feature.beneficiary.beneficiary_application.BeneficiaryApplicationScreen +import org.mifos.mobile.feature.beneficiary.beneficiary_detail.BeneficiaryDetailScreen +import org.mifos.mobile.feature.beneficiary.beneficiary_list.BeneficiaryListScreen +import org.mifos.mobile.feature.beneficiary.navigation.BeneficiaryRoute.BENEFICIARY_LIST_ROUTE +import org.mifos.mobile.feature.beneficiary.navigation.BeneficiaryRoute.BENEFICIARY_NAVIGATION_ROUTE +import org.mifos.mobile.feature.beneficiary.presentation.BeneficiaryScreen + +@RequiresApi(Build.VERSION_CODES.TIRAMISU) +fun NavGraphBuilder.beneficiaryNavGraph( + startDestination: String, + navController: NavHostController, + navigateBack: () -> Unit, + openQrReaderScreen: () -> Unit, + openQrImportScreen: () -> Unit +) { + navigation( + startDestination = startDestination, + route = BENEFICIARY_NAVIGATION_ROUTE + ) { + beneficiaryListRoute( + navigateBack = navigateBack, + addBeneficiary = { + navController.navigate(BeneficiaryNavigation.AddBeneficiary.route) + }, + showBeneficiaryDetail = { beneficiaryId, beneficiaryList -> + navController.navigate( + BeneficiaryNavigation.BeneficiaryDetail( + beneficiaryList[beneficiaryId] + ).route + ) + } + ) + + addBeneficiaryRoute( + navigateBack= { navController.popBackStack() }, + addBeneficiaryManually = { + navController.navigate( + BeneficiaryNavigation.BeneficiaryApplication( + BeneficiaryState.CREATE_MANUAL, + null, + ).route + ) + }, + openQrScanner = openQrReaderScreen, + uploadQrCode = openQrImportScreen + ) + + beneficiaryDetailRoute( + navigateBack = { navController.popBackStack() }, + updateBeneficiary = { beneficiary -> + navController.navigate( + BeneficiaryNavigation.BeneficiaryApplication( + BeneficiaryState.UPDATE, + beneficiary + ).route + ) + } + ) + + beneficiaryApplicationRoute( + navigateBack = { navController.popBackStack() } + ) + } +} + +fun NavGraphBuilder.beneficiaryListRoute( + navigateBack: () -> Unit, + addBeneficiary: () -> Unit, + showBeneficiaryDetail: ( Int, List) -> Unit +) { + composable(route = BeneficiaryNavigation.BeneficiaryList.route) { + BeneficiaryListScreen( + navigateBack = navigateBack, + addBeneficiaryClicked = addBeneficiary, + onBeneficiaryItemClick = { beneficiaryId, beneficiaryList -> + showBeneficiaryDetail(beneficiaryId, beneficiaryList) + }, + ) + } +} + +@RequiresApi(Build.VERSION_CODES.TIRAMISU) +fun NavGraphBuilder.addBeneficiaryRoute( + navigateBack: () -> Unit, + addBeneficiaryManually: () -> Unit, + openQrScanner: () -> Unit, + uploadQrCode: () -> Unit +) { + composable(route = BeneficiaryNavigation.AddBeneficiary.route) { + BeneficiaryScreen( + topAppbarNavigateback= navigateBack, + addiconClicked= addBeneficiaryManually, + scaniconClicked= openQrScanner, + uploadIconClicked = uploadQrCode + ) + } +} + +fun NavGraphBuilder.beneficiaryDetailRoute( + navigateBack: () -> Unit, + updateBeneficiary: ( beneficiary : Beneficiary? ) -> Unit, + beneficiary : Beneficiary? = null +) { + composable(route = BeneficiaryNavigation.BeneficiaryDetail(beneficiary).route) { + BeneficiaryDetailScreen( + navigateBack = navigateBack, + updateBeneficiary = updateBeneficiary, + beneficiary = beneficiary + ) + } +} + +fun NavGraphBuilder.beneficiaryApplicationRoute( + navigateBack: () -> Unit, + beneficiary : Beneficiary? = null, + beneficiaryState: BeneficiaryState? = null +) { + composable(route = BeneficiaryNavigation.BeneficiaryApplication(beneficiaryState, beneficiary).route) { + BeneficiaryApplicationScreen( + navigateBack = navigateBack, + beneficiary = beneficiary, + beneficiaryState = beneficiaryState + ) + } +} \ No newline at end of file diff --git a/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/navigation/BeneficiaryNavigationScreen.kt b/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/navigation/BeneficiaryNavigationScreen.kt new file mode 100644 index 000000000..dac3628c0 --- /dev/null +++ b/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/navigation/BeneficiaryNavigationScreen.kt @@ -0,0 +1,19 @@ +package org.mifos.mobile.feature.beneficiary.navigation + +import org.mifos.mobile.core.model.entity.beneficiary.Beneficiary +import org.mifos.mobile.core.model.enums.BeneficiaryState +import org.mifos.mobile.feature.beneficiary.navigation.BeneficiaryRoute.ADD_BENEFICIARY_SCREEN_ROUTE +import org.mifos.mobile.feature.beneficiary.navigation.BeneficiaryRoute.BENEFICIARY_APPLICATION_SCREEN_ROUTE +import org.mifos.mobile.feature.beneficiary.navigation.BeneficiaryRoute.BENEFICIARY_DETAIL_SCREEN_ROUTE +import org.mifos.mobile.feature.beneficiary.navigation.BeneficiaryRoute.BENEFICIARY_LIST_ROUTE + +sealed class BeneficiaryNavigation(val route: String) { + data object AddBeneficiary: BeneficiaryNavigation(route = ADD_BENEFICIARY_SCREEN_ROUTE) + data class BeneficiaryDetail(val beneficiary: Beneficiary?) : + BeneficiaryNavigation(route = BENEFICIARY_DETAIL_SCREEN_ROUTE) + data class BeneficiaryApplication( + val beneficiaryState: BeneficiaryState?, + val beneficiary: Beneficiary?, + ) : BeneficiaryNavigation(route = BENEFICIARY_APPLICATION_SCREEN_ROUTE) + data object BeneficiaryList : BeneficiaryNavigation(route = BENEFICIARY_LIST_ROUTE) +} \ No newline at end of file diff --git a/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/navigation/BeneficiaryRoute.kt b/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/navigation/BeneficiaryRoute.kt new file mode 100644 index 000000000..af8af6ad4 --- /dev/null +++ b/feature/beneficiary/src/main/java/org/mifos/mobile/feature/beneficiary/navigation/BeneficiaryRoute.kt @@ -0,0 +1,9 @@ +package org.mifos.mobile.feature.beneficiary.navigation + +object BeneficiaryRoute { + const val BENEFICIARY_NAVIGATION_ROUTE = "beneficiary_route" + const val BENEFICIARY_LIST_ROUTE = "beneficiary_list_screen" + const val BENEFICIARY_DETAIL_SCREEN_ROUTE = "beneficiary_detail_screen" + const val BENEFICIARY_APPLICATION_SCREEN_ROUTE = "beneficiary_application_screen" + const val ADD_BENEFICIARY_SCREEN_ROUTE = "add_beneficiary_screen" +} \ No newline at end of file