Skip to content

Commit

Permalink
refactor: refactor client screen to screen module (openMF#2178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 authored Aug 5, 2024
1 parent a2f9acf commit 200beab
Show file tree
Hide file tree
Showing 37 changed files with 93 additions and 1,740 deletions.
12 changes: 10 additions & 2 deletions core/data/src/main/java/com/mifos/core/data/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import com.mifos.core.data.repository.ReportCategoryRepository
import com.mifos.core.data.repository.ReportDetailRepository
import com.mifos.core.data.repository.SearchRepository
import com.mifos.core.data.repository.SignatureRepository
import com.mifos.core.data.repository.SyncGroupPayloadsRepository
import com.mifos.core.data.repository.SurveyListRepository
import com.mifos.core.data.repository.SurveySubmitRepository
import com.mifos.core.data.repository_imp.ActivateRepositoryImp
import com.mifos.core.data.repository_imp.CenterDetailsRepositoryImp
import com.mifos.core.data.repository_imp.CenterListRepositoryImp
Expand Down Expand Up @@ -62,7 +63,8 @@ import com.mifos.core.data.repository_imp.ReportCategoryRepositoryImp
import com.mifos.core.data.repository_imp.ReportDetailRepositoryImp
import com.mifos.core.data.repository_imp.SearchRepositoryImp
import com.mifos.core.data.repository_imp.SignatureRepositoryImp
import com.mifos.core.data.repository_imp.SyncGroupPayloadsRepositoryImp
import com.mifos.core.data.repository_imp.SurveyListRepositoryImp
import com.mifos.core.data.repository_imp.SurveySubmitRepositoryImp
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -161,4 +163,10 @@ abstract class DataModule {

@Binds
internal abstract fun bindGenerateCollectionSheetRepository(impl: GenerateCollectionSheetRepositoryImp): GenerateCollectionSheetRepository

@Binds
internal abstract fun bindSurveyListRepository(impl: SurveyListRepositoryImp): SurveyListRepository

@Binds
internal abstract fun bindSurveySubmitRepository(impl: SurveySubmitRepositoryImp): SurveySubmitRepository
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.online.surveylist
package com.mifos.core.data.repository

import com.mifos.core.objects.survey.QuestionDatas
import com.mifos.core.objects.survey.ResponseDatas
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.online.surveysubmit
package com.mifos.core.data.repository

import com.mifos.core.objects.survey.Scorecard
import rx.Observable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mifos.mifosxdroid.online.surveylist
package com.mifos.core.data.repository_imp

import com.mifos.core.data.repository.SurveyListRepository
import com.mifos.core.network.datamanager.DataManagerSurveys
import com.mifos.core.objects.survey.QuestionDatas
import com.mifos.core.objects.survey.ResponseDatas
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mifos.mifosxdroid.online.surveysubmit
package com.mifos.core.data.repository_imp

import com.mifos.core.data.repository.SurveySubmitRepository
import com.mifos.core.network.datamanager.DataManagerSurveys
import com.mifos.core.objects.survey.Scorecard
import rx.Observable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.online.surveylist
package com.mifos.feature.client.clientSurveyList

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
Expand All @@ -10,10 +10,8 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CardElevation
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
Expand All @@ -38,12 +36,9 @@ import com.mifos.core.designsystem.component.MifosCircularProgress
import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.designsystem.component.MifosSweetError
import com.mifos.core.designsystem.icon.MifosIcons
import com.mifos.core.designsystem.theme.BluePrimary
import com.mifos.core.objects.survey.Survey
import com.mifos.core.ui.components.MifosEmptyUi
import com.mifos.mifosxdroid.R
import com.mifos.mifosxdroid.online.datatable.DataTablePreviewProvider
import com.mifos.mifosxdroid.online.datatable.DataTableUiState
import com.mifos.feature.client.R

/**
* Created by Pronay Sarker on 03/07/2024 (6:05 AM)
Expand All @@ -54,7 +49,6 @@ fun SurveyListScreen(
viewModel: SurveyListViewModel = hiltViewModel(),
navigateBack: () -> Unit,
onCardClicked: (index: Int, surveys: List<Survey>) -> Unit

) {
val uiState by viewModel.surveyListUiState.collectAsStateWithLifecycle()

Expand Down Expand Up @@ -85,14 +79,14 @@ fun SurveyListScreen(
snackbarHostState = snackbarHostState,
icon = MifosIcons.arrowBack,
onBackPressed = navigateBack,
title = stringResource(id = R.string.surveys)
title = stringResource(id = R.string.feature_client_surveys)
) {
Box(modifier = Modifier.padding(it)) {
when (uiState) {

is SurveyListUiState.ShowAllSurvey -> {
if (uiState.syncSurvey.isEmpty()) {
MifosEmptyUi(text = stringResource(id = R.string.no_survey_available_for_client))
MifosEmptyUi(text = stringResource(id = R.string.feature_client_no_survey_available_for_client))
} else {
SurveyListContent(
surveyList = uiState.syncSurvey,
Expand Down Expand Up @@ -128,7 +122,7 @@ fun SurveyListContent(
modifier = Modifier
.padding(horizontal = 18.dp)
.padding(top = 16.dp, bottom = 8.dp),
text = stringResource(id = R.string.select_one_survey),
text = stringResource(id = R.string.feature_client_select_one_survey),
style = TextStyle(
fontSize = 20.sp,
fontWeight = FontWeight.Normal,
Expand Down Expand Up @@ -207,7 +201,7 @@ class SurveyListPreviewProvider : PreviewParameterProvider<SurveyListUiState> {
override val values: Sequence<SurveyListUiState>
get() = sequenceOf(
SurveyListUiState.ShowProgressbar,
SurveyListUiState.ShowFetchingError(R.string.failed_to_fetch_datatable),
SurveyListUiState.ShowFetchingError(R.string.feature_client_failed_to_fetch_datatable),
SurveyListUiState.ShowAllSurvey(demoSurvey)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.online.surveylist
package com.mifos.feature.client.clientSurveyList

import com.mifos.core.objects.survey.Survey

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.mifos.mifosxdroid.online.surveylist
package com.mifos.feature.client.clientSurveyList

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.mifos.core.data.repository.SurveyListRepository
import com.mifos.core.datastore.PrefManager
import com.mifos.core.objects.survey.QuestionDatas
import com.mifos.core.objects.survey.ResponseDatas
import com.mifos.core.objects.survey.Survey
import com.mifos.mifosxdroid.R
import com.mifos.utils.PrefManager
import com.mifos.feature.client.R
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -20,10 +19,13 @@ import javax.inject.Inject
* Created by Aditya Gupta on 08/08/23.
*/
@HiltViewModel
class SurveyListViewModel @Inject constructor(private val repository: SurveyListRepository) :
ViewModel() {
class SurveyListViewModel @Inject constructor(
private val repository: SurveyListRepository,
private val prefManager: PrefManager
) : ViewModel() {

private val _surveyListUiState = MutableStateFlow<SurveyListUiState>(SurveyListUiState.ShowProgressbar)
private val _surveyListUiState =
MutableStateFlow<SurveyListUiState>(SurveyListUiState.ShowProgressbar)
val surveyListUiState: StateFlow<SurveyListUiState> get() = _surveyListUiState


Expand All @@ -41,7 +43,7 @@ class SurveyListViewModel @Inject constructor(private val repository: SurveyList
override fun onCompleted() {}
override fun onError(e: Throwable) {
_surveyListUiState.value =
SurveyListUiState.ShowFetchingError(R.string.failed_to_fetch_surveys_list)
SurveyListUiState.ShowFetchingError(R.string.feature_client_failed_to_fetch_surveys_list)
}

override fun onNext(surveys: List<Survey>) {
Expand All @@ -64,12 +66,12 @@ class SurveyListViewModel @Inject constructor(private val repository: SurveyList

override fun onError(e: Throwable) {
_surveyListUiState.value =
SurveyListUiState.ShowFetchingError(R.string.failed_to_load_db_surveys)
SurveyListUiState.ShowFetchingError(R.string.feature_client_failed_to_fetch_datatable)
}

override fun onNext(surveyList: List<Survey>) {
mDbSurveyList = surveyList
if (PrefManager.userStatus) {
if (prefManager.userStatus) {
for (survey in mSyncSurveyList) {
loadDatabaseQuestionData(survey.id, survey)
}
Expand All @@ -88,7 +90,7 @@ class SurveyListViewModel @Inject constructor(private val repository: SurveyList
override fun onCompleted() {}
override fun onError(e: Throwable) {
_surveyListUiState.value =
SurveyListUiState.ShowFetchingError(R.string.failed_to_load_db_question_datas)
SurveyListUiState.ShowFetchingError(R.string.feature_client_failed_to_load_db_question_data)
}

override fun onNext(questionDatasList: List<QuestionDatas>) {
Expand All @@ -110,7 +112,7 @@ class SurveyListViewModel @Inject constructor(private val repository: SurveyList
override fun onCompleted() {}
override fun onError(e: Throwable) {
_surveyListUiState.value =
SurveyListUiState.ShowFetchingError(R.string.failed_to_load_db_response_datas)
SurveyListUiState.ShowFetchingError(R.string.feature_client_failed_to_load_db_question_data)
}

override fun onNext(responseDatas: List<ResponseDatas>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.mifos.mifosxdroid.online.surveyquestion
package com.mifos.feature.client.clientSurveyQuestion

import android.annotation.SuppressLint
import android.widget.Toast
import androidx.compose.runtime.Composable
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
Expand All @@ -29,6 +28,7 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
Expand All @@ -40,7 +40,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
Expand All @@ -60,11 +59,10 @@ import com.mifos.core.designsystem.theme.White
import com.mifos.core.objects.survey.Scorecard
import com.mifos.core.objects.survey.ScorecardValues
import com.mifos.core.objects.survey.Survey
import com.mifos.mifosxdroid.R
import com.mifos.mifosxdroid.online.surveysubmit.SurveySubmitScreen
import com.mifos.mifosxdroid.online.surveysubmit.SurveySubmitUiState
import com.mifos.mifosxdroid.online.surveysubmit.SurveySubmitViewModel
import com.mifos.utils.PrefManager
import com.mifos.feature.client.R
import com.mifos.feature.client.clientSurveySubmit.SurveySubmitScreen
import com.mifos.feature.client.clientSurveySubmit.SurveySubmitUiState
import com.mifos.feature.client.clientSurveySubmit.SurveySubmitViewModel
import java.util.Date


Expand All @@ -78,6 +76,7 @@ fun SurveyQuestionScreen(
) {
val context = LocalContext.current
val uiState by viewModel.surveySubmitUiState.collectAsStateWithLifecycle()
val userId by viewModel.userId.collectAsStateWithLifecycle()
val questionData: MutableList<String> = mutableListOf()
val optionsData: MutableList<MutableList<String>> = mutableListOf()
val scoreCardData: MutableList<ScorecardValues> by rememberSaveable {
Expand Down Expand Up @@ -132,7 +131,7 @@ fun SurveyQuestionScreen(
survey = survey.id,
scorecardPayload =
Scorecard(
userId = PrefManager.getUserId(),
userId = userId,
clientId = clientId,
createdOn = Date(),
scorecardValues = scoreCardData
Expand All @@ -141,7 +140,7 @@ fun SurveyQuestionScreen(
} else {
Toast.makeText(
context,
context.getString(R.string.please_attempt_atleast_one_question),
context.getString(R.string.feature_client_please_attempt_at_least_one_question),
Toast.LENGTH_SHORT
).show()
}
Expand Down Expand Up @@ -225,7 +224,7 @@ fun SurveyQuestionContent(
Column(
modifier = Modifier
.fillMaxWidth()
.background(colorResource(id = R.color.primary))
.background(BluePrimary)
.padding(24.dp)
) {
Text(
Expand Down Expand Up @@ -266,7 +265,7 @@ fun SurveyQuestionContent(
disabledContentColor = White
),
) {
Text(text = stringResource(id = R.string.next))
Text(text = stringResource(id = R.string.feature_client_next))
}
}
}
Expand All @@ -281,7 +280,7 @@ fun RadioGroup(options: List<String>, selectedOptionIndex: Int, onOptionSelected
RadioButton(
selected = index == selectedOptionIndex,
onClick = { onOptionSelected(index) },
colors = RadioButtonDefaults.colors(selectedColor = colorResource(id = R.color.primary))
colors = RadioButtonDefaults.colors(BluePrimary)
)
Text(
text = option,
Expand Down Expand Up @@ -316,7 +315,7 @@ fun SurveyQuestionTopBar(
title = {
Column {
Text(
text = stringResource(id = R.string.survey),
text = stringResource(id = R.string.feature_client_survey),
style = TextStyle(
fontSize = 20.sp,
fontWeight = FontWeight.Medium,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.online.surveysubmit
package com.mifos.feature.client.clientSurveySubmit

import android.widget.Toast
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -32,7 +32,7 @@ import com.mifos.core.designsystem.component.MifosCircularProgress
import com.mifos.core.designsystem.theme.BluePrimary
import com.mifos.core.designsystem.theme.White
import com.mifos.core.objects.survey.Scorecard
import com.mifos.mifosxdroid.R
import com.mifos.feature.client.R


@Composable
Expand All @@ -57,13 +57,14 @@ fun SurveySubmitScreen(

SurveySubmitContent(
showButton = false,
displayText = stringResource(id = R.string.survey_successfully_submitted),
displayText = stringResource(id = R.string.feature_client_survey_successfully_submitted),
submitSurvey = submitSurvey
)

LaunchedEffect(key1 = true) {
Toast.makeText(
context, context.getString(R.string.scorecard_created_successfully),
context,
context.getString(R.string.feature_client_scorecard_created_successfully),
Toast.LENGTH_LONG
).show()
}
Expand All @@ -72,7 +73,7 @@ fun SurveySubmitScreen(
is SurveySubmitUiState.ShowError -> {
SurveySubmitContent(
showButton = false,
displayText = stringResource(id = R.string.error_submitting_survey),
displayText = stringResource(id = R.string.feature_client_failed_to_submit_survey),
submitSurvey = submitSurvey
)
LaunchedEffect(key1 = true) {
Expand All @@ -86,7 +87,7 @@ fun SurveySubmitScreen(
SurveySubmitUiState.ShowProgressbar -> {
SurveySubmitContent(
showButton = false,
displayText = stringResource(id = R.string.survey_successfully_submitted),
displayText = stringResource(id = R.string.feature_client_survey_successfully_submitted),
submitSurvey = submitSurvey
)
MifosCircularProgress()
Expand Down Expand Up @@ -156,7 +157,7 @@ fun SurveySubmitContent(
disabledContentColor = White
),
) {
Text(text = stringResource(id = R.string.submit_survey))
Text(text = stringResource(id = R.string.feature_client_submit_survey))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.online.surveysubmit
package com.mifos.feature.client.clientSurveySubmit

import com.mifos.core.objects.survey.Scorecard

Expand All @@ -7,9 +7,9 @@ import com.mifos.core.objects.survey.Scorecard
*/
sealed class SurveySubmitUiState {

object Initial : SurveySubmitUiState()
data object Initial : SurveySubmitUiState()

object ShowProgressbar : SurveySubmitUiState()
data object ShowProgressbar : SurveySubmitUiState()

data class ShowError(val message: String) : SurveySubmitUiState()

Expand Down
Loading

0 comments on commit 200beab

Please sign in to comment.