Skip to content

Commit

Permalink
feat: Implemented compose navigation in activate module (openMF#2195)
Browse files Browse the repository at this point in the history
* implemented compose navigation in activateModule

* MIFOSAC-260 implemented compose navigation in document module (openMF#2193)

* MIFOSAC-258: compose navigation in activate module
  • Loading branch information
itsPronay authored Aug 21, 2024
1 parent 39f9fd4 commit bd1948b
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ object Constants {
const val ACTIVATE_CENTER = "activate_center"
const val ACTIVATE_GROUP = "activate_group"
const val ACTIVATE_TYPE = "activation_type"
const val ACTIVATE_ID = "activation_id"
const val INTIAL_LOGIN = "initial_login"
const val INDIVIDUAL_SHEET = "collection_sheet"
const val DISBURSEMENT_DATE = "disbursement_date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ import java.util.Locale

@Composable
fun ActivateScreen(
id: Int,
activateType: String,
onBackPressed: () -> Unit
) {

val viewModel: ActivateViewModel = hiltViewModel()
val state by viewModel.activateUiState.collectAsStateWithLifecycle()
val id by viewModel.id.collectAsStateWithLifecycle()
val activateType by viewModel.activateType.collectAsStateWithLifecycle()

ActivateScreen(
state = state,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mifos.feature.activate

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.common.utils.Constants
import com.mifos.core.common.utils.Resource
import com.mifos.core.domain.use_cases.ActivateCenterUseCase
import com.mifos.core.domain.use_cases.ActivateClientUseCase
Expand All @@ -18,9 +20,13 @@ import javax.inject.Inject
class ActivateViewModel @Inject constructor(
private val activateClientUseCase: ActivateClientUseCase,
private val activateCenterUseCase: ActivateCenterUseCase,
private val activateGroupUseCase: ActivateGroupUseCase
private val activateGroupUseCase: ActivateGroupUseCase,
savedStateHandle: SavedStateHandle
) : ViewModel() {

val id = savedStateHandle.getStateFlow(key = Constants.ACTIVATE_ID, initialValue = 0)
val activateType = savedStateHandle.getStateFlow(key = Constants.ACTIVATE_TYPE, initialValue = "")

private val _activateUiState = MutableStateFlow<ActivateUiState>(ActivateUiState.Initial)
val activateUiState = _activateUiState.asStateFlow()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mifos.feature.activate.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.mifos.core.common.utils.Constants
import com.mifos.feature.activate.ActivateScreen

/**
* Created by Pronay Sarker on 18/08/2024 (1:40 PM)
*/
fun NavGraphBuilder.activateScreen(
onBackPressed: () -> Unit
) {
composable(
route = ActivateScreens.ActivateScreen.route,
arguments = listOf(
navArgument(name = Constants.ACTIVATE_ID, builder = { NavType.IntType }),
navArgument(name = Constants.ACTIVATE_TYPE, builder = { NavType.StringType })
)
) {
ActivateScreen(
onBackPressed = onBackPressed
)
}
}

fun NavController.navigateToActivateScreen(id : Int, type : String){
navigate(ActivateScreens.ActivateScreen.argument(id, type))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mifos.feature.activate.navigation

import com.mifos.core.common.utils.Constants

/**
* Created by Pronay Sarker on 18/08/2024 (1:40 PM)
*/
sealed class ActivateScreens(val route: String) {
data object ActivateScreen : ActivateScreens("activate_screen/{${Constants.ACTIVATE_ID}}/{${Constants.ACTIVATE_TYPE}}") {
fun argument(id: Int, type: String) = "activate_screen/$id/$type"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import com.mifos.core.common.utils.Constants
import com.mifos.feature.about.navigation.aboutScreen
import com.mifos.feature.activate.navigation.activateScreen
import com.mifos.feature.activate.navigation.navigateToActivateScreen
import com.mifos.feature.center.navigation.centerNavGraph
import com.mifos.feature.checker_inbox_task.navigation.checkerInboxTasksScreen
import com.mifos.feature.client.navigation.clientNavGraph
Expand Down Expand Up @@ -56,7 +58,7 @@ fun Navigation(
savingsAccountSelected = { id, type ->
navController.navigateToSavingsAccountSummaryScreen(id, type)
},
activateClient = { }
activateClient = { navController.navigateToActivateScreen(it, Constants.ACTIVATE_CLIENT) }
)

savingsNavGraph(
Expand Down Expand Up @@ -89,6 +91,8 @@ fun Navigation(
onBackPressed = navController::popBackStack
)

activateScreen ( onBackPressed = navController::popBackStack )

searchScreen(
modifier = Modifier.padding(padding),
centerListScreen = { },
Expand All @@ -99,7 +103,7 @@ fun Navigation(
centerNavGraph(
navController = navController,
paddingValues = padding,
onActivateCenter = { _, _ -> },
onActivateCenter = navController::navigateToActivateScreen,
addSavingsAccount = {
// navController.navigateToAddSavingsAccount(0, it, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class ActivateFragment : Fragment() {

private val arg: ActivateFragmentArgs by navArgs()
// private val arg: ActivateFragmentArgs by navArgs()
private var id = 0
private lateinit var activateType: String

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
id = arg.clientId
activateType = arg.activationType
// id = arg.clientId
// activateType = arg.activationType
}

override fun onCreateView(
Expand All @@ -38,8 +38,8 @@ class ActivateFragment : Fragment() {
)
setContent {
ActivateScreen(
id = id,
activateType = activateType,
// id = id,
// activateType = activateType,
onBackPressed = {
findNavController().popBackStack()
}
Expand Down

0 comments on commit bd1948b

Please sign in to comment.