From 0e8e54cfc93efbf5420286af85517ffb004db24f Mon Sep 17 00:00:00 2001 From: Pronay Sarker Date: Mon, 5 Aug 2024 08:56:27 +0600 Subject: [PATCH] moved createNewGroup & syncGroupPayload to group module (#2175) b moved createNewGroup & syncGroupPayload to group module --- .../java/com/mifos/core/data/di/DataModule.kt | 11 +- .../repository}/CreateNewGroupRepository.kt | 3 +- .../SyncGroupPayloadsRepository.kt | 2 +- .../CreateNewGroupRepositoryImp.kt | 3 +- .../SyncGroupPayloadsRepositoryImp.kt | 3 +- .../AllDatabaseGroupPayloadUseCase.kt | 45 +++++ .../domain/use_cases/CreateGroupUseCase.kt | 41 +++++ .../domain/use_cases/CreateNewGroupUseCase.kt | 46 +++++ .../DeleteAndUpdateGroupPayloadUseCase.kt | 49 ++++++ .../use_cases/GetGroupOfficesUseCase.kt | 48 ++++++ .../use_cases/UpdateGroupPayloadUseCase.kt | 45 +++++ core/domain/src/main/res/values/string.xml | 2 + feature/groups/build.gradle.kts | 1 + .../GroupListScreenTest.kt | 5 +- .../create_new_group}/CreateNewGroupScreen.kt | 81 +++++---- .../CreateNewGroupUiState.kt | 2 +- .../CreateNewGroupViewModel.kt | 74 ++++++++ .../group_details/GroupDetailsScreen.kt | 2 +- .../group_details/GroupDetailsUiState.kt | 2 +- .../group_details/GroupDetailsViewModel.kt | 2 +- .../group_list/GroupsListScreen.kt | 3 +- .../group_list/GroupsListViewModel.kt | 2 +- .../SyncGroupPayloadsScreenRoute.kt | 72 +++++--- .../SyncGroupPayloadsUiState.kt | 13 +- .../SyncGroupPayloadsViewModel.kt | 162 ++++++++++++++++++ ...ups_ic_assignment_turned_in_black_24dp.xml | 9 + .../groups/src/main/res/values/strings.xml | 26 ++- .../syncgroupsdialog/SyncGroupDialogScreen.kt | 2 +- .../injection/module/RepositoryModule.kt | 12 +- .../SyncGroupPayloadsFragment.kt | 1 + .../SyncGroupPayloadsViewModel.kt | 147 ---------------- .../createnewgroup/CreateNewGroupFragment.kt | 1 + .../createnewgroup/CreateNewGroupViewModel.kt | 70 -------- .../groupdetails/GroupDetailsFragment.kt | 2 +- .../online/groupslist/GroupsListFragment.kt | 2 +- .../LoanAccountDisbursementFragment.kt | 20 --- .../main/java/com/mifos/utils/PrefManager.kt | 3 +- .../layout/checker_inbox_tasks_fragment.xml | 2 +- 38 files changed, 673 insertions(+), 343 deletions(-) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup => core/data/src/main/java/com/mifos/core/data/repository}/CreateNewGroupRepository.kt (82%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads => core/data/src/main/java/com/mifos/core/data/repository}/SyncGroupPayloadsRepository.kt (89%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup => core/data/src/main/java/com/mifos/core/data/repository_imp}/CreateNewGroupRepositoryImp.kt (88%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads => core/data/src/main/java/com/mifos/core/data/repository_imp}/SyncGroupPayloadsRepositoryImp.kt (89%) create mode 100644 core/domain/src/main/java/com/mifos/core/domain/use_cases/AllDatabaseGroupPayloadUseCase.kt create mode 100644 core/domain/src/main/java/com/mifos/core/domain/use_cases/CreateGroupUseCase.kt create mode 100644 core/domain/src/main/java/com/mifos/core/domain/use_cases/CreateNewGroupUseCase.kt create mode 100644 core/domain/src/main/java/com/mifos/core/domain/use_cases/DeleteAndUpdateGroupPayloadUseCase.kt create mode 100644 core/domain/src/main/java/com/mifos/core/domain/use_cases/GetGroupOfficesUseCase.kt create mode 100644 core/domain/src/main/java/com/mifos/core/domain/use_cases/UpdateGroupPayloadUseCase.kt rename feature/groups/src/androidTest/java/com/mifos/feature/{groupsList => groups}/GroupListScreenTest.kt (99%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup => feature/groups/src/main/java/com/mifos/feature/groups/create_new_group}/CreateNewGroupScreen.kt (84%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup => feature/groups/src/main/java/com/mifos/feature/groups/create_new_group}/CreateNewGroupUiState.kt (90%) create mode 100644 feature/groups/src/main/java/com/mifos/feature/groups/create_new_group/CreateNewGroupViewModel.kt rename feature/groups/src/main/java/com/mifos/feature/{groupsList => groups}/group_details/GroupDetailsScreen.kt (99%) rename feature/groups/src/main/java/com/mifos/feature/{groupsList => groups}/group_details/GroupDetailsUiState.kt (85%) rename feature/groups/src/main/java/com/mifos/feature/{groupsList => groups}/group_details/GroupDetailsViewModel.kt (98%) rename feature/groups/src/main/java/com/mifos/feature/{groupsList => groups}/group_list/GroupsListScreen.kt (99%) rename feature/groups/src/main/java/com/mifos/feature/{groupsList => groups}/group_list/GroupsListViewModel.kt (94%) rename mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsScreen.kt => feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads/SyncGroupPayloadsScreenRoute.kt (77%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads => feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads}/SyncGroupPayloadsUiState.kt (79%) create mode 100644 feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads/SyncGroupPayloadsViewModel.kt create mode 100644 feature/groups/src/main/res/drawable/feature_groups_ic_assignment_turned_in_black_24dp.xml delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsViewModel.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupViewModel.kt diff --git a/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt b/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt index 7d8cba8b629..94c8d6aac12 100644 --- a/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt +++ b/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt @@ -11,6 +11,7 @@ import com.mifos.core.data.repository.ClientChargeRepository import com.mifos.core.data.repository.ClientIdentifierDialogRepository import com.mifos.core.data.repository.ClientIdentifiersRepository import com.mifos.core.data.repository.CreateNewCenterRepository +import com.mifos.core.data.repository.CreateNewGroupRepository import com.mifos.core.data.repository.DataTableDataRepository import com.mifos.core.data.repository.DataTableRowDialogRepository import com.mifos.core.data.repository.DocumentListRepository @@ -30,6 +31,7 @@ import com.mifos.core.data.repository.ReportCategoryRepository import com.mifos.core.data.repository.ReportDetailRepository import com.mifos.core.data.repository.SearchRepository import com.mifos.core.data.repository.SignatureRepository +import com.mifos.core.data.repository.SyncGroupPayloadsRepository import com.mifos.core.data.repository_imp.ActivateRepositoryImp import com.mifos.core.data.repository_imp.CenterDetailsRepositoryImp import com.mifos.core.data.repository_imp.CenterListRepositoryImp @@ -40,6 +42,7 @@ import com.mifos.core.data.repository_imp.ClientChargeRepositoryImp import com.mifos.core.data.repository_imp.ClientIdentifierDialogRepositoryImp import com.mifos.core.data.repository_imp.ClientIdentifiersRepositoryImp import com.mifos.core.data.repository_imp.CreateNewCenterRepositoryImp +import com.mifos.core.data.repository_imp.CreateNewGroupRepositoryImp import com.mifos.core.data.repository_imp.DataTableDataRepositoryImp import com.mifos.core.data.repository_imp.DataTableRowDialogRepositoryImp import com.mifos.core.data.repository_imp.DocumentListRepositoryImp @@ -59,6 +62,7 @@ import com.mifos.core.data.repository_imp.ReportCategoryRepositoryImp import com.mifos.core.data.repository_imp.ReportDetailRepositoryImp import com.mifos.core.data.repository_imp.SearchRepositoryImp import com.mifos.core.data.repository_imp.SignatureRepositoryImp +import com.mifos.core.data.repository_imp.SyncGroupPayloadsRepositoryImp import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -75,9 +79,7 @@ abstract class DataModule { abstract fun bindNewIndividualCollectionSheetRepository(impl: NewIndividualCollectionSheetRepositoryImp): NewIndividualCollectionSheetRepository @Binds - internal abstract fun provideGroupListRepository( - groupsListRepositoryImpl: GroupsListRepositoryImpl - ): GroupsListRepository + internal abstract fun provideGroupListRepository(groupsListRepositoryImpl: GroupsListRepositoryImpl): GroupsListRepository @Binds internal abstract fun provideGroupDetailsRepository(impl: GroupDetailsRepositoryImp): GroupDetailsRepository @@ -106,6 +108,9 @@ abstract class DataModule { @Binds internal abstract fun bindClientIdentifiersRepository(impl: ClientIdentifiersRepositoryImp): ClientIdentifiersRepository + @Binds + internal abstract fun bindCreateNewGroupRepository(impl: CreateNewGroupRepositoryImp): CreateNewGroupRepository + @Binds internal abstract fun bindPinpointRepository(impl: PinPointClientRepositoryImp): PinPointClientRepository diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/CreateNewGroupRepository.kt similarity index 82% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupRepository.kt rename to core/data/src/main/java/com/mifos/core/data/repository/CreateNewGroupRepository.kt index 0e424c1d304..20cba4babfa 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/CreateNewGroupRepository.kt @@ -1,5 +1,6 @@ -package com.mifos.mifosxdroid.online.createnewgroup +package com.mifos.core.data.repository +import com.mifos.core.datastore.PrefManager import com.mifos.core.objects.group.GroupPayload import com.mifos.core.objects.organisation.Office import com.mifos.core.objects.response.SaveResponse diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/SyncGroupPayloadsRepository.kt similarity index 89% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsRepository.kt rename to core/data/src/main/java/com/mifos/core/data/repository/SyncGroupPayloadsRepository.kt index 09a41ede70a..914aed6186a 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/SyncGroupPayloadsRepository.kt @@ -1,4 +1,4 @@ -package com.mifos.mifosxdroid.offline.syncgrouppayloads +package com.mifos.core.data.repository import com.mifos.core.objects.group.GroupPayload import com.mifos.core.objects.response.SaveResponse diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repository_imp/CreateNewGroupRepositoryImp.kt similarity index 88% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupRepositoryImp.kt rename to core/data/src/main/java/com/mifos/core/data/repository_imp/CreateNewGroupRepositoryImp.kt index 3412b674eab..26246367e3e 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository_imp/CreateNewGroupRepositoryImp.kt @@ -1,5 +1,6 @@ -package com.mifos.mifosxdroid.online.createnewgroup +package com.mifos.core.data.repository_imp +import com.mifos.core.data.repository.CreateNewGroupRepository import com.mifos.core.network.datamanager.DataManagerGroups import com.mifos.core.network.datamanager.DataManagerOffices import com.mifos.core.objects.group.GroupPayload diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repository_imp/SyncGroupPayloadsRepositoryImp.kt similarity index 89% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsRepositoryImp.kt rename to core/data/src/main/java/com/mifos/core/data/repository_imp/SyncGroupPayloadsRepositoryImp.kt index 32a7027ff08..787f31eb3d1 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository_imp/SyncGroupPayloadsRepositoryImp.kt @@ -1,5 +1,6 @@ -package com.mifos.mifosxdroid.offline.syncgrouppayloads +package com.mifos.core.data.repository_imp +import com.mifos.core.data.repository.SyncGroupPayloadsRepository import com.mifos.core.network.datamanager.DataManagerGroups import com.mifos.core.objects.group.GroupPayload import com.mifos.core.objects.response.SaveResponse diff --git a/core/domain/src/main/java/com/mifos/core/domain/use_cases/AllDatabaseGroupPayloadUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/use_cases/AllDatabaseGroupPayloadUseCase.kt new file mode 100644 index 00000000000..8cc48e3dafd --- /dev/null +++ b/core/domain/src/main/java/com/mifos/core/domain/use_cases/AllDatabaseGroupPayloadUseCase.kt @@ -0,0 +1,45 @@ +package com.mifos.core.domain.use_cases + +import com.mifos.core.common.utils.Resource +import com.mifos.core.data.repository.SyncGroupPayloadsRepository +import com.mifos.core.objects.group.GroupPayload +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.callbackFlow +import rx.Subscriber +import rx.android.schedulers.AndroidSchedulers +import rx.schedulers.Schedulers +import javax.inject.Inject + +/** + * Created by Pronay Sarker on 02/08/2024 (12:04 AM) + */ +class AllDatabaseGroupPayloadUseCase @Inject constructor(private val repository: SyncGroupPayloadsRepository) { + + suspend operator fun invoke(): Flow>> = + callbackFlow { + try { + trySend(Resource.Loading()) + + repository.allDatabaseGroupPayload() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber>() { + override fun onCompleted() {} + + override fun onError(e: Throwable) { + trySend(Resource.Error(e.message.toString())) + } + + override fun onNext(groupPayloads: List ) { + trySend(Resource.Success(groupPayloads)) + } + }) + + awaitClose { channel.close() } + } catch (e: Exception) { + trySend(Resource.Error(e.message.toString())) + } + } + +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/use_cases/CreateGroupUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/use_cases/CreateGroupUseCase.kt new file mode 100644 index 00000000000..0dfa3e5653e --- /dev/null +++ b/core/domain/src/main/java/com/mifos/core/domain/use_cases/CreateGroupUseCase.kt @@ -0,0 +1,41 @@ +package com.mifos.core.domain.use_cases + +import com.mifos.core.common.utils.Resource +import com.mifos.core.data.repository.CreateNewGroupRepository +import com.mifos.core.objects.group.GroupPayload +import com.mifos.core.objects.response.SaveResponse +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.callbackFlow +import rx.Subscriber +import rx.android.schedulers.AndroidSchedulers +import rx.schedulers.Schedulers +import javax.inject.Inject + +class CreateGroupUseCase @Inject constructor(private val repository: CreateNewGroupRepository) { + + suspend operator fun invoke(groupPayload : GroupPayload): Flow> = callbackFlow { + try { + trySend(Resource.Loading()) + + repository.createGroup(groupPayload) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() {} + + override fun onError(e: Throwable) { + trySend(Resource.Error(e.message.toString())) + } + + override fun onNext(group: SaveResponse) { + trySend(Resource.Success(group)) + } + }) + + awaitClose { channel.close() } + } catch (e: Exception) { + trySend(Resource.Error(e.message.toString())) + } + } +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/use_cases/CreateNewGroupUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/use_cases/CreateNewGroupUseCase.kt new file mode 100644 index 00000000000..267497536d7 --- /dev/null +++ b/core/domain/src/main/java/com/mifos/core/domain/use_cases/CreateNewGroupUseCase.kt @@ -0,0 +1,46 @@ +package com.mifos.core.domain.use_cases + +import com.mifos.core.common.utils.Resource +import com.mifos.core.data.repository.CreateNewGroupRepository +import com.mifos.core.objects.group.GroupPayload +import com.mifos.core.objects.response.SaveResponse +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.callbackFlow +import rx.Subscriber +import rx.android.schedulers.AndroidSchedulers +import rx.schedulers.Schedulers +import javax.inject.Inject + +/** + * Created by Pronay Sarker on 01/08/2024 (9:18 AM) + */ +class CreateNewGroupUseCase @Inject constructor(private val repository: CreateNewGroupRepository) { + + suspend operator fun invoke(groupPayload: GroupPayload): Flow> = callbackFlow { + try { + trySend(Resource.Loading()) + + repository.createGroup(groupPayload) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() { + } + + override fun onError(e: Throwable) { + trySend(Resource.Error(e.message.toString())) + } + + override fun onNext(saveResponse: SaveResponse) { + trySend(Resource.Success(saveResponse)) + } + }) + + awaitClose { channel.close() } + } + catch (e: Exception){ + trySend(Resource.Error(e.message.toString())) + } + } +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/use_cases/DeleteAndUpdateGroupPayloadUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/use_cases/DeleteAndUpdateGroupPayloadUseCase.kt new file mode 100644 index 00000000000..fdd76b054ca --- /dev/null +++ b/core/domain/src/main/java/com/mifos/core/domain/use_cases/DeleteAndUpdateGroupPayloadUseCase.kt @@ -0,0 +1,49 @@ +package com.mifos.core.domain.use_cases + +import com.mifos.core.common.utils.Resource +import com.mifos.core.data.CenterPayload +import com.mifos.core.data.repository.CreateNewCenterRepository +import com.mifos.core.data.repository.SyncGroupPayloadsRepository +import com.mifos.core.domain.R +import com.mifos.core.objects.group.GroupPayload +import com.mifos.core.objects.response.SaveResponse +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.callbackFlow +import rx.Subscriber +import rx.android.schedulers.AndroidSchedulers +import rx.schedulers.Schedulers +import javax.inject.Inject + +/** + * Created by Pronay Sarker on 01/08/2024 (9:13 PM) + */ +class DeleteAndUpdateGroupPayloadUseCase @Inject constructor(private val repository: SyncGroupPayloadsRepository) { + + suspend operator fun invoke(id: Int): Flow>> = + callbackFlow { + try { + trySend(Resource.Loading()) + + repository.deleteAndUpdateGroupPayloads(id) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber>() { + override fun onCompleted() {} + + override fun onError(e: Throwable) { + trySend(Resource.Error(e.message.toString())) + } + + override fun onNext(groupPayloads: List) { + trySend(Resource.Success(groupPayloads)) + } + }) + + awaitClose { channel.close() } + } catch (e: Exception) { + trySend(Resource.Error(e.message.toString())) + } + } + +} diff --git a/core/domain/src/main/java/com/mifos/core/domain/use_cases/GetGroupOfficesUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/use_cases/GetGroupOfficesUseCase.kt new file mode 100644 index 00000000000..400d36dffb5 --- /dev/null +++ b/core/domain/src/main/java/com/mifos/core/domain/use_cases/GetGroupOfficesUseCase.kt @@ -0,0 +1,48 @@ +package com.mifos.core.domain.use_cases + +import com.mifos.core.common.utils.Resource +import com.mifos.core.data.repository.CreateNewGroupRepository +import com.mifos.core.data.repository.GroupListRepository +import com.mifos.core.objects.organisation.Office +import com.mifos.core.objects.zipmodels.GroupAndGroupAccounts +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.callbackFlow +import kotlinx.coroutines.flow.flow +import rx.Observable +import rx.Subscriber +import rx.android.schedulers.AndroidSchedulers +import rx.schedulers.Schedulers +import javax.inject.Inject + +/** + * Created by Pronay Sarker on 01/08/2024 (8:23 AM) + */ + +class GetGroupOfficesUseCase @Inject constructor(private val repository: CreateNewGroupRepository) { + + suspend operator fun invoke(): Flow>> = callbackFlow { + try { + trySend(Resource.Loading()) + + repository.offices() + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber>() { + override fun onCompleted() { } + + override fun onError(e: Throwable) { + trySend(Resource.Error(e.message.toString())) + } + + override fun onNext(offices: List) { + trySend(Resource.Success(offices)) + } + }) + + awaitClose { channel.close() } + } catch (e: Exception) { + trySend(Resource.Error(e.message.toString())) + } + } +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/use_cases/UpdateGroupPayloadUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/use_cases/UpdateGroupPayloadUseCase.kt new file mode 100644 index 00000000000..347431cf576 --- /dev/null +++ b/core/domain/src/main/java/com/mifos/core/domain/use_cases/UpdateGroupPayloadUseCase.kt @@ -0,0 +1,45 @@ +package com.mifos.core.domain.use_cases + +import com.mifos.core.common.utils.Resource +import com.mifos.core.data.repository.SyncGroupPayloadsRepository +import com.mifos.core.objects.group.GroupPayload +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.callbackFlow +import rx.Subscriber +import rx.android.schedulers.AndroidSchedulers +import rx.schedulers.Schedulers +import javax.inject.Inject + +/** + * Created by Pronay Sarker on 01/08/2024 (10:26 PM) + */ +class UpdateGroupPayloadUseCase @Inject constructor(private val repository: SyncGroupPayloadsRepository) { + + suspend operator fun invoke(groupPayload : GroupPayload): Flow> = + callbackFlow { + try { + trySend(Resource.Loading()) + + repository.updateGroupPayload(groupPayload) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe(object : Subscriber() { + override fun onCompleted() {} + + override fun onError(e: Throwable) { + trySend(Resource.Error(e.message.toString())) + } + + override fun onNext(groupPayload: GroupPayload) { + trySend(Resource.Success(groupPayload)) + } + }) + + awaitClose { channel.close() } + } catch (e: Exception) { + trySend(Resource.Error(e.message.toString())) + } + } + +} \ No newline at end of file diff --git a/core/domain/src/main/res/values/string.xml b/core/domain/src/main/res/values/string.xml index 6834df4a551..461d59100d7 100644 --- a/core/domain/src/main/res/values/string.xml +++ b/core/domain/src/main/res/values/string.xml @@ -19,4 +19,6 @@ Server tenant cannot be blank Server tenant must only contain alphanumeric characters + + \ No newline at end of file diff --git a/feature/groups/build.gradle.kts b/feature/groups/build.gradle.kts index 8f6a35ff9ef..3cb1e78813e 100644 --- a/feature/groups/build.gradle.kts +++ b/feature/groups/build.gradle.kts @@ -4,6 +4,7 @@ plugins { alias(libs.plugins.mifos.android.library.jacoco) } + android { namespace = "com.mifos.feature.groups" } diff --git a/feature/groups/src/androidTest/java/com/mifos/feature/groupsList/GroupListScreenTest.kt b/feature/groups/src/androidTest/java/com/mifos/feature/groups/GroupListScreenTest.kt similarity index 99% rename from feature/groups/src/androidTest/java/com/mifos/feature/groupsList/GroupListScreenTest.kt rename to feature/groups/src/androidTest/java/com/mifos/feature/groups/GroupListScreenTest.kt index 9fba5b5ead0..5d8e92c1a05 100644 --- a/feature/groups/src/androidTest/java/com/mifos/feature/groupsList/GroupListScreenTest.kt +++ b/feature/groups/src/androidTest/java/com/mifos/feature/groups/GroupListScreenTest.kt @@ -1,4 +1,4 @@ -package com.mifos.feature.groupsList +package com.mifos.feature.groups import androidx.activity.ComponentActivity import androidx.compose.foundation.lazy.LazyListState @@ -35,8 +35,7 @@ import com.mifos.core.domain.use_cases.GroupsListPagingDataSource import com.mifos.core.objects.group.Group import com.mifos.core.testing.repository.TestGroupsListRepository import com.mifos.core.testing.repository.sampleGroups -import com.mifos.feature.groups.R -import com.mifos.feature.groupsList.group_list.GroupsListScreen +import com.mifos.feature.groups.group_list.GroupsListScreen import kotlinx.coroutines.delay import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.runBlocking diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupScreen.kt b/feature/groups/src/main/java/com/mifos/feature/groups/create_new_group/CreateNewGroupScreen.kt similarity index 84% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupScreen.kt rename to feature/groups/src/main/java/com/mifos/feature/groups/create_new_group/CreateNewGroupScreen.kt index d4d648ef72a..c788bc999d7 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupScreen.kt +++ b/feature/groups/src/main/java/com/mifos/feature/groups/create_new_group/CreateNewGroupScreen.kt @@ -1,7 +1,14 @@ -package com.mifos.mifosxdroid.online.createnewgroup +package com.mifos.feature.groups.create_new_group import android.content.Context import android.widget.Toast +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.expandVertically +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.shrinkVertically +import androidx.compose.animation.slideInVertically +import androidx.compose.animation.slideOutVertically import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -13,7 +20,6 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults @@ -22,10 +28,7 @@ import androidx.compose.material3.CheckboxDefaults import androidx.compose.material3.DatePicker import androidx.compose.material3.DatePickerDialog import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.OutlinedTextField -import androidx.compose.material3.OutlinedTextFieldDefaults import androidx.compose.material3.SelectableDates import androidx.compose.material3.Text import androidx.compose.material3.TextButton @@ -40,20 +43,16 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.input.ImeAction -import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.mifos.core.common.utils.Network import com.mifos.core.designsystem.component.MifosCircularProgress import com.mifos.core.designsystem.component.MifosDatePickerTextField import com.mifos.core.designsystem.component.MifosOutlinedTextField @@ -61,14 +60,10 @@ import com.mifos.core.designsystem.component.MifosSweetError import com.mifos.core.designsystem.component.MifosTextFieldDropdown import com.mifos.core.designsystem.theme.BluePrimary import com.mifos.core.designsystem.theme.BluePrimaryDark -import com.mifos.core.designsystem.theme.DarkGray -import com.mifos.core.designsystem.theme.White import com.mifos.core.objects.group.GroupPayload import com.mifos.core.objects.organisation.Office import com.mifos.core.objects.response.SaveResponse -import com.mifos.mifosxdroid.R -import com.mifos.utils.MifosResponseHandler -import com.mifos.utils.Network +import com.mifos.feature.groups.R import java.text.SimpleDateFormat import java.util.Locale @@ -93,9 +88,9 @@ fun CreateNewGroupScreen( invokeGroupCreation = { groupPayload -> viewModel.createGroup(groupPayload) }, - onGroupCreated = onGroupCreated + onGroupCreated = onGroupCreated, + getResponse = { viewModel.getResponse() } ) - } @Composable @@ -103,7 +98,8 @@ fun CreateNewGroupScreen( uiState: CreateNewGroupUiState, onRetry: () -> Unit, invokeGroupCreation: (GroupPayload) -> Unit, - onGroupCreated: (group: SaveResponse?) -> Unit + onGroupCreated: (group: SaveResponse?) -> Unit, + getResponse: () -> String ) { val context = LocalContext.current @@ -119,7 +115,7 @@ fun CreateNewGroupScreen( } is CreateNewGroupUiState.ShowGroupCreatedSuccessfully -> { - Toast.makeText(context, "Group " + MifosResponseHandler.response, Toast.LENGTH_LONG) + Toast.makeText(context, "Group " + getResponse() , Toast.LENGTH_LONG) .show() onGroupCreated.invoke(uiState.saveResponse) } @@ -164,10 +160,12 @@ fun CreateNewGroupContent( } val context = LocalContext.current + val density = LocalDensity.current val scrollState = rememberScrollState() var officeId by rememberSaveable { mutableIntStateOf(0) } var activationDate by rememberSaveable { mutableLongStateOf(System.currentTimeMillis()) } var submittedOnDate by rememberSaveable { mutableLongStateOf(System.currentTimeMillis()) } + val activateDatePickerState = rememberDatePickerState( initialSelectedDateMillis = activationDate, selectableDates = object : SelectableDates { @@ -206,7 +204,7 @@ fun CreateNewGroupContent( submitDatePicker = false activationDatePicker = false } - ) { Text(stringResource(id = R.string.select_date)) } + ) { Text(stringResource(id = R.string.feature_groups_select_date)) } }, dismissButton = { TextButton( @@ -214,7 +212,7 @@ fun CreateNewGroupContent( activationDatePicker = false submitDatePicker = false } - ) { Text(stringResource(id = R.string.cancel)) } + ) { Text(stringResource(id = R.string.feature_groups_dismiss)) } } ) { @@ -232,7 +230,7 @@ fun CreateNewGroupContent( Text( style = MaterialTheme.typography.headlineSmall, - text = stringResource(id = R.string.create_new_group), + text = stringResource(id = R.string.feature_groups_create_new_group), modifier = Modifier.padding(start = 16.dp) ) @@ -241,7 +239,7 @@ fun CreateNewGroupContent( MifosOutlinedTextField( value = groupName, onValueChange = { groupName = it }, - label = stringResource(id = R.string.name) + "*", + label = stringResource(id = R.string.feature_groups_name), error = null ) @@ -259,7 +257,7 @@ fun CreateNewGroupContent( } }, - label = R.string.office_name_mandatory, + label = R.string.feature_groups_office_name_mandatory, options = officeList.map { it.name.toString() }, readOnly = true ) @@ -270,7 +268,7 @@ fun CreateNewGroupContent( value = SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format( submittedOnDate ), - label = R.string.submit_date, + label = R.string.feature_groups_submit_date, openDatePicker = { submitDatePicker = true } @@ -281,7 +279,7 @@ fun CreateNewGroupContent( MifosOutlinedTextField( value = externalId, onValueChange = { externalId = it }, - label = stringResource(id = R.string.external_id), + label = stringResource(id = R.string.feature_groups_external_id), error = null ) @@ -298,17 +296,27 @@ fun CreateNewGroupContent( checked = isActive, onCheckedChange = { isActive = !isActive } ) - Text(text = stringResource(id = R.string.active)) + Text(text = stringResource(id = R.string.feature_groups_active)) } - if (isActive) { + AnimatedVisibility( + visible = isActive, + enter = slideInVertically { + with(density) { -40.dp.roundToPx() } + } + expandVertically( + expandFrom = Alignment.Top + ) + fadeIn( + initialAlpha = 0.3f + ), + exit = slideOutVertically() + shrinkVertically() + fadeOut() + ) { Spacer(modifier = Modifier.height(16.dp)) MifosDatePickerTextField( value = SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format( activationDate ), - label = R.string.activation_date, + label = R.string.feature_groups_activation_date, openDatePicker = { activationDatePicker = true } @@ -357,13 +365,13 @@ fun CreateNewGroupContent( } else { Toast.makeText( context, - context.resources.getString(R.string.error_not_connected_internet), + context.resources.getString(R.string.feature_groups_error_not_connected_internet), Toast.LENGTH_SHORT ).show() } } }) { - Text(text = stringResource(id = R.string.submit)) + Text(text = stringResource(id = R.string.feature_groups_submit)) } } } @@ -373,7 +381,7 @@ fun validateFields(groupName: String, officeName: String, context: Context): Boo groupName.isEmpty() -> { Toast.makeText( context, - context.resources.getString(R.string.error_group_name_cannot_be_empty), + context.resources.getString(R.string.feature_groups_error_group_name_cannot_be_empty), Toast.LENGTH_SHORT ).show() return false @@ -382,7 +390,7 @@ fun validateFields(groupName: String, officeName: String, context: Context): Boo groupName.trim().length < 4 -> { Toast.makeText( context, - context.resources.getString(R.string.error_group_name_must_be_at_least_four_characters_long), + context.resources.getString(R.string.feature_groups_error_group_name_must_be_at_least_four_characters_long), Toast.LENGTH_SHORT ).show() return false @@ -391,7 +399,7 @@ fun validateFields(groupName: String, officeName: String, context: Context): Boo groupName.contains("[^a-zA-Z ]".toRegex()) -> { Toast.makeText( context, - context.resources.getString(R.string.error_group_name_should_contain_only_alphabets), + context.resources.getString(R.string.feature_groups_error_group_name_should_contain_only_alphabets), Toast.LENGTH_SHORT ).show() return false @@ -400,7 +408,7 @@ fun validateFields(groupName: String, officeName: String, context: Context): Boo officeName.isEmpty() -> { Toast.makeText( context, - context.resources.getString(R.string.error_office_not_selected), + context.resources.getString(R.string.feature_groups_error_office_not_selected), Toast.LENGTH_SHORT ).show() return false @@ -431,6 +439,7 @@ fun PreviewCreateNewGroupScreen( invokeGroupCreation = {}, onGroupCreated = { _ -> - } + }, + getResponse = { "" } ) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupUiState.kt b/feature/groups/src/main/java/com/mifos/feature/groups/create_new_group/CreateNewGroupUiState.kt similarity index 90% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupUiState.kt rename to feature/groups/src/main/java/com/mifos/feature/groups/create_new_group/CreateNewGroupUiState.kt index 88217449184..1725c952593 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupUiState.kt +++ b/feature/groups/src/main/java/com/mifos/feature/groups/create_new_group/CreateNewGroupUiState.kt @@ -1,4 +1,4 @@ -package com.mifos.mifosxdroid.online.createnewgroup +package com.mifos.feature.groups.create_new_group import com.mifos.core.objects.organisation.Office import com.mifos.core.objects.response.SaveResponse diff --git a/feature/groups/src/main/java/com/mifos/feature/groups/create_new_group/CreateNewGroupViewModel.kt b/feature/groups/src/main/java/com/mifos/feature/groups/create_new_group/CreateNewGroupViewModel.kt new file mode 100644 index 00000000000..36d2fc6ef1e --- /dev/null +++ b/feature/groups/src/main/java/com/mifos/feature/groups/create_new_group/CreateNewGroupViewModel.kt @@ -0,0 +1,74 @@ +package com.mifos.feature.groups.create_new_group + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.mifos.core.common.utils.Resource +import com.mifos.core.data.repository.CreateNewGroupRepository +import com.mifos.core.datastore.PrefManager +import com.mifos.core.domain.use_cases.GetGroupOfficesUseCase +import com.mifos.core.domain.use_cases.CreateNewGroupUseCase +import com.mifos.core.objects.group.GroupPayload +import com.mifos.core.objects.organisation.Office +import com.mifos.core.objects.response.SaveResponse +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch +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 getGroupOfficesUseCase: GetGroupOfficesUseCase, + private val createNewGroupUseCase: CreateNewGroupUseCase, + private val prefManager: PrefManager +) : ViewModel() { + + private val _createNewGroupUiState = MutableStateFlow( + CreateNewGroupUiState.ShowProgressbar + ) + val createNewGroupUiState: StateFlow + get() = _createNewGroupUiState + + fun getResponse() : String { + return when(prefManager.userStatus){ + false -> "created successfully" + true -> "Saved into DB Successfully" + } + } + + fun loadOffices() = viewModelScope.launch { + getGroupOfficesUseCase().collect { result -> + when (result) { + is Resource.Loading -> _createNewGroupUiState.value = + CreateNewGroupUiState.ShowProgressbar + + is Resource.Error -> _createNewGroupUiState.value = + CreateNewGroupUiState.ShowFetchingError(result.message.toString()) + + is Resource.Success -> _createNewGroupUiState.value = + CreateNewGroupUiState.ShowOffices(result.data ?: emptyList()) + } + } + } + + fun createGroup(groupPayload: GroupPayload) = viewModelScope.launch { + createNewGroupUseCase(groupPayload).collect { result -> + when (result) { + is Resource.Error -> _createNewGroupUiState.value = + CreateNewGroupUiState.ShowFetchingError(result.message.toString()) + + is Resource.Loading -> _createNewGroupUiState.value = + CreateNewGroupUiState.ShowProgressbar + + is Resource.Success -> _createNewGroupUiState.value = + result.data?.let { CreateNewGroupUiState.ShowGroupCreatedSuccessfully(it) }!! + } + } + } +} \ No newline at end of file diff --git a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsScreen.kt b/feature/groups/src/main/java/com/mifos/feature/groups/group_details/GroupDetailsScreen.kt similarity index 99% rename from feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsScreen.kt rename to feature/groups/src/main/java/com/mifos/feature/groups/group_details/GroupDetailsScreen.kt index 51240e995f9..6b0c8afa761 100644 --- a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsScreen.kt +++ b/feature/groups/src/main/java/com/mifos/feature/groups/group_details/GroupDetailsScreen.kt @@ -1,4 +1,4 @@ -package com.mifos.feature.groupsList.group_details +package com.mifos.feature.groups.group_details import androidx.compose.animation.animateContentSize import androidx.compose.animation.core.LinearOutSlowInEasing diff --git a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsUiState.kt b/feature/groups/src/main/java/com/mifos/feature/groups/group_details/GroupDetailsUiState.kt similarity index 85% rename from feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsUiState.kt rename to feature/groups/src/main/java/com/mifos/feature/groups/group_details/GroupDetailsUiState.kt index 5eada9f25df..843a9284ad6 100644 --- a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsUiState.kt +++ b/feature/groups/src/main/java/com/mifos/feature/groups/group_details/GroupDetailsUiState.kt @@ -1,4 +1,4 @@ -package com.mifos.feature.groupsList.group_details +package com.mifos.feature.groups.group_details import com.mifos.core.objects.group.Group diff --git a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsViewModel.kt b/feature/groups/src/main/java/com/mifos/feature/groups/group_details/GroupDetailsViewModel.kt similarity index 98% rename from feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsViewModel.kt rename to feature/groups/src/main/java/com/mifos/feature/groups/group_details/GroupDetailsViewModel.kt index 302ccb7cc0f..7e10eafd47f 100644 --- a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsViewModel.kt +++ b/feature/groups/src/main/java/com/mifos/feature/groups/group_details/GroupDetailsViewModel.kt @@ -1,4 +1,4 @@ -package com.mifos.feature.groupsList.group_details +package com.mifos.feature.groups.group_details import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope diff --git a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_list/GroupsListScreen.kt b/feature/groups/src/main/java/com/mifos/feature/groups/group_list/GroupsListScreen.kt similarity index 99% rename from feature/groups/src/main/java/com/mifos/feature/groupsList/group_list/GroupsListScreen.kt rename to feature/groups/src/main/java/com/mifos/feature/groups/group_list/GroupsListScreen.kt index e2a0b6fee1e..bad3b934103 100644 --- a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_list/GroupsListScreen.kt +++ b/feature/groups/src/main/java/com/mifos/feature/groups/group_list/GroupsListScreen.kt @@ -1,4 +1,4 @@ -package com.mifos.feature.groupsList.group_list +package com.mifos.feature.groups.group_list import androidx.activity.compose.BackHandler import androidx.compose.animation.AnimatedVisibility @@ -22,7 +22,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.DoneAll -import androidx.compose.material.icons.rounded.Sync import androidx.compose.material3.CardDefaults import androidx.compose.material3.FabPosition import androidx.compose.material3.FilledTonalButton diff --git a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_list/GroupsListViewModel.kt b/feature/groups/src/main/java/com/mifos/feature/groups/group_list/GroupsListViewModel.kt similarity index 94% rename from feature/groups/src/main/java/com/mifos/feature/groupsList/group_list/GroupsListViewModel.kt rename to feature/groups/src/main/java/com/mifos/feature/groups/group_list/GroupsListViewModel.kt index 3c852c3253e..55677c8d175 100644 --- a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_list/GroupsListViewModel.kt +++ b/feature/groups/src/main/java/com/mifos/feature/groups/group_list/GroupsListViewModel.kt @@ -1,4 +1,4 @@ -package com.mifos.feature.groupsList.group_list +package com.mifos.feature.groups.group_list import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsScreen.kt b/feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads/SyncGroupPayloadsScreenRoute.kt similarity index 77% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsScreen.kt rename to feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads/SyncGroupPayloadsScreenRoute.kt index ebbb40caf42..a06eb530a43 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsScreen.kt +++ b/feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads/SyncGroupPayloadsScreenRoute.kt @@ -1,4 +1,4 @@ -package com.mifos.mifosxdroid.offline.syncgrouppayloads +package com.mifos.feature.groups.sync_group_payloads import android.content.Context import android.widget.Toast @@ -9,17 +9,16 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items -import androidx.compose.material.ExperimentalMaterialApi -import androidx.compose.material.pullrefresh.PullRefreshIndicator -import androidx.compose.material.pullrefresh.pullRefresh -import androidx.compose.material.pullrefresh.rememberPullRefreshState import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text +import androidx.compose.material3.pulltorefresh.PullToRefreshContainer +import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -27,6 +26,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource @@ -35,14 +35,13 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.mifos.core.common.utils.Network import com.mifos.core.designsystem.component.MifosCircularProgress import com.mifos.core.designsystem.component.MifosErrorContent import com.mifos.core.designsystem.component.MifosScaffold import com.mifos.core.designsystem.icon.MifosIcons import com.mifos.core.objects.group.GroupPayload -import com.mifos.mifosxdroid.R -import com.mifos.utils.Network -import com.mifos.utils.PrefManager.userStatus +import com.mifos.feature.groups.R @Composable fun SyncGroupPayloadsScreenRoute( @@ -67,11 +66,12 @@ fun SyncGroupPayloadsScreenRoute( }, syncGroupPayloads = { viewModel.syncGroupPayloadFromStart() - } + }, + userStatus = viewModel.getUserStatus() ) } -@OptIn(ExperimentalMaterialApi::class) +@OptIn(ExperimentalMaterial3Api::class) @Composable fun SyncGroupPayloadsScreen( uiState: SyncGroupPayloadsUiState, @@ -79,17 +79,16 @@ fun SyncGroupPayloadsScreen( refreshState: Boolean, groupPayloadsList: List, onRefresh: () -> Unit, - syncGroupPayloads: () -> Unit + syncGroupPayloads: () -> Unit, + userStatus : Boolean ) { - val snackBarHostState = remember { SnackbarHostState() } val context = LocalContext.current - val pullRefreshState = - rememberPullRefreshState(refreshing = refreshState, onRefresh = onRefresh) + val pullRefreshState = rememberPullToRefreshState() MifosScaffold( icon = MifosIcons.arrowBack, - title = stringResource(id = R.string.sync_groups), + title = stringResource(id = R.string.feature_groups_sync_groups), onBackPressed = onBackPressed, actions = { IconButton(onClick = { @@ -104,7 +103,7 @@ fun SyncGroupPayloadsScreen( }) { Icon( MifosIcons.sync, - contentDescription = stringResource(id = R.string.sync_groups) + contentDescription = stringResource(id = R.string.feature_groups_sync) ) } }, @@ -113,7 +112,7 @@ fun SyncGroupPayloadsScreen( Box( modifier = Modifier .padding(paddingValues) - .pullRefresh(pullRefreshState) + .nestedScroll(pullRefreshState.nestedScrollConnection) ) { when (uiState) { is SyncGroupPayloadsUiState.Loading -> { @@ -124,7 +123,7 @@ fun SyncGroupPayloadsScreen( MifosErrorContent( message = stringResource(id = uiState.messageResId), onRefresh = onRefresh, - refreshButtonText = stringResource(id = R.string.click_to_refresh) + refreshButtonText = stringResource(id = R.string.feature_groups_click_to_refresh) ) } @@ -140,12 +139,28 @@ fun SyncGroupPayloadsScreen( } } } - PullRefreshIndicator( - refreshing = refreshState, + + PullToRefreshContainer( state = pullRefreshState, modifier = Modifier.align(Alignment.TopCenter) ) } + + LaunchedEffect(key1 = refreshState) { + if (refreshState) + pullRefreshState.startRefresh() + } + + LaunchedEffect(key1 = pullRefreshState.isRefreshing) { + if (pullRefreshState.isRefreshing) { + if (Network.isOnline(context)) { + onRefresh() + } else { + Toast.makeText(context, context.resources.getText(R.string.feature_groups_error_not_connected_internet), Toast.LENGTH_SHORT,).show() + } + pullRefreshState.endRefresh() + } + } } } @@ -173,21 +188,21 @@ fun GroupPayloadItem(payload: GroupPayload) { false.toString() } - GroupPayloadField(stringResource(id = R.string.name), payload.name ?: "") - GroupPayloadField(stringResource(id = R.string.external_id), payload.externalId ?: "") + GroupPayloadField(stringResource(id = R.string.feature_groups_name), payload.name ?: "") + GroupPayloadField(stringResource(id = R.string.feature_groups_external_id), payload.externalId ?: "") GroupPayloadField( - stringResource(id = R.string.office_id), + stringResource(id = R.string.feature_groups_office_id), payload.officeId.toString() ?: "" ) GroupPayloadField( - stringResource(id = R.string.submit_date), + stringResource(id = R.string.feature_groups_submit_date), payload.submittedOnDate ?: "" ) GroupPayloadField( - stringResource(id = R.string.activation_date), + stringResource(id = R.string.feature_groups_activation_date), payload.activationDate ?: "" ) - GroupPayloadField(stringResource(id = R.string.active), status) + GroupPayloadField(stringResource(id = R.string.feature_groups_active), status) if (payload.errorMessage != null) { Text( @@ -231,7 +246,7 @@ fun checkNetworkConnectionAndSync( } else { Toast.makeText( context, - context.getString(R.string.error_not_connected_internet), + context.getString(R.string.feature_groups_error_not_connected_internet), Toast.LENGTH_SHORT ).show() } @@ -247,6 +262,7 @@ fun SyncGroupPayloadsScreenPreview() { onBackPressed = { }, refreshState = false, syncGroupPayloads = { }, - groupPayloadsList = dummyGroupPayloads + groupPayloadsList = dummyGroupPayloads, + userStatus = true ) } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsUiState.kt b/feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads/SyncGroupPayloadsUiState.kt similarity index 79% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsUiState.kt rename to feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads/SyncGroupPayloadsUiState.kt index 5215d604f21..bab5094787d 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsUiState.kt +++ b/feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads/SyncGroupPayloadsUiState.kt @@ -1,7 +1,8 @@ -package com.mifos.mifosxdroid.offline.syncgrouppayloads +package com.mifos.feature.groups.sync_group_payloads import com.mifos.core.objects.group.GroupPayload -import com.mifos.mifosxdroid.R +import com.mifos.feature.groups.R + /** * Created by Aditya Gupta on 16/08/23. @@ -17,12 +18,12 @@ enum class GroupPayloadEmptyState( val iconResId: Int ) { ALL_SYNCED( - messageResId = R.string.all_groups_synced, - iconResId = R.drawable.ic_assignment_turned_in_black_24dp + messageResId = R.string.feature_groups_all_groups_synced, + iconResId = R.drawable.feature_groups_ic_assignment_turned_in_black_24dp ), NOTHING_TO_SYNC ( - messageResId = R.string.no_group_payload_to_sync, - iconResId = R.drawable.ic_assignment_turned_in_black_24dp + messageResId = R.string.feature_groups_no_group_payload_to_sync, + iconResId = R.drawable.feature_groups_ic_assignment_turned_in_black_24dp ) } diff --git a/feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads/SyncGroupPayloadsViewModel.kt b/feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads/SyncGroupPayloadsViewModel.kt new file mode 100644 index 00000000000..5649812c520 --- /dev/null +++ b/feature/groups/src/main/java/com/mifos/feature/groups/sync_group_payloads/SyncGroupPayloadsViewModel.kt @@ -0,0 +1,162 @@ +package com.mifos.feature.groups.sync_group_payloads + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.mifos.core.common.utils.Resource +import com.mifos.core.data.repository.SyncGroupPayloadsRepository +import com.mifos.core.datastore.PrefManager +import com.mifos.core.domain.use_cases.AllDatabaseGroupPayloadUseCase +import com.mifos.core.domain.use_cases.CreateGroupUseCase +import com.mifos.core.domain.use_cases.DeleteAndUpdateGroupPayloadUseCase +import com.mifos.core.domain.use_cases.UpdateGroupPayloadUseCase +import com.mifos.core.objects.group.GroupPayload +import com.mifos.core.objects.response.SaveResponse +import com.mifos.feature.groups.R +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch +import rx.Subscriber +import rx.android.schedulers.AndroidSchedulers +import rx.schedulers.Schedulers +import javax.inject.Inject + +/** + * Created by Aditya Gupta on 16/08/23. + */ +@HiltViewModel +class SyncGroupPayloadsViewModel @Inject constructor( + private val allDatabaseGroupPayloadUseCase: AllDatabaseGroupPayloadUseCase, + private val createGroupUseCase: CreateGroupUseCase, + private val deleteAndUpdateGroupPayloadUseCase: DeleteAndUpdateGroupPayloadUseCase, + private val updateGroupPayloadUseCase: UpdateGroupPayloadUseCase, + private val prefManager: PrefManager +) : ViewModel() { + + val syncGroupPayloadsUiState get() = _syncGroupPayloadsUiState + private val _syncGroupPayloadsUiState = + MutableStateFlow(SyncGroupPayloadsUiState.Loading) + + val groupPayloadsList get() = _groupPayloadsList + private val _groupPayloadsList = MutableStateFlow>(listOf()) + + private val _isRefreshing = MutableStateFlow(false) + val isRefreshing: StateFlow = _isRefreshing.asStateFlow() + + private var groupPayloadSyncIndex = 0 + + /*** + * check use cases names + */ + fun refreshGroupPayload() { + _isRefreshing.value = true + loanDatabaseGroupPayload() + _isRefreshing.value = false + } + + fun getUserStatus() : Boolean { + return prefManager.userStatus + } + + fun loanDatabaseGroupPayload() = viewModelScope.launch { + allDatabaseGroupPayloadUseCase().collect { result -> + when (result) { + is Resource.Error -> _syncGroupPayloadsUiState.value = + SyncGroupPayloadsUiState.Error(R.string.feature_groups_error_failed_to_load_groupPayload) + + is Resource.Loading -> _syncGroupPayloadsUiState.value = + SyncGroupPayloadsUiState.Loading + + is Resource.Success -> { + _groupPayloadsList.value = result.data ?: emptyList() + _syncGroupPayloadsUiState.value = SyncGroupPayloadsUiState.Success( + if ((result.data + ?: emptyList()).isEmpty() + ) GroupPayloadEmptyState.NOTHING_TO_SYNC + else null + ) + } + } + } + } + + fun syncGroupPayloadFromStart() { + groupPayloadSyncIndex = 0 + syncGroupPayload() + } + + private fun syncGroupPayload() { + groupPayloadsList.value.indexOfFirst { it.errorMessage == null }.takeIf { it != -1 } + ?.let { index -> + groupPayloadSyncIndex = index + syncGroupPayload(groupPayloadsList.value[index]) + } + } + + private fun syncGroupPayload(groupPayload: GroupPayload?) = viewModelScope.launch { + createGroupUseCase(groupPayload!!).collect { result -> + when (result) { + is Resource.Error -> { + _syncGroupPayloadsUiState.value = + SyncGroupPayloadsUiState.Error(R.string.feature_groups_error_group_sync_failed) + updateGroupPayload() + } + + is Resource.Loading -> _syncGroupPayloadsUiState.value = + SyncGroupPayloadsUiState.Loading + + is Resource.Success -> deleteAndUpdateGroupPayload() + } + } + } + + private fun deleteAndUpdateGroupPayload() = viewModelScope.launch { + val id = groupPayloadsList.value[groupPayloadSyncIndex].id + + deleteAndUpdateGroupPayloadUseCase(id).collect { result -> + when (result) { + is Resource.Error -> _syncGroupPayloadsUiState.value = + SyncGroupPayloadsUiState.Error(R.string.feature_groups_error_failed_to_update_list) + + is Resource.Loading -> Unit + + is Resource.Success -> { + groupPayloadSyncIndex = 0 + _groupPayloadsList.value = result.data ?: emptyList() + _syncGroupPayloadsUiState.value = SyncGroupPayloadsUiState.Success( + if ((result.data ?: emptyList()).isEmpty() + ) GroupPayloadEmptyState.ALL_SYNCED + else null + ) + } + } + } + } + + private fun updateGroupPayload() = viewModelScope.launch { + val groupPayload = groupPayloadsList.value[groupPayloadSyncIndex] + + updateGroupPayloadUseCase(groupPayload).collect { result -> + when (result) { + is Resource.Error -> _syncGroupPayloadsUiState.value = + SyncGroupPayloadsUiState.Error(R.string.feature_groups_error_failed_to_load_groupPayload) + + is Resource.Loading -> _syncGroupPayloadsUiState.value = + SyncGroupPayloadsUiState.Loading + + is Resource.Success -> { + _syncGroupPayloadsUiState.value = + SyncGroupPayloadsUiState.Success() + val payloadList = groupPayloadsList.value.toMutableList() + payloadList[groupPayloadSyncIndex] = groupPayload + groupPayloadsList.value = payloadList + groupPayloadSyncIndex += 1 + if (groupPayloadsList.value.size != groupPayloadSyncIndex) { + syncGroupPayload() + } + } + } + } + } +} \ No newline at end of file diff --git a/feature/groups/src/main/res/drawable/feature_groups_ic_assignment_turned_in_black_24dp.xml b/feature/groups/src/main/res/drawable/feature_groups_ic_assignment_turned_in_black_24dp.xml new file mode 100644 index 00000000000..b591ed5ee54 --- /dev/null +++ b/feature/groups/src/main/res/drawable/feature_groups_ic_assignment_turned_in_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/feature/groups/src/main/res/values/strings.xml b/feature/groups/src/main/res/values/strings.xml index 33456f14883..2bf22e26e75 100644 --- a/feature/groups/src/main/res/values/strings.xml +++ b/feature/groups/src/main/res/values/strings.xml @@ -5,7 +5,6 @@ Failed to load Database Groups Failed to Fetch Groups No more Groups Available - Group Add Loan Account Add Savings Account Documents @@ -24,5 +23,26 @@ Failed to Load Client Activate Group Sync - - \ No newline at end of file + Group + Name + Not connected to Network + Office* + Submit Date + Submit + All Groups have been Synced + There is No Group Payload to Sync + Active + Group name can not be empty + Group name must be at least 4 characters long + Group name should contain only alphabets + Office not selected + Select Date + Groups + Dismiss + Create New Group + Click to Refresh + Office Id + Group sync failed + Failed to load GroupPayload + Failed to Update List + diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/syncgroupsdialog/SyncGroupDialogScreen.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/syncgroupsdialog/SyncGroupDialogScreen.kt index 2beec4d6581..efeea09e544 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/syncgroupsdialog/SyncGroupDialogScreen.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/syncgroupsdialog/SyncGroupDialogScreen.kt @@ -26,8 +26,8 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.mifos.core.designsystem.component.MifosCircularProgress +import com.mifos.feature.groups.sync_group_payloads.GroupPayloadField import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.offline.syncgrouppayloads.GroupPayloadField @Composable fun SyncGroupDialogScreen( 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 8b879cf4dec..f6678b1b5c4 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 @@ -34,8 +34,8 @@ import com.mifos.mifosxdroid.offline.synccenterpayloads.SyncCenterPayloadsReposi import com.mifos.mifosxdroid.offline.synccenterpayloads.SyncCenterPayloadsRepositoryImp import com.mifos.mifosxdroid.offline.syncclientpayloads.SyncClientPayloadsRepository import com.mifos.mifosxdroid.offline.syncclientpayloads.SyncClientPayloadsRepositoryImp -import com.mifos.mifosxdroid.offline.syncgrouppayloads.SyncGroupPayloadsRepository -import com.mifos.mifosxdroid.offline.syncgrouppayloads.SyncGroupPayloadsRepositoryImp +import com.mifos.core.data.repository.SyncGroupPayloadsRepository +import com.mifos.core.data.repository_imp.SyncGroupPayloadsRepositoryImp import com.mifos.mifosxdroid.offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionRepository import com.mifos.mifosxdroid.offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionRepositoryImp import com.mifos.mifosxdroid.offline.syncsavingsaccounttransaction.SyncSavingsAccountTransactionRepository @@ -54,8 +54,6 @@ import com.mifos.mifosxdroid.online.collectionsheet.CollectionSheetRepository import com.mifos.mifosxdroid.online.collectionsheet.CollectionSheetRepositoryImp import com.mifos.mifosxdroid.online.createnewclient.CreateNewClientRepository import com.mifos.mifosxdroid.online.createnewclient.CreateNewClientRepositoryImp -import com.mifos.mifosxdroid.online.createnewgroup.CreateNewGroupRepository -import com.mifos.mifosxdroid.online.createnewgroup.CreateNewGroupRepositoryImp import com.mifos.mifosxdroid.online.datatable.DataTableRepository import com.mifos.mifosxdroid.online.datatable.DataTableRepositoryImp import com.mifos.mifosxdroid.online.datatablelistfragment.DataTableListRepository @@ -207,12 +205,6 @@ class RepositoryModule { return CreateNewClientRepositoryImp(dataManagerClient, dataManagerOffices, dataManagerStaff) } - @Provides - fun providesCreateNewGroupRepository( - dataManagerOffices: DataManagerOffices, dataManagerGroups: DataManagerGroups - ): CreateNewGroupRepository { - return CreateNewGroupRepositoryImp(dataManagerOffices, dataManagerGroups) - } @Provides fun providesDataTableListRepository( diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsFragment.kt index 8043f16c582..cc3381a4dc7 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsFragment.kt @@ -7,6 +7,7 @@ import android.view.ViewGroup import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.navigation.findNavController +import com.mifos.feature.groups.sync_group_payloads.SyncGroupPayloadsScreenRoute import com.mifos.mifosxdroid.core.MifosBaseFragment import dagger.hilt.android.AndroidEntryPoint diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsViewModel.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsViewModel.kt deleted file mode 100644 index 23279396148..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncgrouppayloads/SyncGroupPayloadsViewModel.kt +++ /dev/null @@ -1,147 +0,0 @@ -package com.mifos.mifosxdroid.offline.syncgrouppayloads - -import androidx.lifecycle.ViewModel -import com.mifos.core.objects.group.GroupPayload -import com.mifos.core.objects.response.SaveResponse -import com.mifos.mifosxdroid.R -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 16/08/23. - */ -@HiltViewModel -class SyncGroupPayloadsViewModel @Inject constructor(private val repository: SyncGroupPayloadsRepository) : - ViewModel() { - - val syncGroupPayloadsUiState get() = _syncGroupPayloadsUiState - private val _syncGroupPayloadsUiState = - MutableStateFlow(SyncGroupPayloadsUiState.Loading) - - val groupPayloadsList get() = _groupPayloadsList - private val _groupPayloadsList = MutableStateFlow>(listOf()) - - private val _isRefreshing = MutableStateFlow(false) - val isRefreshing: StateFlow = _isRefreshing.asStateFlow() - - private var groupPayloadSyncIndex = 0 - - fun refreshGroupPayload() { - _isRefreshing.value = true - loanDatabaseGroupPayload() - _isRefreshing.value = false - } - - fun loanDatabaseGroupPayload() { - _syncGroupPayloadsUiState.value = SyncGroupPayloadsUiState.Loading - repository.allDatabaseGroupPayload() - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - _syncGroupPayloadsUiState.value = - SyncGroupPayloadsUiState.Error(R.string.failed_to_load_grouppayload) - } - - override fun onNext(groupPayloads: List) { - _groupPayloadsList.value = groupPayloads - _syncGroupPayloadsUiState.value = SyncGroupPayloadsUiState.Success( - if (groupPayloads.isEmpty()) GroupPayloadEmptyState.NOTHING_TO_SYNC - else null - ) - } - }) - - } - - fun syncGroupPayloadFromStart() { - groupPayloadSyncIndex = 0 - syncGroupPayload() - } - - fun syncGroupPayload() { - groupPayloadsList.value.indexOfFirst { it.errorMessage == null }.takeIf { it != -1 } - ?.let { index -> - groupPayloadSyncIndex = index - syncGroupPayload(groupPayloadsList.value[index]) - } - } - - private fun syncGroupPayload(groupPayload: GroupPayload?) { - _syncGroupPayloadsUiState.value = SyncGroupPayloadsUiState.Loading - repository.createGroup(groupPayload!!) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - _syncGroupPayloadsUiState.value = - SyncGroupPayloadsUiState.Error(R.string.group_sync_failed) - updateGroupPayload() - } - - override fun onNext(group: SaveResponse) { - deleteAndUpdateGroupPayload() - } - }) - } - - fun deleteAndUpdateGroupPayload() { - val id = groupPayloadsList.value[groupPayloadSyncIndex].id - repository.deleteAndUpdateGroupPayloads(id) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - _syncGroupPayloadsUiState.value = - SyncGroupPayloadsUiState.Error(R.string.failed_to_update_list) - } - - override fun onNext(groupPayloads: List) { - groupPayloadSyncIndex = 0 - _groupPayloadsList.value = groupPayloads - _syncGroupPayloadsUiState.value = SyncGroupPayloadsUiState.Success( - if (groupPayloads.isEmpty()) GroupPayloadEmptyState.ALL_SYNCED - else null - ) - } - }) - - } - - fun updateGroupPayload() { - val groupPayload = groupPayloadsList.value[groupPayloadSyncIndex] - _syncGroupPayloadsUiState.value = SyncGroupPayloadsUiState.Loading - repository.updateGroupPayload(groupPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - _syncGroupPayloadsUiState.value = - SyncGroupPayloadsUiState.Error(R.string.failed_to_load_grouppayload) - } - - override fun onNext(groupPayload: GroupPayload) { - _syncGroupPayloadsUiState.value = - SyncGroupPayloadsUiState.Success() - var payloadList = groupPayloadsList.value.toMutableList() - payloadList[groupPayloadSyncIndex] = groupPayload - groupPayloadsList.value = payloadList - groupPayloadSyncIndex += 1 - if (groupPayloadsList.value.size != groupPayloadSyncIndex) { - syncGroupPayload() - } - } - }) - - } -} \ 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 03531228f30..9b8af02cb4a 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 @@ -10,6 +10,7 @@ import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy import com.mifos.core.common.utils.Constants import com.mifos.core.objects.response.SaveResponse +import com.mifos.feature.groups.create_new_group.CreateNewGroupScreen import com.mifos.mifosxdroid.core.MifosBaseFragment import com.mifos.mifosxdroid.online.GroupsActivity import com.mifos.utils.PrefManager diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupViewModel.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupViewModel.kt deleted file mode 100644 index ca8da2df4f8..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupViewModel.kt +++ /dev/null @@ -1,70 +0,0 @@ -package com.mifos.mifosxdroid.online.createnewgroup - -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import com.mifos.core.objects.group.GroupPayload -import com.mifos.core.objects.organisation.Office -import com.mifos.core.objects.response.SaveResponse -import com.mifos.mifosxdroid.online.createnewclient.CreateNewClientUiState -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -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 = MutableStateFlow(CreateNewGroupUiState.ShowProgressbar) - val createNewGroupUiState: StateFlow - 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/mifosxdroid/online/groupdetails/GroupDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupdetails/GroupDetailsFragment.kt index c17b65bdc34..5c7df2726b5 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupdetails/GroupDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupdetails/GroupDetailsFragment.kt @@ -12,7 +12,7 @@ import com.mifos.core.common.utils.Constants import com.mifos.core.objects.accounts.savings.DepositType import com.mifos.core.objects.client.Client import com.mifos.core.objects.navigation.ClientListArgs -import com.mifos.feature.groupsList.group_details.GroupDetailsScreen +import com.mifos.feature.groups.group_details.GroupDetailsScreen import com.mifos.mifosxdroid.core.MifosBaseFragment import dagger.hilt.android.AndroidEntryPoint diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt index 371c8bf5860..e6e2a075713 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt @@ -11,7 +11,7 @@ import android.view.ViewGroup import androidx.compose.ui.platform.ComposeView import androidx.navigation.findNavController import com.mifos.core.common.utils.Constants -import com.mifos.feature.groupsList.group_list.GroupsListRoute +import com.mifos.feature.groups.group_list.GroupsListRoute import com.mifos.mifosxdroid.R import com.mifos.mifosxdroid.activity.home.HomeActivity import com.mifos.mifosxdroid.core.MifosBaseFragment 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 10047c98943..c29888702fc 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 @@ -8,32 +8,12 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.AdapterView.OnItemSelectedListener -import android.widget.ArrayAdapter -import android.widget.Toast import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.fragment.app.DialogFragment import androidx.fragment.app.viewModels -import androidx.lifecycle.ViewModelProvider import androidx.navigation.findNavController import androidx.navigation.fragment.navArgs -import com.mifos.core.network.GenericResponse -import com.mifos.core.objects.accounts.loan.LoanDisbursement -import com.mifos.core.objects.templates.loans.LoanTransactionTemplate -import com.mifos.exceptions.RequiredFieldException -import com.mifos.mifosxdroid.R import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.core.util.Toaster -import com.mifos.mifosxdroid.databinding.DialogFragmentDisburseLoanBinding -import com.mifos.mifosxdroid.online.createnewgroup.CreateNewGroupScreen -import com.mifos.mifosxdroid.online.loanrepaymentschedule.LoanRepaymentScheduleViewModel -import com.mifos.mifosxdroid.uihelpers.MFDatePicker -import com.mifos.mifosxdroid.uihelpers.MFDatePicker.OnDatePickListener -import com.mifos.utils.DateHelper -import com.mifos.utils.FragmentConstants -import com.mifos.utils.Network import dagger.hilt.android.AndroidEntryPoint /** diff --git a/mifosng-android/src/main/java/com/mifos/utils/PrefManager.kt b/mifosng-android/src/main/java/com/mifos/utils/PrefManager.kt index ba46b522bf2..c573d8edb2f 100644 --- a/mifosng-android/src/main/java/com/mifos/utils/PrefManager.kt +++ b/mifosng-android/src/main/java/com/mifos/utils/PrefManager.kt @@ -18,8 +18,7 @@ object PrefManager : UserPreferences() { private const val AUTH_USERNAME = "auth_username" private const val AUTH_PASSWORD = "auth_password" - override val preference: SharedPreferences = - PreferenceManager.getDefaultSharedPreferences(App.instance?.applicationContext) + override val preference: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(App.instance?.applicationContext) override fun getUser(): User { return get(Key.Custom(USER_DETAILS)) diff --git a/mifosng-android/src/main/res/layout/checker_inbox_tasks_fragment.xml b/mifosng-android/src/main/res/layout/checker_inbox_tasks_fragment.xml index b8ed18779d6..567acf22e1c 100644 --- a/mifosng-android/src/main/res/layout/checker_inbox_tasks_fragment.xml +++ b/mifosng-android/src/main/res/layout/checker_inbox_tasks_fragment.xml @@ -110,7 +110,7 @@ android:layout_height="@dimen/dimension_32_dp" android:layout_centerVertical="true" android:scaleType="centerInside" - app:srcCompat="@drawable/ic_assignment_turned_in_black_24dp" /> + app:srcCompat="@drawable/feature_groups_ic_assignment_turned_in_black_24dp" />