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 document module #2193

Merged
merged 1 commit into from
Aug 17, 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
MIFOSAC-260 implemented compose navigation in document module
  • Loading branch information
itsPronay committed Aug 16, 2024
commit 0e90070047a13436ad1bf0ead6dbc122c06876b7
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 @@ -11,6 +11,8 @@ import com.mifos.feature.about.navigation.aboutScreen
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,7 +49,7 @@ 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) },
Expand All @@ -61,13 +63,17 @@ fun Navigation(
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 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