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

[2656] : Beneficiary Module Compose Navigation #2659

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
15 changes: 12 additions & 3 deletions app/src/main/java/org/mifos/mobile/navigation/MifosNavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -40,6 +41,14 @@ fun RootNavGraph(
navigateBack = navigateBack,
loanId = loanId
)

beneficiaryNavGraph(
navController = navController,
navigateBack = { navController.popBackStack() },
startDestination = nestedStartDestination,
openQrImportScreen = {},
openQrReaderScreen = {}
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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() },
// )
}

}

}
Expand Down Expand Up @@ -189,4 +190,4 @@ class BeneficiaryAddOptionsFragment : BaseFragment() {
return fragment
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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
// )
}
}

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

/*
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -75,6 +76,4 @@ class BeneficiaryDetailFragment : BaseFragment() {
}
}
}



*/
Original file line number Diff line number Diff line change
@@ -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<Beneficiary>) {
(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<Beneficiary>) {
// (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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,16 +43,24 @@ 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()

BeneficiaryDetailScreen(
beneficiary = beneficiary,
uiState = uiState,
navigateBack = navigateBack,
updateBeneficiary = updateBeneficiary,
updateBeneficiary = {
updateBeneficiary.invoke(
viewModel.getBeneficiary()
)
},
deleteBeneficiary = {
viewModel.deleteBeneficiary(it)
}
Expand Down
Loading
Loading