From 200beaba6062325bf80871ba2def6e8f69b5d4d7 Mon Sep 17 00:00:00 2001 From: Aditya Gupta <94394661+Aditya-gupta99@users.noreply.github.com> Date: Tue, 6 Aug 2024 00:06:01 +0530 Subject: [PATCH] refactor: refactor client screen to screen module (#2178) --- .../java/com/mifos/core/data/di/DataModule.kt | 12 +- .../data/repository}/SurveyListRepository.kt | 2 +- .../repository}/SurveySubmitRepository.kt | 2 +- .../SurveyListRepositoryImp.kt | 3 +- .../SurveySubmitRepositoryImp.kt | 3 +- .../clientSurveyList}/SurveyListScreen.kt | 18 +- .../clientSurveyList}/SurveyListUiState.kt | 2 +- .../clientSurveyList}/SurveyListViewModel.kt | 28 +-- .../SurveyQuestionScreen.kt | 27 ++- .../clientSurveySubmit}/SurveySubmitScreen.kt | 15 +- .../SurveySubmitUiState.kt | 6 +- .../SurveySubmitViewModel.kt | 17 +- .../client/src/main/res/values/strings.xml | 13 ++ .../injection/module/RepositoryModule.kt | 43 +---- .../clientcharge/ClientChargeRepository.kt | 13 -- .../clientcharge/ClientChargeRepositoryImp.kt | 21 -- .../clientcharge/ClientChargeUiState.kt | 18 -- .../clientcharge/ClientChargeViewModel.kt | 62 ------ .../clientdetails/ClientDetailsRepository.kt | 22 --- .../ClientDetailsRepositoryImp.kt | 32 --- .../clientdetails/ClientDetailsUiState.kt | 28 --- .../clientdetails/ClientDetailsViewModel.kt | 107 ---------- .../online/clientlist/ClientListRepository.kt | 16 -- .../clientlist/ClientListRepositoryImp.kt | 22 --- .../online/clientlist/ClientListUiState.kt | 23 --- .../online/clientlist/ClientListViewModel.kt | 174 ----------------- .../online/surveylist/SurveyListFragment.kt | 11 +- .../surveylist/SurveyListFragmentOld.kt | 122 ------------ .../online/surveyquestion/Communicator.kt | 14 -- .../surveyquestion/SurveyQuestionActivity.kt | 182 ------------------ .../surveyquestion/SurveyQuestionFragment.kt | 110 ----------- .../SurveyQuestionsComposeActivity.kt | 1 + .../viewmodels/CenterListViewModelTest.kt | 163 ---------------- .../viewmodels/ClientChargeViewModelTest.kt | 126 ------------ .../viewmodels/ClientListViewModelTest.kt | 140 -------------- .../viewmodels/GroupsListViewModelTest.kt | 151 --------------- .../mifos/viewmodels/LoginViewModelTest.kt | 84 -------- 37 files changed, 93 insertions(+), 1740 deletions(-) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist => core/data/src/main/java/com/mifos/core/data/repository}/SurveyListRepository.kt (91%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit => core/data/src/main/java/com/mifos/core/data/repository}/SurveySubmitRepository.kt (82%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist => core/data/src/main/java/com/mifos/core/data/repository_imp}/SurveyListRepositoryImp.kt (90%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit => core/data/src/main/java/com/mifos/core/data/repository_imp}/SurveySubmitRepositoryImp.kt (83%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist => feature/client/src/main/java/com/mifos/feature/client/clientSurveyList}/SurveyListScreen.kt (91%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist => feature/client/src/main/java/com/mifos/feature/client/clientSurveyList}/SurveyListUiState.kt (87%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist => feature/client/src/main/java/com/mifos/feature/client/clientSurveyList}/SurveyListViewModel.kt (86%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion => feature/client/src/main/java/com/mifos/feature/client/clientSurveyQuestion}/SurveyQuestionScreen.kt (93%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit => feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit}/SurveySubmitScreen.kt (90%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit => feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit}/SurveySubmitUiState.kt (66%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit => feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit}/SurveySubmitViewModel.kt (72%) delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeRepository.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeRepositoryImp.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeUiState.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeViewModel.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsRepository.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsRepositoryImp.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsUiState.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsViewModel.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListRepository.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListRepositoryImp.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListUiState.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListViewModel.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragmentOld.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/Communicator.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionActivity.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionFragment.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/viewmodels/CenterListViewModelTest.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/viewmodels/ClientChargeViewModelTest.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/viewmodels/ClientListViewModelTest.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/viewmodels/GroupsListViewModelTest.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/viewmodels/LoginViewModelTest.kt diff --git a/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt b/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt index 94c8d6aac12..ede38c5b56d 100644 --- a/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt +++ b/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt @@ -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 @@ -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 @@ -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 } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/SurveyListRepository.kt similarity index 91% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListRepository.kt rename to core/data/src/main/java/com/mifos/core/data/repository/SurveyListRepository.kt index f67ba9af76e..913f66d452d 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/SurveyListRepository.kt @@ -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 diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/SurveySubmitRepository.kt similarity index 82% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitRepository.kt rename to core/data/src/main/java/com/mifos/core/data/repository/SurveySubmitRepository.kt index 685cc8fa953..0dc08c5b3e4 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/SurveySubmitRepository.kt @@ -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 diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repository_imp/SurveyListRepositoryImp.kt similarity index 90% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListRepositoryImp.kt rename to core/data/src/main/java/com/mifos/core/data/repository_imp/SurveyListRepositoryImp.kt index 5c45440fb34..c9995fb0e61 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository_imp/SurveyListRepositoryImp.kt @@ -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 diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repository_imp/SurveySubmitRepositoryImp.kt similarity index 83% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitRepositoryImp.kt rename to core/data/src/main/java/com/mifos/core/data/repository_imp/SurveySubmitRepositoryImp.kt index 615ee6f3567..d0d2940377d 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository_imp/SurveySubmitRepositoryImp.kt @@ -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 diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListScreen.kt b/feature/client/src/main/java/com/mifos/feature/client/clientSurveyList/SurveyListScreen.kt similarity index 91% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListScreen.kt rename to feature/client/src/main/java/com/mifos/feature/client/clientSurveyList/SurveyListScreen.kt index b2eddcc3370..541a67061ce 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListScreen.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/clientSurveyList/SurveyListScreen.kt @@ -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 @@ -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 @@ -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) @@ -54,7 +49,6 @@ fun SurveyListScreen( viewModel: SurveyListViewModel = hiltViewModel(), navigateBack: () -> Unit, onCardClicked: (index: Int, surveys: List) -> Unit - ) { val uiState by viewModel.surveyListUiState.collectAsStateWithLifecycle() @@ -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, @@ -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, @@ -207,7 +201,7 @@ class SurveyListPreviewProvider : PreviewParameterProvider { override val values: Sequence 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) ) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListUiState.kt b/feature/client/src/main/java/com/mifos/feature/client/clientSurveyList/SurveyListUiState.kt similarity index 87% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListUiState.kt rename to feature/client/src/main/java/com/mifos/feature/client/clientSurveyList/SurveyListUiState.kt index 84f236b1a59..84045ac6fc3 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListUiState.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/clientSurveyList/SurveyListUiState.kt @@ -1,4 +1,4 @@ -package com.mifos.mifosxdroid.online.surveylist +package com.mifos.feature.client.clientSurveyList import com.mifos.core.objects.survey.Survey diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListViewModel.kt b/feature/client/src/main/java/com/mifos/feature/client/clientSurveyList/SurveyListViewModel.kt similarity index 86% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListViewModel.kt rename to feature/client/src/main/java/com/mifos/feature/client/clientSurveyList/SurveyListViewModel.kt index 3b385a9b3f1..6d405914096 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListViewModel.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/clientSurveyList/SurveyListViewModel.kt @@ -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 @@ -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.ShowProgressbar) + private val _surveyListUiState = + MutableStateFlow(SurveyListUiState.ShowProgressbar) val surveyListUiState: StateFlow get() = _surveyListUiState @@ -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) { @@ -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) { mDbSurveyList = surveyList - if (PrefManager.userStatus) { + if (prefManager.userStatus) { for (survey in mSyncSurveyList) { loadDatabaseQuestionData(survey.id, survey) } @@ -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) { @@ -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) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionScreen.kt b/feature/client/src/main/java/com/mifos/feature/client/clientSurveyQuestion/SurveyQuestionScreen.kt similarity index 93% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionScreen.kt rename to feature/client/src/main/java/com/mifos/feature/client/clientSurveyQuestion/SurveyQuestionScreen.kt index 392e3cd57fa..305003277ab 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionScreen.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/clientSurveyQuestion/SurveyQuestionScreen.kt @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 = mutableListOf() val optionsData: MutableList> = mutableListOf() val scoreCardData: MutableList by rememberSaveable { @@ -132,7 +131,7 @@ fun SurveyQuestionScreen( survey = survey.id, scorecardPayload = Scorecard( - userId = PrefManager.getUserId(), + userId = userId, clientId = clientId, createdOn = Date(), scorecardValues = scoreCardData @@ -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() } @@ -225,7 +224,7 @@ fun SurveyQuestionContent( Column( modifier = Modifier .fillMaxWidth() - .background(colorResource(id = R.color.primary)) + .background(BluePrimary) .padding(24.dp) ) { Text( @@ -266,7 +265,7 @@ fun SurveyQuestionContent( disabledContentColor = White ), ) { - Text(text = stringResource(id = R.string.next)) + Text(text = stringResource(id = R.string.feature_client_next)) } } } @@ -281,7 +280,7 @@ fun RadioGroup(options: List, 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, @@ -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, diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitScreen.kt b/feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit/SurveySubmitScreen.kt similarity index 90% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitScreen.kt rename to feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit/SurveySubmitScreen.kt index 286273590d4..0fe57041f5a 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitScreen.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit/SurveySubmitScreen.kt @@ -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 @@ -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 @@ -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() } @@ -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) { @@ -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() @@ -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)) } } } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitUiState.kt b/feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit/SurveySubmitUiState.kt similarity index 66% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitUiState.kt rename to feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit/SurveySubmitUiState.kt index 9a690b8decb..47032358db4 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitUiState.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit/SurveySubmitUiState.kt @@ -1,4 +1,4 @@ -package com.mifos.mifosxdroid.online.surveysubmit +package com.mifos.feature.client.clientSurveySubmit import com.mifos.core.objects.survey.Scorecard @@ -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() diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitViewModel.kt b/feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit/SurveySubmitViewModel.kt similarity index 72% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitViewModel.kt rename to feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit/SurveySubmitViewModel.kt index c1e984397fe..ddc0b4e5f72 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveysubmit/SurveySubmitViewModel.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/clientSurveySubmit/SurveySubmitViewModel.kt @@ -1,8 +1,8 @@ -package com.mifos.mifosxdroid.online.surveysubmit +package com.mifos.feature.client.clientSurveySubmit -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import com.mifos.core.data.repository.SurveySubmitRepository +import com.mifos.core.datastore.PrefManager import com.mifos.core.objects.survey.Scorecard import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow @@ -16,14 +16,19 @@ import javax.inject.Inject * Created by Aditya Gupta on 13/08/23. */ @HiltViewModel -class SurveySubmitViewModel @Inject constructor(private val repository: SurveySubmitRepository) : - ViewModel() { +class SurveySubmitViewModel @Inject constructor( + private val repository: SurveySubmitRepository, + private val prefManager: PrefManager +) : ViewModel() { - private val _surveySubmitUiState = MutableStateFlow(SurveySubmitUiState.Initial) + private val _surveySubmitUiState = + MutableStateFlow(SurveySubmitUiState.Initial) val surveySubmitUiState: StateFlow get() = _surveySubmitUiState + val userId = MutableStateFlow(prefManager.getUserId()) + fun submitSurvey(survey: Int, scorecardPayload: Scorecard?) { _surveySubmitUiState.value = SurveySubmitUiState.ShowProgressbar repository.submitScore(survey, scorecardPayload) diff --git a/feature/client/src/main/res/values/strings.xml b/feature/client/src/main/res/values/strings.xml index f6b0e52a8f4..b01622e3edb 100644 --- a/feature/client/src/main/res/values/strings.xml +++ b/feature/client/src/main/res/values/strings.xml @@ -94,4 +94,17 @@ Reset Gallery + Surveys + No survey available for client + Select one survey + Failed to fetch datatable + Failed to fetch surveys list + Failed to load db question data + Survey successfully submitted + Failed to submit survey + Scorecard created successfully + Submit Survey + Next + Please attempt at least one question + \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt index 1f2efdf120f..51b52c039c1 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt @@ -2,8 +2,10 @@ package com.mifos.mifosxdroid.injection.module import com.mifos.core.data.repository.DocumentDialogRepository import com.mifos.core.data.repository.NoteRepository +import com.mifos.core.data.repository.SyncGroupPayloadsRepository import com.mifos.core.data.repository_imp.DocumentDialogRepositoryImp import com.mifos.core.data.repository_imp.NoteRepositoryImp +import com.mifos.core.data.repository_imp.SyncGroupPayloadsRepositoryImp import com.mifos.core.network.DataManager import com.mifos.core.network.datamanager.DataManagerAuth import com.mifos.core.network.datamanager.DataManagerCenter @@ -18,6 +20,8 @@ import com.mifos.core.network.datamanager.DataManagerOffices import com.mifos.core.network.datamanager.DataManagerSavings import com.mifos.core.network.datamanager.DataManagerStaff import com.mifos.core.network.datamanager.DataManagerSurveys +import com.mifos.feature.settings.syncSurvey.SyncSurveysDialogRepository +import com.mifos.feature.settings.syncSurvey.SyncSurveysDialogRepositoryImp import com.mifos.mifosxdroid.activity.login.LoginRepository import com.mifos.mifosxdroid.activity.login.LoginRepositoryImp import com.mifos.mifosxdroid.dialogfragments.synccenterdialog.SyncCentersDialogRepository @@ -26,16 +30,12 @@ import com.mifos.mifosxdroid.dialogfragments.syncclientsdialog.SyncClientsDialog import com.mifos.mifosxdroid.dialogfragments.syncclientsdialog.SyncClientsDialogRepositoryImp import com.mifos.mifosxdroid.dialogfragments.syncgroupsdialog.SyncGroupsDialogRepository import com.mifos.mifosxdroid.dialogfragments.syncgroupsdialog.SyncGroupsDialogRepositoryImp -import com.mifos.feature.settings.syncSurvey.SyncSurveysDialogRepository -import com.mifos.feature.settings.syncSurvey.SyncSurveysDialogRepositoryImp import com.mifos.mifosxdroid.offline.offlinedashbarod.OfflineDashboardRepository import com.mifos.mifosxdroid.offline.offlinedashbarod.OfflineDashboardRepositoryImp import com.mifos.mifosxdroid.offline.synccenterpayloads.SyncCenterPayloadsRepository import com.mifos.mifosxdroid.offline.synccenterpayloads.SyncCenterPayloadsRepositoryImp import com.mifos.mifosxdroid.offline.syncclientpayloads.SyncClientPayloadsRepository import com.mifos.mifosxdroid.offline.syncclientpayloads.SyncClientPayloadsRepositoryImp -import com.mifos.core.data.repository.SyncGroupPayloadsRepository -import com.mifos.core.data.repository_imp.SyncGroupPayloadsRepositoryImp import com.mifos.mifosxdroid.offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionRepository import com.mifos.mifosxdroid.offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionRepositoryImp import com.mifos.mifosxdroid.offline.syncsavingsaccounttransaction.SyncSavingsAccountTransactionRepository @@ -44,12 +44,6 @@ import com.mifos.mifosxdroid.online.activate.ActivateRepository import com.mifos.mifosxdroid.online.activate.ActivateRepositoryImp import com.mifos.mifosxdroid.online.centerlist.CenterListRepository import com.mifos.mifosxdroid.online.centerlist.CenterListRepositoryImp -import com.mifos.mifosxdroid.online.clientcharge.ClientChargeRepository -import com.mifos.mifosxdroid.online.clientcharge.ClientChargeRepositoryImp -import com.mifos.mifosxdroid.online.clientdetails.ClientDetailsRepository -import com.mifos.mifosxdroid.online.clientdetails.ClientDetailsRepositoryImp -import com.mifos.mifosxdroid.online.clientlist.ClientListRepository -import com.mifos.mifosxdroid.online.clientlist.ClientListRepositoryImp import com.mifos.mifosxdroid.online.collectionsheet.CollectionSheetRepository import com.mifos.mifosxdroid.online.collectionsheet.CollectionSheetRepositoryImp import com.mifos.mifosxdroid.online.createnewclient.CreateNewClientRepository @@ -84,10 +78,6 @@ import com.mifos.mifosxdroid.online.savingsaccountactivate.SavingsAccountActivat import com.mifos.mifosxdroid.online.savingsaccountactivate.SavingsAccountActivateRepositoryImp import com.mifos.mifosxdroid.online.savingsaccountapproval.SavingsAccountApprovalRepository import com.mifos.mifosxdroid.online.savingsaccountapproval.SavingsAccountApprovalRepositoryImp -import com.mifos.mifosxdroid.online.surveylist.SurveyListRepository -import com.mifos.mifosxdroid.online.surveylist.SurveyListRepositoryImp -import com.mifos.mifosxdroid.online.surveysubmit.SurveySubmitRepository -import com.mifos.mifosxdroid.online.surveysubmit.SurveySubmitRepositoryImp import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -111,11 +101,6 @@ class RepositoryModule { return CenterListRepositoryImp(dataManagerCenter) } - @Provides - fun providesClientDetailsRepository(dataManagerClient: DataManagerClient): ClientDetailsRepository { - return ClientDetailsRepositoryImp(dataManagerClient) - } - @Provides fun providesGroupDetailsRepository(dataManagerGroups: DataManagerGroups): GroupDetailsRepository { return GroupDetailsRepositoryImp(dataManagerGroups) @@ -130,21 +115,11 @@ class RepositoryModule { return ActivateRepositoryImp(dataManagerClient, dataManagerCenter, dataManagerGroups) } - @Provides - fun providesClientListRepository(dataManagerClient: DataManagerClient): ClientListRepository { - return ClientListRepositoryImp(dataManagerClient) - } - @Provides fun providesGroupsListRepository(dataManagerGroups: DataManagerGroups): GroupsListRepository { return GroupsListRepositoryImp(dataManagerGroups) } - @Provides - fun providesClientChargeRepository(dataManagerCharge: DataManagerCharge): ClientChargeRepository { - return ClientChargeRepositoryImp(dataManagerCharge) - } - @Provides fun providesLoanAccountSummary(dataManagerLoan: DataManagerLoan): LoanAccountSummaryRepository { return LoanAccountSummaryRepositoryImp(dataManagerLoan) @@ -171,11 +146,6 @@ class RepositoryModule { return SavingsAccountRepositoryImp(dataManagerSavings) } - @Provides - fun providesSurveyListRepository(dataManagerSurveys: DataManagerSurveys): SurveyListRepository { - return SurveyListRepositoryImp(dataManagerSurveys) - } - @Provides fun providesLoanAccountApprovalRepository(dataManager: DataManager): LoanAccountApprovalRepository { return LoanAccountApprovalRepositoryImp(dataManager) @@ -240,11 +210,6 @@ class RepositoryModule { return SavingsAccountApprovalRepositoryImp(dataManagerSavings) } - @Provides - fun providesSurveySubmitRepository(dataManagerSurveys: DataManagerSurveys): SurveySubmitRepository { - return SurveySubmitRepositoryImp(dataManagerSurveys) - } - @Provides fun providesDocumentDialogRepository(dataManagerDocument: DataManagerDocument): DocumentDialogRepository { return DocumentDialogRepositoryImp(dataManagerDocument) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeRepository.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeRepository.kt deleted file mode 100644 index 89e446c88f7..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeRepository.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.mifos.mifosxdroid.online.clientcharge - -import com.mifos.core.objects.client.Charges -import com.mifos.core.objects.client.Page -import rx.Observable - -/** - * Created by Aditya Gupta on 08/08/23. - */ -interface ClientChargeRepository { - - fun getClientCharges(clientId: Int, offset: Int, limit: Int): Observable> -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeRepositoryImp.kt deleted file mode 100644 index bc88ade833b..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeRepositoryImp.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.mifos.mifosxdroid.online.clientcharge - -import com.mifos.core.network.datamanager.DataManagerCharge -import com.mifos.core.objects.client.Charges -import com.mifos.core.objects.client.Page -import rx.Observable -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 08/08/23. - */ -class ClientChargeRepositoryImp @Inject constructor(private val dataManagerCharge: DataManagerCharge) : - ClientChargeRepository { - override fun getClientCharges( - clientId: Int, - offset: Int, - limit: Int - ): Observable> { - return dataManagerCharge.getClientCharges(clientId, offset, limit) - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeUiState.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeUiState.kt deleted file mode 100644 index d41958f19ee..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeUiState.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.mifos.mifosxdroid.online.clientcharge - -import com.mifos.core.objects.client.Charges -import com.mifos.core.objects.client.Page - -/** - * Created by Aditya Gupta on 08/08/23. - */ -sealed class ClientChargeUiState { - - data object ShowProgressbar : ClientChargeUiState() - - data class ShowFetchingErrorCharges(val message: String) : ClientChargeUiState() - - data class ShowChargesList(val chargesPage: Page) : ClientChargeUiState() - - data object ShowEmptyCharges : ClientChargeUiState() -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeViewModel.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeViewModel.kt deleted file mode 100644 index 7c505fcc1a9..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeViewModel.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.mifos.mifosxdroid.online.clientcharge - -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import com.mifos.core.objects.client.Charges -import com.mifos.core.objects.client.Page -import dagger.hilt.android.lifecycle.HiltViewModel -import retrofit2.HttpException -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.plugins.RxJavaPlugins -import rx.schedulers.Schedulers -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 08/08/23. - */ -@HiltViewModel -class ClientChargeViewModel @Inject constructor(private val repository: ClientChargeRepository) : - ViewModel() { - - private val _clientChargeUiState = MutableLiveData() - - val clientChargeUiState: LiveData - get() = _clientChargeUiState - - fun loadCharges(clientId: Int, offset: Int, limit: Int) { - _clientChargeUiState.value = ClientChargeUiState.ShowProgressbar - repository.getClientCharges(clientId, offset, limit) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - try { - if (e is HttpException) { - val errorMessage = e.response()?.errorBody()?.string() - _clientChargeUiState.value = errorMessage?.let { - ClientChargeUiState.ShowFetchingErrorCharges( - it - ) - } - } - } catch (throwable: Throwable) { - RxJavaPlugins.getInstance().errorHandler.handleError(e) - } - } - - override fun onNext(chargesPage: Page) { - if (chargesPage.pageItems.isNotEmpty()) { - _clientChargeUiState.value = - ClientChargeUiState.ShowChargesList(chargesPage) - } else { - _clientChargeUiState.value = ClientChargeUiState.ShowEmptyCharges - } - } - }) - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsRepository.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsRepository.kt deleted file mode 100644 index c103dc0e1da..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsRepository.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.mifos.mifosxdroid.online.clientdetails - -import com.mifos.core.objects.accounts.ClientAccounts -import com.mifos.core.objects.client.Client -import okhttp3.MultipartBody -import okhttp3.ResponseBody -import rx.Observable - -/** - * Created by Aditya Gupta on 06/08/23. - */ -interface ClientDetailsRepository { - - fun uploadClientImage(id: Int, file: MultipartBody.Part?): Observable - - fun deleteClientImage(clientId: Int): Observable - - fun getClientAccounts(clientId: Int): Observable - - fun getClient(clientId: Int): Observable - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsRepositoryImp.kt deleted file mode 100644 index 544df5f328b..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsRepositoryImp.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.mifos.mifosxdroid.online.clientdetails - -import com.mifos.core.network.datamanager.DataManagerClient -import com.mifos.core.objects.accounts.ClientAccounts -import com.mifos.core.objects.client.Client -import okhttp3.MultipartBody -import okhttp3.ResponseBody -import rx.Observable -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 06/08/23. - */ -class ClientDetailsRepositoryImp @Inject constructor(private val dataManagerClient: DataManagerClient) : - ClientDetailsRepository { - override fun uploadClientImage(id: Int, file: MultipartBody.Part?): Observable { - return dataManagerClient.uploadClientImage(id, file) - } - - override fun deleteClientImage(clientId: Int): Observable { - return dataManagerClient.deleteClientImage(clientId) - } - - override fun getClientAccounts(clientId: Int): Observable { - return dataManagerClient.getClientAccounts(clientId) - } - - override fun getClient(clientId: Int): Observable { - return dataManagerClient.getClient(clientId) - } - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsUiState.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsUiState.kt deleted file mode 100644 index 0346f19f3de..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsUiState.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.mifos.mifosxdroid.online.clientdetails - -import com.mifos.core.objects.accounts.ClientAccounts -import com.mifos.core.objects.client.Client -import okhttp3.ResponseBody - -/** - * Created by Aditya Gupta on 06/08/23. - */ -sealed class ClientDetailsUiState { - - data class ShowUploadImageProgressbar(val state: Boolean) : ClientDetailsUiState() - - data class ShowUploadImageFailed(val message: String) : ClientDetailsUiState() - - data class ShowUploadImageSuccessfully(val response: ResponseBody?, val imagePath: String?) : - ClientDetailsUiState() - - data class ShowFetchingError(val message: String) : ClientDetailsUiState() - - object ShowClientImageDeletedSuccessfully : ClientDetailsUiState() - - data class ShowProgressbar(val boolean: Boolean) : ClientDetailsUiState() - - data class ShowClientAccount(val clientAccounts: ClientAccounts) : ClientDetailsUiState() - - data class ShowClientInformation(val client: Client) : ClientDetailsUiState() -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsViewModel.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsViewModel.kt deleted file mode 100644 index 9b3ec667157..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsViewModel.kt +++ /dev/null @@ -1,107 +0,0 @@ -package com.mifos.mifosxdroid.online.clientdetails - -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import com.mifos.core.objects.zipmodels.ClientAndClientAccounts -import dagger.hilt.android.lifecycle.HiltViewModel -import okhttp3.MediaType.Companion.toMediaTypeOrNull -import okhttp3.MultipartBody -import okhttp3.RequestBody.Companion.asRequestBody -import okhttp3.ResponseBody -import rx.Observable -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import java.io.File -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 06/08/23. - */ -@HiltViewModel -class ClientDetailsViewModel @Inject constructor(private val repository: ClientDetailsRepository) : - ViewModel() { - - private val _clientDetailsUiState = MutableLiveData() - - val clientDetailsUiState: LiveData - get() = _clientDetailsUiState - - fun uploadImage(id: Int, pngFile: File) { - val imagePath = pngFile.absolutePath - val requestFile = pngFile.asRequestBody("image/png".toMediaTypeOrNull()) - val body = MultipartBody.Part.createFormData("file", pngFile.name, requestFile) - _clientDetailsUiState.value = ClientDetailsUiState.ShowUploadImageProgressbar(true) - repository.uploadClientImage(id, body) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - _clientDetailsUiState.value = - ClientDetailsUiState.ShowUploadImageFailed("Unable to update image") - } - - override fun onNext(response: ResponseBody?) { - _clientDetailsUiState.value = - ClientDetailsUiState.ShowUploadImageSuccessfully(response, imagePath) - } - }) - } - - fun deleteClientImage(clientId: Int) { - repository.deleteClientImage(clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - _clientDetailsUiState.value = - ClientDetailsUiState.ShowFetchingError("Failed to delete image") - } - - override fun onNext(response: ResponseBody?) { - _clientDetailsUiState.value = - ClientDetailsUiState.ShowClientImageDeletedSuccessfully - } - }) - } - - fun loadClientDetailsAndClientAccounts(clientId: Int) { - _clientDetailsUiState.value = ClientDetailsUiState.ShowProgressbar(true) - Observable.zip( - repository.getClientAccounts(clientId), - repository.getClient(clientId) - ) { clientAccounts, client -> - val clientAndClientAccounts = ClientAndClientAccounts() - clientAndClientAccounts.client = client - clientAndClientAccounts.clientAccounts = clientAccounts - clientAndClientAccounts - } - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - _clientDetailsUiState.value = - ClientDetailsUiState.ShowFetchingError("Client not found") - } - - override fun onNext(clientAndClientAccounts: ClientAndClientAccounts) { - _clientDetailsUiState.value = clientAndClientAccounts.clientAccounts?.let { - ClientDetailsUiState.ShowClientAccount( - it - ) - } - _clientDetailsUiState.value = clientAndClientAccounts.client?.let { - ClientDetailsUiState.ShowClientInformation( - it - ) - } - } - }) - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListRepository.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListRepository.kt deleted file mode 100644 index 4476e78ac46..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListRepository.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.mifos.mifosxdroid.online.clientlist - -import com.mifos.core.objects.client.Client -import com.mifos.core.objects.client.Page -import rx.Observable - -/** - * Created by Aditya Gupta on 08/08/23. - */ -interface ClientListRepository { - - fun getAllClients(offset: Int, limit: Int): Observable> - - fun allDatabaseClients(): Observable> - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListRepositoryImp.kt deleted file mode 100644 index 00d2a7ee82a..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListRepositoryImp.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.mifos.mifosxdroid.online.clientlist - -import com.mifos.core.network.datamanager.DataManagerClient -import com.mifos.core.objects.client.Client -import com.mifos.core.objects.client.Page -import rx.Observable -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 08/08/23. - */ -class ClientListRepositoryImp @Inject constructor(private val dataManagerClient: DataManagerClient) : - ClientListRepository { - - override fun getAllClients(offset: Int, limit: Int): Observable> { - return dataManagerClient.getAllClients(offset, limit) - } - - override fun allDatabaseClients(): Observable> { - return dataManagerClient.allDatabaseClients - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListUiState.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListUiState.kt deleted file mode 100644 index b302760e4c9..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListUiState.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.mifos.mifosxdroid.online.clientlist - -import com.mifos.core.objects.client.Client - -/** - * Created by Aditya Gupta on 08/08/23. - */ -sealed class ClientListUiState { - - data class ShowProgressbar(val state: Boolean) : ClientListUiState() - - data class ShowMessage(val message: Int) : ClientListUiState() - - data object ShowError : ClientListUiState() - - data object UnregisterSwipeAndScrollListener : ClientListUiState() - - data class ShowEmptyClientList(val message: Int) : ClientListUiState() - - data class ShowLoadMoreClients(val clients: List) : ClientListUiState() - - data class ShowClientList(val clients: List) : ClientListUiState() -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListViewModel.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListViewModel.kt deleted file mode 100644 index e7f6ed2482c..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListViewModel.kt +++ /dev/null @@ -1,174 +0,0 @@ -package com.mifos.mifosxdroid.online.clientlist - -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import com.mifos.core.objects.client.Client -import com.mifos.core.objects.client.Page -import com.mifos.mifosxdroid.R -import dagger.hilt.android.lifecycle.HiltViewModel -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 08/08/23. - */ -@HiltViewModel -class ClientListViewModel @Inject constructor(private val repository: ClientListRepository) : - ViewModel() { - - private val _clientListUiState = MutableLiveData() - - val clientListUiState: LiveData - get() = _clientListUiState - - private var mDbClientList: List = ArrayList() - private var mSyncClientList: List = ArrayList() - private val limit = 100 - private var loadmore = false - private var mRestApiClientSyncStatus = false - private var mDatabaseClientSyncStatus = false - - - /** - * Loading Client List from Rest API and setting loadmore status - * - * @param loadmore Status, need ClientList page other then first. - * @param offset Index from Where ClientList will be fetched. - */ - fun loadClients(loadmore: Boolean, offset: Int) { - this.loadmore = loadmore - loadClients(true, offset, limit) - } - - /** - * Showing Client List in View, If loadmore is true call showLoadMoreClients(...) and else - * call showClientList(...). - */ - private fun showClientList(clients: List) { - if (loadmore) { - _clientListUiState.value = ClientListUiState.ShowLoadMoreClients(clients) - } else { - _clientListUiState.value = ClientListUiState.ShowClientList(clients) - } - } - - /** - * This Method will called, when Parent (Fragment or Activity) will be true. - * If Parent Fragment is true there is no need to fetch ClientList, Just show the Parent - * (Fragment or Activity) ClientList in View - * - * @param clients List> - */ - fun showParentClients(clients: List?) { - _clientListUiState.value = ClientListUiState.UnregisterSwipeAndScrollListener - if (clients != null) { - if (clients.isEmpty()) { - _clientListUiState.value = ClientListUiState.ShowEmptyClientList(R.string.client) - } else { - mRestApiClientSyncStatus = true - mSyncClientList = clients - setAlreadyClientSyncStatus() - } - } - } - - /** - * Setting ClientSync Status True when mRestApiClientSyncStatus && mDatabaseClientSyncStatus - * are true. - */ - fun setAlreadyClientSyncStatus() { - if (mRestApiClientSyncStatus && mDatabaseClientSyncStatus) { - showClientList(checkClientAlreadySyncedOrNot(mSyncClientList)) - } - } - - /** - * This Method fetching Client List from Rest API. - * - * @param paged True Enabling the Pagination of the API - * @param offset Value give from which position Fetch ClientList - * @param limit Maximum size of the Center - */ - private fun loadClients(paged: Boolean, offset: Int, limit: Int) { - _clientListUiState.value = ClientListUiState.ShowProgressbar(true) - repository.getAllClients(offset, limit) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - if (loadmore) { - _clientListUiState.value = - ClientListUiState.ShowMessage(R.string.failed_to_load_client) - } else { - _clientListUiState.value = ClientListUiState.ShowError - } - } - - override fun onNext(clientPage: Page) { - mSyncClientList = clientPage.pageItems - if (mSyncClientList.isEmpty() && !loadmore) { - _clientListUiState.value = - ClientListUiState.ShowEmptyClientList(R.string.client) - _clientListUiState.value = - ClientListUiState.UnregisterSwipeAndScrollListener - } else if (mSyncClientList.isEmpty() && loadmore) { - _clientListUiState.value = - ClientListUiState.ShowMessage(R.string.no_more_clients_available) - } else { - mRestApiClientSyncStatus = true - setAlreadyClientSyncStatus() - } - } - }) - } - - /** - * This Method Loading the Client From Database. It request Observable to DataManagerClient - * and DataManagerClient Request to DatabaseHelperClient to load the Client List Page from the - * Client_Table and As the Client List Page is loaded DataManagerClient gives the Client List - * Page after getting response from DatabaseHelperClient - */ - fun loadDatabaseClients() { - repository.allDatabaseClients() - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - _clientListUiState.value = - ClientListUiState.ShowMessage(R.string.failed_to_load_db_clients) - } - - override fun onNext(clientPage: Page) { - mDatabaseClientSyncStatus = true - mDbClientList = clientPage.pageItems - setAlreadyClientSyncStatus() - } - }) - } - - /** - * This Method Filtering the Clients Loaded from Server is already sync or not. If yes the - * put the client.setSync(true) and view will show those clients as sync already to user - * - * @param - * @return Page - */ - private fun checkClientAlreadySyncedOrNot(clients: List): List { - if (mDbClientList.isNotEmpty()) { - for (dbClient in mDbClientList) { - for (syncClient in clients) { - if (dbClient.id == syncClient.id) { - syncClient.sync = true - break - } - } - } - } - return clients - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragment.kt index d2e84a09d62..8362a5735d5 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragment.kt @@ -11,20 +11,14 @@ import android.view.LayoutInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup -import android.widget.AdapterView import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.lifecycle.ViewModelProvider import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.mifos.core.objects.survey.Survey +import com.mifos.feature.client.clientSurveyList.SurveyListScreen import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.adapters.SurveyListAdapter import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.core.ProgressableFragment -import com.mifos.mifosxdroid.core.util.Toaster -import com.mifos.mifosxdroid.databinding.FragmentSurveyListBinding -import com.mifos.mifosxdroid.online.datatable.DataTableScreen import dagger.hilt.android.AndroidEntryPoint /** @@ -37,7 +31,6 @@ import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class SurveyListFragment : MifosBaseFragment() { - private lateinit var binding: FragmentSurveyListBinding private val arg: SurveyListFragmentArgs by navArgs() private var mListener: OnFragmentInteractionListener? = null @@ -83,7 +76,7 @@ class SurveyListFragment : MifosBaseFragment() { super.onStop() toolbar?.visibility = View.VISIBLE } - + override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == R.id.mItem_search) requireActivity().finish() return super.onOptionsItemSelected(item) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragmentOld.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragmentOld.kt deleted file mode 100644 index 6a45cfc8f49..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragmentOld.kt +++ /dev/null @@ -1,122 +0,0 @@ -///* -// * This project is licensed under the open source MPL V2. -// * See https://github.com/openMF/android-client/blob/master/LICENSE.md -// */ -//package com.mifos.mifosxdroid.online.surveylist -// -//import android.app.Activity -//import android.content.Context -//import android.os.Bundle -//import android.view.LayoutInflater -//import android.view.MenuItem -//import android.view.View -//import android.view.ViewGroup -//import android.widget.AdapterView -//import androidx.lifecycle.ViewModelProvider -//import androidx.navigation.fragment.navArgs -//import com.mifos.core.objects.survey.Survey -//import com.mifos.mifosxdroid.R -//import com.mifos.mifosxdroid.adapters.SurveyListAdapter -//import com.mifos.mifosxdroid.core.ProgressableFragment -//import com.mifos.mifosxdroid.core.util.Toaster -//import com.mifos.mifosxdroid.databinding.FragmentSurveyListBinding -//import dagger.hilt.android.AndroidEntryPoint -// -///** -// * This Class shows the List of Surveys after fetching the surveys list from the REST API : -// * https://demo.openmf.org/fineract-provider/api/v1/surveys -// * -// * -// * Created by Nasim Banu on 27,January,2016. -// */ -//@AndroidEntryPoint -//class SurveyListFragment : ProgressableFragment() { -// -// private lateinit var binding: FragmentSurveyListBinding -// private val arg: SurveyListFragmentArgs by navArgs() -// -// private lateinit var viewModel: SurveyListViewModel -// -// private var mListener: OnFragmentInteractionListener? = null -// private var clientId = 0 -// override fun onCreate(savedInstanceState: Bundle?) { -// super.onCreate(savedInstanceState) -// clientId = arg.clientId -// } -// -// override fun onCreateView( -// inflater: LayoutInflater, -// container: ViewGroup?, -// savedInstanceState: Bundle? -// ): View { -// binding = FragmentSurveyListBinding.inflate(inflater, container, false) -// viewModel = ViewModelProvider(this)[SurveyListViewModel::class.java] -// setToolbarTitle(getString(R.string.surveys)) -// viewModel.loadSurveyList() -// -// viewModel.surveyListUiState.observe(viewLifecycleOwner) { -// when (it) { -// is SurveyListUiState.ShowAllSurvey -> { -// showProgressbar(false) -// showAllSurvey(it.syncSurvey) -// } -// -// is SurveyListUiState.ShowFetchingError -> { -// showProgressbar(false) -// showFetchingError(it.message) -// } -// -// is SurveyListUiState.ShowProgressbar -> showProgressbar(true) -// } -// } -// -// return binding.root -// } -// -// private fun showAllSurvey(surveys: List) { -// if (surveys.isEmpty()) { -// binding.tvSurveyName.text = -// resources.getString(R.string.no_survey_available_for_client) -// } else { -// val surveyListAdapter = SurveyListAdapter(requireActivity(), surveys) -// binding.lvSurveysList.adapter = surveyListAdapter -// binding.lvSurveysList.onItemClickListener = -// AdapterView.OnItemClickListener { adapterView, view, position, l -> -// mListener?.loadSurveyQuestion( -// surveys[position], -// clientId -// ) -// } -// } -// } -// -// private fun showFetchingError(errorMessage: Int) { -// Toaster.show(binding.root, resources.getString(errorMessage)) -// } -// -// private fun showProgressbar(b: Boolean) { -// showProgress(b) -// } -// -// override fun onOptionsItemSelected(item: MenuItem): Boolean { -// if (item.itemId == R.id.mItem_search) requireActivity().finish() -// return super.onOptionsItemSelected(item) -// } -// -// override fun onAttach(context: Context) { -// super.onAttach(context) -// val activity = if (context is Activity) context else null -// mListener = try { -// activity as OnFragmentInteractionListener? -// } catch (e: ClassCastException) { -// throw ClassCastException( -// activity.toString() + " must implement " + -// "OnFragmentInteractionListener" -// ) -// } -// } -// -// interface OnFragmentInteractionListener { -// fun loadSurveyQuestion(survey: Survey?, clientId: Int) -// } -//} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/Communicator.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/Communicator.kt deleted file mode 100644 index fead585f6e7..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/Communicator.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.mifosxdroid.online.surveyquestion - -import com.mifos.core.objects.survey.Scorecard - -/** - * Created by Nasim Banu on 28,January,2016. - */ -interface Communicator { - fun passScoreCardData(scorecard: Scorecard, surveyid: Int) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionActivity.kt deleted file mode 100644 index 162f2bc5c40..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionActivity.kt +++ /dev/null @@ -1,182 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.mifosxdroid.online.surveyquestion - -/* -import android.os.Bundle -import android.util.Log -import android.view.View -import androidx.fragment.app.Fragment -import androidx.viewpager.widget.PagerAdapter -import androidx.viewpager.widget.ViewPager.OnPageChangeListener -import com.google.gson.Gson -import com.mifos.core.common.utils.Constants -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.adapters.SurveyPagerAdapter -import com.mifos.mifosxdroid.core.MifosBaseActivity -import com.mifos.mifosxdroid.databinding.ActivitySurveyQuestionBinding -import com.mifos.mifosxdroid.online.surveyquestion.SurveyQuestionFragment.OnAnswerSelectedListener -import com.mifos.mifosxdroid.online.surveysubmit.SurveySubmitFragment.Companion.newInstance -import com.mifos.mifosxdroid.online.surveysubmit.SurveySubmitFragment.DisableSwipe -import com.mifos.utils.PrefManager -import dagger.hilt.android.AndroidEntryPoint -import java.util.Date -import java.util.Vector - -/** - * Created by Nasim Banu on 28,January,2016. - */ -@AndroidEntryPoint -class SurveyQuestionActivity : MifosBaseActivity(), OnAnswerSelectedListener, DisableSwipe, - OnPageChangeListener { - - private lateinit var binding: ActivitySurveyQuestionBinding - - private val fragments: MutableList = Vector() - private val listScorecardValues: MutableList = ArrayList() - private var survey: Survey? = null - private val mScorecard = Scorecard() - private var mScorecardValue: ScorecardValues? = null - private var mMapScores = HashMap() - private var clientId = 0 - private var mCurrentQuestionPosition = 1 - var fragmentCommunicator: Communicator? = null - private var mPagerAdapter: PagerAdapter? = null - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - binding = ActivitySurveyQuestionBinding.inflate(layoutInflater) - setContentView(binding.root) - setSupportActionBar(toolbar) - //Getting Survey Gson Object - val mIntent = intent - survey = Gson().fromJson(mIntent.getStringExtra(Constants.SURVEYS), Survey::class.java) - clientId = mIntent.getIntExtra(Constants.CLIENT_ID, 1) - setSubtitleToolbar() - mPagerAdapter = SurveyPagerAdapter(supportFragmentManager, fragments) - binding.surveyPager.adapter = mPagerAdapter - binding.surveyPager.addOnPageChangeListener(this) - loadSurvey(survey) - val actionBar = supportActionBar - actionBar?.setDisplayHomeAsUpEnabled(true) - - binding.btnNext.setOnClickListener { - onClickButtonNext() - } - - } - - - override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {} - override fun onPageSelected(position: Int) { - updateAnswerList() - mCurrentQuestionPosition = position + 1 - setSubtitleToolbar() - } - - override fun onPageScrollStateChanged(state: Int) {} - - private fun onClickButtonNext() { - updateAnswerList() - binding.surveyPager.setCurrentItem(binding.surveyPager.currentItem + 1, true) - setSubtitleToolbar() - } - - override fun answer(scorecardValues: ScorecardValues?) { - mScorecardValue = scorecardValues - } - - private fun loadSurvey(survey: Survey?) { - if (survey != null) { - if (survey.questionDatas.isNotEmpty()) { - for (i in survey.questionDatas.indices) { - fragments.add( - SurveyQuestionFragment.newInstance( - Gson().toJson( - survey - .questionDatas[i] - ) - ) - ) - } - fragments.add(newInstance()) - mPagerAdapter!!.notifyDataSetChanged() - } else { - binding.surveyPager.visibility = View.GONE - binding.btnNext.visibility = View.GONE - binding.tvSurveyEmpty.visibility = View.VISIBLE - } - } - } - - private fun setUpScoreCard() { - listScorecardValues.clear() - for ((_, value) in mMapScores) { - listScorecardValues.add(value) - } - mScorecard.clientId = clientId - mScorecard.userId = PrefManager.getUserId() - mScorecard.createdOn = Date() - mScorecard.scorecardValues = listScorecardValues - } - - private fun updateAnswerList() { - if (mScorecardValue != null) { - Log.d( - LOG_TAG, - "" + mScorecardValue?.questionId + mScorecardValue?.responseId + mScorecardValue?.value - ) - mMapScores[mScorecardValue?.questionId!!] = mScorecardValue!! - mScorecardValue = null - } - nextButtonState() - if (fragmentCommunicator != null) { - setUpScoreCard() - fragmentCommunicator?.passScoreCardData(mScorecard, survey!!.id) - } - } - - private fun nextButtonState() { - if (binding.surveyPager.currentItem == mPagerAdapter!!.count - 1) { - binding.btnNext.visibility = View.GONE - } else { - binding.btnNext.visibility = View.VISIBLE - } - } - - private fun setSubtitleToolbar() { - if (survey!!.questionDatas.size == 0) { - toolbar?.subtitle = resources.getString(R.string.survey_subtitle) - } else if (mCurrentQuestionPosition <= survey!!.questionDatas.size) { - toolbar?.subtitle = mCurrentQuestionPosition.toString() + - resources.getString(R.string.slash) + survey!!.questionDatas.size - } else { - toolbar?.subtitle = resources.getString(R.string.submit_survey) - } - } - - override fun disableSwipe() { - binding.surveyPager.beginFakeDrag() - toolbar?.subtitle = null - } - - public override fun onSaveInstanceState(savedInstanceState: Bundle) { - super.onSaveInstanceState(savedInstanceState) - savedInstanceState.putSerializable(Constants.ANSWERS, mMapScores) - } - - public override fun onRestoreInstanceState(savedInstanceState: Bundle) { - super.onRestoreInstanceState(savedInstanceState) - mMapScores = - savedInstanceState.getSerializable(Constants.ANSWERS) as HashMap - } - - companion object { - val LOG_TAG = SurveyQuestionActivity::class.java.simpleName - } -} -*/ \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionFragment.kt deleted file mode 100644 index 7c2da89d94d..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionFragment.kt +++ /dev/null @@ -1,110 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.mifosxdroid.online.surveyquestion - -/* -import android.app.Activity -import android.content.Context -import android.os.Bundle -import android.util.Log -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.RadioButton -import android.widget.RadioGroup -import com.google.gson.Gson -import com.mifos.core.common.utils.Constants -import com.mifos.core.objects.survey.QuestionDatas -import com.mifos.core.objects.survey.ScorecardValues -import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.databinding.FragmentSurveyQuestionBinding - -/** - * Created by Nasim Banu on 28,January,2016. - */ -class SurveyQuestionFragment : MifosBaseFragment(), RadioGroup.OnCheckedChangeListener { - - private lateinit var binding: FragmentSurveyQuestionBinding - - var rb_add_answer: RadioButton? = null - private var mCallback: OnAnswerSelectedListener? = null - private var mQuestionDatas: QuestionDatas? = null - private var answer: String? = null - private var mScorecardValues: ScorecardValues? = null - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - mQuestionDatas = Gson().fromJson( - requireArguments().getString(Constants.QUESTION_DATA), - QuestionDatas::class.java - ) - mScorecardValues = ScorecardValues() - } - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - binding = FragmentSurveyQuestionBinding.inflate(inflater, container, false) - binding.surveyQuestionTextView.text = mQuestionDatas?.text - for (i in mQuestionDatas!!.responseDatas.indices) { - rb_add_answer = RadioButton(activity) - rb_add_answer?.id = i - rb_add_answer?.text = mQuestionDatas!!.responseDatas[i].text - binding.radioBtnAnswer.addView(rb_add_answer) - binding.radioBtnAnswer.setOnCheckedChangeListener(this) - } - return binding.root - } - - override fun onCheckedChanged(group: RadioGroup, checkedId: Int) { - for (j in 0 until group.childCount) { - val btn = group.getChildAt(j) as RadioButton - val t = group.id - Log.d(LOG_TAG, "" + t) - if (btn.id == checkedId) { - answer = btn.text.toString() - mScorecardValues?.questionId = mQuestionDatas?.questionId - mScorecardValues?.responseId = mQuestionDatas!!.responseDatas[j].responseId - mScorecardValues?.value = mQuestionDatas!!.responseDatas[j].value - mCallback?.answer(mScorecardValues) - Log.d( - LOG_TAG, "Q R V" + mQuestionDatas?.questionId + " " + - mQuestionDatas!!.responseDatas[j].responseId - + " " + mQuestionDatas!!.responseDatas[j].value - ) - return - } - } - } - - override fun onAttach(context: Context) { - super.onAttach(context) - val activity = if (context is Activity) context else null - mCallback = try { - activity as OnAnswerSelectedListener? - } catch (e: ClassCastException) { - throw ClassCastException( - activity.toString() - + " must implement OnAnswerSelectedListener" - ) - } - } - - interface OnAnswerSelectedListener { - fun answer(scorecardValues: ScorecardValues?) - } - - companion object { - private val LOG_TAG = SurveyQuestionFragment::class.java.simpleName - fun newInstance(QuestionDatas: String?): SurveyQuestionFragment { - val fragment = SurveyQuestionFragment() - val bundle = Bundle() - bundle.putString(Constants.QUESTION_DATA, QuestionDatas) - fragment.arguments = bundle - return fragment - } - } -} - */ \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionsComposeActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionsComposeActivity.kt index 57424860e8d..f0e6da91942 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionsComposeActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveyquestion/SurveyQuestionsComposeActivity.kt @@ -13,6 +13,7 @@ import com.mifos.core.common.utils.Constants import com.mifos.core.objects.survey.Scorecard import com.mifos.core.objects.survey.ScorecardValues import com.mifos.core.objects.survey.Survey +import com.mifos.feature.client.clientSurveyQuestion.SurveyQuestionScreen import com.mifos.mifosxdroid.core.MifosBaseActivity import com.mifos.utils.PrefManager import dagger.hilt.android.AndroidEntryPoint diff --git a/mifosng-android/src/test/java/com/mifos/viewmodels/CenterListViewModelTest.kt b/mifosng-android/src/test/java/com/mifos/viewmodels/CenterListViewModelTest.kt deleted file mode 100644 index 5c765b57db5..00000000000 --- a/mifosng-android/src/test/java/com/mifos/viewmodels/CenterListViewModelTest.kt +++ /dev/null @@ -1,163 +0,0 @@ -package com.mifos.viewmodels - -import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import androidx.lifecycle.Observer -import com.mifos.core.objects.client.Page -import com.mifos.core.objects.group.Center -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.online.centerlist.CenterListRepository -import com.mifos.mifosxdroid.online.centerlist.CenterListUiState -import com.mifos.mifosxdroid.online.centerlist.CenterListViewModel -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import org.junit.After -import org.junit.Assert.* -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.MockitoAnnotations -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Aditya Gupta on 06/09/23. - */ -@RunWith(MockitoJUnitRunner::class) -class CenterListViewModelTest { - - @get:Rule - val overrideSchedulersRule = RxSchedulersOverrideRule() - - @get:Rule - val instantTaskExecutorRule = InstantTaskExecutorRule() - - @Mock - private lateinit var centerListRepository: CenterListRepository - - private lateinit var centerListViewModel: CenterListViewModel - - @Mock - private lateinit var centerListUiObserver: Observer - - @Mock - private lateinit var mockCenterList: Page
- - @Before - fun setUp() { - MockitoAnnotations.openMocks(this) - centerListViewModel = CenterListViewModel(centerListRepository) - centerListViewModel.centerListUiState.observeForever(centerListUiObserver) - } - - @Test - fun testCenterList_SuccessfulCenterListReceivedFromRepository_ReturnsCenterList() { - val list1 = Mockito.mock(Center::class.java) - val list2 = Mockito.mock(Center::class.java) - val list = listOf(list1, list2) - val mockPage = Page(2, list) - - Mockito.`when`( - centerListRepository.getCenters( - Mockito.anyBoolean(), - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn( - Observable.just(mockPage) - ) - centerListViewModel.loadCenters(false, 1) - Mockito.verify(centerListUiObserver).onChanged(CenterListUiState.ShowProgressbar(true)) - Mockito.verify(centerListUiObserver, Mockito.never()) - .onChanged(CenterListUiState.ShowFetchingError) - Mockito.verify(centerListUiObserver, Mockito.never()) - .onChanged(CenterListUiState.ShowMessage(R.string.failed_to_fetch_centers)) - Mockito.verify(centerListUiObserver, Mockito.never()) - .onChanged(CenterListUiState.ShowEmptyCenters(R.string.center)) - Mockito.verify(centerListUiObserver, Mockito.never()) - .onChanged(CenterListUiState.UnregisterSwipeAndScrollListener) - Mockito.verify(centerListUiObserver) - .onChanged(CenterListUiState.ShowCenters(mockPage.pageItems)) - Mockito.verifyNoMoreInteractions(centerListUiObserver) - } - - - @Test - fun testCenterList_SuccessfulCenterListReceivedFromRepository_ReturnsEmptyCenterList() { - Mockito.`when`( - centerListRepository.getCenters( - Mockito.anyBoolean(), - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn( - Observable.just(mockCenterList) - ) - centerListViewModel.loadCenters(false, 1) - Mockito.verify(centerListUiObserver).onChanged(CenterListUiState.ShowProgressbar(true)) - Mockito.verify(centerListUiObserver, Mockito.never()) - .onChanged(CenterListUiState.ShowFetchingError) - Mockito.verify(centerListUiObserver, Mockito.never()) - .onChanged(CenterListUiState.ShowMessage(R.string.failed_to_fetch_centers)) - Mockito.verify(centerListUiObserver) - .onChanged(CenterListUiState.ShowEmptyCenters(R.string.center)) - Mockito.verify(centerListUiObserver) - .onChanged(CenterListUiState.UnregisterSwipeAndScrollListener) - Mockito.verifyNoMoreInteractions(centerListUiObserver) - } - - @Test - fun testCenterList_UnsuccessfulCenterListReceivedFromRepository_ReturnsError() { - Mockito.`when`( - centerListRepository.getCenters( - Mockito.anyBoolean(), - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn( - Observable.error(RuntimeException("some error message")) - ) - centerListViewModel.loadCenters(false, 1) - Mockito.verify(centerListUiObserver).onChanged(CenterListUiState.ShowProgressbar(true)) - Mockito.verify(centerListUiObserver).onChanged(CenterListUiState.ShowFetchingError) - Mockito.verify(centerListUiObserver, Mockito.never()) - .onChanged(CenterListUiState.ShowEmptyCenters(R.string.center)) - Mockito.verify(centerListUiObserver, Mockito.never()) - .onChanged(CenterListUiState.ShowMessage(R.string.failed_to_fetch_centers)) - Mockito.verifyNoMoreInteractions(centerListUiObserver) - } - - @Test - fun testCenterList_UnsuccessfulDbCenterListReceivedFromRepository_ReturnsCenterList() { - Mockito.`when`( - centerListRepository.allDatabaseCenters() - ).thenReturn( - Observable.just(mockCenterList) - ) - centerListViewModel.loadDatabaseCenters() - Mockito.verify(centerListUiObserver, Mockito.never()) - .onChanged(CenterListUiState.ShowMessage(R.string.failed_to_load_db_centers)) - Mockito.verifyNoMoreInteractions(centerListUiObserver) - } - - @Test - fun testCenterList_UnsuccessfulDbCenterListReceivedFromRepository_ReturnsError() { - Mockito.`when`( - centerListRepository.allDatabaseCenters() - ).thenReturn( - Observable.error(RuntimeException("some error message")) - ) - centerListViewModel.loadDatabaseCenters() - Mockito.verify(centerListUiObserver) - .onChanged(CenterListUiState.ShowMessage(R.string.failed_to_load_db_centers)) - Mockito.verify(centerListUiObserver, Mockito.never()) - .onChanged(CenterListUiState.ShowCenters(mockCenterList.pageItems)) - Mockito.verifyNoMoreInteractions(centerListUiObserver) - } - - @After - fun tearDown() { - centerListViewModel.centerListUiState.removeObserver(centerListUiObserver) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/viewmodels/ClientChargeViewModelTest.kt b/mifosng-android/src/test/java/com/mifos/viewmodels/ClientChargeViewModelTest.kt deleted file mode 100644 index 979c548047b..00000000000 --- a/mifosng-android/src/test/java/com/mifos/viewmodels/ClientChargeViewModelTest.kt +++ /dev/null @@ -1,126 +0,0 @@ -package com.mifos.viewmodels - -import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import androidx.lifecycle.Observer -import com.mifos.core.objects.client.Charges -import com.mifos.core.objects.client.Page -import com.mifos.mifosxdroid.online.clientcharge.ClientChargeRepository -import com.mifos.mifosxdroid.online.clientcharge.ClientChargeUiState -import com.mifos.mifosxdroid.online.clientcharge.ClientChargeViewModel -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import org.junit.After -import org.junit.Assert.* -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.Mockito.mock -import org.mockito.MockitoAnnotations -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Aditya Gupta on 02/09/23. - */ -@RunWith(MockitoJUnitRunner::class) -class ClientChargeViewModelTest { - - @JvmField - @Rule - val overrideSchedulersRule = RxSchedulersOverrideRule() - - @JvmField - @Rule - val instantTaskExecutorRule = InstantTaskExecutorRule() - - @Mock - private lateinit var clientChargeRepository: ClientChargeRepository - - @Mock - private lateinit var clientUiStateObserver: Observer - - private lateinit var clientChargeViewModel: ClientChargeViewModel - - @Mock - lateinit var mockChargesPage: Page - - - @Before - fun setUp() { - MockitoAnnotations.openMocks(this) - clientChargeViewModel = ClientChargeViewModel(clientChargeRepository) - clientChargeViewModel.clientChargeUiState.observeForever(clientUiStateObserver) - } - - @Test - fun testLoadChargesEmptyList_SuccessfulChargesReceivedFromRepository_ReturnsSuccess() { - - Mockito.`when`( - clientChargeRepository.getClientCharges( - Mockito.anyInt(), - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn(Observable.just(mockChargesPage)) - clientChargeViewModel.loadCharges(1, 1, 1) - Mockito.verify(clientUiStateObserver).onChanged(ClientChargeUiState.ShowProgressbar) - Mockito.verify(clientUiStateObserver, Mockito.never()) - .onChanged(ClientChargeUiState.ShowFetchingErrorCharges("some error message")) - Mockito.verify(clientUiStateObserver, Mockito.never()) - .onChanged(ClientChargeUiState.ShowChargesList(mockChargesPage)) - Mockito.verify(clientUiStateObserver).onChanged(ClientChargeUiState.ShowEmptyCharges) - Mockito.verifyNoMoreInteractions(clientUiStateObserver) - } - - @Test - fun testLoadChargesList_SuccessfulChargesReceivedFromRepository_ReturnsSuccess() { - - val list1 = mock(Charges::class.java) - val list2 = mock(Charges::class.java) - val list = listOf(list1, list2) - val mockPage = Page(2, list) - - Mockito.`when`( - clientChargeRepository.getClientCharges( - Mockito.anyInt(), - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn(Observable.just(mockPage)) - clientChargeViewModel.loadCharges(1, 1, 1) - Mockito.verify(clientUiStateObserver).onChanged(ClientChargeUiState.ShowProgressbar) - Mockito.verify(clientUiStateObserver, Mockito.never()) - .onChanged(ClientChargeUiState.ShowFetchingErrorCharges("some error message")) - Mockito.verify(clientUiStateObserver) - .onChanged(ClientChargeUiState.ShowChargesList(mockPage)) - Mockito.verify(clientUiStateObserver, Mockito.never()) - .onChanged(ClientChargeUiState.ShowEmptyCharges) - Mockito.verifyNoMoreInteractions(clientUiStateObserver) - } - - @Test - fun testLoadCharges_UnsuccessfulChargesReceivedFromRepository_ReturnsError() { - - Mockito.`when`( - clientChargeRepository.getClientCharges( - Mockito.anyInt(), - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn(Observable.error(RuntimeException("some error message"))) - clientChargeViewModel.loadCharges(1, 1, 1) - Mockito.verify(clientUiStateObserver).onChanged(ClientChargeUiState.ShowProgressbar) - Mockito.verify(clientUiStateObserver, Mockito.never()) - .onChanged(ClientChargeUiState.ShowChargesList(mockChargesPage)) - Mockito.verify(clientUiStateObserver, Mockito.never()) - .onChanged(ClientChargeUiState.ShowEmptyCharges) - Mockito.verifyNoMoreInteractions(clientUiStateObserver) - } - - @After - fun tearDown() { - clientChargeViewModel.clientChargeUiState.removeObserver(clientUiStateObserver) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/viewmodels/ClientListViewModelTest.kt b/mifosng-android/src/test/java/com/mifos/viewmodels/ClientListViewModelTest.kt deleted file mode 100644 index 1c4c23caac7..00000000000 --- a/mifosng-android/src/test/java/com/mifos/viewmodels/ClientListViewModelTest.kt +++ /dev/null @@ -1,140 +0,0 @@ -package com.mifos.viewmodels - -import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import androidx.lifecycle.Observer -import com.mifos.core.objects.client.Client -import com.mifos.core.objects.client.Page -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.online.clientlist.ClientListRepository -import com.mifos.mifosxdroid.online.clientlist.ClientListUiState -import com.mifos.mifosxdroid.online.clientlist.ClientListViewModel -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.MockitoAnnotations -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Aditya Gupta on 06/09/23. - */ -@RunWith(MockitoJUnitRunner::class) -class ClientListViewModelTest { - - @get:Rule - val overrideSchedulersRule = RxSchedulersOverrideRule() - - @get:Rule - val instantTaskExecutorRule = InstantTaskExecutorRule() - - @Mock - private lateinit var clientListRepository: ClientListRepository - - @Mock - private lateinit var clientListUiObserver: Observer - - private lateinit var clientListViewModel: ClientListViewModel - - @Mock - private lateinit var mockClientList: Page - - @Before - fun setUp() { - MockitoAnnotations.openMocks(this) - clientListViewModel = ClientListViewModel(clientListRepository) - clientListViewModel.clientListUiState.observeForever(clientListUiObserver) - } - - @Test - fun testClientList_SuccessfulClientListReceivedFromRepository_ReturnsClientList() { - val list1 = Mockito.mock(Client::class.java) - val list2 = Mockito.mock(Client::class.java) - val list = listOf(list1, list2) - val mockPage = Page(2, list) - Mockito.`when`( - clientListRepository.getAllClients( - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn(Observable.just(mockPage)) - clientListViewModel.loadClients(false, 1) - Mockito.verify(clientListUiObserver).onChanged(ClientListUiState.ShowProgressbar(true)) - Mockito.verify(clientListUiObserver, Mockito.never()) - .onChanged(ClientListUiState.ShowEmptyClientList(R.string.client)) - Mockito.verify(clientListUiObserver, Mockito.never()) - .onChanged(ClientListUiState.UnregisterSwipeAndScrollListener) - Mockito.verify(clientListUiObserver, Mockito.never()).onChanged(ClientListUiState.ShowError) - Mockito.verify(clientListUiObserver, Mockito.never()) - .onChanged(ClientListUiState.ShowMessage(R.string.failed_to_load_client)) - Mockito.verifyNoMoreInteractions(clientListUiObserver) - } - - @Test - fun testClientList_SuccessfulClientListReceivedFromRepository_ReturnsEmptyClientList() { - Mockito.`when`( - clientListRepository.getAllClients( - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn(Observable.just(mockClientList)) - clientListViewModel.loadClients(false, 0) - Mockito.verify(clientListUiObserver).onChanged(ClientListUiState.ShowProgressbar(true)) - Mockito.verify(clientListUiObserver) - .onChanged(ClientListUiState.ShowEmptyClientList(R.string.client)) - Mockito.verify(clientListUiObserver) - .onChanged(ClientListUiState.UnregisterSwipeAndScrollListener) - Mockito.verify(clientListUiObserver, Mockito.never()).onChanged(ClientListUiState.ShowError) - Mockito.verify(clientListUiObserver, Mockito.never()) - .onChanged(ClientListUiState.ShowMessage(R.string.failed_to_load_client)) - Mockito.verifyNoMoreInteractions(clientListUiObserver) - } - - @Test - fun testClientList_UnsuccessfulClientListReceivedFromRepository_ReturnsError() { - Mockito.`when`( - clientListRepository.getAllClients( - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn( - Observable.error(RuntimeException("some error message")) - ) - clientListViewModel.loadClients(false, 0) - Mockito.verify(clientListUiObserver).onChanged(ClientListUiState.ShowProgressbar(true)) - Mockito.verify(clientListUiObserver, Mockito.never()) - .onChanged(ClientListUiState.ShowClientList(mockClientList.pageItems)) - Mockito.verify(clientListUiObserver).onChanged(ClientListUiState.ShowError) - Mockito.verifyNoMoreInteractions(clientListUiObserver) - } - - @Test - fun testClientList_SuccessfulClientListReceivedFromRepository_ReturnsDbClientList() { - Mockito.`when`( - clientListRepository.allDatabaseClients() - ).thenReturn(Observable.just(mockClientList)) - clientListViewModel.loadDatabaseClients() - Mockito.verify(clientListUiObserver, Mockito.never()) - .onChanged(ClientListUiState.ShowMessage(R.string.failed_to_load_db_clients)) - Mockito.verifyNoMoreInteractions(clientListUiObserver) - } - - @Test - fun testClientListDatabase_UnsuccessfulClientListReceivedFromRepository_ReturnsError() { - Mockito.`when`(clientListRepository.allDatabaseClients()) - .thenReturn(Observable.error(RuntimeException("some error message"))) - clientListViewModel.loadDatabaseClients() - Mockito.verify(clientListUiObserver) - .onChanged(ClientListUiState.ShowMessage(R.string.failed_to_load_db_clients)) - Mockito.verifyNoMoreInteractions(clientListUiObserver) - } - - @After - fun tearDown() { - clientListViewModel.clientListUiState.removeObserver(clientListUiObserver) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/viewmodels/GroupsListViewModelTest.kt b/mifosng-android/src/test/java/com/mifos/viewmodels/GroupsListViewModelTest.kt deleted file mode 100644 index 0531776afc1..00000000000 --- a/mifosng-android/src/test/java/com/mifos/viewmodels/GroupsListViewModelTest.kt +++ /dev/null @@ -1,151 +0,0 @@ -package com.mifos.viewmodels - -import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import androidx.lifecycle.Observer -import com.mifos.core.objects.client.Page -import com.mifos.core.objects.group.Group -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.online.groupslist.GroupsListRepository -import com.mifos.mifosxdroid.online.groupslist.GroupsListUiState -import com.mifos.mifosxdroid.online.groupslist.GroupsListViewModel -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.MockitoAnnotations -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Aditya Gupta on 06/09/23. - */ -@RunWith(MockitoJUnitRunner::class) -class GroupsListViewModelTest { - - - @get:Rule - val overrideSchedulersRule = RxSchedulersOverrideRule() - - @get:Rule - val instantTaskExecutorRule = InstantTaskExecutorRule() - - @Mock - private lateinit var groupsListRepository: GroupsListRepository - - private lateinit var groupsListViewModel: GroupsListViewModel - - @Mock - private lateinit var groupsListObserver: Observer - - @Mock - private lateinit var mockGroupList: Page - - @Before - fun setUp() { - MockitoAnnotations.openMocks(this) - groupsListViewModel = GroupsListViewModel(groupsListRepository) - groupsListViewModel.groupsListUiState.observeForever(groupsListObserver) - - - } - - @Test - fun testGroupsListDatabase_SuccessfulGroupsListReceivedFromRepository_ReturnsGroupsList() { - val list1 = Mockito.mock(Group::class.java) - val list2 = Mockito.mock(Group::class.java) - val list = listOf(list1, list2) - val mockPage = Page(2, list) - - Mockito.`when`( - groupsListRepository.getGroups( - Mockito.anyBoolean(), - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn(Observable.just(mockPage)) - groupsListViewModel.loadGroups(false, 1) - Mockito.verify(groupsListObserver).onChanged(GroupsListUiState.ShowProgressbar) - Mockito.verify(groupsListObserver, Mockito.never()) - .onChanged(GroupsListUiState.ShowEmptyGroups(R.string.group)) - Mockito.verify(groupsListObserver, Mockito.never()) - .onChanged(GroupsListUiState.UnregisterSwipeAndScrollListener) - Mockito.verify(groupsListObserver, Mockito.never()) - .onChanged(GroupsListUiState.ShowEmptyGroups(R.string.group)) - Mockito.verify(groupsListObserver, Mockito.never()) - .onChanged(GroupsListUiState.ShowFetchingError) - Mockito.verifyNoMoreInteractions(groupsListObserver) - } - - @Test - fun testGroupsListDatabase_SuccessfulGroupsListReceivedFromRepository_ReturnsEmptyGroupsList() { - Mockito.`when`( - groupsListRepository.getGroups( - Mockito.anyBoolean(), - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn(Observable.just(mockGroupList)) - groupsListViewModel.loadGroups(false, 1) - Mockito.verify(groupsListObserver).onChanged(GroupsListUiState.ShowProgressbar) - Mockito.verify(groupsListObserver) - .onChanged(GroupsListUiState.ShowEmptyGroups(R.string.group)) - Mockito.verify(groupsListObserver) - .onChanged(GroupsListUiState.UnregisterSwipeAndScrollListener) - Mockito.verify(groupsListObserver) - .onChanged(GroupsListUiState.ShowEmptyGroups(R.string.group)) - Mockito.verify(groupsListObserver, Mockito.never()) - .onChanged(GroupsListUiState.ShowFetchingError) - Mockito.verifyNoMoreInteractions(groupsListObserver) - } - - @Test - fun testGroupsListDatabase_UnsuccessfulGroupsListReceivedFromRepository_ReturnsError() { - Mockito.`when`( - groupsListRepository.getGroups( - Mockito.anyBoolean(), - Mockito.anyInt(), - Mockito.anyInt() - ) - ).thenReturn(Observable.error(RuntimeException("some error message"))) - groupsListViewModel.loadGroups(false, 1) - Mockito.verify(groupsListObserver).onChanged(GroupsListUiState.ShowProgressbar) - Mockito.verify(groupsListObserver, Mockito.never()) - .onChanged(GroupsListUiState.ShowEmptyGroups(R.string.group)) - Mockito.verify(groupsListObserver, Mockito.never()) - .onChanged(GroupsListUiState.UnregisterSwipeAndScrollListener) - Mockito.verify(groupsListObserver).onChanged(GroupsListUiState.ShowFetchingError) - Mockito.verifyNoMoreInteractions(groupsListObserver) - } - - @Test - fun testGroupsListDatabase_SuccessfulDbGroupsListReceivedFromRepository_ReturnsGroupsList() { - Mockito.`when`(groupsListRepository.databaseGroups()) - .thenReturn(Observable.just(mockGroupList)) - groupsListViewModel.loadDatabaseGroups() - Mockito.verify(groupsListObserver).onChanged(GroupsListUiState.ShowProgressbar) - Mockito.verify(groupsListObserver, Mockito.never()) - .onChanged(GroupsListUiState.ShowMessage(R.string.feature_groups_failed_to_load_db_groups)) - Mockito.verifyNoMoreInteractions(groupsListObserver) - } - - @Test - fun testGroupsListDatabase_UnsuccessfulDbGroupsListReceivedFromRepository_ReturnsError() { - Mockito.`when`(groupsListRepository.databaseGroups()) - .thenReturn(Observable.error(RuntimeException("some error message"))) - groupsListViewModel.loadDatabaseGroups() - Mockito.verify(groupsListObserver).onChanged(GroupsListUiState.ShowProgressbar) - Mockito.verify(groupsListObserver) - .onChanged(GroupsListUiState.ShowMessage(R.string.feature_groups_failed_to_load_db_groups)) - Mockito.verifyNoMoreInteractions(groupsListObserver) - } - - - @After - fun tearDown() { - groupsListViewModel.groupsListUiState.removeObserver(groupsListObserver) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/viewmodels/LoginViewModelTest.kt b/mifosng-android/src/test/java/com/mifos/viewmodels/LoginViewModelTest.kt deleted file mode 100644 index ff62cb7dc99..00000000000 --- a/mifosng-android/src/test/java/com/mifos/viewmodels/LoginViewModelTest.kt +++ /dev/null @@ -1,84 +0,0 @@ -package com.mifos.viewmodels - -import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import androidx.lifecycle.Observer -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import com.mifos.mifosxdroid.activity.login.LoginRepository -import com.mifos.mifosxdroid.activity.login.LoginUiState -import com.mifos.mifosxdroid.activity.login.LoginViewModel -import org.apache.fineract.client.models.PostAuthenticationResponse -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.MockitoAnnotations -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Aditya Gupta on 02/09/23. - */ -@RunWith(MockitoJUnitRunner::class) -class LoginViewModelTest { - - @get:Rule - val overrideSchedulersRule = RxSchedulersOverrideRule() - - @get:Rule - val instantTaskExecutorRule = InstantTaskExecutorRule() - - @Mock - lateinit var loginRepository: LoginRepository - - @Mock - lateinit var loginUiStateObserver: Observer - - private lateinit var loginViewModel: LoginViewModel - - @Mock - private lateinit var mockUser: PostAuthenticationResponse - - - @Before - fun setUp() { - MockitoAnnotations.openMocks(this) - loginViewModel = LoginViewModel(loginRepository) - loginViewModel.loginUiState.observeForever(loginUiStateObserver) - } - - @Test - fun testLogin_SuccessfulLoginReceivedFromRepository_ReturnsLoginSuccess() { - - Mockito.`when`(loginRepository.login(Mockito.anyString(), Mockito.anyString())).thenReturn( - Observable.just(mockUser) - ) - loginViewModel.login("username", "password") - Mockito.verify(loginUiStateObserver).onChanged(LoginUiState.ShowProgress(true)) - Mockito.verify(loginUiStateObserver).onChanged(LoginUiState.ShowLoginSuccessful(mockUser)) - Mockito.verify(loginUiStateObserver, Mockito.never()) - .onChanged(LoginUiState.ShowError("Some error message")) - Mockito.verifyNoMoreInteractions(loginUiStateObserver) - } - - @Test - fun testLogin_unsuccessfulLoginReceivedFromRepository_ReturnError() { - - Mockito.`when`(loginRepository.login(Mockito.anyString(), Mockito.anyString())).thenReturn( - Observable.error(RuntimeException("Some error message")) - ) - loginViewModel.login("username", "password") - Mockito.verify(loginUiStateObserver).onChanged(LoginUiState.ShowProgress(true)) - Mockito.verify(loginUiStateObserver).onChanged(LoginUiState.ShowError("Some error message")) - Mockito.verify(loginUiStateObserver, Mockito.never()) - .onChanged(LoginUiState.ShowLoginSuccessful(mockUser)) - Mockito.verifyNoMoreInteractions(loginUiStateObserver) - } - - @After - fun tearDown() { - loginViewModel.loginUiState.removeObserver(loginUiStateObserver) - } -} \ No newline at end of file