From f6538a8432b490e76a540276779a1c123c6b1b61 Mon Sep 17 00:00:00 2001 From: Aditya Gupta <94394661+Aditya-gupta99@users.noreply.github.com> Date: Fri, 11 Aug 2023 23:48:27 +0530 Subject: [PATCH] Fixes #2024 : MVP to MVVM Migration (#2031) * loan details mvp to mvvm * datatable mvp to mvvm --- .../src/main/java/com/mifos/api/BaseUrl.kt | 2 +- .../injection/module/RepositoryModule.kt | 131 +++++++++-- .../online/SurveyQuestionActivity.kt | 2 + .../CollectionSheetFragment.kt | 69 +++--- .../collectionsheet/CollectionSheetMvpView.kt | 16 -- .../CollectionSheetPresenter.kt | 68 ------ .../IndividualCollectionSheetMvpView.kt | 18 -- .../NewIndividualCollectionSheetFragment.kt | 75 +++++-- .../NewIndividualCollectionSheetPresenter.kt | 157 -------------- ...ndividualCollectionSheetDetailsFragment.kt | 44 ++-- ...IndividualCollectionSheetDetailsMvpView.kt | 11 - ...dividualCollectionSheetDetailsPresenter.kt | 92 -------- .../PaymentDetailsFragment.kt | 6 +- .../CreateNewCenterFragment.kt | 57 +++-- .../createnewcenter/CreateNewCenterMvpView.kt | 15 -- .../CreateNewCenterPresenter.kt | 73 ------- .../CreateNewClientFragment.kt | 123 +++++++---- .../createnewclient/CreateNewClientMvpView.kt | 23 -- .../CreateNewClientPresenter.kt | 203 ------------------ .../createnewgroup/CreateNewGroupFragment.kt | 54 +++-- .../createnewgroup/CreateNewGroupMvpView.kt | 14 -- .../createnewgroup/CreateNewGroupPresenter.kt | 78 ------- .../datatabledata/DataTableDataFragment.kt | 73 +++++-- .../datatabledata/DataTableDataMvpView.kt | 15 -- .../datatabledata/DataTableDataPresenter.kt | 80 ------- .../DataTableListFragment.kt | 59 +++-- .../DataTableListMvpView.kt | 11 - .../DataTableListPresenter.kt | 113 ---------- .../LoanAccountApproval.kt | 44 ++-- .../LoanAccountApprovalMvpView.kt | 13 -- .../LoanAccountApprovalPresenter.kt | 61 ------ .../LoanAccountDisbursementFragment.kt | 57 +++-- .../LoanAccountDisbursementMvpView.kt | 17 -- .../LoanAccountDisbursementPresenter.kt | 76 ------- .../online/loancharge/LoanChargeFragment.kt | 50 +++-- .../loanrepayment/LoanRepaymentFragment.kt | 84 ++++---- .../loanrepayment/LoanRepaymentMvpView.kt | 17 -- .../loanrepayment/LoanRepaymentPresenter.kt | 101 --------- .../repositories/CollectionSheetRepository.kt | 20 ++ .../CollectionSheetRepositoryImp.kt | 29 +++ .../repositories/CreateNewCenterRepository.kt | 16 ++ .../CreateNewCenterRepositoryImp.kt | 23 ++ .../repositories/CreateNewClientRepository.kt | 26 +++ .../CreateNewClientRepositoryImp.kt | 45 ++++ .../repositories/CreateNewGroupRepository.kt | 16 ++ .../CreateNewGroupRepositoryImp.kt | 26 +++ .../repositories/DataTableDataRepository.kt | 16 ++ .../DataTableDataRepositoryImp.kt | 28 +++ .../repositories/DataTableListRepository.kt | 20 ++ .../DataTableListRepositoryImp.kt | 33 +++ ...ividualCollectionSheetDetailsRepository.kt | 16 ++ ...dualCollectionSheetDetailsRepositoryImp.kt | 18 ++ .../LoanAccountApprovalRepository.kt | 14 ++ .../LoanAccountApprovalRepositoryImp.kt | 21 ++ .../LoanAccountDisbursementRepository.kt | 23 ++ .../LoanAccountDisbursementRepositoryImp.kt | 31 +++ .../repositories/LoanChargeRepository.kt | 13 ++ .../repositories/LoanChargeRepositoryImp.kt | 17 ++ .../repositories/LoanRepaymentRepository.kt | 22 ++ .../LoanRepaymentRepositoryImp.kt | 32 +++ .../NewIndividualCollectionSheetRepository.kt | 22 ++ ...wIndividualCollectionSheetRepositoryImp.kt | 32 +++ .../mifos/states/CollectionSheetUiState.kt | 20 ++ .../mifos/states/CreateNewCenterUiState.kt | 20 ++ .../mifos/states/CreateNewClientUiState.kt | 31 +++ .../com/mifos/states/CreateNewGroupUiState.kt | 19 ++ .../com/mifos/states/DataTableDataUiState.kt | 21 ++ .../com/mifos/states/DataTableListUiState.kt | 19 ++ ...IndividualCollectionSheetDetailsUiState.kt | 13 ++ .../states/LoanAccountApprovalUiState.kt | 16 ++ .../states/LoanAccountDisbursementUiState.kt | 20 ++ .../com/mifos/states/LoanChargeUiState.kt | 17 ++ .../com/mifos/states/LoanRepaymentUiState.kt | 24 +++ .../NewIndividualCollectionSheetUiState.kt | 27 +++ .../java/com/mifos/utils/MifosDatePicker.kt | 2 +- .../viewmodels/CollectionSheetViewModel.kt | 72 +++++++ .../viewmodels/CreateNewCenterViewModel.kt | 68 ++++++ .../viewmodels/CreateNewClientViewModel.kt | 197 +++++++++++++++++ .../viewmodels/CreateNewGroupViewModel.kt | 70 ++++++ .../viewmodels/DataTableDataViewModel.kt | 73 +++++++ .../viewmodels/DataTableListViewModel.kt | 100 +++++++++ ...dividualCollectionSheetDetailsViewModel.kt | 92 ++++++++ .../LoanAccountApprovalViewModel.kt | 62 ++++++ .../LoanAccountDisbursementViewModel.kt | 71 ++++++ .../mifos/viewmodels/LoanChargeViewModel.kt | 56 +++++ .../viewmodels/LoanRepaymentViewModel.kt | 97 +++++++++ .../NewIndividualCollectionSheetViewModel.kt | 146 +++++++++++++ 87 files changed, 2554 insertions(+), 1560 deletions(-) delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApprovalMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApprovalPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentPresenter.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/CollectionSheetRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/CollectionSheetRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/CreateNewCenterRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/CreateNewCenterRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/CreateNewClientRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/CreateNewClientRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/CreateNewGroupRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/CreateNewGroupRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/DataTableDataRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/DataTableDataRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/DataTableListRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/DataTableListRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/IndividualCollectionSheetDetailsRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/IndividualCollectionSheetDetailsRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/LoanAccountApprovalRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/LoanAccountApprovalRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/LoanAccountDisbursementRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/LoanAccountDisbursementRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/LoanChargeRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/LoanChargeRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/LoanRepaymentRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/LoanRepaymentRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/NewIndividualCollectionSheetRepository.kt create mode 100644 mifosng-android/src/main/java/com/mifos/repositories/NewIndividualCollectionSheetRepositoryImp.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/CollectionSheetUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/CreateNewCenterUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/CreateNewClientUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/CreateNewGroupUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/DataTableDataUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/DataTableListUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/IndividualCollectionSheetDetailsUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/LoanAccountApprovalUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/LoanAccountDisbursementUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/LoanChargeUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/LoanRepaymentUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/states/NewIndividualCollectionSheetUiState.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/CollectionSheetViewModel.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewCenterViewModel.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewClientViewModel.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewGroupViewModel.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/DataTableDataViewModel.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/DataTableListViewModel.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/IndividualCollectionSheetDetailsViewModel.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/LoanAccountApprovalViewModel.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/LoanAccountDisbursementViewModel.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/LoanChargeViewModel.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/LoanRepaymentViewModel.kt create mode 100644 mifosng-android/src/main/java/com/mifos/viewmodels/NewIndividualCollectionSheetViewModel.kt diff --git a/mifosng-android/src/main/java/com/mifos/api/BaseUrl.kt b/mifosng-android/src/main/java/com/mifos/api/BaseUrl.kt index 1d8bf52e952..038e4ca4317 100644 --- a/mifosng-android/src/main/java/com/mifos/api/BaseUrl.kt +++ b/mifosng-android/src/main/java/com/mifos/api/BaseUrl.kt @@ -11,7 +11,7 @@ class BaseUrl { // "/" in the last of the base url always companion object { const val PROTOCOL_HTTPS = "https://" - const val API_ENDPOINT = "demo.mifos.community" + const val API_ENDPOINT = "dev.mifos.io" const val API_PATH = "/fineract-provider/api/v1/" const val PORT = "80" } 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 590e279b748..2fe636f90f2 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 @@ -5,14 +5,17 @@ import com.mifos.api.datamanager.DataManagerAuth import com.mifos.api.datamanager.DataManagerCenter import com.mifos.api.datamanager.DataManagerCharge import com.mifos.api.datamanager.DataManagerClient +import com.mifos.api.datamanager.DataManagerCollectionSheet import com.mifos.api.datamanager.DataManagerDataTable import com.mifos.api.datamanager.DataManagerDocument import com.mifos.api.datamanager.DataManagerGroups import com.mifos.api.datamanager.DataManagerLoan import com.mifos.api.datamanager.DataManagerNote +import com.mifos.api.datamanager.DataManagerOffices import com.mifos.api.datamanager.DataManagerRunReport import com.mifos.api.datamanager.DataManagerSavings import com.mifos.api.datamanager.DataManagerSearch +import com.mifos.api.datamanager.DataManagerStaff import com.mifos.api.datamanager.DataManagerSurveys import com.mifos.repositories.ActivateRepository import com.mifos.repositories.ActivateRepositoryImp @@ -28,6 +31,18 @@ import com.mifos.repositories.ClientIdentifiersRepository import com.mifos.repositories.ClientIdentifiersRepositoryImp import com.mifos.repositories.ClientListRepository import com.mifos.repositories.ClientListRepositoryImp +import com.mifos.repositories.CollectionSheetRepository +import com.mifos.repositories.CollectionSheetRepositoryImp +import com.mifos.repositories.CreateNewCenterRepository +import com.mifos.repositories.CreateNewCenterRepositoryImp +import com.mifos.repositories.CreateNewClientRepository +import com.mifos.repositories.CreateNewClientRepositoryImp +import com.mifos.repositories.CreateNewGroupRepository +import com.mifos.repositories.CreateNewGroupRepositoryImp +import com.mifos.repositories.DataTableDataRepository +import com.mifos.repositories.DataTableDataRepositoryImp +import com.mifos.repositories.DataTableListRepository +import com.mifos.repositories.DataTableListRepositoryImp import com.mifos.repositories.DataTableRepository import com.mifos.repositories.DataTableRepositoryImp import com.mifos.repositories.DocumentListRepository @@ -38,12 +53,24 @@ import com.mifos.repositories.GroupListRepository import com.mifos.repositories.GroupListRepositoryImp import com.mifos.repositories.GroupsListRepository import com.mifos.repositories.GroupsListRepositoryImp +import com.mifos.repositories.IndividualCollectionSheetDetailsRepository +import com.mifos.repositories.IndividualCollectionSheetDetailsRepositoryImp +import com.mifos.repositories.LoanAccountApprovalRepository +import com.mifos.repositories.LoanAccountApprovalRepositoryImp +import com.mifos.repositories.LoanAccountDisbursementRepository +import com.mifos.repositories.LoanAccountDisbursementRepositoryImp import com.mifos.repositories.LoanAccountRepository import com.mifos.repositories.LoanAccountRepositoryImp import com.mifos.repositories.LoanAccountSummaryRepository import com.mifos.repositories.LoanAccountSummaryRepositoryImp +import com.mifos.repositories.LoanChargeRepository +import com.mifos.repositories.LoanChargeRepositoryImp +import com.mifos.repositories.LoanRepaymentRepository +import com.mifos.repositories.LoanRepaymentRepositoryImp import com.mifos.repositories.LoginRepository import com.mifos.repositories.LoginRepositoryImp +import com.mifos.repositories.NewIndividualCollectionSheetRepository +import com.mifos.repositories.NewIndividualCollectionSheetRepositoryImp import com.mifos.repositories.NoteRepository import com.mifos.repositories.NoteRepositoryImp import com.mifos.repositories.PathTrackingRepository @@ -60,7 +87,6 @@ import com.mifos.repositories.SignatureRepository import com.mifos.repositories.SignatureRepositoryImp import com.mifos.repositories.SurveyListRepository import com.mifos.repositories.SurveyListRepositoryImp -import com.mifos.services.data.LoansPayload import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -106,8 +132,7 @@ class RepositoryModule { @Provides fun providesCenterDetailsRepository( - dataManagerCenter: DataManagerCenter, - dataManagerRunReport: DataManagerRunReport + dataManagerCenter: DataManagerCenter, dataManagerRunReport: DataManagerRunReport ): CenterDetailsRepository { return CenterDetailsRepositoryImp(dataManagerCenter, dataManagerRunReport) } @@ -127,72 +152,144 @@ class RepositoryModule { } @Provides - fun providesClientListRepository(dataManagerClient: DataManagerClient) : ClientListRepository { + fun providesClientListRepository(dataManagerClient: DataManagerClient): ClientListRepository { return ClientListRepositoryImp(dataManagerClient) } @Provides - fun providesGroupsListRepository(dataManagerGroups: DataManagerGroups) : GroupsListRepository { + fun providesGroupsListRepository(dataManagerGroups: DataManagerGroups): GroupsListRepository { return GroupsListRepositoryImp(dataManagerGroups) } @Provides - fun providesClientChargeRepository(dataManagerCharge: DataManagerCharge) : ClientChargeRepository { + fun providesClientChargeRepository(dataManagerCharge: DataManagerCharge): ClientChargeRepository { return ClientChargeRepositoryImp(dataManagerCharge) } @Provides - fun providesLoanAccountSummary(dataManagerLoan: DataManagerLoan) : LoanAccountSummaryRepository { + fun providesLoanAccountSummary(dataManagerLoan: DataManagerLoan): LoanAccountSummaryRepository { return LoanAccountSummaryRepositoryImp(dataManagerLoan) } @Provides - fun providesSavingsAccountSummaryRepository(dataManagerSavings: DataManagerSavings) : SavingsAccountSummaryRepository { + fun providesSavingsAccountSummaryRepository(dataManagerSavings: DataManagerSavings): SavingsAccountSummaryRepository { return SavingsAccountSummaryRepositoryImp(dataManagerSavings) } @Provides - fun providesDataTableRepository(dataManagerDataTable: DataManagerDataTable) : DataTableRepository { + fun providesDataTableRepository(dataManagerDataTable: DataManagerDataTable): DataTableRepository { return DataTableRepositoryImp(dataManagerDataTable) } @Provides - fun providesPinPointClientRepository(dataManagerClient: DataManagerClient) : PinPointClientRepository { + fun providesPinPointClientRepository(dataManagerClient: DataManagerClient): PinPointClientRepository { return PinPointClientRepositoryImp(dataManagerClient) } @Provides - fun providesDocumentListRepository(dataManagerDocument: DataManagerDocument) : DocumentListRepository { + fun providesDocumentListRepository(dataManagerDocument: DataManagerDocument): DocumentListRepository { return DocumentListRepositoryImp(dataManagerDocument) } @Provides - fun providesNoteRepository(dataManagerNote: DataManagerNote) : NoteRepository{ + fun providesNoteRepository(dataManagerNote: DataManagerNote): NoteRepository { return NoteRepositoryImp(dataManagerNote) } @Provides - fun providesSavingAccountRepository(dataManagerSavings: DataManagerSavings) : SavingsAccountRepository { + fun providesSavingAccountRepository(dataManagerSavings: DataManagerSavings): SavingsAccountRepository { return SavingsAccountRepositoryImp(dataManagerSavings) } @Provides - fun providesLoanAccountRepository(dataManagerLoan: DataManagerLoan) : LoanAccountRepository { + fun providesLoanAccountRepository(dataManagerLoan: DataManagerLoan): LoanAccountRepository { return LoanAccountRepositoryImp(dataManagerLoan) } @Provides - fun providesSignatureRepository(dataManagerDocument: DataManagerDocument) : SignatureRepository { + fun providesSignatureRepository(dataManagerDocument: DataManagerDocument): SignatureRepository { return SignatureRepositoryImp(dataManagerDocument) } @Provides - fun providesClientIdentifiersRepository(dataManagerClient: DataManagerClient) : ClientIdentifiersRepository { + fun providesClientIdentifiersRepository(dataManagerClient: DataManagerClient): ClientIdentifiersRepository { return ClientIdentifiersRepositoryImp(dataManagerClient) } @Provides - fun providesSurveyListRepository(dataManagerSurveys: DataManagerSurveys) : SurveyListRepository { + fun providesSurveyListRepository(dataManagerSurveys: DataManagerSurveys): SurveyListRepository { return SurveyListRepositoryImp(dataManagerSurveys) } + + @Provides + fun providesLoanChargeRepository(dataManager: DataManager): LoanChargeRepository { + return LoanChargeRepositoryImp(dataManager) + } + + @Provides + fun providesLoanAccountApprovalRepository(dataManager: DataManager): LoanAccountApprovalRepository { + return LoanAccountApprovalRepositoryImp(dataManager) + } + + @Provides + fun providesLoanAccountDisbursementRepository(dataManagerLoan: DataManagerLoan): LoanAccountDisbursementRepository { + return LoanAccountDisbursementRepositoryImp(dataManagerLoan) + } + + @Provides + fun providesLoanRepaymentRepository(dataManagerLoan: DataManagerLoan): LoanRepaymentRepository { + return LoanRepaymentRepositoryImp(dataManagerLoan) + } + + @Provides + fun providesCollectionSheetRepository(dataManager: DataManager): CollectionSheetRepository { + return CollectionSheetRepositoryImp(dataManager) + } + + @Provides + fun providesNewIndividualCollectionSheetRepository( + dataManager: DataManager, dataManagerCollection: DataManagerCollectionSheet + ): NewIndividualCollectionSheetRepository { + return NewIndividualCollectionSheetRepositoryImp(dataManager, dataManagerCollection) + } + + @Provides + fun providesIndividualCollectionSheetDetailsRepository(dataManagerCollection: DataManagerCollectionSheet): IndividualCollectionSheetDetailsRepository { + return IndividualCollectionSheetDetailsRepositoryImp(dataManagerCollection) + } + + @Provides + fun providesCreateNewCenterRepository(dataManagerCenter: DataManagerCenter): CreateNewCenterRepository { + return CreateNewCenterRepositoryImp(dataManagerCenter) + } + + @Provides + fun providesCreateNewClientRepository( + dataManagerClient: DataManagerClient, + dataManagerOffices: DataManagerOffices, + dataManagerStaff: DataManagerStaff + ): CreateNewClientRepository { + return CreateNewClientRepositoryImp(dataManagerClient, dataManagerOffices, dataManagerStaff) + } + + @Provides + fun providesCreateNewGroupRepository( + dataManagerOffices: DataManagerOffices, dataManagerGroups: DataManagerGroups + ): CreateNewGroupRepository { + return CreateNewGroupRepositoryImp(dataManagerOffices, dataManagerGroups) + } + + @Provides + fun providesDataTableDataRepository(dataManagerDataTable: DataManagerDataTable): DataTableDataRepository { + return DataTableDataRepositoryImp(dataManagerDataTable) + } + + @Provides + fun providesDataTableListRepository( + dataManagerLoan: DataManagerLoan, + dataManager: DataManager, + dataManagerClient: DataManagerClient + ): DataTableListRepository { + return DataTableListRepositoryImp(dataManagerLoan, dataManager, dataManagerClient) + } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/SurveyQuestionActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/SurveyQuestionActivity.kt index 11dd16815ca..c5d53e1e340 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/SurveyQuestionActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/SurveyQuestionActivity.kt @@ -23,12 +23,14 @@ import com.mifos.objects.survey.ScorecardValues import com.mifos.objects.survey.Survey import com.mifos.utils.Constants 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 { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetFragment.kt index 8f9820186ad..4d1814eb9e2 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetFragment.kt @@ -8,6 +8,7 @@ import android.os.Bundle import android.util.Log import android.view.* import android.widget.Toast +import androidx.lifecycle.ViewModelProvider import com.joanzapata.iconify.IconDrawable import com.joanzapata.iconify.fonts.MaterialIcons import com.mifos.api.model.BulkRepaymentTransactions @@ -19,11 +20,12 @@ import com.mifos.mifosxdroid.core.MifosBaseFragment import com.mifos.mifosxdroid.databinding.FragmentCollectionSheetBinding import com.mifos.objects.db.CollectionSheet import com.mifos.objects.response.SaveResponse +import com.mifos.states.CollectionSheetUiState import com.mifos.utils.Constants +import com.mifos.viewmodels.CollectionSheetViewModel import dagger.hilt.android.AndroidEntryPoint -import retrofit2.adapter.rxjava.HttpException +import retrofit2.HttpException import java.util.* -import javax.inject.Inject /** * A simple [Fragment] subclass. @@ -31,14 +33,14 @@ import javax.inject.Inject * create an instance of this fragment. */ @AndroidEntryPoint -class CollectionSheetFragment : MifosBaseFragment(), CollectionSheetMvpView { +class CollectionSheetFragment : MifosBaseFragment() { val LOG_TAG = javaClass.simpleName private lateinit var binding: FragmentCollectionSheetBinding - @Inject - lateinit var mCollectionSheetPresenter: CollectionSheetPresenter - var collectionListAdapter: CollectionListAdapter? = null + private lateinit var viewModel: CollectionSheetViewModel + + private var collectionListAdapter: CollectionListAdapter? = null private var centerId: Int? = null // Center for which collection sheet is being generated = 0 private var dateOfCollection: String? = null // Date of Meeting on which collection has to be done. @@ -65,8 +67,26 @@ class CollectionSheetFragment : MifosBaseFragment(), CollectionSheetMvpView { ): View { // Inflate the layout for this fragment binding = FragmentCollectionSheetBinding.inflate(inflater, container, false) - mCollectionSheetPresenter.attachView(this) + viewModel = ViewModelProvider(this)[CollectionSheetViewModel::class.java] fetchCollectionSheet() + + viewModel.collectionSheetUiState.observe(viewLifecycleOwner) { + when(it) { + is CollectionSheetUiState.ShowCollectionSheet -> { + showCollectionSheet(it.collectionSheet) + } + is CollectionSheetUiState.ShowCollectionSheetSuccessfullySaved -> { + showCollectionSheetSuccessfullySaved(it.saveResponse) + } + is CollectionSheetUiState.ShowFailedToSaveCollectionSheet -> { + showFailedToSaveCollectionSheet(it.e) + } + is CollectionSheetUiState.ShowFetchingError -> { + showFetchingError(it.message) + } + } + } + return binding.root } @@ -107,7 +127,7 @@ class CollectionSheetFragment : MifosBaseFragment(), CollectionSheetMvpView { payload.calendarId = calendarInstanceId.toLong() payload.transactionDate = dateOfCollection payload.dateFormat = "dd-MM-YYYY" - mCollectionSheetPresenter.loadCollectionSheet(centerId!!.toLong(), payload) + viewModel.loadCollectionSheet(centerId!!.toLong(), payload) } @Synchronized @@ -134,21 +154,21 @@ class CollectionSheetFragment : MifosBaseFragment(), CollectionSheetMvpView { //Saving Collection Sheet centerId?.let { - mCollectionSheetPresenter.saveCollectionSheet( + viewModel.saveCollectionSheet( it, collectionSheetPayload ) } } - override fun showCollectionSheet(collectionSheet: CollectionSheet) { + private fun showCollectionSheet(collectionSheet: CollectionSheet) { Log.i(COLLECTION_SHEET_ONLINE, "Received") val mifosGroups = collectionSheet.groups collectionListAdapter = CollectionListAdapter(requireActivity(), mifosGroups) binding.exlvCollectionSheet.setAdapter(collectionListAdapter) } - override fun showCollectionSheetSuccessfullySaved(saveResponse: SaveResponse?) { + private fun showCollectionSheetSuccessfullySaved(saveResponse: SaveResponse?) { if (saveResponse != null) { Toast.makeText( activity, "Collection Sheet Saved Successfully", @@ -157,24 +177,22 @@ class CollectionSheetFragment : MifosBaseFragment(), CollectionSheetMvpView { } } - override fun showFailedToSaveCollectionSheet(response: HttpException?) { - if (response != null) { - if (response.code() == 400 || response.code() == 403) { - //TODO for now, It is commented - //MFErrorParser.parseError(response.response().body()); - } - Toast.makeText( - activity, "Collection Sheet could not be saved.", - Toast.LENGTH_SHORT - ).show() + private fun showFailedToSaveCollectionSheet(response: HttpException) { + if (response.code() == 400 || response.code() == 403) { + //TODO for now, It is commented + //MFErrorParser.parseError(response.response().body()); } + Toast.makeText( + activity, "Collection Sheet could not be saved.", + Toast.LENGTH_SHORT + ).show() } - override fun showFetchingError(s: String?) { + private fun showFetchingError(s: String?) { Toast.makeText(activity, s, Toast.LENGTH_SHORT).show() } - override fun showProgressbar(b: Boolean) { + private fun showProgressbar(b: Boolean) { if (b) { showMifosProgressDialog() } else { @@ -182,11 +200,6 @@ class CollectionSheetFragment : MifosBaseFragment(), CollectionSheetMvpView { } } - override fun onDestroyView() { - super.onDestroyView() - mCollectionSheetPresenter.detachView() - } - companion object { const val COLLECTION_SHEET_ONLINE = "Collection Sheet Online" private const val MENU_ITEM_SEARCH = 2000 diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetMvpView.kt deleted file mode 100644 index 1cc1ca149eb..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetMvpView.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.mifos.mifosxdroid.online.collectionsheet - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.db.CollectionSheet -import com.mifos.objects.response.SaveResponse -import retrofit2.adapter.rxjava.HttpException - -/** - * Created by Rajan Maurya on 7/6/16. - */ -interface CollectionSheetMvpView : MvpView { - fun showCollectionSheet(collectionSheet: CollectionSheet) - fun showCollectionSheetSuccessfullySaved(saveResponse: SaveResponse?) - fun showFailedToSaveCollectionSheet(response: HttpException?) - fun showFetchingError(s: String?) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetPresenter.kt deleted file mode 100644 index f92c596b4c3..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetPresenter.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.mifos.mifosxdroid.online.collectionsheet - -import com.mifos.api.DataManager -import com.mifos.api.model.CollectionSheetPayload -import com.mifos.api.model.Payload -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.db.CollectionSheet -import com.mifos.objects.response.SaveResponse -import retrofit2.adapter.rxjava.HttpException -import rx.Subscriber -import rx.Subscription -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 7/6/16. - */ -class CollectionSheetPresenter @Inject constructor(private val mDataManager: DataManager) : BasePresenter() { - private var mSubscription: Subscription? = null - override fun attachView(mvpView: CollectionSheetMvpView?) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - if (mSubscription != null) mSubscription!!.unsubscribe() - } - - fun loadCollectionSheet(id: Long, payload: Payload?) { - checkViewAttached() - if (mSubscription != null) mSubscription!!.unsubscribe() - mSubscription = mDataManager.getCollectionSheet(id, payload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showFetchingError("Failed to fetch CollectionSheet") - } - - override fun onNext(collectionSheet: CollectionSheet?) { - collectionSheet?.let { mvpView!!.showCollectionSheet(it) } - } - }) - } - - fun saveCollectionSheet(id: Int, payload: CollectionSheetPayload?) { - checkViewAttached() - if (mSubscription != null) mSubscription!!.unsubscribe() - mSubscription = mDataManager.saveCollectionSheetAsync(id, payload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - if (e is HttpException) { - mvpView!!.showFailedToSaveCollectionSheet(e) - } - } - - override fun onNext(saveResponse: SaveResponse?) { - mvpView!!.showCollectionSheetSuccessfullySaved(saveResponse) - } - }) - } - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetMvpView.kt deleted file mode 100644 index dd8920be950..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetMvpView.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.mifos.mifosxdroid.online.collectionsheetindividual - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.collectionsheet.IndividualCollectionSheet -import com.mifos.objects.organisation.Office -import com.mifos.objects.organisation.Staff - -/** - * Created by Tarun on 05-07-2017. - */ -interface IndividualCollectionSheetMvpView : MvpView { - fun showSheet(sheet: IndividualCollectionSheet?) - fun showSuccess() - fun showError(error: String?) - fun setOfficeSpinner(officeList: List?) - fun setStaffSpinner(staffList: List?) - fun showNoSheetFound() -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetFragment.kt index 7b2c68df922..fd344d2ec96 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetFragment.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.lifecycle.ViewModelProvider import androidx.navigation.fragment.findNavController import com.mifos.api.model.RequestCollectionSheetPayload import com.mifos.mifosxdroid.R @@ -14,29 +15,29 @@ import com.mifos.mifosxdroid.dialogfragments.collectionsheetdialog.CollectionShe import com.mifos.objects.collectionsheet.IndividualCollectionSheet import com.mifos.objects.organisation.Office import com.mifos.objects.organisation.Staff +import com.mifos.states.NewIndividualCollectionSheetUiState import com.mifos.utils.Constants import com.mifos.utils.DatePickerConstrainType import com.mifos.utils.FragmentConstants import com.mifos.utils.getDatePickerDialog import com.mifos.utils.getTodayFormatted +import com.mifos.viewmodels.NewIndividualCollectionSheetViewModel import dagger.hilt.android.AndroidEntryPoint import java.text.SimpleDateFormat import java.time.Instant import java.util.Locale -import javax.inject.Inject /** * Created by aksh on 18/6/18. */ @AndroidEntryPoint -class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualCollectionSheetMvpView, - View.OnClickListener { +class NewIndividualCollectionSheetFragment : MifosBaseFragment(), View.OnClickListener { private lateinit var binding: FragmentNewCollectionSheetBinding - @Inject - lateinit var presenter: NewIndividualCollectionSheetPresenter + private lateinit var viewModel: NewIndividualCollectionSheetViewModel + private var sheet: IndividualCollectionSheet? = null private var requestPayload: RequestCollectionSheetPayload? = null private lateinit var officeNameList: ArrayList @@ -53,7 +54,7 @@ class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualColl private var selectedRepaymentDate: Instant = Instant.now() private val datePickerDialog by lazy { getDatePickerDialog(selectedRepaymentDate, DatePickerConstrainType.ONLY_FUTURE_DAYS) { - val formattedDate = SimpleDateFormat("dd MM yyyy", Locale.getDefault()).format(it) + val formattedDate = SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format(it) selectedRepaymentDate = Instant.ofEpochMilli(it) binding.repaymentDateFieldContainer.editText?.setText(formattedDate) } @@ -74,8 +75,44 @@ class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualColl ): View { binding = FragmentNewCollectionSheetBinding.inflate(inflater, container, false) setToolbarTitle(getStringMessage(R.string.individual_collection_sheet)) - presenter.attachView(this) + viewModel = ViewModelProvider(this)[NewIndividualCollectionSheetViewModel::class.java] setUpUi() + + viewModel.newIndividualCollectionSheetUiState.observe(viewLifecycleOwner) { + when (it) { + is NewIndividualCollectionSheetUiState.SetOfficeSpinner -> { + showProgressbar(false) + setOfficeSpinner(it.officeList) + } + + is NewIndividualCollectionSheetUiState.SetStaffSpinner -> { + showProgressbar(false) + setStaffSpinner(it.staffList) + } + + is NewIndividualCollectionSheetUiState.ShowError -> { + showProgressbar(false) + showError(it.errorMessage) + } + + is NewIndividualCollectionSheetUiState.ShowNoSheetFound -> { + showProgressbar(false) + showNoSheetFound() + } + + is NewIndividualCollectionSheetUiState.ShowProgressbar -> showProgressbar(true) + is NewIndividualCollectionSheetUiState.ShowSheet -> { + showProgressbar(false) + showSheet(it.individualCollectionSheet) + } + + is NewIndividualCollectionSheetUiState.ShowSuccess -> { + showProgressbar(false) + showSuccess() + } + } + } + return binding.root } @@ -95,7 +132,7 @@ class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualColl val i = officeNameList.indexOf(adapterView.getItemAtPosition(relativePosition)) Toaster.show(binding.root, officeNameList[i]) officeId = officeList[i].id - presenter.fetchStaff(officeId!!) + viewModel.fetchStaff(officeId!!) } staffNameList = ArrayList() binding.staffSelectionField.setSimpleItems(staffNameList.toTypedArray()) @@ -106,7 +143,7 @@ class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualColl ) } binding.btnFetchCollectionSheet.setOnClickListener(this) - presenter.fetchOffices() + viewModel.fetchOffices() } @@ -124,21 +161,21 @@ class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualColl binding.repaymentDateFieldContainer.editText?.text.toString() } - override fun setOfficeSpinner(offices: List?) { + private fun setOfficeSpinner(offices: List?) { if (offices != null) { officeList = offices } officeNameList.clear() - officeNameList.addAll(presenter.filterOffices(officeList)) + officeNameList.addAll(viewModel.filterOffices(officeList)) binding.officeListField.setSimpleItems(officeNameList.toTypedArray()) } private fun retrieveCollectionSheet() { prepareRequestPayload() - presenter.fetchIndividualCollectionSheet(requestPayload) + viewModel.fetchIndividualCollectionSheet(requestPayload) } - override fun setStaffSpinner(staffs: List?) { + private fun setStaffSpinner(staffs: List?) { binding.staffSelectionField.setOnItemClickListener { adapterView, _, relativePosition, _ -> val i = staffNameList.indexOf(adapterView.getItemAtPosition(relativePosition)) staffId = staffList[i].id @@ -147,7 +184,7 @@ class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualColl staffList = staffs } staffNameList.clear() - staffNameList.addAll(presenter.filterStaff(staffList)) + staffNameList.addAll(viewModel.filterStaff(staffList)) binding.staffSelectionField.setSimpleItems(staffNameList.toTypedArray()) } @@ -183,7 +220,7 @@ class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualColl } } - override fun showSheet(individualCollectionSheet: IndividualCollectionSheet?) { + private fun showSheet(individualCollectionSheet: IndividualCollectionSheet?) { sheet = individualCollectionSheet } @@ -192,22 +229,22 @@ class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualColl outState.putParcelable(Constants.EXTRA_COLLECTION_INDIVIDUAL, sheet) } - override fun showSuccess() { + private fun showSuccess() { if (success) { popupDialog() } } - override fun showError(message: String?) { + private fun showError(message: String?) { Toaster.show(binding.root, message) } - override fun showNoSheetFound() { + private fun showNoSheetFound() { success = false Toaster.show(binding.root, getStringMessage(R.string.no_collectionsheet_found)) } - override fun showProgressbar(b: Boolean) { + private fun showProgressbar(b: Boolean) { if (b) { showMifosProgressDialog() } else { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetPresenter.kt deleted file mode 100644 index 4229d47554d..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetPresenter.kt +++ /dev/null @@ -1,157 +0,0 @@ -package com.mifos.mifosxdroid.online.collectionsheetindividual - -import com.mifos.api.DataManager -import com.mifos.api.datamanager.DataManagerCollectionSheet -import com.mifos.api.model.RequestCollectionSheetPayload -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.collectionsheet.IndividualCollectionSheet -import com.mifos.objects.organisation.Office -import com.mifos.objects.organisation.Staff -import com.mifos.utils.MFErrorParser -import retrofit2.HttpException -import rx.Observable -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.plugins.RxJavaPlugins -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import javax.inject.Inject - -/** - * Created by Tarun on 05-07-2017. - */ -class NewIndividualCollectionSheetPresenter @Inject internal constructor( - private val mDataManager: DataManager, - private val mDataManagerCollection: DataManagerCollectionSheet -) : BasePresenter() { - private val mSubscription: CompositeSubscription? - - override fun detachView() { - super.detachView() - mSubscription?.unsubscribe() - } - - fun fetchIndividualCollectionSheet(requestCollectionSheetPayload: RequestCollectionSheetPayload?) { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscription?.add(mDataManagerCollection - .getIndividualCollectionSheet(requestCollectionSheetPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView?.showSuccess() - } - - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - if (e is HttpException) { - try { - val errorMessage = e.response()?.errorBody() - ?.string() - mvpView?.showError( - MFErrorParser.parseError(errorMessage) - .errors[0].defaultUserMessage - ) - } catch (throwable: Throwable) { - RxJavaPlugins.getInstance().errorHandler.handleError(e) - } - } else { - mvpView?.showError(e.localizedMessage) - } - } - - override fun onNext(individualCollectionSheet: IndividualCollectionSheet?) { - mvpView?.showProgressbar(false) - if (individualCollectionSheet?.clients?.size!! > 0) { - mvpView?.showSheet(individualCollectionSheet) - } else { - mvpView?.showNoSheetFound() - } - } - }) - ) - } - - fun fetchOffices() { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscription?.add(mDataManager.offices - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber?>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - try { - if (e is HttpException) { - val errorMessage = e.response()?.errorBody() - ?.string() - mvpView?.showError( - MFErrorParser.parseError(errorMessage) - .errors[0].defaultUserMessage - ) - } - } catch (throwable: Throwable) { - RxJavaPlugins.getInstance().errorHandler.handleError(e) - } - } - - override fun onNext(officeList: List?) { - mvpView?.setOfficeSpinner(officeList as List?) - mvpView?.showProgressbar(false) - } - }) - ) - } - - fun fetchStaff(officeId: Int) { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscription?.add(mDataManager.getStaffInOffice(officeId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber?>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - try { - if (e is HttpException) { - val errorMessage = e.response()?.errorBody() - ?.string() - mvpView?.showError( - MFErrorParser.parseError(errorMessage) - .errors[0].defaultUserMessage - ) - } - } catch (throwable: Throwable) { - RxJavaPlugins.getInstance().errorHandler.handleError(e) - } - } - - override fun onNext(staffList: List?) { - mvpView?.setStaffSpinner(staffList as List?) - mvpView?.showProgressbar(false) - } - }) - ) - } - - fun filterOffices(offices: List?): List { - val officesList: MutableList = ArrayList() - Observable.from(offices) - .subscribe { office -> office.name?.let { officesList.add(it) } } - return officesList - } - - fun filterStaff(staffs: List?): List { - val staffList: MutableList = ArrayList() - Observable.from(staffs) - .subscribe { staff -> staff.displayName?.let { staffList.add(it) } } - return staffList - } - - init { - mSubscription = CompositeSubscription() - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsFragment.kt index f3a168c3d81..a41470dd1ce 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsFragment.kt @@ -7,6 +7,7 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup +import androidx.lifecycle.ViewModelProvider import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager @@ -21,22 +22,23 @@ import com.mifos.mifosxdroid.databinding.IndividualCollectionsSheetDetailsBindin import com.mifos.mifosxdroid.online.GenerateCollectionSheetActivity import com.mifos.objects.collectionsheet.IndividualCollectionSheet import com.mifos.objects.collectionsheet.LoanAndClientName +import com.mifos.states.IndividualCollectionSheetDetailsUiState import com.mifos.utils.Constants +import com.mifos.viewmodels.IndividualCollectionSheetDetailsViewModel import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject /** * Created by aksh on 20/6/18. */ @AndroidEntryPoint -class IndividualCollectionSheetDetailsFragment : MifosBaseFragment(), - IndividualCollectionSheetDetailsMvpView, OnRetrieveSheetItemData, ListAdapterListener { +class IndividualCollectionSheetDetailsFragment : MifosBaseFragment(), OnRetrieveSheetItemData, + ListAdapterListener { private lateinit var binding: IndividualCollectionsSheetDetailsBinding private val arg: IndividualCollectionSheetDetailsFragmentArgs by navArgs() - @Inject - lateinit var presenter: IndividualCollectionSheetDetailsPresenter + private lateinit var viewModel: IndividualCollectionSheetDetailsViewModel + var sheetsAdapter: IndividualCollectionSheetDetailsAdapter? = null private var sheet: IndividualCollectionSheet? = null private var paymentTypeList: List? = null @@ -65,9 +67,25 @@ class IndividualCollectionSheetDetailsFragment : MifosBaseFragment(), binding = IndividualCollectionsSheetDetailsBinding.inflate(inflater, container, false) setToolbarTitle(getStringMessage(R.string.individual_collection_sheet)) sheetsAdapter = IndividualCollectionSheetDetailsAdapter(requireContext(), this) - presenter.attachView(this) + viewModel = ViewModelProvider(this)[IndividualCollectionSheetDetailsViewModel::class.java] payload = (activity as GenerateCollectionSheetActivity).payload showCollectionSheetViews(sheet) + + viewModel.individualCollectionSheetDetailsUiState.observe(viewLifecycleOwner) { + when (it) { + is IndividualCollectionSheetDetailsUiState.ShowError -> { + showProgressbar(false) + showError(it.message) + } + + is IndividualCollectionSheetDetailsUiState.ShowProgressbar -> showProgressbar(true) + is IndividualCollectionSheetDetailsUiState.ShowSuccess -> { + showProgressbar(false) + showSuccess() + } + } + } + return binding.root } @@ -87,8 +105,8 @@ class IndividualCollectionSheetDetailsFragment : MifosBaseFragment(), } private fun showCollectionSheetViews(sheet: IndividualCollectionSheet?) { - paymentTypeList = presenter.filterPaymentTypeOptions(sheet?.paymentTypeOptions) - loansAndClientNames = presenter.filterLoanAndClientNames(sheet?.clients) + paymentTypeList = viewModel.filterPaymentTypeOptions(sheet?.paymentTypeOptions) + loansAndClientNames = viewModel.filterLoanAndClientNames(sheet?.clients) //Initialize payload's BulkRepaymentTransactions array with default values. //The changes made (if any) will be updated by the interface 'OnRetrieveSheetItemData' @@ -96,7 +114,7 @@ class IndividualCollectionSheetDetailsFragment : MifosBaseFragment(), //methods. if (payload == null) { payload = IndividualCollectionSheetPayload() - for (loanAndClientName in presenter.filterLoanAndClientNames(sheet?.clients)) { + for (loanAndClientName in viewModel.filterLoanAndClientNames(sheet?.clients)) { val loanCollectionSheet = loanAndClientName.loan if (loanCollectionSheet != null) { payload?.bulkRepaymentTransactions?.add( @@ -119,15 +137,15 @@ class IndividualCollectionSheetDetailsFragment : MifosBaseFragment(), sheetsAdapter?.notifyDataSetChanged() } - override fun showSuccess() { + private fun showSuccess() { Toaster.show(binding.root, getStringMessage(R.string.collectionsheet_submit_success)) } - override fun showError(error: String?) { + private fun showError(error: String?) { Toaster.show(binding.root, error) } - override fun showProgressbar(b: Boolean) { + private fun showProgressbar(b: Boolean) { if (b) { showMifosProgressDialog() } else { @@ -168,7 +186,7 @@ class IndividualCollectionSheetDetailsFragment : MifosBaseFragment(), } else { payload?.actualDisbursementDate = actualDisbursementDate payload?.transactionDate = transactionDate - presenter.submitIndividualCollectionSheet(payload) + viewModel.submitIndividualCollectionSheet(payload) } } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsMvpView.kt deleted file mode 100644 index 577354b7dc8..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsMvpView.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.mifos.mifosxdroid.online.collectionsheetindividualdetails - -import com.mifos.mifosxdroid.base.MvpView - -/** - * Created by aksh on 20/6/18. - */ -interface IndividualCollectionSheetDetailsMvpView : MvpView { - fun showSuccess() - fun showError(error: String?) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsPresenter.kt deleted file mode 100644 index eb2b9c8101e..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsPresenter.kt +++ /dev/null @@ -1,92 +0,0 @@ -package com.mifos.mifosxdroid.online.collectionsheetindividualdetails - -import com.mifos.api.DataManager -import com.mifos.api.GenericResponse -import com.mifos.api.datamanager.DataManagerCollectionSheet -import com.mifos.api.model.IndividualCollectionSheetPayload -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.accounts.loan.PaymentTypeOptions -import com.mifos.objects.collectionsheet.ClientCollectionSheet -import com.mifos.objects.collectionsheet.LoanAndClientName -import com.mifos.utils.MFErrorParser -import retrofit2.HttpException -import rx.Observable -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.plugins.RxJavaPlugins -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import java.util.* -import javax.inject.Inject - -/** - * Created by aksh on 20/6/18. - */ -class IndividualCollectionSheetDetailsPresenter @Inject internal constructor(private val mDataManager: DataManager, - private val mDataManagerCollection: DataManagerCollectionSheet) : BasePresenter() { - private val mSubscription: CompositeSubscription? - override fun attachView(mvpView: IndividualCollectionSheetDetailsMvpView?) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - mSubscription?.unsubscribe() - } - - fun submitIndividualCollectionSheet(individualCollectionSheetPayload: IndividualCollectionSheetPayload?) { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscription!!.add(mDataManagerCollection - .saveIndividualCollectionSheet(individualCollectionSheetPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - try { - if (e is HttpException) { - val errorMessage = e.response()?.errorBody() - ?.string() - mvpView!!.showError(MFErrorParser.parseError(errorMessage) - .errors[0].defaultUserMessage) - } - } catch (throwable: Throwable) { - RxJavaPlugins.getInstance().errorHandler.handleError(e) - } - } - - override fun onNext(genericResponse: GenericResponse?) { - mvpView!!.showProgressbar(false) - mvpView!!.showSuccess() - } - })) - } - - fun filterPaymentTypeOptions(paymentTypeOptionsList: List?): List { - val paymentList: MutableList = ArrayList() - Observable.from(paymentTypeOptionsList) - .subscribe { paymentTypeOption -> paymentTypeOption.name?.let { paymentList.add(it) } } - return paymentList - } - - fun filterLoanAndClientNames(clientCollectionSheets: List?): List { - val loansAndClientNames: MutableList = ArrayList() - Observable.from(clientCollectionSheets) - .subscribe { clientCollectionSheet -> - if (clientCollectionSheet.loans != null) { - for (loanCollectionSheet in clientCollectionSheet.loans!!) { - loansAndClientNames.add(LoanAndClientName(loanCollectionSheet, - clientCollectionSheet.clientName, - clientCollectionSheet.clientId)) - } - } - } - return loansAndClientNames - } - - init { - mSubscription = CompositeSubscription() - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt index 903c541b409..5cb30b35064 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt @@ -29,10 +29,10 @@ class PaymentDetailsFragment : MifosBaseFragment(), View.OnClickListener, OnItem private lateinit var binding: AddPaymentDetailBinding private val arg: PaymentDetailsFragmentArgs by navArgs() - var paymentTypeList: List? = null - var paymentTypeOptionsList: List? = null + private var paymentTypeList: List? = null + private var paymentTypeOptionsList: List? = null var payload: IndividualCollectionSheetPayload? = null - var mCallback: OnPayloadSelectedListener? = null + private var mCallback: OnPayloadSelectedListener? = null private lateinit var bulkRepaymentTransaction: BulkRepaymentTransactions private var position = 0 private var clientId = 0 diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterFragment.kt index 578936f4100..2fe32a2399b 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterFragment.kt @@ -10,6 +10,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.lifecycle.ViewModelProvider import com.mifos.exceptions.InvalidTextInputException import com.mifos.exceptions.RequiredFieldException import com.mifos.exceptions.ShortOfLengthException @@ -19,31 +20,32 @@ import com.mifos.mifosxdroid.databinding.FragmentCreateNewCenterBinding import com.mifos.objects.organisation.Office import com.mifos.objects.response.SaveResponse import com.mifos.services.data.CenterPayload +import com.mifos.states.CreateNewCenterUiState import com.mifos.utils.DatePickerConstrainType import com.mifos.utils.FragmentConstants import com.mifos.utils.MifosResponseHandler import com.mifos.utils.ValidationUtil import com.mifos.utils.getDatePickerDialog import com.mifos.utils.getTodayFormatted +import com.mifos.viewmodels.CreateNewCenterViewModel import dagger.hilt.android.AndroidEntryPoint import java.text.SimpleDateFormat import java.time.Instant import java.util.Locale -import javax.inject.Inject /** * Created by nellyk on 1/22/2016. */ @AndroidEntryPoint -class CreateNewCenterFragment : MifosBaseFragment(), CreateNewCenterMvpView { +class CreateNewCenterFragment : MifosBaseFragment() { private lateinit var binding: FragmentCreateNewCenterBinding var officeId: Int? = 0 var result = true - @Inject - lateinit var mCreateNewCenterPresenter: CreateNewCenterPresenter + private lateinit var viewModel: CreateNewCenterViewModel + private var activationDateString: String? = null private val officeNameIdHashMap = HashMap() @@ -62,11 +64,37 @@ class CreateNewCenterFragment : MifosBaseFragment(), CreateNewCenterMvpView { savedInstanceState: Bundle? ): View { binding = FragmentCreateNewCenterBinding.inflate(inflater, container, false) - mCreateNewCenterPresenter.attachView(this) + viewModel = ViewModelProvider(this)[CreateNewCenterViewModel::class.java] inflateOfficeSpinner() inflateActivationDate() //client active checkbox onCheckedListener + viewModel.createNewCenterUiState.observe(viewLifecycleOwner) { + when (it) { + is CreateNewCenterUiState.CenterCreatedSuccessfully -> { + showProgressbar(false) + centerCreatedSuccessfully(it.saveResponse) + } + + is CreateNewCenterUiState.ShowFetchingError -> { + showProgressbar(false) + showFetchingError(it.message) + } + + is CreateNewCenterUiState.ShowFetchingErrorString -> { + showProgressbar(false) + showFetchingError(it.message) + } + + is CreateNewCenterUiState.ShowOffices -> { + showProgressbar(false) + showOffices(it.offices) + } + + is CreateNewCenterUiState.ShowProgressbar -> showProgressbar(true) + } + } + return binding.root } @@ -102,12 +130,12 @@ class CreateNewCenterFragment : MifosBaseFragment(), CreateNewCenterMvpView { //inflating office list spinner private fun inflateOfficeSpinner() { - mCreateNewCenterPresenter.loadOffices() + viewModel.loadOffices() } private fun initiateCenterCreation(centerPayload: CenterPayload) { if (isCenterNameValid) { - mCreateNewCenterPresenter.createCenter(centerPayload) + viewModel.createCenter(centerPayload) } } @@ -151,7 +179,7 @@ class CreateNewCenterFragment : MifosBaseFragment(), CreateNewCenterMvpView { return result } - override fun showOffices(offices: List?) { + private fun showOffices(offices: List?) { val officeList: MutableList = ArrayList() if (offices != null) { for (office in offices) { @@ -179,7 +207,7 @@ class CreateNewCenterFragment : MifosBaseFragment(), CreateNewCenterMvpView { } } - override fun centerCreatedSuccessfully(saveResponse: SaveResponse?) { + private fun centerCreatedSuccessfully(saveResponse: SaveResponse?) { Toast.makeText( activity, "Center " + MifosResponseHandler.response, Toast.LENGTH_LONG @@ -187,15 +215,15 @@ class CreateNewCenterFragment : MifosBaseFragment(), CreateNewCenterMvpView { requireActivity().supportFragmentManager.popBackStack() } - override fun showFetchingError(errorMessage: Int) { + private fun showFetchingError(errorMessage: Int) { Toast.makeText(activity, errorMessage, Toast.LENGTH_SHORT).show() } - override fun showFetchingError(s: String?) { + private fun showFetchingError(s: String?) { Toast.makeText(activity, s, Toast.LENGTH_SHORT).show() } - override fun showProgressbar(show: Boolean) { + private fun showProgressbar(show: Boolean) { if (show) { binding.llCenter.visibility = View.GONE showMifosProgressBar() @@ -204,9 +232,4 @@ class CreateNewCenterFragment : MifosBaseFragment(), CreateNewCenterMvpView { hideMifosProgressBar() } } - - override fun onDestroyView() { - super.onDestroyView() - mCreateNewCenterPresenter.detachView() - } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterMvpView.kt deleted file mode 100644 index d79fa4b0365..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterMvpView.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.mifos.mifosxdroid.online.createnewcenter - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.organisation.Office -import com.mifos.objects.response.SaveResponse - -/** - * Created by Rajan Maurya on 06/06/16. - */ -interface CreateNewCenterMvpView : MvpView { - fun showOffices(offices: List?) - fun centerCreatedSuccessfully(saveResponse: SaveResponse?) - fun showFetchingError(errorMessage: Int) - fun showFetchingError(s: String?) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterPresenter.kt deleted file mode 100644 index ce9760d649b..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterPresenter.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.mifos.mifosxdroid.online.createnewcenter - -import com.mifos.api.datamanager.DataManagerCenter -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.organisation.Office -import com.mifos.objects.response.SaveResponse -import com.mifos.services.data.CenterPayload -import com.mifos.utils.MFErrorParser -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 06/06/16. - */ -class CreateNewCenterPresenter @Inject constructor(private val dataManagerCenter: DataManagerCenter) : BasePresenter() { - private val subscriptions: CompositeSubscription = CompositeSubscription() - override fun attachView(mvpView: CreateNewCenterMvpView?) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - subscriptions.unsubscribe() - } - - fun loadOffices() { - checkViewAttached() - mvpView!!.showProgressbar(true) - subscriptions.add(dataManagerCenter.offices - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber?>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showFetchingError(R.string.failed_to_fetch_offices) - } - - override fun onNext(offices: List?) { - mvpView!!.showProgressbar(false) - mvpView!!.showOffices(offices) - } - })) - } - - fun createCenter(centerPayload: CenterPayload) { - checkViewAttached() - mvpView!!.showProgressbar(true) - subscriptions.add(dataManagerCenter.createCenter(centerPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView!!.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showFetchingError(MFErrorParser.errorMessage(e)) - } - - override fun onNext(saveResponse: SaveResponse?) { - mvpView!!.showProgressbar(false) - mvpView!!.centerCreatedSuccessfully(saveResponse) - } - })) - } - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt index 996a6c0fa21..5a58c593526 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt @@ -11,7 +11,6 @@ import android.content.Intent import android.content.pm.PackageManager import android.graphics.BitmapFactory import android.net.Uri -import android.os.Build import android.os.Bundle import android.provider.MediaStore import android.telephony.PhoneNumberUtils @@ -22,6 +21,7 @@ import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.appcompat.widget.PopupMenu +import androidx.lifecycle.ViewModelProvider import com.mifos.exceptions.InvalidTextInputException import com.mifos.exceptions.RequiredFieldException import com.mifos.mifosxdroid.R @@ -33,26 +33,26 @@ import com.mifos.objects.client.ClientPayload import com.mifos.objects.organisation.Office import com.mifos.objects.organisation.Staff import com.mifos.objects.templates.clients.ClientsTemplate +import com.mifos.states.CreateNewClientUiState import com.mifos.utils.Constants import com.mifos.utils.DatePickerConstrainType import com.mifos.utils.FragmentConstants import com.mifos.utils.ValidationUtil import com.mifos.utils.getDatePickerDialog import com.mifos.utils.getTodayFormatted +import com.mifos.viewmodels.CreateNewClientViewModel import dagger.hilt.android.AndroidEntryPoint import java.io.File import java.text.SimpleDateFormat import java.time.Instant import java.util.Locale -import javax.inject.Inject @AndroidEntryPoint -class CreateNewClientFragment : ProgressableFragment(), CreateNewClientMvpView { +class CreateNewClientFragment : ProgressableFragment() { private lateinit var binding: FragmentCreateNewClientBinding - @Inject - lateinit var createNewClientPresenter: CreateNewClientPresenter + private lateinit var viewModel: CreateNewClientViewModel // It checks whether the user wants to create the new client with or without picture private var createClientWithImage = false @@ -102,9 +102,56 @@ class CreateNewClientFragment : ProgressableFragment(), CreateNewClientMvpView { savedInstanceState: Bundle? ): View { binding = FragmentCreateNewClientBinding.inflate(inflater, container, false) - createNewClientPresenter.attachView(this) + viewModel = ViewModelProvider(this)[CreateNewClientViewModel::class.java] showUserInterface() - createNewClientPresenter.loadClientTemplate() + viewModel.loadClientTemplate() + + viewModel.createNewClientUiState.observe(viewLifecycleOwner) { + when (it) { + is CreateNewClientUiState.SetClientId -> { + showProgressbar(false) + setClientId(it.id) + } + + is CreateNewClientUiState.ShowClientCreatedSuccessfully -> { + showProgressbar(false) + showClientCreatedSuccessfully(it.message) + } + + is CreateNewClientUiState.ShowClientTemplate -> { + showProgressbar(false) + showClientTemplate(it.clientsTemplate) + } + + is CreateNewClientUiState.ShowMessage -> { + showProgressbar(false) + showMessage(it.message) + } + + is CreateNewClientUiState.ShowMessageString -> { + showProgressbar(false) + showMessage(it.message) + } + + is CreateNewClientUiState.ShowOffices -> { + showProgressbar(false) + showOffices(it.officeList) + } + + is CreateNewClientUiState.ShowProgress -> showProgress(it.message) + is CreateNewClientUiState.ShowProgressbar -> showProgressbar(true) + is CreateNewClientUiState.ShowStaffInOffices -> { + showProgressbar(false) + showStaffInOffices(it.staffList) + } + + is CreateNewClientUiState.ShowWaitingForCheckerApproval -> { + showProgressbar(false) + showWaitingForCheckerApproval(it.message) + } + } + } + return binding.root } @@ -145,7 +192,7 @@ class CreateNewClientFragment : ProgressableFragment(), CreateNewClientMvpView { binding.officeListField.setOnItemClickListener { adapterView, view, relativePosition, l -> val index = officeList.indexOf(adapterView.getItemAtPosition(relativePosition)) officeId = clientOffices?.get(index)?.id - officeId?.let { createNewClientPresenter.loadStaffInOffices(it) } + officeId?.let { viewModel.loadStaffInOffices(it) } } binding.staffListField.setOnItemClickListener { adapterView, view, relativePosition, l -> @@ -162,7 +209,7 @@ class CreateNewClientFragment : ProgressableFragment(), CreateNewClientMvpView { } - override fun showUserInterface() { + private fun showUserInterface() { binding.submissionDateFieldContainer.editText?.setText(getTodayFormatted()) @@ -275,7 +322,7 @@ class CreateNewClientFragment : ProgressableFragment(), CreateNewClientMvpView { fragmentTransaction.replace(R.id.container, fragment).commit() } else { clientPayload.datatables = null - createNewClientPresenter.createClient(clientPayload) + viewModel.createClient(clientPayload) } } } @@ -285,7 +332,7 @@ class CreateNewClientFragment : ProgressableFragment(), CreateNewClientMvpView { if (binding.cbClientActiveStatus.isChecked) View.VISIBLE else View.GONE } - override fun showClientTemplate(clientsTemplate: ClientsTemplate?) { + private fun showClientTemplate(clientsTemplate: ClientsTemplate?) { this.clientsTemplate = clientsTemplate if (clientsTemplate != null) { if (clientsTemplate.dataTables.isNotEmpty()) { @@ -293,67 +340,60 @@ class CreateNewClientFragment : ProgressableFragment(), CreateNewClientMvpView { } } genderOptionsList.addAll( - createNewClientPresenter.filterOptions(clientsTemplate?.genderOptions) + viewModel.filterOptions(clientsTemplate?.genderOptions) ) binding.genderListField.setSimpleItems(genderOptionsList.toTypedArray()) clientTypeList.addAll( - createNewClientPresenter.filterOptions(clientsTemplate?.clientTypeOptions) + viewModel.filterOptions(clientsTemplate?.clientTypeOptions) ) binding.clientTypeListField.setSimpleItems(clientTypeList.toTypedArray()) clientClassificationList.addAll( - createNewClientPresenter + viewModel .filterOptions(clientsTemplate?.clientClassificationOptions) ) binding.clientTypeListField.setSimpleItems(clientTypeList.toTypedArray()) } - override fun showOffices(offices: List?) { - clientOffices = offices as List? - officeList.addAll(createNewClientPresenter.filterOffices(offices)) + private fun showOffices(offices: List) { + clientOffices = offices + officeList.addAll(viewModel.filterOffices(offices)) officeList.sort() binding.officeListField.setSimpleItems(officeList.toTypedArray()) } - override fun showStaffInOffices(staffs: List?) { - if (staffs != null) { - if (staffs.isEmpty()) { - showMessage(R.string.no_staff_associated_with_office) - } + private fun showStaffInOffices(staffs: List) { + if (staffs.isEmpty()) { + showMessage(R.string.no_staff_associated_with_office) } - clientStaff = staffs as List? + clientStaff = staffs staffList.clear() - staffList.addAll(createNewClientPresenter.filterStaff(staffs)) + staffList.addAll(viewModel.filterStaff(staffs)) binding.staffListField.setSimpleItems(staffList.toTypedArray()) } - override fun showClientCreatedSuccessfully(message: Int) { + private fun showClientCreatedSuccessfully(message: Int) { Toaster.show(binding.root, message) } - override fun showWaitingForCheckerApproval(message: Int) { + private fun showWaitingForCheckerApproval(message: Int) { Toaster.show(binding.root, message) requireActivity().supportFragmentManager.popBackStack() } - override fun showMessage(message: Int) { + private fun showMessage(message: Int) { Toaster.show(binding.root, message) } - override fun showMessage(message: String?) { + private fun showMessage(message: String?) { Toast.makeText(activity, message, Toast.LENGTH_SHORT).show() } - override fun showProgressbar(show: Boolean) { + private fun showProgressbar(show: Boolean) { showProgress(show) } - override fun onDestroyView() { - super.onDestroyView() - createNewClientPresenter.detachView() - } - private val isFirstNameValid: Boolean get() { result = true @@ -431,10 +471,10 @@ class CreateNewClientFragment : ProgressableFragment(), CreateNewClientMvpView { return result } - override fun setClientId(id: Int?) { + private fun setClientId(id: Int) { returnedClientId = id if (createClientWithImage) { - ClientImageFile?.let { createNewClientPresenter.uploadImage(returnedClientId!!, it) } + ClientImageFile?.let { viewModel.uploadImage(returnedClientId!!, it) } } else { requireActivity().supportFragmentManager.popBackStack() } @@ -464,7 +504,7 @@ class CreateNewClientFragment : ProgressableFragment(), CreateNewClientMvpView { } } - override fun showProgress(message: String?) { + private fun showProgress(message: String?) { if (progress == null) { progress = ProgressDialog(activity, ProgressDialog.STYLE_SPINNER) progress?.setCancelable(false) @@ -473,13 +513,13 @@ class CreateNewClientFragment : ProgressableFragment(), CreateNewClientMvpView { progress?.show() } - override fun hideProgress() { + private fun hideProgress() { if (progress != null && progress!!.isShowing) progress?.dismiss() } //permission is automatically granted on sdk<23 upon installation - val isStoragePermissionGranted: Boolean - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + private val isStoragePermissionGranted: Boolean + get() = if (requireActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED ) { @@ -491,9 +531,6 @@ class CreateNewClientFragment : ProgressableFragment(), CreateNewClientMvpView { ) false } - } else { //permission is automatically granted on sdk<23 upon installation - true - } override fun onRequestPermissionsResult( requestCode: Int, permissions: Array, grantResults: IntArray diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientMvpView.kt deleted file mode 100644 index e5f75532d60..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientMvpView.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.mifos.mifosxdroid.online.createnewclient - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.organisation.Office -import com.mifos.objects.organisation.Staff -import com.mifos.objects.templates.clients.ClientsTemplate - -/** - * Created by Rajan Maurya on 6/6/16. - */ -interface CreateNewClientMvpView : MvpView { - fun showUserInterface() - fun showClientTemplate(clientsTemplate: ClientsTemplate?) - fun showOffices(offices: List?) - fun showStaffInOffices(staffs: List?) - fun showClientCreatedSuccessfully(s: Int) - fun showWaitingForCheckerApproval(s: Int) - fun showMessage(message: Int) - fun showMessage(message: String?) - fun setClientId(id: Int?) - fun showProgress(message: String?) - fun hideProgress() -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientPresenter.kt deleted file mode 100644 index 55666b6d4b5..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientPresenter.kt +++ /dev/null @@ -1,203 +0,0 @@ -package com.mifos.mifosxdroid.online.createnewclient - -import com.mifos.api.datamanager.DataManagerClient -import com.mifos.api.datamanager.DataManagerOffices -import com.mifos.api.datamanager.DataManagerStaff -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.client.Client -import com.mifos.objects.client.ClientPayload -import com.mifos.objects.organisation.Office -import com.mifos.objects.organisation.Staff -import com.mifos.objects.templates.clients.ClientsTemplate -import com.mifos.objects.templates.clients.Options -import com.mifos.utils.MFErrorParser -import okhttp3.MediaType.Companion.toMediaTypeOrNull -import okhttp3.MultipartBody -import okhttp3.RequestBody -import okhttp3.ResponseBody -import retrofit2.HttpException -import rx.Observable -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.plugins.RxJavaPlugins -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import java.io.File -import java.util.* -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 6/6/16. - */ -class CreateNewClientPresenter @Inject constructor(private val mDataManagerClient: DataManagerClient, - private val mDataManagerOffices: DataManagerOffices, - private val mDataManagerStaff: DataManagerStaff) : BasePresenter() { - private val mSubscriptions: CompositeSubscription = CompositeSubscription() - override fun attachView(mvpView: CreateNewClientMvpView?) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - mSubscriptions.unsubscribe() - } - - fun loadClientTemplate() { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscriptions.add(mDataManagerClient.clientTemplate - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView?.showProgressbar(false) - loadOffices() - } - - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - mvpView?.showMessage(R.string.failed_to_fetch_client_template) - } - - override fun onNext(t: ClientsTemplate?) { - mvpView?.showProgressbar(false) - mvpView?.showClientTemplate(t) - } - })) - } - - fun loadOffices() { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscriptions.add(mDataManagerOffices.offices - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() { - mvpView?.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - mvpView?.showMessage(R.string.failed_to_fetch_offices) - } - - override fun onNext(t: List) { - mvpView?.showProgressbar(false) - mvpView?.showOffices(t) - } - })) - } - - fun loadStaffInOffices(officeId: Int) { - checkViewAttached() - mSubscriptions.add(mDataManagerStaff.getStaffInOffice(officeId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showMessage(R.string.failed_to_fetch_staffs) - } - - override fun onNext(t: List) { - mvpView?.showStaffInOffices(t) - } - })) - } - - fun createClient(clientPayload: ClientPayload) { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscriptions.add(mDataManagerClient.createClient(clientPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView?.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - try { - if (e is HttpException) { - val errorMessage = e.response()?.errorBody() - ?.string() - mvpView?.showMessage(MFErrorParser.parseError(errorMessage) - .errors[0].defaultUserMessage) - } - } catch (throwable: Throwable) { - RxJavaPlugins.getInstance().errorHandler.handleError(e) - } - } - - override fun onNext(t: Client?) { - mvpView?.showProgressbar(false) - if (t != null) { - if (t.clientId != null) { - mvpView?.showClientCreatedSuccessfully( - R.string.client_created_successfully) - mvpView?.setClientId(t.clientId) - } else { - mvpView?.showWaitingForCheckerApproval( - R.string.waiting_for_checker_approval - ) - } - } - } - })) - } - - fun filterOptions(options: List?): List { - val filterValues: MutableList = ArrayList() - Observable.from(options) - .subscribe { options -> filterValues.add(options.name) } - return filterValues - } - - fun filterOffices(offices: List?): List { - val officesList: MutableList = ArrayList() - Observable.from(offices) - .subscribe { office -> office.name?.let { officesList.add(it) } } - return officesList - } - - fun filterStaff(staffs: List?): List { - val staffList: MutableList = ArrayList() - Observable.from(staffs) - .subscribe { staff -> staff.displayName?.let { staffList.add(it) } } - return staffList - } - - fun uploadImage(id: Int, pngFile: File) { - checkViewAttached() - mvpView?.showProgress("Uploading Client's Picture...") - val imagePath = pngFile.absolutePath - - // create RequestBody instance from file - val requestFile = RequestBody.create("image/png".toMediaTypeOrNull(), pngFile) - - // MultipartBody.Part is used to send also the actual file name - val body = MultipartBody.Part.createFormData("file", pngFile.name, requestFile) - mSubscriptions.add(mDataManagerClient.uploadClientImage(id, body) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView?.hideProgress() - } - - override fun onError(e: Throwable) { - mvpView?.hideProgress() - mvpView?.showMessage(R.string.Image_Upload_Failed) - } - - override fun onNext(t: ResponseBody) { - mvpView?.hideProgress() - mvpView?.showMessage(R.string.Image_Upload_Successful) - } - })) - } - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupFragment.kt index c723ccd9f22..f5957c84f91 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupFragment.kt @@ -11,6 +11,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.lifecycle.ViewModelProvider import com.mifos.exceptions.InvalidTextInputException import com.mifos.exceptions.RequiredFieldException import com.mifos.exceptions.ShortOfLengthException @@ -22,6 +23,7 @@ import com.mifos.mifosxdroid.online.GroupsActivity import com.mifos.objects.group.GroupPayload import com.mifos.objects.organisation.Office import com.mifos.objects.response.SaveResponse +import com.mifos.states.CreateNewGroupUiState import com.mifos.utils.Constants import com.mifos.utils.DatePickerConstrainType import com.mifos.utils.FragmentConstants @@ -31,23 +33,23 @@ import com.mifos.utils.PrefManager import com.mifos.utils.ValidationUtil import com.mifos.utils.getDatePickerDialog import com.mifos.utils.getTodayFormatted +import com.mifos.viewmodels.CreateNewGroupViewModel import dagger.hilt.android.AndroidEntryPoint import java.text.SimpleDateFormat import java.time.Instant import java.util.Locale -import javax.inject.Inject /** * Created by nellyk on 1/22/2016. */ //TODO Show Image and Text after successful or Failed during creation of Group and //TODO A button to Continue or Finish the GroupCreation. @AndroidEntryPoint -class CreateNewGroupFragment : ProgressableFragment(), CreateNewGroupMvpView { +class CreateNewGroupFragment : ProgressableFragment() { private lateinit var binding: FragmentCreateNewGroupBinding - @Inject - lateinit var mCreateNewGroupPresenter: CreateNewGroupPresenter + private lateinit var viewModel: CreateNewGroupViewModel + private var activationDateString: String? = null var officeId: Int? = 0 var result = true @@ -58,7 +60,7 @@ class CreateNewGroupFragment : ProgressableFragment(), CreateNewGroupMvpView { private var submissionDate: Instant = Instant.now() private val submissionDatePickerDialog by lazy { getDatePickerDialog(submissionDate, DatePickerConstrainType.ONLY_FUTURE_DAYS) { - val formattedDate = SimpleDateFormat("dd MM yyyy", Locale.getDefault()).format(it) + val formattedDate = SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format(it) submissionDate = Instant.ofEpochMilli(it) binding.submittedDateFieldContainer.editText?.setText(formattedDate) dateofsubmissionstring = binding.submittedDateFieldContainer.editText.toString() @@ -80,10 +82,10 @@ class CreateNewGroupFragment : ProgressableFragment(), CreateNewGroupMvpView { savedInstanceState: Bundle? ): View { binding = FragmentCreateNewGroupBinding.inflate(inflater, container, false) - mCreateNewGroupPresenter.attachView(this) + viewModel = ViewModelProvider(this)[CreateNewGroupViewModel::class.java] inflateSubmissionDate() inflateActivationDate() - mCreateNewGroupPresenter.loadOffices() + viewModel.loadOffices() //client active checkbox onCheckedListener dateofsubmissionstring = getTodayFormatted() @@ -92,6 +94,27 @@ class CreateNewGroupFragment : ProgressableFragment(), CreateNewGroupMvpView { activationDateString = getTodayFormatted() binding.activateDateFieldContainer.editText?.setText(getTodayFormatted()) + viewModel.createNewGroupUiState.observe(viewLifecycleOwner) { + when (it) { + is CreateNewGroupUiState.ShowFetchingError -> { + showProgressbar(false) + showFetchingError(it.message) + } + + is CreateNewGroupUiState.ShowGroupCreatedSuccessfully -> { + showProgressbar(false) + showGroupCreatedSuccessfully(it.saveResponse) + } + + is CreateNewGroupUiState.ShowOffices -> { + showProgressbar(false) + showOffices(it.offices) + } + + is CreateNewGroupUiState.ShowProgressbar -> showProgressbar(true) + } + } + return binding.root } @@ -134,7 +157,7 @@ class CreateNewGroupFragment : ProgressableFragment(), CreateNewGroupMvpView { if (!isGroupNameValid) { return } - mCreateNewGroupPresenter.createGroup(groupPayload) + viewModel.createGroup(groupPayload) } private fun inflateSubmissionDate() { @@ -191,8 +214,8 @@ class CreateNewGroupFragment : ProgressableFragment(), CreateNewGroupMvpView { return result } - override fun showOffices(offices: List?) { - officeList = offices as List + private fun showOffices(offices: List) { + officeList = offices for (office in offices) { office.name?.let { mListOffices.add(it) } } @@ -200,7 +223,7 @@ class CreateNewGroupFragment : ProgressableFragment(), CreateNewGroupMvpView { binding.officeListField.setSimpleItems(mListOffices.toTypedArray()) } - override fun showGroupCreatedSuccessfully(group: SaveResponse?) { + private fun showGroupCreatedSuccessfully(group: SaveResponse?) { Toast.makeText( activity, "Group " + MifosResponseHandler.response, Toast.LENGTH_LONG @@ -213,16 +236,11 @@ class CreateNewGroupFragment : ProgressableFragment(), CreateNewGroupMvpView { } } - override fun showFetchingError(s: String?) { + private fun showFetchingError(s: String?) { Toast.makeText(activity, s, Toast.LENGTH_SHORT).show() } - override fun showProgressbar(b: Boolean) { + private fun showProgressbar(b: Boolean) { showProgress(b) } - - override fun onDestroyView() { - super.onDestroyView() - mCreateNewGroupPresenter.detachView() - } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupMvpView.kt deleted file mode 100644 index 36dbb6e7708..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupMvpView.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.mifos.mifosxdroid.online.createnewgroup - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.organisation.Office -import com.mifos.objects.response.SaveResponse - -/** - * Created by Rajan Maurya on 06/06/16. - */ -interface CreateNewGroupMvpView : MvpView { - fun showOffices(offices: List?) - fun showGroupCreatedSuccessfully(group: SaveResponse?) - fun showFetchingError(s: String?) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupPresenter.kt deleted file mode 100644 index 937862185df..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupPresenter.kt +++ /dev/null @@ -1,78 +0,0 @@ -package com.mifos.mifosxdroid.online.createnewgroup - -import com.mifos.api.datamanager.DataManagerGroups -import com.mifos.api.datamanager.DataManagerOffices -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.group.GroupPayload -import com.mifos.objects.organisation.Office -import com.mifos.objects.response.SaveResponse -import com.mifos.utils.MFErrorParser -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 06/06/16. - */ -class CreateNewGroupPresenter @Inject constructor( - private val mDataManagerOffices: DataManagerOffices, - private val mDataManagerGroups: DataManagerGroups -) : BasePresenter() { - private val mSubscriptions: CompositeSubscription = CompositeSubscription() - - override fun detachView() { - super.detachView() - mSubscriptions.unsubscribe() - } - - fun loadOffices() { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscriptions.add(mDataManagerOffices.offices - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() { - mvpView!!.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showFetchingError("Failed to fetch office list") - } - - override fun onNext(offices: List) { - mvpView!!.showProgressbar(false) - mvpView!!.showOffices(offices) - } - }) - ) - } - - fun createGroup(groupPayload: GroupPayload) { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscriptions.add(mDataManagerGroups.createGroup(groupPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView!!.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showFetchingError(MFErrorParser.errorMessage(e)) - } - - override fun onNext(saveResponse: SaveResponse) { - mvpView!!.showProgressbar(false) - mvpView!!.showGroupCreatedSuccessfully(saveResponse) - } - }) - ) - } - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt index e1b3fa0f6d9..0617e391881 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt @@ -7,6 +7,7 @@ package com.mifos.mifosxdroid.online.datatabledata import android.app.Activity import android.content.Intent import android.os.Bundle +import android.util.Log import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater @@ -14,6 +15,7 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.lifecycle.ViewModelProvider import androidx.navigation.fragment.navArgs import androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener import com.google.gson.JsonArray @@ -24,22 +26,22 @@ import com.mifos.mifosxdroid.core.util.Toaster import com.mifos.mifosxdroid.databinding.FragmentDatatableBinding import com.mifos.mifosxdroid.dialogfragments.datatablerowdialog.DataTableRowDialogFragment import com.mifos.objects.noncore.DataTable +import com.mifos.states.DataTableDataUiState import com.mifos.utils.Constants import com.mifos.utils.DataTableUIBuilder import com.mifos.utils.DataTableUIBuilder.DataTableActionListener import com.mifos.utils.FragmentConstants +import com.mifos.viewmodels.DataTableDataViewModel import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject @AndroidEntryPoint -class DataTableDataFragment : MifosBaseFragment(), DataTableActionListener, DataTableDataMvpView, - OnRefreshListener { +class DataTableDataFragment : MifosBaseFragment(), DataTableActionListener, OnRefreshListener { private lateinit var binding: FragmentDatatableBinding private val arg: DataTableDataFragmentArgs by navArgs() - @Inject - lateinit var mDataTableDataPresenter: DataTableDataPresenter + private lateinit var viewModel: DataTableDataViewModel + private var dataTable: DataTable? = null private var entityId = 0 override fun onCreate(savedInstanceState: Bundle?) { @@ -56,27 +58,59 @@ class DataTableDataFragment : MifosBaseFragment(), DataTableActionListener, Data ): View { // Inflate the layout for this fragment binding = FragmentDatatableBinding.inflate(inflater, container, false) - mDataTableDataPresenter.attachView(this) + viewModel = ViewModelProvider(this)[DataTableDataViewModel::class.java] dataTable!!.registeredTableName?.let { setToolbarTitle(it) } binding.swipeContainer.setColorSchemeColors( *activity ?.resources!!.getIntArray(R.array.swipeRefreshColors) ) binding.swipeContainer.setOnRefreshListener(this) - mDataTableDataPresenter.loadDataTableInfo(dataTable?.registeredTableName, entityId) + viewModel.loadDataTableInfo(dataTable?.registeredTableName, entityId) + + viewModel.dataTableDataUiState.observe(viewLifecycleOwner) { + when (it) { + is DataTableDataUiState.ShowDataTableDeletedSuccessfully -> { + showProgressbar(false) + showDataTableDeletedSuccessfully() + } + + is DataTableDataUiState.ShowDataTableInfo -> { + showProgressbar(false) + showDataTableInfo(it.jsonElements) + } + + is DataTableDataUiState.ShowEmptyDataTable -> { + showProgressbar(false) + showEmptyDataTable() + } + + is DataTableDataUiState.ShowFetchingError -> { + showProgressbar(false) + showFetchingError(it.message) + } + + is DataTableDataUiState.ShowFetchingErrorString -> { + showProgressbar(false) + showFetchingError(it.message) + } + + is DataTableDataUiState.ShowProgressbar -> showProgressbar(true) + } + } + return binding.root } override fun onRefresh() { binding.linearLayoutDatatables.visibility = View.GONE - mDataTableDataPresenter.loadDataTableInfo(dataTable?.registeredTableName, entityId) + viewModel.loadDataTableInfo(dataTable?.registeredTableName, entityId) } override fun showDataTableOptions(table: String, entity: Int, rowId: Int) { MaterialDialog.Builder().init(activity) .setItems(R.array.datatable_options) { dialog, which -> when (which) { - 0 -> mDataTableDataPresenter.deleteDataTableEntry(table, entity, rowId) + 0 -> viewModel.deleteDataTableEntry(table, entity, rowId) else -> { } } @@ -85,7 +119,7 @@ class DataTableDataFragment : MifosBaseFragment(), DataTableActionListener, Data .show() } - override fun showDataTableInfo(jsonElements: JsonArray?) { + private fun showDataTableInfo(jsonElements: JsonArray?) { if (jsonElements != null) { binding.linearLayoutDatatables.visibility = View.VISIBLE binding.llError.visibility = View.GONE @@ -102,29 +136,29 @@ class DataTableDataFragment : MifosBaseFragment(), DataTableActionListener, Data } } - override fun showDataTableDeletedSuccessfully() { - mDataTableDataPresenter.loadDataTableInfo(dataTable?.registeredTableName, entityId) + private fun showDataTableDeletedSuccessfully() { + viewModel.loadDataTableInfo(dataTable?.registeredTableName, entityId) } - override fun showEmptyDataTable() { + private fun showEmptyDataTable() { binding.linearLayoutDatatables.visibility = View.GONE binding.llError.visibility = View.VISIBLE binding.tvError.setText(R.string.empty_data_table) Toaster.show(binding.root, R.string.empty_data_table) } - override fun showFetchingError(message: Int) { + private fun showFetchingError(message: Int) { showFetchingError(getString(message)) } - override fun showFetchingError(errorMessage: String?) { + private fun showFetchingError(errorMessage: String?) { binding.linearLayoutDatatables.visibility = View.GONE binding.llError.visibility = View.VISIBLE binding.tvError.text = errorMessage Toast.makeText(activity, errorMessage, Toast.LENGTH_SHORT).show() } - override fun showProgressbar(show: Boolean) { + private fun showProgressbar(show: Boolean) { binding.swipeContainer.isRefreshing = false if (show) { binding.linearLayoutDatatables.visibility = View.GONE @@ -156,14 +190,9 @@ class DataTableDataFragment : MifosBaseFragment(), DataTableActionListener, Data override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { when (requestCode) { Constants.DIALOG_FRAGMENT -> if (resultCode == Activity.RESULT_OK) { - mDataTableDataPresenter + viewModel .loadDataTableInfo(dataTable?.registeredTableName, entityId) } } } - - override fun onDestroyView() { - super.onDestroyView() - mDataTableDataPresenter.detachView() - } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataMvpView.kt deleted file mode 100644 index b51d85a614d..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataMvpView.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.mifos.mifosxdroid.online.datatabledata - -import com.google.gson.JsonArray -import com.mifos.mifosxdroid.base.MvpView - -/** - * Created by Rajan Maurya on 7/6/16. - */ -interface DataTableDataMvpView : MvpView { - fun showDataTableInfo(jsonElements: JsonArray?) - fun showDataTableDeletedSuccessfully() - fun showEmptyDataTable() - fun showFetchingError(message: Int) - fun showFetchingError(s: String?) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataPresenter.kt deleted file mode 100644 index e6f406bcea1..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataPresenter.kt +++ /dev/null @@ -1,80 +0,0 @@ -package com.mifos.mifosxdroid.online.datatabledata - -import com.google.gson.JsonArray -import com.mifos.api.GenericResponse -import com.mifos.api.datamanager.DataManagerDataTable -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.utils.MFErrorParser -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 7/6/16. - */ -class DataTableDataPresenter @Inject constructor(private val dataManagerDataTable: DataManagerDataTable) : BasePresenter() { - private val subscriptions: CompositeSubscription - override fun attachView(mvpView: DataTableDataMvpView?) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - subscriptions.unsubscribe() - } - - fun loadDataTableInfo(table: String?, entityId: Int) { - checkViewAttached() - mvpView!!.showProgressbar(true) - subscriptions.add(dataManagerDataTable.getDataTableInfo(table, entityId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView!!.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showFetchingError(R.string.failed_to_fetch_datatable_info) - } - - override fun onNext(jsonElements: JsonArray?) { - mvpView!!.showProgressbar(false) - if (jsonElements!!.size() == 0) { - mvpView!!.showEmptyDataTable() - } else { - mvpView!!.showDataTableInfo(jsonElements) - } - } - })) - } - - fun deleteDataTableEntry(table: String?, entity: Int, rowId: Int) { - checkViewAttached() - mvpView!!.showProgressbar(true) - subscriptions.add(dataManagerDataTable.deleteDataTableEntry(table, entity, rowId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showFetchingError(MFErrorParser.errorMessage(e)) - } - - override fun onNext(genericResponse: GenericResponse?) { - mvpView!!.showProgressbar(false) - mvpView!!.showDataTableDeletedSuccessfully() - } - }) - ) - } - - init { - subscriptions = CompositeSubscription() - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt index fc45d75fd47..46dac5fdb43 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt @@ -14,6 +14,7 @@ import android.widget.Button import android.widget.TextView import android.widget.Toast import androidx.fragment.app.Fragment +import androidx.lifecycle.ViewModelProvider import com.mifos.exceptions.RequiredFieldException import com.mifos.mifosxdroid.R import com.mifos.mifosxdroid.core.util.Toaster @@ -26,13 +27,14 @@ import com.mifos.objects.noncore.DataTable import com.mifos.objects.noncore.DataTablePayload import com.mifos.services.data.GroupLoanPayload import com.mifos.services.data.LoansPayload +import com.mifos.states.DataTableListUiState import com.mifos.utils.Constants import com.mifos.utils.MifosResponseHandler import com.mifos.utils.PrefManager import com.mifos.utils.SafeUIBlockingUtility +import com.mifos.viewmodels.DataTableListViewModel import dagger.hilt.android.AndroidEntryPoint import java.util.* -import javax.inject.Inject /** * A generic fragment to show the DataTables at the runtime. @@ -46,14 +48,14 @@ import javax.inject.Inject * a single datatable. */ @AndroidEntryPoint -class DataTableListFragment : Fragment(), DataTableListMvpView { +class DataTableListFragment : Fragment() { private lateinit var binding: DialogFragmentAddEntryToDatatableBinding private val LOG_TAG = javaClass.simpleName - @Inject - lateinit var mDataTableListPresenter: DataTableListPresenter + private lateinit var viewModel: DataTableListViewModel + private var dataTables: List? = null private var dataTablePayloadElements: ArrayList? = null private var clientLoansPayload: LoansPayload? = null @@ -70,7 +72,7 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { ): View { requireActivity().window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) binding = DialogFragmentAddEntryToDatatableBinding.inflate(inflater, container, false) - mDataTableListPresenter.attachView(this) + viewModel = ViewModelProvider(this)[DataTableListViewModel::class.java] requireActivity().title = requireActivity().resources.getString( R.string.associated_datatables ) @@ -81,6 +83,32 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { createForm(datatable) } addSaveButton() + + viewModel.dataTableListUiState.observe(viewLifecycleOwner) { + when (it) { + is DataTableListUiState.ShowClientCreatedSuccessfully -> { + showProgressbar(false) + showClientCreatedSuccessfully(it.client) + } + + is DataTableListUiState.ShowMessage -> { + showProgressbar(false) + showMessage(it.message) + } + + is DataTableListUiState.ShowMessageString -> { + showProgressbar(false) + showMessage(it.message) + } + + is DataTableListUiState.ShowProgressBar -> showProgressbar(true) + is DataTableListUiState.ShowWaitingForCheckerApproval -> { + showProgressbar(false) + showWaitingForCheckerApproval(it.message) + } + } + } + return binding.root } @@ -181,15 +209,15 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { when (requestType) { Constants.CLIENT_LOAN -> { clientLoansPayload?.dataTables = dataTablePayloadElements - mDataTableListPresenter.createLoansAccount(clientLoansPayload) + viewModel.createLoansAccount(clientLoansPayload) } Constants.GROUP_LOAN -> //Add Datatables in GroupLoan Payload and then add them here. - mDataTableListPresenter.createGroupLoanAccount(groupLoanPayload) + viewModel.createGroupLoanAccount(groupLoanPayload) Constants.CREATE_CLIENT -> { clientPayload.datatables = dataTablePayloadElements - mDataTableListPresenter.createClient(clientPayload) + viewModel.createClient(clientPayload) } } } @@ -218,17 +246,17 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { return payload } - override fun showMessage(messageId: Int) { + private fun showMessage(messageId: Int) { Toaster.show(binding.root, getString(messageId)) requireActivity().supportFragmentManager.popBackStackImmediate() } - override fun showMessage(message: String?) { + private fun showMessage(message: String?) { Toaster.show(binding.root, message) requireActivity().supportFragmentManager.popBackStackImmediate() } - override fun showClientCreatedSuccessfully(client: Client) { + private fun showClientCreatedSuccessfully(client: Client) { requireActivity().supportFragmentManager.popBackStack() requireActivity().supportFragmentManager.popBackStack() Toast.makeText( @@ -242,12 +270,12 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { } } - override fun showWaitingForCheckerApproval(message: Int) { + private fun showWaitingForCheckerApproval(message: Int) { requireActivity().supportFragmentManager.popBackStack() Toaster.show(binding.root, message, Toast.LENGTH_SHORT) } - override fun showProgressbar(b: Boolean) { + private fun showProgressbar(b: Boolean) { if (b) { safeUIBlockingUtility?.safelyBlockUI() } else { @@ -255,11 +283,6 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { } } - override fun onDestroyView() { - super.onDestroyView() - mDataTableListPresenter.detachView() - } - companion object { @JvmStatic fun newInstance( diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListMvpView.kt deleted file mode 100644 index 5e0048b459a..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListMvpView.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.mifos.mifosxdroid.online.datatablelistfragment - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.client.Client - -interface DataTableListMvpView : MvpView { - fun showMessage(messageId: Int) - fun showMessage(message: String?) - fun showClientCreatedSuccessfully(client: Client) - fun showWaitingForCheckerApproval(message: Int) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListPresenter.kt deleted file mode 100644 index fd92f7c035e..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListPresenter.kt +++ /dev/null @@ -1,113 +0,0 @@ -package com.mifos.mifosxdroid.online.datatablelistfragment - -import com.mifos.api.DataManager -import com.mifos.api.datamanager.DataManagerClient -import com.mifos.api.datamanager.DataManagerLoan -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.accounts.loan.Loans -import com.mifos.objects.client.Client -import com.mifos.objects.client.ClientPayload -import com.mifos.services.data.GroupLoanPayload -import com.mifos.services.data.LoansPayload -import com.mifos.utils.MFErrorParser -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import javax.inject.Inject - -class DataTableListPresenter @Inject constructor(private val mDataManagerLoan: DataManagerLoan, private val mDataManager: DataManager, - private val dataManagerClient: DataManagerClient) : BasePresenter() { - private val mSubscription: CompositeSubscription? - override fun attachView(mvpView: DataTableListMvpView?) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - mSubscription?.unsubscribe() - } - - fun createLoansAccount(loansPayload: LoansPayload?) { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscription!!.add(mDataManagerLoan.createLoansAccount(loansPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView!!.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showMessage(R.string.generic_failure_message) - } - - override fun onNext(loans: Loans?) { - mvpView!!.showProgressbar(false) - mvpView!!.showMessage(R.string.loan_creation_success) - } - })) - } - - fun createGroupLoanAccount(loansPayload: GroupLoanPayload?) { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscription!!.add(mDataManager.createGroupLoansAccount(loansPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView!!.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showMessage(R.string.generic_failure_message) - } - - override fun onNext(loans: Loans?) { - mvpView!!.showProgressbar(false) - mvpView!!.showMessage(R.string.loan_creation_success) - } - }) - ) - } - - fun createClient(clientPayload: ClientPayload) { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscription!!.add(dataManagerClient.createClient(clientPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView!!.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showMessage(MFErrorParser.errorMessage(e)) - } - - override fun onNext(client: Client?) { - mvpView!!.showProgressbar(false) - if (client != null) { - if (client.clientId != null) { - mvpView!!.showClientCreatedSuccessfully( - client) - } else { - mvpView!!.showWaitingForCheckerApproval( - R.string.waiting_for_checker_approval) - } - } - } - })) - } - - init { - mSubscription = CompositeSubscription() - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApproval.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApproval.kt index 7b17accd72f..81ebf4dd800 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApproval.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApproval.kt @@ -10,6 +10,7 @@ import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.fragment.app.DialogFragment +import androidx.lifecycle.ViewModelProvider import androidx.navigation.fragment.navArgs import com.mifos.api.GenericResponse import com.mifos.exceptions.RequiredFieldException @@ -20,22 +21,23 @@ import com.mifos.mifosxdroid.uihelpers.MFDatePicker import com.mifos.mifosxdroid.uihelpers.MFDatePicker.OnDatePickListener import com.mifos.objects.accounts.loan.LoanApproval import com.mifos.objects.accounts.loan.LoanWithAssociations +import com.mifos.states.LoanAccountApprovalUiState import com.mifos.utils.DateHelper import com.mifos.utils.FragmentConstants +import com.mifos.viewmodels.LoanAccountApprovalViewModel import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject /** * @author nellyk */ @AndroidEntryPoint -class LoanAccountApproval : MifosBaseFragment(), OnDatePickListener, LoanAccountApprovalMvpView { +class LoanAccountApproval : MifosBaseFragment(), OnDatePickListener { private lateinit var binding: DialogFragmentApproveLoanBinding private val arg: LoanAccountApprovalArgs by navArgs() - @Inject - lateinit var mLoanAccountApprovalPresenter: LoanAccountApprovalPresenter + private lateinit var viewModel: LoanAccountApprovalViewModel + private var approvalDate: String? = null private var disbursementDate: String? = null var loanAccountNumber = 0 @@ -59,8 +61,25 @@ class LoanAccountApproval : MifosBaseFragment(), OnDatePickListener, LoanAccount // Inflate the layout for this fragment activity?.actionBar?.setDisplayHomeAsUpEnabled(true) binding = DialogFragmentApproveLoanBinding.inflate(inflater, container, false) - mLoanAccountApprovalPresenter.attachView(this) + viewModel = ViewModelProvider(this)[LoanAccountApprovalViewModel::class.java] showUserInterface() + + viewModel.loanAccountApprovalUiState.observe(viewLifecycleOwner) { + when (it) { + is LoanAccountApprovalUiState.ShowLoanApproveFailed -> { + showProgressbar(false) + showLoanApproveFailed(it.message) + } + + is LoanAccountApprovalUiState.ShowLoanApproveSuccessfully -> { + showProgressbar(false) + showLoanApproveSuccessfully(it.genericResponse) + } + + is LoanAccountApprovalUiState.ShowProgressbar -> showProgressbar(true) + } + } + return binding.root } @@ -128,7 +147,7 @@ class LoanAccountApproval : MifosBaseFragment(), OnDatePickListener, LoanAccount .replace("-", " ") } - override fun showUserInterface() { + private fun showUserInterface() { mfDatePicker = MFDatePicker.newInsance(this) binding.tvLoanApprovalDates.text = MFDatePicker.datePickedAsString approvalDate = binding.tvLoanApprovalDates.text.toString() @@ -159,28 +178,23 @@ class LoanAccountApproval : MifosBaseFragment(), OnDatePickListener, LoanAccount } private fun initiateLoanApproval(loanApproval: LoanApproval) { - mLoanAccountApprovalPresenter.approveLoan(loanAccountNumber, loanApproval) + viewModel.approveLoan(loanAccountNumber, loanApproval) } - override fun showLoanApproveSuccessfully(genericResponse: GenericResponse?) { + private fun showLoanApproveSuccessfully(genericResponse: GenericResponse?) { Toast.makeText(activity, "Loan Approved", Toast.LENGTH_LONG).show() requireActivity().supportFragmentManager.popBackStackImmediate() } - override fun showLoanApproveFailed(s: String?) { + private fun showLoanApproveFailed(s: String?) { Toast.makeText(activity, s, Toast.LENGTH_LONG).show() } - override fun showProgressbar(show: Boolean) { + private fun showProgressbar(show: Boolean) { if (show) { showMifosProgressDialog() } else { hideMifosProgressDialog() } } - - override fun onDestroyView() { - super.onDestroyView() - mLoanAccountApprovalPresenter.detachView() - } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApprovalMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApprovalMvpView.kt deleted file mode 100644 index 17a52e6abe2..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApprovalMvpView.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.mifos.mifosxdroid.online.loanaccountapproval - -import com.mifos.api.GenericResponse -import com.mifos.mifosxdroid.base.MvpView - -/** - * Created by Rajan Maurya on 8/6/16. - */ -interface LoanAccountApprovalMvpView : MvpView { - fun showUserInterface() - fun showLoanApproveSuccessfully(genericResponse: GenericResponse?) - fun showLoanApproveFailed(s: String?) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApprovalPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApprovalPresenter.kt deleted file mode 100644 index bbf2ffaabea..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApprovalPresenter.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.mifos.mifosxdroid.online.loanaccountapproval - -import com.mifos.api.DataManager -import com.mifos.api.GenericResponse -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.accounts.loan.LoanApproval -import com.mifos.utils.MFErrorParser -import retrofit2.HttpException -import rx.Subscriber -import rx.Subscription -import rx.android.schedulers.AndroidSchedulers -import rx.plugins.RxJavaPlugins -import rx.schedulers.Schedulers -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 8/6/16. - */ -class LoanAccountApprovalPresenter @Inject constructor(private val mDataManager: DataManager) : BasePresenter() { - private var mSubscription: Subscription? = null - override fun attachView(mvpView: LoanAccountApprovalMvpView?) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - if (mSubscription != null) mSubscription!!.unsubscribe() - } - - fun approveLoan(loanId: Int, loanApproval: LoanApproval?) { - checkViewAttached() - mvpView!!.showProgressbar(true) - if (mSubscription != null) mSubscription!!.unsubscribe() - mSubscription = mDataManager.approveLoan(loanId, loanApproval) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - try { - if (e is HttpException) { - val errorMessage = e.response()?.errorBody() - ?.string() - mvpView!!.showLoanApproveFailed( - MFErrorParser.parseError(errorMessage) - .errors[0].defaultUserMessage) - } - } catch (throwable: Throwable) { - RxJavaPlugins.getInstance().errorHandler.handleError(e) - } - } - - override fun onNext(genericResponse: GenericResponse?) { - mvpView!!.showProgressbar(false) - mvpView!!.showLoanApproveSuccessfully(genericResponse) - } - }) - } - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementFragment.kt index f2be53a3d38..deb10b0a5e2 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementFragment.kt @@ -13,6 +13,7 @@ import android.widget.AdapterView.OnItemSelectedListener import android.widget.ArrayAdapter import android.widget.Toast import androidx.fragment.app.DialogFragment +import androidx.lifecycle.ViewModelProvider import androidx.navigation.fragment.navArgs import com.mifos.api.GenericResponse import com.mifos.exceptions.RequiredFieldException @@ -24,24 +25,25 @@ import com.mifos.mifosxdroid.uihelpers.MFDatePicker import com.mifos.mifosxdroid.uihelpers.MFDatePicker.OnDatePickListener import com.mifos.objects.accounts.loan.LoanDisbursement import com.mifos.objects.templates.loans.LoanTransactionTemplate +import com.mifos.states.LoanAccountDisbursementUiState import com.mifos.utils.DateHelper import com.mifos.utils.FragmentConstants import com.mifos.utils.Network +import com.mifos.viewmodels.LoanAccountDisbursementViewModel import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject /** * Created by nellyk on 1/22/2016. */ @AndroidEntryPoint class LoanAccountDisbursementFragment : MifosBaseFragment(), OnDatePickListener, - LoanAccountDisbursementMvpView, OnItemSelectedListener { + OnItemSelectedListener { private lateinit var binding: DialogFragmentDisburseLoanBinding private val arg: LoanAccountDisbursementFragmentArgs by navArgs() - @Inject - lateinit var loanAccountDisbursementPresenter: LoanAccountDisbursementPresenter + private lateinit var viewModel: LoanAccountDisbursementViewModel + private var paymentTypeId = 0 private var disbursementDates: String? = null private var loanAccountNumber = 0 @@ -63,9 +65,31 @@ class LoanAccountDisbursementFragment : MifosBaseFragment(), OnDatePickListener, ): View { activity?.actionBar?.setDisplayHomeAsUpEnabled(true) binding = DialogFragmentDisburseLoanBinding.inflate(inflater, container, false) - loanAccountDisbursementPresenter.attachView(this) + viewModel = ViewModelProvider(this)[LoanAccountDisbursementViewModel::class.java] showUserInterface() - loanAccountDisbursementPresenter.loadLoanTemplate(loanAccountNumber) + viewModel.loadLoanTemplate(loanAccountNumber) + + viewModel.loanAccountDisbursementUiState.observe(viewLifecycleOwner) { + when (it) { + is LoanAccountDisbursementUiState.ShowDisburseLoanSuccessfully -> { + showProgressbar(false) + showDisburseLoanSuccessfully(it.genericResponse) + } + + is LoanAccountDisbursementUiState.ShowError -> { + showProgressbar(false) + showError(it.message) + } + + is LoanAccountDisbursementUiState.ShowLoanTransactionTemplate -> { + showProgressbar(false) + showLoanTransactionTemplate(it.loanTransactionTemplate) + } + + is LoanAccountDisbursementUiState.ShowProgressbar -> showProgressbar(true) + } + } + return binding.root } @@ -97,13 +121,13 @@ class LoanAccountDisbursementFragment : MifosBaseFragment(), OnDatePickListener, loanDisbursement.transactionAmount = java.lang.Double.valueOf(binding.etDisbursedAmount.editableText.toString()) loanDisbursement.paymentId = paymentTypeId - loanAccountDisbursementPresenter.disburseLoan(loanAccountNumber, loanDisbursement) + viewModel.disburseLoan(loanAccountNumber, loanDisbursement) } else { Toaster.show(binding.root, R.string.error_network_not_available, Toaster.LONG) } } - override fun showUserInterface() { + private fun showUserInterface() { setToolbarTitle(getString(R.string.disburse_loan)) mfDatePicker = MFDatePicker.newInsance(this) binding.tvLoanDisbursementDates.text = MFDatePicker.datePickedAsString @@ -118,7 +142,7 @@ class LoanAccountDisbursementFragment : MifosBaseFragment(), OnDatePickListener, binding.spLoanPaymentType.onItemSelectedListener = this } - override fun showDisbursementDate(date: String?) { + private fun showDisbursementDate(date: String?) { disbursementDates = DateHelper.getDateAsStringUsedForCollectionSheetPayload(date) .replace("-", " ") } @@ -136,14 +160,14 @@ class LoanAccountDisbursementFragment : MifosBaseFragment(), OnDatePickListener, showDisbursementDate(date) } - override fun showLoanTransactionTemplate(loanTransactionTemplate: LoanTransactionTemplate) { + private fun showLoanTransactionTemplate(loanTransactionTemplate: LoanTransactionTemplate) { this.loanTransactionTemplate = loanTransactionTemplate binding.etDisbursedAmount.setText(loanTransactionTemplate.amount.toString()) paymentTypeOptions.addAll() paymentTypeOptionAdapter?.notifyDataSetChanged() } - override fun showDisburseLoanSuccessfully(genericResponse: GenericResponse?) { + private fun showDisburseLoanSuccessfully(genericResponse: GenericResponse?) { Toast.makeText( activity, R.string.loan_disburse_successfully, Toast.LENGTH_LONG @@ -151,15 +175,15 @@ class LoanAccountDisbursementFragment : MifosBaseFragment(), OnDatePickListener, requireActivity().supportFragmentManager.popBackStack() } - override fun showError(message: String?) { + private fun showError(message: String?) { Toaster.show(binding.root, message, Toaster.INDEFINITE) } - override fun showError(errorMessage: Int) { + private fun showError(errorMessage: Int) { Toaster.show(binding.root, errorMessage) } - override fun showProgressbar(show: Boolean) { + private fun showProgressbar(show: Boolean) { if (show) { showMifosProgressBar() binding.llDisburse.visibility = View.GONE @@ -169,11 +193,6 @@ class LoanAccountDisbursementFragment : MifosBaseFragment(), OnDatePickListener, } } - override fun onDestroyView() { - super.onDestroyView() - loanAccountDisbursementPresenter.detachView() - } - override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) { if (parent.id == R.id.sp_loan_payment_type) { paymentTypeId = loanTransactionTemplate!!.paymentTypeOptions[position].id diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementMvpView.kt deleted file mode 100644 index b698c022d3e..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementMvpView.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.mifos.mifosxdroid.online.loanaccountdisbursement - -import com.mifos.api.GenericResponse -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.templates.loans.LoanTransactionTemplate - -/** - * Created by Rajan Maurya on 8/6/16. - */ -interface LoanAccountDisbursementMvpView : MvpView { - fun showUserInterface() - fun showDisbursementDate(date: String?) - fun showLoanTransactionTemplate(loanTransactionTemplate: LoanTransactionTemplate) - fun showDisburseLoanSuccessfully(genericResponse: GenericResponse?) - fun showError(s: String?) - fun showError(errorMessage: Int) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementPresenter.kt deleted file mode 100644 index 3c6d182b91c..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementPresenter.kt +++ /dev/null @@ -1,76 +0,0 @@ -package com.mifos.mifosxdroid.online.loanaccountdisbursement - -import com.mifos.api.GenericResponse -import com.mifos.api.datamanager.DataManagerLoan -import com.mifos.api.model.APIEndPoint -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.accounts.loan.LoanDisbursement -import com.mifos.objects.templates.loans.LoanTransactionTemplate -import com.mifos.utils.MFErrorParser -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 8/6/16. - */ -class LoanAccountDisbursementPresenter @Inject constructor(private val dataManagerLoan: DataManagerLoan) : BasePresenter() { - private val subscriptions: CompositeSubscription - override fun attachView(mvpView: LoanAccountDisbursementMvpView?) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - subscriptions.unsubscribe() - } - - fun loadLoanTemplate(loanId: Int) { - checkViewAttached() - mvpView!!.showProgressbar(true) - subscriptions.add(dataManagerLoan.getLoanTransactionTemplate(loanId, APIEndPoint.DISBURSE) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showError("s") - } - - override fun onNext(loanTransactionTemplate: LoanTransactionTemplate?) { - mvpView!!.showProgressbar(false) - if (loanTransactionTemplate != null) { - mvpView!!.showLoanTransactionTemplate(loanTransactionTemplate) - } - } - }) - ) - } - - fun disburseLoan(loanId: Int, loanDisbursement: LoanDisbursement?) { - checkViewAttached() - mvpView!!.showProgressbar(true) - subscriptions.add(dataManagerLoan.disburseLoan(loanId, loanDisbursement) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showError(MFErrorParser.errorMessage(e)) - } - - override fun onNext(genericResponse: GenericResponse?) { - mvpView!!.showProgressbar(false) - mvpView!!.showDisburseLoanSuccessfully(genericResponse) - } - })) - } - - init { - subscriptions = CompositeSubscription() - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeFragment.kt index 47c76e5643e..f0b26f1a179 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeFragment.kt @@ -10,6 +10,7 @@ import android.view.Menu import android.view.MenuItem import android.view.View import android.view.ViewGroup +import androidx.lifecycle.ViewModelProvider import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.LinearLayoutManager import com.mifos.mifosxdroid.R @@ -21,21 +22,22 @@ import com.mifos.mifosxdroid.databinding.FragmentChargeListBinding import com.mifos.mifosxdroid.dialogfragments.chargedialog.OnChargeCreateListener import com.mifos.mifosxdroid.dialogfragments.loanchargedialog.LoanChargeDialogFragment import com.mifos.objects.client.Charges +import com.mifos.states.LoanChargeUiState import com.mifos.utils.FragmentConstants +import com.mifos.viewmodels.LoanChargeViewModel import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject /** * Created by nellyk on 1/22/2016. */ @AndroidEntryPoint -class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, OnChargeCreateListener { +class LoanChargeFragment : MifosBaseFragment(), OnChargeCreateListener { private lateinit var binding: FragmentChargeListBinding private val arg: LoanChargeFragmentArgs by navArgs() - @Inject - lateinit var mLoanChargePresenter: LoanChargePresenter + private lateinit var viewModel: LoanChargeViewModel + private var chargesList: MutableList = ArrayList() private var mChargesNameListAdapter: ChargeNameListAdapter? = null private var loanAccountNumber = 0 @@ -52,7 +54,7 @@ class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, OnChargeCreat ): View { binding = FragmentChargeListBinding.inflate(inflater, container, false) setHasOptionsMenu(true) - mLoanChargePresenter.attachView(this) + viewModel = ViewModelProvider(this)[LoanChargeViewModel::class.java] val layoutManager = LinearLayoutManager(activity) layoutManager.orientation = LinearLayoutManager.VERTICAL binding.rvCharge.layoutManager = layoutManager @@ -60,7 +62,7 @@ class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, OnChargeCreat //Loading LoanChargesList - mLoanChargePresenter.loadLoanChargesList(loanAccountNumber) + viewModel.loadLoanChargesList(loanAccountNumber) setToolbarTitle(getString(R.string.charges)) /** * Setting mApiRestCounter to 1 and send Refresh Request to Server @@ -72,7 +74,7 @@ class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, OnChargeCreat R.color.red_light ) binding.swipeContainer.setOnRefreshListener { - mLoanChargePresenter.loadLoanChargesList(loanAccountNumber) + viewModel.loadLoanChargesList(loanAccountNumber) if (binding.swipeContainer.isRefreshing) binding.swipeContainer.isRefreshing = false } /** @@ -88,6 +90,23 @@ class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, OnChargeCreat //Future Implementation } }) + + viewModel.loanChargeUiState.observe(viewLifecycleOwner) { + when (it) { + is LoanChargeUiState.ShowFetchingError -> { + showProgressbar(false) + showFetchingError(it.message) + } + + is LoanChargeUiState.ShowLoanChargesList -> { + showProgressbar(false) + showLoanChargesList(it.chargesPage) + } + + is LoanChargeUiState.ShowProgressbar -> showProgressbar(true) + } + } + return binding.root } @@ -105,14 +124,14 @@ class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, OnChargeCreat */ private fun reloadOnError() { binding.llError.visibility = View.GONE - mLoanChargePresenter.loadLoanChargesList(loanAccountNumber) + viewModel.loadLoanChargesList(loanAccountNumber) } - fun setChargesList(chargesList: MutableList) { + private fun setChargesList(chargesList: MutableList) { this.chargesList = chargesList } - override fun showLoanChargesList(charges: MutableList) { + private fun showLoanChargesList(charges: MutableList) { chargesList = charges mChargesNameListAdapter = ChargeNameListAdapter(chargesList, loanAccountNumber) binding.rvCharge.adapter = mChargesNameListAdapter @@ -123,14 +142,14 @@ class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, OnChargeCreat } } - override fun showFetchingError(s: String) { + private fun showFetchingError(s: String) { binding.llError.visibility = View.VISIBLE binding.noChargesText.text = "$s\n Click to Refresh " - mLoanChargePresenter.loadLoanChargesList(loanAccountNumber) + viewModel.loadLoanChargesList(loanAccountNumber) Toaster.show(binding.root, s) } - override fun showProgressbar(b: Boolean) { + private fun showProgressbar(b: Boolean) { if (b) { showMifosProgressBar() } else { @@ -138,11 +157,6 @@ class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, OnChargeCreat } } - override fun onDestroyView() { - super.onDestroyView() - mLoanChargePresenter.detachView() - } - override fun onPrepareOptionsMenu(menu: Menu) { menu.clear() val menuItemAddNewLoanCharge = menu.add( diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentFragment.kt index c91ddbbd8a7..55a0f52b035 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentFragment.kt @@ -16,6 +16,7 @@ import android.widget.AdapterView import android.widget.AdapterView.OnItemSelectedListener import android.widget.ArrayAdapter import androidx.fragment.app.DialogFragment +import androidx.lifecycle.ViewModelProvider import androidx.navigation.fragment.navArgs import com.google.gson.Gson import com.jakewharton.fliptables.FlipTable @@ -28,24 +29,22 @@ import com.mifos.mifosxdroid.uihelpers.MFDatePicker import com.mifos.mifosxdroid.uihelpers.MFDatePicker.OnDatePickListener import com.mifos.objects.accounts.loan.LoanRepaymentRequest import com.mifos.objects.accounts.loan.LoanRepaymentResponse -import com.mifos.objects.accounts.loan.LoanWithAssociations import com.mifos.objects.templates.loans.LoanRepaymentTemplate -import com.mifos.utils.Constants +import com.mifos.states.LoanRepaymentUiState import com.mifos.utils.FragmentConstants import com.mifos.utils.Utils +import com.mifos.viewmodels.LoanRepaymentViewModel import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject @AndroidEntryPoint -class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepaymentMvpView, +class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, DialogInterface.OnClickListener { private lateinit var binding: FragmentLoanRepaymentBinding val LOG_TAG = javaClass.simpleName private val arg: LoanRepaymentFragmentArgs by navArgs() - @Inject - lateinit var mLoanRepaymentPresenter: LoanRepaymentPresenter + private lateinit var viewModel: LoanRepaymentViewModel // Arguments Passed From the Loan Account Summary Fragment private var clientName: String? = null @@ -71,12 +70,44 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay ): View { binding = FragmentLoanRepaymentBinding.inflate(inflater, container, false) setToolbarTitle("Loan Repayment") - mLoanRepaymentPresenter.attachView(this) + viewModel = ViewModelProvider(this)[LoanRepaymentViewModel::class.java] //This Method Checking LoanRepayment made before in Offline mode or not. //If yes then User have to sync this first then he can able to make transaction. //If not then User able to make LoanRepayment in Online or Offline. checkLoanRepaymentStatusInDatabase() + + viewModel.loanRepaymentUiState.observe(viewLifecycleOwner) { + when (it) { + is LoanRepaymentUiState.ShowError -> { + showProgressbar(false) + showError(it.message) + } + + is LoanRepaymentUiState.ShowLoanRepayTemplate -> { + showProgressbar(false) + showLoanRepayTemplate(it.loanRepaymentTemplate) + } + + is LoanRepaymentUiState.ShowLoanRepaymentDoesNotExistInDatabase -> { + showProgressbar(false) + showLoanRepaymentDoesNotExistInDatabase() + } + + is LoanRepaymentUiState.ShowLoanRepaymentExistInDatabase -> { + showProgressbar(false) + showLoanRepaymentExistInDatabase() + } + + is LoanRepaymentUiState.ShowPaymentSubmittedSuccessfully -> { + showProgressbar(false) + showPaymentSubmittedSuccessfully(it.loanRepaymentResponse) + } + + is LoanRepaymentUiState.ShowProgressbar -> showProgressbar(true) + } + } + return binding.root } @@ -92,12 +123,12 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay } } - override fun checkLoanRepaymentStatusInDatabase() { + private fun checkLoanRepaymentStatusInDatabase() { // Checking LoanRepayment Already made in Offline mode or Not. - mLoanRepaymentPresenter.checkDatabaseLoanRepaymentByLoanId(loanId!!.toInt()) + viewModel.checkDatabaseLoanRepaymentByLoanId(loanId!!.toInt()) } - override fun showLoanRepaymentExistInDatabase() { + private fun showLoanRepaymentExistInDatabase() { //Visibility of ParentLayout GONE, If Repayment Already made in Offline Mode binding.rlLoanRepayment.visibility = View.GONE MaterialDialog.Builder().init(activity) @@ -115,13 +146,13 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay } } - override fun showLoanRepaymentDoesNotExistInDatabase() { + private fun showLoanRepaymentDoesNotExistInDatabase() { // This Method Inflating UI and Initializing the Loading LoadRepayment // Template for transaction inflateUI() // Loading PaymentOptions. - mLoanRepaymentPresenter.loanLoanRepaymentTemplate(loanId!!.toInt()) + viewModel.loanLoanRepaymentTemplate(loanId!!.toInt()) } /** @@ -295,10 +326,10 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay request.transactionDate = dateString val builtRequest = Gson().toJson(request) Log.i("LOG_TAG", builtRequest) - mLoanRepaymentPresenter.submitPayment(loanId!!.toInt(), request) + viewModel.submitPayment(loanId!!.toInt(), request) } - override fun showLoanRepayTemplate(loanRepaymentTemplate: LoanRepaymentTemplate?) { + private fun showLoanRepayTemplate(loanRepaymentTemplate: LoanRepaymentTemplate?) { /* Activity is null - Fragment has been detached; no need to do anything. */ if (activity == null) return if (loanRepaymentTemplate != null) { @@ -341,7 +372,7 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay } } - override fun showPaymentSubmittedSuccessfully(loanRepaymentResponse: LoanRepaymentResponse?) { + private fun showPaymentSubmittedSuccessfully(loanRepaymentResponse: LoanRepaymentResponse?) { if (loanRepaymentResponse != null) { Toaster.show( binding.root, "Payment Successful, Transaction ID = " + @@ -351,11 +382,11 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay requireActivity().supportFragmentManager.popBackStackImmediate() } - override fun showError(errorMessage: Int) { + private fun showError(errorMessage: Int) { Toaster.show(binding.root, errorMessage) } - override fun showProgressbar(b: Boolean) { + private fun showProgressbar(b: Boolean) { if (b) { binding.rlLoanRepayment.visibility = View.GONE showMifosProgressBar() @@ -364,23 +395,4 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay hideMifosProgressBar() } } - - override fun onDestroyView() { - super.onDestroyView() - mLoanRepaymentPresenter.detachView() - } - - interface OnFragmentInteractionListener - companion object { - @JvmStatic - fun newInstance(loanWithAssociations: LoanWithAssociations?): LoanRepaymentFragment { - val fragment = LoanRepaymentFragment() - val args = Bundle() - if (loanWithAssociations != null) { - args.putParcelable(Constants.LOAN_SUMMARY, loanWithAssociations) - fragment.arguments = args - } - return fragment - } - } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentMvpView.kt deleted file mode 100644 index b758e61c5f7..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentMvpView.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.mifos.mifosxdroid.online.loanrepayment - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.accounts.loan.LoanRepaymentResponse -import com.mifos.objects.templates.loans.LoanRepaymentTemplate - -/** - * Created by Rajan Maurya on 8/6/16. - */ -interface LoanRepaymentMvpView : MvpView { - fun showLoanRepayTemplate(loanRepaymentTemplate: LoanRepaymentTemplate?) - fun showPaymentSubmittedSuccessfully(loanRepaymentResponse: LoanRepaymentResponse?) - fun checkLoanRepaymentStatusInDatabase() - fun showLoanRepaymentExistInDatabase() - fun showLoanRepaymentDoesNotExistInDatabase() - fun showError(errorMessage: Int) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentPresenter.kt deleted file mode 100644 index edd160a9430..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentPresenter.kt +++ /dev/null @@ -1,101 +0,0 @@ -package com.mifos.mifosxdroid.online.loanrepayment - -import com.mifos.api.datamanager.DataManagerLoan -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.accounts.loan.LoanRepaymentRequest -import com.mifos.objects.accounts.loan.LoanRepaymentResponse -import com.mifos.objects.templates.loans.LoanRepaymentTemplate -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 8/6/16. - */ -class LoanRepaymentPresenter @Inject constructor(private val mDataManagerLoan: DataManagerLoan) : BasePresenter() { - val LOG_TAG = javaClass.simpleName - private val mSubscriptions: CompositeSubscription = CompositeSubscription() - override fun attachView(mvpView: LoanRepaymentMvpView?) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - mSubscriptions.unsubscribe() - } - - fun loanLoanRepaymentTemplate(loanId: Int) { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscriptions.add(mDataManagerLoan.getLoanRepayTemplate(loanId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView!!.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showError(R.string.failed_to_load_loanrepayment) - } - - override fun onNext(loanRepaymentTemplate: LoanRepaymentTemplate?) { - mvpView!!.showProgressbar(false) - mvpView!!.showLoanRepayTemplate(loanRepaymentTemplate) - } - })) - } - - fun submitPayment(loanId: Int, request: LoanRepaymentRequest) { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscriptions.add(mDataManagerLoan.submitPayment(loanId, request) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - mvpView!!.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showError(R.string.payment_failed) - } - - override fun onNext(loanRepaymentResponse: LoanRepaymentResponse?) { - mvpView!!.showProgressbar(false) - mvpView!!.showPaymentSubmittedSuccessfully(loanRepaymentResponse) - } - })) - } - - fun checkDatabaseLoanRepaymentByLoanId(loanId: Int) { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscriptions.add(mDataManagerLoan.getDatabaseLoanRepaymentByLoanId(loanId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showError(R.string.failed_to_load_loanrepayment) - } - - override fun onNext(loanRepaymentRequest: LoanRepaymentRequest?) { - mvpView!!.showProgressbar(false) - if (loanRepaymentRequest != null) { - mvpView!!.showLoanRepaymentExistInDatabase() - } else { - mvpView!!.showLoanRepaymentDoesNotExistInDatabase() - } - } - }) - ) - } - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/CollectionSheetRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/CollectionSheetRepository.kt new file mode 100644 index 00000000000..46a24900378 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/CollectionSheetRepository.kt @@ -0,0 +1,20 @@ +package com.mifos.repositories + +import com.mifos.api.model.CollectionSheetPayload +import com.mifos.api.model.Payload +import com.mifos.objects.db.CollectionSheet +import com.mifos.objects.response.SaveResponse +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface CollectionSheetRepository { + + fun getCollectionSheet(id: Long, payload: Payload?): Observable + + fun saveCollectionSheetAsync( + id: Int, + payload: CollectionSheetPayload? + ): Observable +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/CollectionSheetRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/CollectionSheetRepositoryImp.kt new file mode 100644 index 00000000000..448bdd0f589 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/CollectionSheetRepositoryImp.kt @@ -0,0 +1,29 @@ +package com.mifos.repositories + +import com.mifos.api.DataManager +import com.mifos.api.model.CollectionSheetPayload +import com.mifos.api.model.Payload +import com.mifos.objects.db.CollectionSheet +import com.mifos.objects.response.SaveResponse +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class CollectionSheetRepositoryImp @Inject constructor(private val dataManager: DataManager) : + CollectionSheetRepository { + + override fun getCollectionSheet(id: Long, payload: Payload?): Observable { + return dataManager.getCollectionSheet(id, payload) + } + + override fun saveCollectionSheetAsync( + id: Int, + payload: CollectionSheetPayload? + ): Observable { + return dataManager.saveCollectionSheetAsync( + id, payload + ) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/CreateNewCenterRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewCenterRepository.kt new file mode 100644 index 00000000000..6162b7042d0 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewCenterRepository.kt @@ -0,0 +1,16 @@ +package com.mifos.repositories + +import com.mifos.objects.organisation.Office +import com.mifos.objects.response.SaveResponse +import com.mifos.services.data.CenterPayload +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface CreateNewCenterRepository { + + fun offices(): Observable> + + fun createCenter(centerPayload: CenterPayload): Observable +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/CreateNewCenterRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewCenterRepositoryImp.kt new file mode 100644 index 00000000000..5e52e0c8b55 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewCenterRepositoryImp.kt @@ -0,0 +1,23 @@ +package com.mifos.repositories + +import com.mifos.api.datamanager.DataManagerCenter +import com.mifos.objects.organisation.Office +import com.mifos.objects.response.SaveResponse +import com.mifos.services.data.CenterPayload +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class CreateNewCenterRepositoryImp @Inject constructor(private val dataManagerCenter: DataManagerCenter) : + CreateNewCenterRepository { + + override fun offices(): Observable> { + return dataManagerCenter.offices + } + + override fun createCenter(centerPayload: CenterPayload): Observable { + return dataManagerCenter.createCenter(centerPayload) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/CreateNewClientRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewClientRepository.kt new file mode 100644 index 00000000000..234fa0600f6 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewClientRepository.kt @@ -0,0 +1,26 @@ +package com.mifos.repositories + +import com.mifos.objects.client.Client +import com.mifos.objects.client.ClientPayload +import com.mifos.objects.organisation.Office +import com.mifos.objects.organisation.Staff +import com.mifos.objects.templates.clients.ClientsTemplate +import okhttp3.MultipartBody +import okhttp3.ResponseBody +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface CreateNewClientRepository { + + fun clientTemplate(): Observable + + fun offices(): Observable> + + fun getStaffInOffice(officeId: Int): Observable> + + fun createClient(clientPayload: ClientPayload): Observable + + fun uploadClientImage(id: Int, file: MultipartBody.Part?): Observable +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/CreateNewClientRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewClientRepositoryImp.kt new file mode 100644 index 00000000000..d96b6c930e6 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewClientRepositoryImp.kt @@ -0,0 +1,45 @@ +package com.mifos.repositories + +import com.mifos.api.datamanager.DataManagerClient +import com.mifos.api.datamanager.DataManagerOffices +import com.mifos.api.datamanager.DataManagerStaff +import com.mifos.objects.client.Client +import com.mifos.objects.client.ClientPayload +import com.mifos.objects.organisation.Office +import com.mifos.objects.organisation.Staff +import com.mifos.objects.templates.clients.ClientsTemplate +import okhttp3.MultipartBody +import okhttp3.ResponseBody +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class CreateNewClientRepositoryImp @Inject constructor( + private val dataManagerClient: DataManagerClient, + private val dataManagerOffices: DataManagerOffices, + private val dataManagerStaff: DataManagerStaff +) : CreateNewClientRepository { + + override fun clientTemplate(): Observable { + return dataManagerClient.clientTemplate + } + + override fun offices(): Observable> { + return dataManagerOffices.offices + } + + override fun getStaffInOffice(officeId: Int): Observable> { + return dataManagerStaff.getStaffInOffice(officeId) + } + + override fun createClient(clientPayload: ClientPayload): Observable { + return dataManagerClient.createClient(clientPayload) + } + + override fun uploadClientImage(id: Int, file: MultipartBody.Part?): Observable { + return dataManagerClient.uploadClientImage(id, file) + } + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/CreateNewGroupRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewGroupRepository.kt new file mode 100644 index 00000000000..f33d443891b --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewGroupRepository.kt @@ -0,0 +1,16 @@ +package com.mifos.repositories + +import com.mifos.objects.group.GroupPayload +import com.mifos.objects.organisation.Office +import com.mifos.objects.response.SaveResponse +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface CreateNewGroupRepository { + + fun offices(): Observable> + + fun createGroup(groupPayload: GroupPayload): Observable +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/CreateNewGroupRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewGroupRepositoryImp.kt new file mode 100644 index 00000000000..53a31bfc774 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/CreateNewGroupRepositoryImp.kt @@ -0,0 +1,26 @@ +package com.mifos.repositories + +import com.mifos.api.datamanager.DataManagerGroups +import com.mifos.api.datamanager.DataManagerOffices +import com.mifos.objects.group.GroupPayload +import com.mifos.objects.organisation.Office +import com.mifos.objects.response.SaveResponse +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class CreateNewGroupRepositoryImp @Inject constructor( + private val dataManagerOffices: DataManagerOffices, + private val dataManagerGroups: DataManagerGroups +) : CreateNewGroupRepository { + + override fun offices(): Observable> { + return dataManagerOffices.offices + } + + override fun createGroup(groupPayload: GroupPayload): Observable { + return dataManagerGroups.createGroup(groupPayload) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/DataTableDataRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/DataTableDataRepository.kt new file mode 100644 index 00000000000..0cb0cffb9d8 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/DataTableDataRepository.kt @@ -0,0 +1,16 @@ +package com.mifos.repositories + +import com.google.gson.JsonArray +import com.mifos.api.GenericResponse +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface DataTableDataRepository { + + fun getDataTableInfo(table: String?, entityId: Int): Observable + + fun deleteDataTableEntry(table: String?, entity: Int, rowId: Int): Observable + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/DataTableDataRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/DataTableDataRepositoryImp.kt new file mode 100644 index 00000000000..46330d2b1fe --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/DataTableDataRepositoryImp.kt @@ -0,0 +1,28 @@ +package com.mifos.repositories + +import com.google.gson.JsonArray +import com.mifos.api.GenericResponse +import com.mifos.api.datamanager.DataManagerDataTable +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class DataTableDataRepositoryImp @Inject constructor(private val dataManagerDataTable: DataManagerDataTable) : + DataTableDataRepository { + + override fun getDataTableInfo(table: String?, entityId: Int): Observable { + return dataManagerDataTable.getDataTableInfo(table, entityId) + } + + override fun deleteDataTableEntry( + table: String?, + entity: Int, + rowId: Int + ): Observable { + return dataManagerDataTable.deleteDataTableEntry(table, entity, rowId) + } + + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/DataTableListRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/DataTableListRepository.kt new file mode 100644 index 00000000000..19c5de7cc96 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/DataTableListRepository.kt @@ -0,0 +1,20 @@ +package com.mifos.repositories + +import com.mifos.objects.accounts.loan.Loans +import com.mifos.objects.client.Client +import com.mifos.objects.client.ClientPayload +import com.mifos.services.data.GroupLoanPayload +import com.mifos.services.data.LoansPayload +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface DataTableListRepository { + + fun createLoansAccount(loansPayload: LoansPayload?): Observable + + fun createGroupLoansAccount(loansPayload: GroupLoanPayload?): Observable + + fun createClient(clientPayload: ClientPayload): Observable +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/DataTableListRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/DataTableListRepositoryImp.kt new file mode 100644 index 00000000000..d776f26bda4 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/DataTableListRepositoryImp.kt @@ -0,0 +1,33 @@ +package com.mifos.repositories + +import com.mifos.api.DataManager +import com.mifos.api.datamanager.DataManagerClient +import com.mifos.api.datamanager.DataManagerLoan +import com.mifos.objects.accounts.loan.Loans +import com.mifos.objects.client.Client +import com.mifos.objects.client.ClientPayload +import com.mifos.services.data.GroupLoanPayload +import com.mifos.services.data.LoansPayload +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class DataTableListRepositoryImp @Inject constructor( + private val dataManagerLoan: DataManagerLoan, private val dataManager: DataManager, + private val dataManagerClient: DataManagerClient +) : DataTableListRepository { + + override fun createLoansAccount(loansPayload: LoansPayload?): Observable { + return dataManagerLoan.createLoansAccount(loansPayload) + } + + override fun createGroupLoansAccount(loansPayload: GroupLoanPayload?): Observable { + return dataManager.createGroupLoansAccount(loansPayload) + } + + override fun createClient(clientPayload: ClientPayload): Observable { + return dataManagerClient.createClient(clientPayload) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/IndividualCollectionSheetDetailsRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/IndividualCollectionSheetDetailsRepository.kt new file mode 100644 index 00000000000..9bb72d9c6ae --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/IndividualCollectionSheetDetailsRepository.kt @@ -0,0 +1,16 @@ +package com.mifos.repositories + +import com.mifos.api.GenericResponse +import com.mifos.api.model.IndividualCollectionSheetPayload +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface IndividualCollectionSheetDetailsRepository { + + fun saveIndividualCollectionSheet( + payload: IndividualCollectionSheetPayload? + ): Observable + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/IndividualCollectionSheetDetailsRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/IndividualCollectionSheetDetailsRepositoryImp.kt new file mode 100644 index 00000000000..02b6c13a044 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/IndividualCollectionSheetDetailsRepositoryImp.kt @@ -0,0 +1,18 @@ +package com.mifos.repositories + +import com.mifos.api.GenericResponse +import com.mifos.api.datamanager.DataManagerCollectionSheet +import com.mifos.api.model.IndividualCollectionSheetPayload +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class IndividualCollectionSheetDetailsRepositoryImp @Inject constructor(private val dataManagerCollection: DataManagerCollectionSheet) : + IndividualCollectionSheetDetailsRepository { + + override fun saveIndividualCollectionSheet(payload: IndividualCollectionSheetPayload?): Observable { + return dataManagerCollection.saveIndividualCollectionSheet(payload) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountApprovalRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountApprovalRepository.kt new file mode 100644 index 00000000000..a11e5372d81 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountApprovalRepository.kt @@ -0,0 +1,14 @@ +package com.mifos.repositories + +import com.mifos.api.GenericResponse +import com.mifos.objects.accounts.loan.LoanApproval +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface LoanAccountApprovalRepository { + + fun approveLoan(loanId: Int, loanApproval: LoanApproval?): Observable + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountApprovalRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountApprovalRepositoryImp.kt new file mode 100644 index 00000000000..5587e80670e --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountApprovalRepositoryImp.kt @@ -0,0 +1,21 @@ +package com.mifos.repositories + +import com.mifos.api.DataManager +import com.mifos.api.GenericResponse +import com.mifos.objects.accounts.loan.LoanApproval +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class LoanAccountApprovalRepositoryImp @Inject constructor(private val dataManager: DataManager) : + LoanAccountApprovalRepository { + + override fun approveLoan( + loanId: Int, + loanApproval: LoanApproval? + ): Observable { + return dataManager.approveLoan(loanId, loanApproval) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountDisbursementRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountDisbursementRepository.kt new file mode 100644 index 00000000000..967a2ca95a9 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountDisbursementRepository.kt @@ -0,0 +1,23 @@ +package com.mifos.repositories + +import com.mifos.api.GenericResponse +import com.mifos.objects.accounts.loan.LoanDisbursement +import com.mifos.objects.templates.loans.LoanTransactionTemplate +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface LoanAccountDisbursementRepository { + + fun getLoanTransactionTemplate( + loanId: Int, + command: String? + ): Observable + + fun disburseLoan( + loanId: Int, + loanDisbursement: LoanDisbursement? + ): Observable + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountDisbursementRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountDisbursementRepositoryImp.kt new file mode 100644 index 00000000000..6a4fd452563 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/LoanAccountDisbursementRepositoryImp.kt @@ -0,0 +1,31 @@ +package com.mifos.repositories + +import com.mifos.api.GenericResponse +import com.mifos.api.datamanager.DataManagerLoan +import com.mifos.objects.accounts.loan.LoanDisbursement +import com.mifos.objects.templates.loans.LoanTransactionTemplate +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class LoanAccountDisbursementRepositoryImp @Inject constructor(private val dataManagerLoan: DataManagerLoan) : + LoanAccountDisbursementRepository { + + override fun getLoanTransactionTemplate( + loanId: Int, + command: String? + ): Observable { + return dataManagerLoan.getLoanTransactionTemplate(loanId, command) + } + + override fun disburseLoan( + loanId: Int, + loanDisbursement: LoanDisbursement? + ): Observable { + return disburseLoan(loanId, loanDisbursement) + } + + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/LoanChargeRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/LoanChargeRepository.kt new file mode 100644 index 00000000000..98bd44ed979 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/LoanChargeRepository.kt @@ -0,0 +1,13 @@ +package com.mifos.repositories + +import com.mifos.objects.client.Charges +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface LoanChargeRepository { + + fun getListOfLoanCharges(loanId: Int): Observable> + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/LoanChargeRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/LoanChargeRepositoryImp.kt new file mode 100644 index 00000000000..ed52827de82 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/LoanChargeRepositoryImp.kt @@ -0,0 +1,17 @@ +package com.mifos.repositories + +import com.mifos.api.DataManager +import com.mifos.objects.client.Charges +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class LoanChargeRepositoryImp @Inject constructor(private val dataManager: DataManager) : + LoanChargeRepository { + + override fun getListOfLoanCharges(loanId: Int): Observable> { + return dataManager.getListOfLoanCharges(loanId) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/LoanRepaymentRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/LoanRepaymentRepository.kt new file mode 100644 index 00000000000..f1ca9a64535 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/LoanRepaymentRepository.kt @@ -0,0 +1,22 @@ +package com.mifos.repositories + +import com.mifos.objects.accounts.loan.LoanRepaymentRequest +import com.mifos.objects.accounts.loan.LoanRepaymentResponse +import com.mifos.objects.templates.loans.LoanRepaymentTemplate +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface LoanRepaymentRepository { + + fun getLoanRepayTemplate(loanId: Int): Observable + + fun submitPayment( + loanId: Int, + request: LoanRepaymentRequest + ): Observable + + fun getDatabaseLoanRepaymentByLoanId(loanId: Int): Observable + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/LoanRepaymentRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/LoanRepaymentRepositoryImp.kt new file mode 100644 index 00000000000..0b10431b7ce --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/LoanRepaymentRepositoryImp.kt @@ -0,0 +1,32 @@ +package com.mifos.repositories + +import com.mifos.api.datamanager.DataManagerLoan +import com.mifos.objects.accounts.loan.LoanRepaymentRequest +import com.mifos.objects.accounts.loan.LoanRepaymentResponse +import com.mifos.objects.templates.loans.LoanRepaymentTemplate +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class LoanRepaymentRepositoryImp @Inject constructor(private val dataManagerLoan: DataManagerLoan) : + LoanRepaymentRepository { + + override fun getLoanRepayTemplate(loanId: Int): Observable { + return dataManagerLoan.getLoanRepayTemplate(loanId) + } + + override fun submitPayment( + loanId: Int, + request: LoanRepaymentRequest + ): Observable { + return submitPayment(loanId, request) + } + + override fun getDatabaseLoanRepaymentByLoanId(loanId: Int): Observable { + return dataManagerLoan.getDatabaseLoanRepaymentByLoanId(loanId) + } + + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/NewIndividualCollectionSheetRepository.kt b/mifosng-android/src/main/java/com/mifos/repositories/NewIndividualCollectionSheetRepository.kt new file mode 100644 index 00000000000..01f8cb7c353 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/NewIndividualCollectionSheetRepository.kt @@ -0,0 +1,22 @@ +package com.mifos.repositories + +import com.mifos.api.model.RequestCollectionSheetPayload +import com.mifos.objects.collectionsheet.IndividualCollectionSheet +import com.mifos.objects.organisation.Office +import com.mifos.objects.organisation.Staff +import rx.Observable + +/** + * Created by Aditya Gupta on 10/08/23. + */ +interface NewIndividualCollectionSheetRepository { + + fun getIndividualCollectionSheet( + payload: RequestCollectionSheetPayload? + ): Observable + + fun offices(): Observable> + + fun getStaffInOffice(officeId: Int): Observable> + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/repositories/NewIndividualCollectionSheetRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/repositories/NewIndividualCollectionSheetRepositoryImp.kt new file mode 100644 index 00000000000..363f06745be --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/repositories/NewIndividualCollectionSheetRepositoryImp.kt @@ -0,0 +1,32 @@ +package com.mifos.repositories + +import com.mifos.api.DataManager +import com.mifos.api.datamanager.DataManagerCollectionSheet +import com.mifos.api.model.RequestCollectionSheetPayload +import com.mifos.objects.collectionsheet.IndividualCollectionSheet +import com.mifos.objects.organisation.Office +import com.mifos.objects.organisation.Staff +import rx.Observable +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +class NewIndividualCollectionSheetRepositoryImp @Inject internal constructor( + private val dataManager: DataManager, + private val dataManagerCollection: DataManagerCollectionSheet +) : NewIndividualCollectionSheetRepository { + + override fun getIndividualCollectionSheet(payload: RequestCollectionSheetPayload?): Observable { + return dataManagerCollection.getIndividualCollectionSheet(payload) + } + + override fun offices(): Observable> { + return dataManager.offices + } + + override fun getStaffInOffice(officeId: Int): Observable> { + return dataManager.getStaffInOffice(officeId) + } + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/states/CollectionSheetUiState.kt b/mifosng-android/src/main/java/com/mifos/states/CollectionSheetUiState.kt new file mode 100644 index 00000000000..bb01ed2dd4f --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/CollectionSheetUiState.kt @@ -0,0 +1,20 @@ +package com.mifos.states + +import com.mifos.objects.db.CollectionSheet +import com.mifos.objects.response.SaveResponse +import retrofit2.HttpException + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class CollectionSheetUiState { + + data class ShowFetchingError(val message: String) : CollectionSheetUiState() + + data class ShowCollectionSheet(val collectionSheet: CollectionSheet) : CollectionSheetUiState() + + data class ShowFailedToSaveCollectionSheet(val e: HttpException) : CollectionSheetUiState() + + data class ShowCollectionSheetSuccessfullySaved(val saveResponse: SaveResponse?) : + CollectionSheetUiState() +} diff --git a/mifosng-android/src/main/java/com/mifos/states/CreateNewCenterUiState.kt b/mifosng-android/src/main/java/com/mifos/states/CreateNewCenterUiState.kt new file mode 100644 index 00000000000..196f848b0eb --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/CreateNewCenterUiState.kt @@ -0,0 +1,20 @@ +package com.mifos.states + +import com.mifos.objects.organisation.Office +import com.mifos.objects.response.SaveResponse + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class CreateNewCenterUiState { + + object ShowProgressbar : CreateNewCenterUiState() + + data class ShowFetchingError(val message: Int) : CreateNewCenterUiState() + + data class ShowOffices(val offices: List) : CreateNewCenterUiState() + + data class ShowFetchingErrorString(val message: String) : CreateNewCenterUiState() + + data class CenterCreatedSuccessfully(val saveResponse: SaveResponse) : CreateNewCenterUiState() +} diff --git a/mifosng-android/src/main/java/com/mifos/states/CreateNewClientUiState.kt b/mifosng-android/src/main/java/com/mifos/states/CreateNewClientUiState.kt new file mode 100644 index 00000000000..3f785d6bf7d --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/CreateNewClientUiState.kt @@ -0,0 +1,31 @@ +package com.mifos.states + +import com.mifos.objects.organisation.Office +import com.mifos.objects.organisation.Staff +import com.mifos.objects.templates.clients.ClientsTemplate + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class CreateNewClientUiState { + + object ShowProgressbar : CreateNewClientUiState() + + data class ShowMessage(val message: Int) : CreateNewClientUiState() + + data class ShowClientTemplate(val clientsTemplate: ClientsTemplate?) : CreateNewClientUiState() + + data class ShowOffices(val officeList: List) : CreateNewClientUiState() + + data class ShowStaffInOffices(val staffList: List) : CreateNewClientUiState() + + data class ShowMessageString(val message: String) : CreateNewClientUiState() + + data class ShowClientCreatedSuccessfully(val message: Int) : CreateNewClientUiState() + + data class SetClientId(val id: Int) : CreateNewClientUiState() + + data class ShowWaitingForCheckerApproval(val message: Int) : CreateNewClientUiState() + + data class ShowProgress(val message: String) : CreateNewClientUiState() +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/states/CreateNewGroupUiState.kt b/mifosng-android/src/main/java/com/mifos/states/CreateNewGroupUiState.kt new file mode 100644 index 00000000000..b4cd9eeba5a --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/CreateNewGroupUiState.kt @@ -0,0 +1,19 @@ +package com.mifos.states + +import com.mifos.objects.organisation.Office +import com.mifos.objects.response.SaveResponse + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class CreateNewGroupUiState { + + object ShowProgressbar : CreateNewGroupUiState() + + data class ShowFetchingError(val message: String) : CreateNewGroupUiState() + + data class ShowOffices(val offices: List) : CreateNewGroupUiState() + + data class ShowGroupCreatedSuccessfully(val saveResponse: SaveResponse) : + CreateNewGroupUiState() +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/states/DataTableDataUiState.kt b/mifosng-android/src/main/java/com/mifos/states/DataTableDataUiState.kt new file mode 100644 index 00000000000..295d9608167 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/DataTableDataUiState.kt @@ -0,0 +1,21 @@ +package com.mifos.states + +import com.google.gson.JsonArray + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class DataTableDataUiState { + + object ShowProgressbar : DataTableDataUiState() + + data class ShowFetchingError(val message: Int) : DataTableDataUiState() + + object ShowEmptyDataTable : DataTableDataUiState() + + data class ShowDataTableInfo(val jsonElements: JsonArray) : DataTableDataUiState() + + data class ShowFetchingErrorString(val message: String) : DataTableDataUiState() + + object ShowDataTableDeletedSuccessfully : DataTableDataUiState() +} diff --git a/mifosng-android/src/main/java/com/mifos/states/DataTableListUiState.kt b/mifosng-android/src/main/java/com/mifos/states/DataTableListUiState.kt new file mode 100644 index 00000000000..8aadc38b542 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/DataTableListUiState.kt @@ -0,0 +1,19 @@ +package com.mifos.states + +import com.mifos.objects.client.Client + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class DataTableListUiState { + + object ShowProgressBar : DataTableListUiState() + + data class ShowMessage(val message: Int) : DataTableListUiState() + + data class ShowMessageString(val message: String) : DataTableListUiState() + + data class ShowClientCreatedSuccessfully(val client: Client) : DataTableListUiState() + + data class ShowWaitingForCheckerApproval(val message: Int) : DataTableListUiState() +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/states/IndividualCollectionSheetDetailsUiState.kt b/mifosng-android/src/main/java/com/mifos/states/IndividualCollectionSheetDetailsUiState.kt new file mode 100644 index 00000000000..af8ecd546c4 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/IndividualCollectionSheetDetailsUiState.kt @@ -0,0 +1,13 @@ +package com.mifos.states + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class IndividualCollectionSheetDetailsUiState { + + object ShowProgressbar : IndividualCollectionSheetDetailsUiState() + + data class ShowError(val message: String) : IndividualCollectionSheetDetailsUiState() + + object ShowSuccess : IndividualCollectionSheetDetailsUiState() +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/states/LoanAccountApprovalUiState.kt b/mifosng-android/src/main/java/com/mifos/states/LoanAccountApprovalUiState.kt new file mode 100644 index 00000000000..c8b55605821 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/LoanAccountApprovalUiState.kt @@ -0,0 +1,16 @@ +package com.mifos.states + +import com.mifos.api.GenericResponse + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class LoanAccountApprovalUiState { + + object ShowProgressbar : LoanAccountApprovalUiState() + + data class ShowLoanApproveFailed(val message: String) : LoanAccountApprovalUiState() + + data class ShowLoanApproveSuccessfully(val genericResponse: GenericResponse) : + LoanAccountApprovalUiState() +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/states/LoanAccountDisbursementUiState.kt b/mifosng-android/src/main/java/com/mifos/states/LoanAccountDisbursementUiState.kt new file mode 100644 index 00000000000..d479afd5dd0 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/LoanAccountDisbursementUiState.kt @@ -0,0 +1,20 @@ +package com.mifos.states + +import com.mifos.api.GenericResponse +import com.mifos.objects.templates.loans.LoanTransactionTemplate + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class LoanAccountDisbursementUiState { + + object ShowProgressbar : LoanAccountDisbursementUiState() + + data class ShowError(val message: String) : LoanAccountDisbursementUiState() + + data class ShowLoanTransactionTemplate(val loanTransactionTemplate: LoanTransactionTemplate) : + LoanAccountDisbursementUiState() + + data class ShowDisburseLoanSuccessfully(val genericResponse: GenericResponse?) : + LoanAccountDisbursementUiState() +} diff --git a/mifosng-android/src/main/java/com/mifos/states/LoanChargeUiState.kt b/mifosng-android/src/main/java/com/mifos/states/LoanChargeUiState.kt new file mode 100644 index 00000000000..b8347788ba5 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/LoanChargeUiState.kt @@ -0,0 +1,17 @@ +package com.mifos.states + +import com.mifos.objects.client.Charges + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class LoanChargeUiState { + + object ShowProgressbar : LoanChargeUiState() + + data class ShowFetchingError(val message: String) : LoanChargeUiState() + + data class ShowLoanChargesList(val chargesPage: MutableList) : LoanChargeUiState() + + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/states/LoanRepaymentUiState.kt b/mifosng-android/src/main/java/com/mifos/states/LoanRepaymentUiState.kt new file mode 100644 index 00000000000..84521bc400d --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/LoanRepaymentUiState.kt @@ -0,0 +1,24 @@ +package com.mifos.states + +import com.mifos.objects.accounts.loan.LoanRepaymentResponse +import com.mifos.objects.templates.loans.LoanRepaymentTemplate + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class LoanRepaymentUiState { + + object ShowProgressbar : LoanRepaymentUiState() + + data class ShowError(val message: Int) : LoanRepaymentUiState() + + data class ShowLoanRepayTemplate(val loanRepaymentTemplate: LoanRepaymentTemplate?) : + LoanRepaymentUiState() + + data class ShowPaymentSubmittedSuccessfully(val loanRepaymentResponse: LoanRepaymentResponse?) : + LoanRepaymentUiState() + + object ShowLoanRepaymentExistInDatabase : LoanRepaymentUiState() + + object ShowLoanRepaymentDoesNotExistInDatabase : LoanRepaymentUiState() +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/states/NewIndividualCollectionSheetUiState.kt b/mifosng-android/src/main/java/com/mifos/states/NewIndividualCollectionSheetUiState.kt new file mode 100644 index 00000000000..c3624286a7b --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/states/NewIndividualCollectionSheetUiState.kt @@ -0,0 +1,27 @@ +package com.mifos.states + +import com.mifos.objects.collectionsheet.IndividualCollectionSheet +import com.mifos.objects.organisation.Office +import com.mifos.objects.organisation.Staff + +/** + * Created by Aditya Gupta on 10/08/23. + */ +sealed class NewIndividualCollectionSheetUiState { + + object ShowProgressbar : NewIndividualCollectionSheetUiState() + + object ShowSuccess : NewIndividualCollectionSheetUiState() + + data class ShowError(val errorMessage: String?) : NewIndividualCollectionSheetUiState() + + data class ShowSheet(val individualCollectionSheet: IndividualCollectionSheet?) : + NewIndividualCollectionSheetUiState() + + object ShowNoSheetFound : NewIndividualCollectionSheetUiState() + + data class SetOfficeSpinner(val officeList: List) : + NewIndividualCollectionSheetUiState() + + data class SetStaffSpinner(val staffList: List) : NewIndividualCollectionSheetUiState() +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/utils/MifosDatePicker.kt b/mifosng-android/src/main/java/com/mifos/utils/MifosDatePicker.kt index ba30b0761e0..1df9e99e494 100644 --- a/mifosng-android/src/main/java/com/mifos/utils/MifosDatePicker.kt +++ b/mifosng-android/src/main/java/com/mifos/utils/MifosDatePicker.kt @@ -41,4 +41,4 @@ fun getDatePickerDialog( } fun getTodayFormatted(): String = - SimpleDateFormat("dd MM yyyy", Locale.getDefault()).format(Calendar.getInstance().time) \ No newline at end of file + SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format(Calendar.getInstance().time) \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/CollectionSheetViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/CollectionSheetViewModel.kt new file mode 100644 index 00000000000..7f2c348256b --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/CollectionSheetViewModel.kt @@ -0,0 +1,72 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mifos.api.model.CollectionSheetPayload +import com.mifos.api.model.Payload +import com.mifos.objects.db.CollectionSheet +import com.mifos.objects.response.SaveResponse +import com.mifos.repositories.CollectionSheetRepository +import com.mifos.states.CollectionSheetUiState +import dagger.hilt.android.lifecycle.HiltViewModel +import retrofit2.HttpException +import rx.Subscriber +import rx.android.schedulers.AndroidSchedulers +import rx.schedulers.Schedulers +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +@HiltViewModel +class CollectionSheetViewModel @Inject constructor(private val repository: CollectionSheetRepository) : + ViewModel() { + + private val _collectionSheetUiState = MutableLiveData() + + val collectionSheetUiState: LiveData + get() = _collectionSheetUiState + + + fun loadCollectionSheet(id: Long, payload: Payload?) { + repository.getCollectionSheet(id, payload) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + _collectionSheetUiState.value = + CollectionSheetUiState.ShowFetchingError(e.message.toString()) + } + + override fun onNext(collectionSheet: CollectionSheet?) { + _collectionSheetUiState.value = collectionSheet?.let { + CollectionSheetUiState.ShowCollectionSheet( + it + ) + } + } + }) + } + + fun saveCollectionSheet(id: Int, payload: CollectionSheetPayload?) { + repository.saveCollectionSheetAsync(id, payload) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + if (e is HttpException) { + _collectionSheetUiState.value = + CollectionSheetUiState.ShowFailedToSaveCollectionSheet(e) + } + } + + override fun onNext(saveResponse: SaveResponse?) { + _collectionSheetUiState.value = + CollectionSheetUiState.ShowCollectionSheetSuccessfullySaved(saveResponse) + } + }) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewCenterViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewCenterViewModel.kt new file mode 100644 index 00000000000..58145a1f06b --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewCenterViewModel.kt @@ -0,0 +1,68 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mifos.mifosxdroid.R +import com.mifos.objects.organisation.Office +import com.mifos.objects.response.SaveResponse +import com.mifos.repositories.CreateNewCenterRepository +import com.mifos.services.data.CenterPayload +import com.mifos.states.CreateNewCenterUiState +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 10/08/23. + */ +@HiltViewModel +class CreateNewCenterViewModel @Inject constructor(private val repository: CreateNewCenterRepository) : + ViewModel() { + + private val _createNewCenterUiState = MutableLiveData() + + val createNewCenterUiState: LiveData + get() = _createNewCenterUiState + + fun loadOffices() { + _createNewCenterUiState.value = CreateNewCenterUiState.ShowProgressbar + repository.offices() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber>() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + _createNewCenterUiState.value = + CreateNewCenterUiState.ShowFetchingError(R.string.failed_to_fetch_offices) + } + + override fun onNext(offices: List) { + _createNewCenterUiState.value = CreateNewCenterUiState.ShowOffices(offices) + } + }) + } + + fun createCenter(centerPayload: CenterPayload) { + _createNewCenterUiState.value = CreateNewCenterUiState.ShowProgressbar + repository.createCenter(centerPayload) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + _createNewCenterUiState.value = + CreateNewCenterUiState.ShowFetchingErrorString(e.message.toString()) + } + + override fun onNext(saveResponse: SaveResponse) { + _createNewCenterUiState.value = + CreateNewCenterUiState.CenterCreatedSuccessfully(saveResponse) + } + }) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewClientViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewClientViewModel.kt new file mode 100644 index 00000000000..8c55c3f75c5 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewClientViewModel.kt @@ -0,0 +1,197 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mifos.mifosxdroid.R +import com.mifos.objects.client.Client +import com.mifos.objects.client.ClientPayload +import com.mifos.objects.organisation.Office +import com.mifos.objects.organisation.Staff +import com.mifos.objects.templates.clients.ClientsTemplate +import com.mifos.objects.templates.clients.Options +import com.mifos.repositories.CreateNewClientRepository +import com.mifos.states.CreateNewClientUiState +import dagger.hilt.android.lifecycle.HiltViewModel +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.MultipartBody +import okhttp3.RequestBody.Companion.asRequestBody +import okhttp3.ResponseBody +import retrofit2.HttpException +import rx.Observable +import rx.Subscriber +import rx.android.schedulers.AndroidSchedulers +import rx.plugins.RxJavaPlugins +import rx.schedulers.Schedulers +import java.io.File +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 10/08/23. + */ +@HiltViewModel +class CreateNewClientViewModel @Inject constructor(private val repository: CreateNewClientRepository) : + ViewModel() { + + private val _createNewClientUiState = MutableLiveData() + + val createNewClientUiState: LiveData + get() = _createNewClientUiState + + fun loadClientTemplate() { + _createNewClientUiState.value = CreateNewClientUiState.ShowProgressbar + repository.clientTemplate() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + loadOffices() + } + + override fun onError(e: Throwable) { + _createNewClientUiState.value = + CreateNewClientUiState.ShowMessage(R.string.failed_to_fetch_client_template) + } + + override fun onNext(clientsTemplate: ClientsTemplate?) { + _createNewClientUiState.value = + CreateNewClientUiState.ShowClientTemplate(clientsTemplate) + } + }) + } + + fun loadOffices() { + _createNewClientUiState.value = CreateNewClientUiState.ShowProgressbar + repository.offices() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber>() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + _createNewClientUiState.value = + CreateNewClientUiState.ShowMessage(R.string.failed_to_fetch_offices) + } + + override fun onNext(officeList: List) { + _createNewClientUiState.value = CreateNewClientUiState.ShowOffices(officeList) + } + }) + } + + fun loadStaffInOffices(officeId: Int) { + repository.getStaffInOffice(officeId) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber>() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + _createNewClientUiState.value = + CreateNewClientUiState.ShowMessage(R.string.failed_to_fetch_staffs) + } + + override fun onNext(staffList: List) { + _createNewClientUiState.value = + CreateNewClientUiState.ShowStaffInOffices(staffList) + } + }) + } + + fun createClient(clientPayload: ClientPayload) { + _createNewClientUiState.value = CreateNewClientUiState.ShowProgressbar + repository.createClient(clientPayload) + .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() + _createNewClientUiState.value = errorMessage?.let { + CreateNewClientUiState.ShowMessageString( + it + ) + } + } + } catch (throwable: Throwable) { + RxJavaPlugins.getInstance().errorHandler.handleError(e) + } + } + + override fun onNext(client: Client?) { + if (client != null) { + if (client.clientId != null) { + _createNewClientUiState.value = + CreateNewClientUiState.ShowClientCreatedSuccessfully(R.string.client_created_successfully) + _createNewClientUiState.value = client.clientId?.let { + CreateNewClientUiState.SetClientId( + it + ) + } + } else { + _createNewClientUiState.value = client.clientId?.let { + CreateNewClientUiState.ShowWaitingForCheckerApproval( + it + ) + } + } + } + } + }) + } + + fun filterOptions(options: List?): List { + val filterValues: MutableList = ArrayList() + Observable.from(options) + .subscribe { options -> filterValues.add(options.name) } + return filterValues + } + + fun filterOffices(offices: List?): List { + val officesList: MutableList = ArrayList() + Observable.from(offices) + .subscribe { office -> office.name?.let { officesList.add(it) } } + return officesList + } + + fun filterStaff(staffs: List?): List { + val staffList: MutableList = ArrayList() + Observable.from(staffs) + .subscribe { staff -> staff.displayName?.let { staffList.add(it) } } + return staffList + } + + fun uploadImage(id: Int, pngFile: File) { + _createNewClientUiState.value = + CreateNewClientUiState.ShowProgress("Uploading Client's Picture...") + val imagePath = pngFile.absolutePath + + // create RequestBody instance from file + val requestFile = pngFile.asRequestBody("image/png".toMediaTypeOrNull()) + + // MultipartBody.Part is used to send also the actual file name + val body = MultipartBody.Part.createFormData("file", pngFile.name, requestFile) + repository.uploadClientImage(id, body) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + _createNewClientUiState.value = + CreateNewClientUiState.ShowMessage(R.string.Image_Upload_Failed) + } + + override fun onNext(t: ResponseBody) { + _createNewClientUiState.value = + CreateNewClientUiState.ShowMessage(R.string.Image_Upload_Successful) + } + }) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewGroupViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewGroupViewModel.kt new file mode 100644 index 00000000000..d9ae59124fe --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/CreateNewGroupViewModel.kt @@ -0,0 +1,70 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mifos.objects.group.GroupPayload +import com.mifos.objects.organisation.Office +import com.mifos.objects.response.SaveResponse +import com.mifos.repositories.CreateNewGroupRepository +import com.mifos.states.CreateNewGroupUiState +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 10/08/23. + */ +@HiltViewModel +class CreateNewGroupViewModel @Inject constructor(private val repository: CreateNewGroupRepository) : + ViewModel() { + + private val _createNewGroupUiState = MutableLiveData() + + val createNewGroupUiState: LiveData + get() = _createNewGroupUiState + + fun loadOffices() { + _createNewGroupUiState.value = CreateNewGroupUiState.ShowProgressbar + repository.offices() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber>() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + _createNewGroupUiState.value = + CreateNewGroupUiState.ShowFetchingError(e.message.toString()) + } + + override fun onNext(offices: List) { + _createNewGroupUiState.value = CreateNewGroupUiState.ShowOffices(offices) + } + }) + } + + fun createGroup(groupPayload: GroupPayload) { + _createNewGroupUiState.value = CreateNewGroupUiState.ShowProgressbar + repository.createGroup(groupPayload) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + _createNewGroupUiState.value = + CreateNewGroupUiState.ShowFetchingError(e.message.toString()) + } + + override fun onNext(saveResponse: SaveResponse) { + _createNewGroupUiState.value = + CreateNewGroupUiState.ShowGroupCreatedSuccessfully(saveResponse) + } + }) + + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/DataTableDataViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/DataTableDataViewModel.kt new file mode 100644 index 00000000000..d1604d0beec --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/DataTableDataViewModel.kt @@ -0,0 +1,73 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.google.gson.JsonArray +import com.mifos.api.GenericResponse +import com.mifos.mifosxdroid.R +import com.mifos.repositories.DataTableDataRepository +import com.mifos.states.DataTableDataUiState +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 10/08/23. + */ +@HiltViewModel +class DataTableDataViewModel @Inject constructor(private val repository: DataTableDataRepository) : + ViewModel() { + + private val _dataTableDataUiState = MutableLiveData() + + val dataTableDataUiState: LiveData + get() = _dataTableDataUiState + + fun loadDataTableInfo(table: String?, entityId: Int) { + _dataTableDataUiState.value = DataTableDataUiState.ShowProgressbar + repository.getDataTableInfo(table, entityId) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + _dataTableDataUiState.value = + DataTableDataUiState.ShowFetchingError(R.string.failed_to_fetch_datatable_info) + } + + override fun onNext(jsonElements: JsonArray) { + if (jsonElements.size() == 0) { + _dataTableDataUiState.value = DataTableDataUiState.ShowEmptyDataTable + } else { + _dataTableDataUiState.value = + DataTableDataUiState.ShowDataTableInfo(jsonElements) + } + } + }) + } + + fun deleteDataTableEntry(table: String?, entity: Int, rowId: Int) { + _dataTableDataUiState.value = DataTableDataUiState.ShowProgressbar + repository.deleteDataTableEntry(table, entity, rowId) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + _dataTableDataUiState.value = + DataTableDataUiState.ShowFetchingErrorString(e.message.toString()) + } + + override fun onNext(genericResponse: GenericResponse) { + _dataTableDataUiState.value = + DataTableDataUiState.ShowDataTableDeletedSuccessfully + } + }) + + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/DataTableListViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/DataTableListViewModel.kt new file mode 100644 index 00000000000..3dbe09599d1 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/DataTableListViewModel.kt @@ -0,0 +1,100 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mifos.mifosxdroid.R +import com.mifos.objects.accounts.loan.Loans +import com.mifos.objects.client.Client +import com.mifos.objects.client.ClientPayload +import com.mifos.repositories.DataTableListRepository +import com.mifos.services.data.GroupLoanPayload +import com.mifos.services.data.LoansPayload +import com.mifos.states.DataTableListUiState +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 10/08/23. + */ +@HiltViewModel +class DataTableListViewModel @Inject constructor(private val repository: DataTableListRepository) : + ViewModel() { + + private val _dataTableListUiState = MutableLiveData() + + val dataTableListUiState: LiveData + get() = _dataTableListUiState + + fun createLoansAccount(loansPayload: LoansPayload?) { + _dataTableListUiState.value = DataTableListUiState.ShowProgressBar + repository.createLoansAccount(loansPayload) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + _dataTableListUiState.value = + DataTableListUiState.ShowMessage(R.string.generic_failure_message) + } + + override fun onNext(loans: Loans) { + _dataTableListUiState.value = + DataTableListUiState.ShowMessage(R.string.loan_creation_success) + } + }) + } + + fun createGroupLoanAccount(loansPayload: GroupLoanPayload?) { + _dataTableListUiState.value = DataTableListUiState.ShowProgressBar + repository.createGroupLoansAccount(loansPayload) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + _dataTableListUiState.value = + DataTableListUiState.ShowMessage(R.string.generic_failure_message) + } + + override fun onNext(loans: Loans?) { + _dataTableListUiState.value = + DataTableListUiState.ShowMessage(R.string.loan_creation_success) + } + }) + + } + + fun createClient(clientPayload: ClientPayload) { + _dataTableListUiState.value = DataTableListUiState.ShowProgressBar + repository.createClient(clientPayload) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + _dataTableListUiState.value = + DataTableListUiState.ShowMessageString(e.message.toString()) + } + + override fun onNext(client: Client) { + if (client.clientId != null) { + _dataTableListUiState.value = + DataTableListUiState.ShowClientCreatedSuccessfully(client) + } else { + _dataTableListUiState.value = + DataTableListUiState.ShowWaitingForCheckerApproval(R.string.waiting_for_checker_approval) + } + } + }) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/IndividualCollectionSheetDetailsViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/IndividualCollectionSheetDetailsViewModel.kt new file mode 100644 index 00000000000..92236a5d123 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/IndividualCollectionSheetDetailsViewModel.kt @@ -0,0 +1,92 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mifos.api.GenericResponse +import com.mifos.api.model.IndividualCollectionSheetPayload +import com.mifos.objects.accounts.loan.PaymentTypeOptions +import com.mifos.objects.collectionsheet.ClientCollectionSheet +import com.mifos.objects.collectionsheet.LoanAndClientName +import com.mifos.repositories.IndividualCollectionSheetDetailsRepositoryImp +import com.mifos.states.IndividualCollectionSheetDetailsUiState +import dagger.hilt.android.lifecycle.HiltViewModel +import retrofit2.HttpException +import rx.Observable +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 10/08/23. + */ +@HiltViewModel +class IndividualCollectionSheetDetailsViewModel @Inject constructor(private val repository: IndividualCollectionSheetDetailsRepositoryImp) : + ViewModel() { + + private val _individualCollectionSheetDetailsUiState = + MutableLiveData() + + val individualCollectionSheetDetailsUiState: LiveData + get() = _individualCollectionSheetDetailsUiState + + fun submitIndividualCollectionSheet(individualCollectionSheetPayload: IndividualCollectionSheetPayload?) { + _individualCollectionSheetDetailsUiState.value = + IndividualCollectionSheetDetailsUiState.ShowProgressbar + repository + .saveIndividualCollectionSheet(individualCollectionSheetPayload) + .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() + _individualCollectionSheetDetailsUiState.value = errorMessage?.let { + IndividualCollectionSheetDetailsUiState.ShowError( + it + ) + } + } + } catch (throwable: Throwable) { + RxJavaPlugins.getInstance().errorHandler.handleError(e) + } + } + + override fun onNext(genericResponse: GenericResponse?) { + _individualCollectionSheetDetailsUiState.value = + IndividualCollectionSheetDetailsUiState.ShowSuccess + } + }) + } + + fun filterPaymentTypeOptions(paymentTypeOptionsList: List?): List { + val paymentList: MutableList = ArrayList() + Observable.from(paymentTypeOptionsList) + .subscribe { paymentTypeOption -> paymentTypeOption.name?.let { paymentList.add(it) } } + return paymentList + } + + fun filterLoanAndClientNames(clientCollectionSheets: List?): List { + val loansAndClientNames: MutableList = ArrayList() + Observable.from(clientCollectionSheets) + .subscribe { clientCollectionSheet -> + if (clientCollectionSheet.loans != null) { + for (loanCollectionSheet in clientCollectionSheet.loans!!) { + loansAndClientNames.add( + LoanAndClientName( + loanCollectionSheet, + clientCollectionSheet.clientName, + clientCollectionSheet.clientId + ) + ) + } + } + } + return loansAndClientNames + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/LoanAccountApprovalViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/LoanAccountApprovalViewModel.kt new file mode 100644 index 00000000000..22162e4f622 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/LoanAccountApprovalViewModel.kt @@ -0,0 +1,62 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mifos.api.GenericResponse +import com.mifos.objects.accounts.loan.LoanApproval +import com.mifos.repositories.LoanAccountApprovalRepository +import com.mifos.states.LoanAccountApprovalUiState +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 10/08/23. + */ +@HiltViewModel +class LoanAccountApprovalViewModel @Inject constructor(private val repository: LoanAccountApprovalRepository) : + ViewModel() { + + private val _loanAccountApprovalUiState = MutableLiveData() + + val loanAccountApprovalUiState: LiveData + get() = _loanAccountApprovalUiState + + fun approveLoan(loanId: Int, loanApproval: LoanApproval?) { + _loanAccountApprovalUiState.value = LoanAccountApprovalUiState.ShowProgressbar + repository.approveLoan(loanId, loanApproval) + .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() + _loanAccountApprovalUiState.value = errorMessage?.let { + LoanAccountApprovalUiState.ShowLoanApproveFailed( + it + ) + } + } + } catch (throwable: Throwable) { + RxJavaPlugins.getInstance().errorHandler.handleError(e) + } + } + + override fun onNext(genericResponse: GenericResponse?) { + _loanAccountApprovalUiState.value = genericResponse?.let { + LoanAccountApprovalUiState.ShowLoanApproveSuccessfully( + it + ) + } + } + }) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/LoanAccountDisbursementViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/LoanAccountDisbursementViewModel.kt new file mode 100644 index 00000000000..f888ba342c3 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/LoanAccountDisbursementViewModel.kt @@ -0,0 +1,71 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mifos.api.GenericResponse +import com.mifos.api.model.APIEndPoint +import com.mifos.objects.accounts.loan.LoanDisbursement +import com.mifos.objects.templates.loans.LoanTransactionTemplate +import com.mifos.repositories.LoanAccountDisbursementRepository +import com.mifos.states.LoanAccountDisbursementUiState +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 10/08/23. + */ +@HiltViewModel +class LoanAccountDisbursementViewModel @Inject constructor(private val repository: LoanAccountDisbursementRepository) : + ViewModel() { + + + private val _loanAccountDisbursementUiState = MutableLiveData() + + val loanAccountDisbursementUiState: LiveData + get() = _loanAccountDisbursementUiState + + fun loadLoanTemplate(loanId: Int) { + _loanAccountDisbursementUiState.value = LoanAccountDisbursementUiState.ShowProgressbar + repository.getLoanTransactionTemplate(loanId, APIEndPoint.DISBURSE) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + _loanAccountDisbursementUiState.value = + LoanAccountDisbursementUiState.ShowError(e.message.toString()) + } + + override fun onNext(loanTransactionTemplate: LoanTransactionTemplate) { + _loanAccountDisbursementUiState.value = + LoanAccountDisbursementUiState.ShowLoanTransactionTemplate( + loanTransactionTemplate + ) + } + }) + } + + fun disburseLoan(loanId: Int, loanDisbursement: LoanDisbursement?) { + _loanAccountDisbursementUiState.value = LoanAccountDisbursementUiState.ShowProgressbar + repository.disburseLoan(loanId, loanDisbursement) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + _loanAccountDisbursementUiState.value = + LoanAccountDisbursementUiState.ShowError(e.message.toString()) + } + + override fun onNext(genericResponse: GenericResponse?) { + _loanAccountDisbursementUiState.value = + LoanAccountDisbursementUiState.ShowDisburseLoanSuccessfully(genericResponse) + } + }) + } + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/LoanChargeViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/LoanChargeViewModel.kt new file mode 100644 index 00000000000..236bf9dffd9 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/LoanChargeViewModel.kt @@ -0,0 +1,56 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mifos.objects.client.Charges +import com.mifos.repositories.LoanChargeRepository +import com.mifos.states.LoanChargeUiState +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 10/08/23. + */ +@HiltViewModel +class LoanChargeViewModel @Inject constructor(private val repository: LoanChargeRepository) : + ViewModel() { + + private val _loanChargeUiState = MutableLiveData() + + val loanChargeUiState: LiveData + get() = _loanChargeUiState + + fun loadLoanChargesList(loanId: Int) { + _loanChargeUiState.value = LoanChargeUiState.ShowProgressbar + repository.getListOfLoanCharges(loanId) + .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() + _loanChargeUiState.value = + errorMessage?.let { LoanChargeUiState.ShowFetchingError(it) } + } + } catch (throwable: Throwable) { + RxJavaPlugins.getInstance().errorHandler.handleError(e) + } + } + + override fun onNext(chargesPage: List) { + _loanChargeUiState.value = + LoanChargeUiState.ShowLoanChargesList(chargesPage as MutableList) + } + }) + } + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/LoanRepaymentViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/LoanRepaymentViewModel.kt new file mode 100644 index 00000000000..d17b647d02e --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/LoanRepaymentViewModel.kt @@ -0,0 +1,97 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mifos.mifosxdroid.R +import com.mifos.objects.accounts.loan.LoanRepaymentRequest +import com.mifos.objects.accounts.loan.LoanRepaymentResponse +import com.mifos.objects.templates.loans.LoanRepaymentTemplate +import com.mifos.repositories.LoanRepaymentRepository +import com.mifos.states.LoanRepaymentUiState +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 10/08/23. + */ +@HiltViewModel +class LoanRepaymentViewModel @Inject constructor(private val repository: LoanRepaymentRepository) : + ViewModel() { + + private val _loanRepaymentUiState = MutableLiveData() + + val loanRepaymentUiState: LiveData + get() = _loanRepaymentUiState + + fun loanLoanRepaymentTemplate(loanId: Int) { + _loanRepaymentUiState.value = LoanRepaymentUiState.ShowProgressbar + repository.getLoanRepayTemplate(loanId) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + _loanRepaymentUiState.value = + LoanRepaymentUiState.ShowError(R.string.failed_to_load_loanrepayment) + } + + override fun onNext(loanRepaymentTemplate: LoanRepaymentTemplate?) { + _loanRepaymentUiState.value = + LoanRepaymentUiState.ShowLoanRepayTemplate(loanRepaymentTemplate) + } + }) + } + + fun submitPayment(loanId: Int, request: LoanRepaymentRequest) { + _loanRepaymentUiState.value = LoanRepaymentUiState.ShowProgressbar + repository.submitPayment(loanId, request) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + _loanRepaymentUiState.value = + LoanRepaymentUiState.ShowError(R.string.payment_failed) + } + + override fun onNext(loanRepaymentResponse: LoanRepaymentResponse?) { + _loanRepaymentUiState.value = + LoanRepaymentUiState.ShowPaymentSubmittedSuccessfully(loanRepaymentResponse) + } + }) + } + + fun checkDatabaseLoanRepaymentByLoanId(loanId: Int) { + _loanRepaymentUiState.value = LoanRepaymentUiState.ShowProgressbar + repository.getDatabaseLoanRepaymentByLoanId(loanId) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + _loanRepaymentUiState.value = + LoanRepaymentUiState.ShowError(R.string.failed_to_load_loanrepayment) + } + + override fun onNext(loanRepaymentRequest: LoanRepaymentRequest?) { + if (loanRepaymentRequest != null) { + _loanRepaymentUiState.value = + LoanRepaymentUiState.ShowLoanRepaymentExistInDatabase + } else { + _loanRepaymentUiState.value = + LoanRepaymentUiState.ShowLoanRepaymentDoesNotExistInDatabase + } + } + }) + + } + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/viewmodels/NewIndividualCollectionSheetViewModel.kt b/mifosng-android/src/main/java/com/mifos/viewmodels/NewIndividualCollectionSheetViewModel.kt new file mode 100644 index 00000000000..44736473086 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/viewmodels/NewIndividualCollectionSheetViewModel.kt @@ -0,0 +1,146 @@ +package com.mifos.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.mifos.api.model.RequestCollectionSheetPayload +import com.mifos.objects.collectionsheet.IndividualCollectionSheet +import com.mifos.objects.organisation.Office +import com.mifos.objects.organisation.Staff +import com.mifos.repositories.NewIndividualCollectionSheetRepository +import com.mifos.states.NewIndividualCollectionSheetUiState +import dagger.hilt.android.lifecycle.HiltViewModel +import retrofit2.HttpException +import rx.Observable +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 10/08/23. + */ +@HiltViewModel +class NewIndividualCollectionSheetViewModel @Inject constructor(private val repository: NewIndividualCollectionSheetRepository) : + ViewModel() { + + private val _newIndividualCollectionSheetUiState = + MutableLiveData() + + val newIndividualCollectionSheetUiState: LiveData + get() = _newIndividualCollectionSheetUiState + + fun fetchIndividualCollectionSheet(requestCollectionSheetPayload: RequestCollectionSheetPayload?) { + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.ShowProgressbar + + repository.getIndividualCollectionSheet(requestCollectionSheetPayload) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.ShowSuccess + } + + override fun onError(e: Throwable) { + if (e is HttpException) { + try { + val errorMessage = e.response()?.errorBody() + ?.string() + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.ShowError(errorMessage) + } catch (throwable: Throwable) { + RxJavaPlugins.getInstance().errorHandler.handleError(e) + } + } else { + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.ShowError(e.localizedMessage) + } + } + + override fun onNext(individualCollectionSheet: IndividualCollectionSheet) { + if (individualCollectionSheet.clients?.size!! > 0) { + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.ShowSheet(individualCollectionSheet) + } else { + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.ShowNoSheetFound + } + } + }) + } + + fun fetchOffices() { + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.ShowProgressbar + repository.offices() + .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() + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.ShowError(errorMessage) + } + } catch (throwable: Throwable) { + RxJavaPlugins.getInstance().errorHandler.handleError(e) + } + } + + override fun onNext(officeList: List) { + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.SetOfficeSpinner(officeList) + } + }) + } + + fun fetchStaff(officeId: Int) { + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.ShowProgressbar + repository.getStaffInOffice(officeId) + .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() + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.ShowError(errorMessage) + } + } catch (throwable: Throwable) { + RxJavaPlugins.getInstance().errorHandler.handleError(e) + } + } + + override fun onNext(staffList: List) { + _newIndividualCollectionSheetUiState.value = + NewIndividualCollectionSheetUiState.SetStaffSpinner(staffList) + } + }) + + } + + fun filterOffices(offices: List): List { + val officesList: MutableList = ArrayList() + Observable.from(offices) + .subscribe { office -> office.name?.let { officesList.add(it) } } + return officesList + } + + fun filterStaff(staffs: List): List { + val staffList: MutableList = ArrayList() + Observable.from(staffs) + .subscribe { staff -> staff.displayName?.let { staffList.add(it) } } + return staffList + } + +} \ No newline at end of file