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 Nav graph client #2186

Merged
merged 3 commits into from
Aug 14, 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 @@ -61,11 +61,11 @@ import kotlinx.coroutines.flow.flowOf

@Composable
fun ClientChargesScreen(
clientId: Int,
onBackPressed: () -> Unit
) {

val viewModel: ClientChargesViewModel = hiltViewModel()
val clientId by viewModel.clientId.collectAsStateWithLifecycle()
val clientChargeUiState by viewModel.clientChargesUiState.collectAsStateWithLifecycle()
val refreshState by viewModel.isRefreshing.collectAsStateWithLifecycle()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mifos.feature.client.clientCharges

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.common.utils.Constants
import com.mifos.core.data.repository.ClientChargeRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
Expand All @@ -12,9 +14,12 @@ import javax.inject.Inject

@HiltViewModel
class ClientChargesViewModel @Inject constructor(
private val repository: ClientChargeRepository
private val repository: ClientChargeRepository,
private val savedStateHandle: SavedStateHandle
) : ViewModel() {

val clientId = savedStateHandle.getStateFlow(key = Constants.CLIENT_ID, initialValue = 0)

// for refresh feature
private val _isRefreshing = MutableStateFlow(false)
val isRefreshing = _isRefreshing.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ import java.util.Objects
@Composable
fun ClientDetailsScreen(
clientDetailsViewModel: ClientDetailsViewModel = hiltViewModel(),
clientId: Int,
onBackPressed: () -> Unit,
addLoanAccount: (Int) -> Unit,
addSavingsAccount: (Int) -> Unit,
Expand All @@ -128,6 +127,7 @@ fun ClientDetailsScreen(
savingsAccountSelected: (Int, DepositType) -> Unit,
activateClient: (Int) -> Unit
) {
val clientId by clientDetailsViewModel.clientId.collectAsStateWithLifecycle()

val context = LocalContext.current
val scope = rememberCoroutineScope()
Expand Down Expand Up @@ -946,7 +946,6 @@ fun MifosClientDetailsText(icon: ImageVector, field: String, value: String) {
@Composable
private fun ClientDetailsScreenPreview() {
ClientDetailsScreen(
clientId = 1,
onBackPressed = {},
addLoanAccount = {},
addSavingsAccount = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.mifos.feature.client.clientDetails.ui

import android.graphics.Bitmap
import android.os.Environment
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import coil.request.ImageResult
import com.mifos.core.common.utils.Constants
import com.mifos.core.common.utils.Resource
import com.mifos.core.domain.use_cases.DeleteClientImageUseCase
import com.mifos.core.domain.use_cases.GetClientDetailsUseCase
Expand All @@ -31,9 +33,12 @@ class ClientDetailsViewModel @Inject constructor(
private val uploadClientImageUseCase: UploadClientImageUseCase,
private val getClientDetailsUseCase: GetClientDetailsUseCase,
private val deleteClientImageUseCase: DeleteClientImageUseCase,
private val imageLoaderUtils: ImageLoaderUtils
private val imageLoaderUtils: ImageLoaderUtils,
savedStateHandle: SavedStateHandle
) : ViewModel() {

val clientId = savedStateHandle.getStateFlow(key = Constants.CLIENT_ID, initialValue = 0)

private val _clientDetailsUiState =
MutableStateFlow<ClientDetailsUiState>(ClientDetailsUiState.Empty)
val clientDetailsUiState = _clientDetailsUiState.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ import com.mifos.feature.client.clientIdentifiersDialog.ClientIdentifiersDialogS

@Composable
fun ClientIdentifiersScreen(
clientId: Int,
onBackPressed: () -> Unit,
onDocumentClicked: (Int) -> Unit
) {

val viewModel: ClientIdentifiersViewModel = hiltViewModel()
val clientId by viewModel.clientId.collectAsStateWithLifecycle()
val state by viewModel.clientIdentifiersUiState.collectAsStateWithLifecycle()
val refreshState by viewModel.isRefreshing.collectAsStateWithLifecycle()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mifos.feature.client.clientIdentifiers

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.DeleteIdentifierUseCase
import com.mifos.core.domain.use_cases.GetClientIdentifiersUseCase
Expand All @@ -16,9 +18,12 @@ import javax.inject.Inject
@HiltViewModel
class ClientIdentifiersViewModel @Inject constructor(
private val getClientIdentifiersUseCase: GetClientIdentifiersUseCase,
private val deleteIdentifierUseCase: DeleteIdentifierUseCase
private val deleteIdentifierUseCase: DeleteIdentifierUseCase,
private val savedStateHandle: SavedStateHandle
) : ViewModel() {

val clientId = savedStateHandle.getStateFlow(key = Constants.CLIENT_ID, initialValue = 0)

private val _clientIdentifiersUiState =
MutableStateFlow<ClientIdentifiersUiState>(ClientIdentifiersUiState.Loading)
val clientIdentifiersUiState = _clientIdentifiersUiState.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun ClientListScreen(
paddingValues: PaddingValues,
createNewClient: () -> Unit,
syncClicked: (List<Client>) -> Unit,
onClientSelect: (Client) -> Unit,
onClientSelect: (Int) -> Unit,
) {

val viewModel: ClientListViewModel = hiltViewModel()
Expand Down Expand Up @@ -233,8 +233,8 @@ fun LazyColumnForClientListApi(
clientPagingList: LazyPagingItems<Client>,
isInSelectionMode: MutableState<Boolean>,
selectedItems: SnapshotStateList<Client>,
failedRefresh : () ->Unit,
onClientSelect: (Client) -> Unit
failedRefresh: () -> Unit,
onClientSelect: (Int) -> Unit
) {

when (clientPagingList.loadState.refresh) {
Expand Down Expand Up @@ -270,7 +270,7 @@ fun LazyColumnForClientListApi(
LightGray
}
} else {
clientPagingList[index]?.let { onClientSelect(it) }
clientPagingList[index]?.id?.let { onClientSelect(it) }
}
},
onLongClick = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mifos.feature.client.clientPinpoint

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.common.utils.Resource
Expand All @@ -24,9 +25,12 @@ class PinPointClientViewModel @Inject constructor(
private val getClientPinpointLocationsUseCase: GetClientPinpointLocationsUseCase,
private val addClientPinpointLocationUseCase: AddClientPinpointLocationUseCase,
private val deleteClientAddressPinpointUseCase: DeleteClientAddressPinpointUseCase,
private val updateClientPinpointUseCase: UpdateClientPinpointUseCase
private val updateClientPinpointUseCase: UpdateClientPinpointUseCase,
private val stateHandle: SavedStateHandle
) : ViewModel() {

val clientId = stateHandle.getStateFlow(key = "clientId", initialValue = 0)

private val _pinPointClientUiState =
MutableStateFlow<PinPointClientUiState>(PinPointClientUiState.Loading)
val pinPointClientUiState = _pinPointClientUiState.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ import com.mifos.feature.client.R

@Composable
fun PinpointClientScreen(
clientId: Int,
onBackPressed: () -> Unit,
) {

val viewModel: PinPointClientViewModel = hiltViewModel()
val clientId by viewModel.clientId.collectAsStateWithLifecycle()
val state by viewModel.pinPointClientUiState.collectAsStateWithLifecycle()
val refreshState by viewModel.isRefreshing.collectAsStateWithLifecycle()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ import kotlin.math.roundToInt

@Composable
fun SignatureScreen(
clientId: Int,
onBackPressed: () -> Unit
) {

val viewmodel: SignatureViewModel = hiltViewModel()
val clientId by viewmodel.clientId.collectAsStateWithLifecycle()
val state by viewmodel.signatureUiState.collectAsStateWithLifecycle()
val context = LocalContext.current

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mifos.feature.client.clientSignature

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.CreateDocumentUseCase
import com.mifos.feature.client.R
Expand All @@ -18,9 +20,12 @@ import javax.inject.Inject

@HiltViewModel
class SignatureViewModel @Inject constructor(
private val createDocumentUseCase: CreateDocumentUseCase
private val createDocumentUseCase: CreateDocumentUseCase,
private val savedStateHandle: SavedStateHandle
) : ViewModel() {

val clientId = savedStateHandle.getStateFlow(key = Constants.CLIENT_ID, initialValue = 0)

private val _signatureUiState = MutableStateFlow<SignatureUiState>(SignatureUiState.Initial)
val signatureUiState = _signatureUiState.asStateFlow()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ import java.util.Date
fun SurveyQuestionScreen(
viewModel: SurveySubmitViewModel = hiltViewModel(),
navigateBack: () -> Unit,
survey: Survey?,
clientId: Int = 1
survey: Survey?
) {
val context = LocalContext.current
val uiState by viewModel.surveySubmitUiState.collectAsStateWithLifecycle()
val clientId by viewModel.clientId.collectAsStateWithLifecycle()
val userId by viewModel.userId.collectAsStateWithLifecycle()
val questionData: MutableList<String> = mutableListOf()
val optionsData: MutableList<MutableList<String>> = mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mifos.feature.client.clientSurveySubmit

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import com.mifos.core.common.utils.Constants
import com.mifos.core.data.repository.SurveySubmitRepository
import com.mifos.core.datastore.PrefManager
import com.mifos.core.objects.survey.Scorecard
Expand All @@ -18,9 +20,12 @@ import javax.inject.Inject
@HiltViewModel
class SurveySubmitViewModel @Inject constructor(
private val repository: SurveySubmitRepository,
private val prefManager: PrefManager
private val prefManager: PrefManager,
private val savedStateHandle: SavedStateHandle
) : ViewModel() {

val clientId = savedStateHandle.getStateFlow(key = Constants.CLIENT_ID, initialValue = -1)

private val _surveySubmitUiState =
MutableStateFlow<SurveySubmitUiState>(SurveySubmitUiState.Initial)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.mifos.core.objects.client.Client
import com.mifos.feature.client.clientList.presentation.ClientListScreen

/**
Expand All @@ -19,14 +20,14 @@ fun NavGraphBuilder.clientListScreen(
paddingValues: PaddingValues,
createNewClient : () -> Unit,
syncClicked : () -> Unit,
onClientSelect : () -> Unit
onClientSelect : (Int) -> Unit
) {
composable(CLIENT_LIST_SCREEN_ROUTE) {
ClientListScreen(
paddingValues = paddingValues,
createNewClient = { },
syncClicked = { },
onClientSelect = { }
onClientSelect = onClientSelect
)
}
}
Loading
Loading