Skip to content

Commit

Permalink
feat: compose nav implementation in client module
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 committed Aug 13, 2024
1 parent a0a26a5 commit 37e04dc
Show file tree
Hide file tree
Showing 19 changed files with 263 additions and 54 deletions.
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 @@ -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 @@ -233,7 +233,7 @@ fun LazyColumnForClientListApi(
clientPagingList: LazyPagingItems<Client>,
isInSelectionMode: MutableState<Boolean>,
selectedItems: SnapshotStateList<Client>,
failedRefresh : () ->Unit,
failedRefresh: () -> Unit,
onClientSelect: (Int) -> Unit
) {

Expand Down Expand Up @@ -270,7 +270,7 @@ fun LazyColumnForClientListApi(
LightGray
}
} else {
clientPagingList[index]?.clientId?.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
Loading

0 comments on commit 37e04dc

Please sign in to comment.