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

feat: Implemented compose navigation in activate module #2195

Merged
merged 3 commits into from
Aug 21, 2024
Merged
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
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 @@ -2,6 +2,7 @@

package com.mifos.feature.document.document_list

import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -69,8 +70,6 @@ import com.mifos.feature.document.document_dialog.DocumentDialogScreen
@Composable
fun DocumentListScreen(
viewModel: DocumentListViewModel = hiltViewModel(),
entityType: String,
entityId: Int,
onBackPressed: () -> Unit,
) {
val context = LocalContext.current
Expand All @@ -81,6 +80,8 @@ fun DocumentListScreen(
var isDialogBoxActive by rememberSaveable { mutableStateOf(false) }
var dialogBoxAction by rememberSaveable { mutableStateOf("") }
var dialogDocument by rememberSaveable { mutableStateOf(Document()) }
val entityId by viewModel.entityId.collectAsStateWithLifecycle()
val entityType by viewModel.entityType.collectAsStateWithLifecycle()


if(isDialogBoxActive)
Expand All @@ -99,6 +100,7 @@ fun DocumentListScreen(
}

LaunchedEffect(Unit) {
Log.d("documentListDebugLog", "id : $entityId, type : $entityType" )
viewModel.loadDocumentList(entityType, entityId)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.mifos.feature.document.document_list

import android.util.Log
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.DownloadDocumentUseCase
import com.mifos.core.domain.use_cases.GetDocumentsListUseCase
Expand All @@ -18,11 +21,14 @@ import javax.inject.Inject
class DocumentListViewModel @Inject constructor(
private val getDocumentsListUseCase: GetDocumentsListUseCase,
private val downloadDocumentUseCase: DownloadDocumentUseCase,
private val removeDocumentUseCase: RemoveDocumentUseCase
private val removeDocumentUseCase: RemoveDocumentUseCase,
savedStateHandle: SavedStateHandle
) : ViewModel() {

private val _documentListUiState =
MutableStateFlow<DocumentListUiState>(DocumentListUiState.Loading)
val entityId = savedStateHandle.getStateFlow(key = Constants.ENTITY_ID, initialValue = 0)
val entityType = savedStateHandle.getStateFlow(key = Constants.ENTITY_TYPE, initialValue = "")

private val _documentListUiState = MutableStateFlow<DocumentListUiState>(DocumentListUiState.Loading)
val documentListUiState = _documentListUiState.asStateFlow()

private val _removeDocumentState = MutableStateFlow(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mifos.feature.document.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.document.document_list.DocumentListScreen

/**
* Created by Pronay Sarker on 17/08/2024 (4:00 AM)
*/
fun NavGraphBuilder.documentListScreen(
onBackPressed: () -> Unit
) {
composable(
route = DocumentScreens.DocumentListScreen.route,
arguments = listOf(
navArgument(name = Constants.ENTITY_ID, builder = { type = NavType.IntType }),
navArgument(name = Constants.ENTITY_TYPE, builder = { type = NavType.StringType })
)
) {
DocumentListScreen(
onBackPressed = onBackPressed
)
}
}

fun NavController.navigateToDocumentListScreen(entityId : Int, entityType : String) {
navigate(DocumentScreens.DocumentListScreen.argument(entityId, entityType))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mifos.feature.document.navigation

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

/**
* Created by Pronay Sarker on 17/08/2024 (4:00 AM)
*/
sealed class DocumentScreens(val route: String) {
data object DocumentListScreen : DocumentScreens("document_list_screen/{${Constants.ENTITY_ID}}/{${Constants.ENTITY_TYPE}}") {
fun argument(entityId : Int, entityType : String) = "document_list_screen/$entityId/$entityType"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ 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
import com.mifos.feature.document.navigation.documentListScreen
import com.mifos.feature.document.navigation.navigateToDocumentListScreen
import com.mifos.feature.groups.navigation.groupListScreen
import com.mifos.feature.individual_collection_sheet.navigation.generateCollectionSheetScreen
import com.mifos.feature.individual_collection_sheet.navigation.individualCollectionSheetScreen
Expand Down Expand Up @@ -47,27 +51,31 @@ fun Navigation(
paddingValues = padding,
addLoanAccount = { navController.navigateToLoanAccountScreen(it) },
addSavingsAccount = { navController.navigateToAddSavingsAccount(it, 0, false) },
documents = {},
documents = { navController.navigateToDocumentListScreen(it, Constants.ENTITY_TYPE_CLIENTS) },
moreClientInfo = {},
notes = { navController.navigateToNoteScreen(it, Constants.ENTITY_TYPE_CLIENTS)},
loanAccountSelected = { navController.navigateToLoanAccountSummaryScreen(it) },
savingsAccountSelected = { id, type ->
navController.navigateToSavingsAccountSummaryScreen(id, type)
},
activateClient = { }
activateClient = { navController.navigateToActivateScreen(it, Constants.ACTIVATE_CLIENT) }
)

savingsNavGraph(
navController = navController,
onBackPressed = navController::popBackStack,
loadMoreSavingsAccountInfo = { },
loadDocuments = { },
loadDocuments = { navController.navigateToDocumentListScreen(it, Constants.ENTITY_TYPE_SAVINGS) },
)

loanNavGraph(
navController = navController,
onMoreInfoClicked = { },
onDocumentsClicked = { _, _ -> }
onDocumentsClicked = navController::navigateToDocumentListScreen
)

documentListScreen(
onBackPressed = navController::popBackStack
)

noteScreen(
Expand All @@ -83,6 +91,8 @@ fun Navigation(
onBackPressed = navController::popBackStack
)

activateScreen ( onBackPressed = navController::popBackStack )

searchScreen(
modifier = Modifier.padding(padding),
centerListScreen = { },
Expand All @@ -93,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
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class DocumentListFragment : MifosBaseFragment() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
entityId = arg.entiyId
entityType = arg.entityType
// entityId = arg.entiyId
// entityType = arg.entityType
}

override fun onCreateView(
Expand All @@ -41,8 +41,8 @@ class DocumentListFragment : MifosBaseFragment() {
)
setContent {
DocumentListScreen(
entityType = entityType,
entityId = entityId,
// entityType = entityType,
// entityId = entityId,
onBackPressed = { requireActivity().supportFragmentManager.popBackStack() }
)
}
Expand Down
Loading