Skip to content

Commit

Permalink
move syncGroupDialog to module
Browse files Browse the repository at this point in the history
  • Loading branch information
itsPronay committed Aug 8, 2024
1 parent 787df6d commit 35f1d5c
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.dialogfragments.syncgroupsdialog
package com.mifos.core.data.repository

import com.mifos.core.objects.accounts.ClientAccounts
import com.mifos.core.objects.accounts.GroupAccounts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mifos.mifosxdroid.dialogfragments.syncgroupsdialog
package com.mifos.core.data.repository_imp

import com.mifos.core.data.repository.SyncGroupsDialogRepository
import com.mifos.core.network.datamanager.DataManagerClient
import com.mifos.core.network.datamanager.DataManagerGroups
import com.mifos.core.network.datamanager.DataManagerLoan
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.dialogfragments.syncgroupsdialog
package com.mifos.feature.groups.sync_group_dialog


import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -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.R
import com.mifos.feature.groups.sync_group_payloads.GroupPayloadField
import com.mifos.mifosxdroid.R

@Composable
fun SyncGroupDialogScreen(
Expand Down Expand Up @@ -75,7 +75,7 @@ fun SyncGroupDialogScreen(
is SyncGroupsDialogUiState.Error -> {
val message = uiState.message
?: uiState.messageResId?.let { stringResource(uiState.messageResId) }
?: stringResource(id = R.string.something_went_wrong)
?: stringResource(id = R.string.feature_groups_something_went_wrong)
LaunchedEffect(key1 = message) {
snackBarHostState.showSnackbar(message = message)
}
Expand All @@ -101,25 +101,25 @@ fun SyncGroupDialogContent(
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
text = stringResource(id = R.string.sync_groups_full_information)
text = stringResource(id = R.string.feature_groups_sync_groups_full_information)
)

GroupPayloadField(
label = stringResource(id = R.string.name),
label = stringResource(id = R.string.feature_groups_name),
value = uiData.groupName,
)

Spacer(modifier = Modifier.height(12.dp))

GroupPayloadField(
label = stringResource(id = R.string.total),
value = uiData.groupList.size.toString() + stringResource(R.string.space) + stringResource(R.string.feature_groups_groups),
label = stringResource(id = R.string.feature_groups_total),
value = uiData.groupList.size.toString() + stringResource(R.string.feature_groups_space) + stringResource(R.string.feature_groups_groups),
)

Spacer(modifier = Modifier.height(12.dp))

GroupPayloadField(
label = stringResource(id = R.string.syncing_group),
label = stringResource(id = R.string.feature_groups_syncing_group),
value = uiData.groupName,
)

Expand All @@ -130,7 +130,7 @@ fun SyncGroupDialogContent(
Spacer(modifier = Modifier.height(12.dp))

GroupPayloadField(
label = stringResource(id = R.string.syncing_client),
label = stringResource(id = R.string.feature_groups_syncing_client),
value = "syncing_client",
)

Expand All @@ -141,8 +141,8 @@ fun SyncGroupDialogContent(
Spacer(modifier = Modifier.height(12.dp))

GroupPayloadField(
label = stringResource(id = R.string.total_sync_progress),
value = stringResource(R.string.space) + uiData.totalSyncCount + stringResource(id = R.string.slash) + uiData.groupList.size,
label = stringResource(id = R.string.feature_groups_total_sync_progress),
value = stringResource(R.string.feature_groups_space) + uiData.totalSyncCount + stringResource(id = R.string.feature_groups_slash) + uiData.groupList.size,
)

LinearProgressIndicator(
Expand All @@ -152,7 +152,7 @@ fun SyncGroupDialogContent(
Spacer(modifier = Modifier.height(12.dp))

GroupPayloadField(
label = stringResource(id = R.string.failed_sync),
label = stringResource(id = R.string.feature_groups_failed_sync),
value = uiData.failedSyncGroupCount.toString(),
)

Expand All @@ -166,14 +166,14 @@ fun SyncGroupDialogContent(
onClick = { okClicked() },
modifier = Modifier.weight(1f)
) {
Text(text = stringResource(id = R.string.dialog_action_ok))
Text(text = stringResource(id = R.string.feature_groups_dialog_action_ok))
}
} else {
FilledTonalButton(
onClick = { cancelClicked() },
modifier = Modifier.weight(1f)
) {
Text(text = stringResource(id = R.string.cancel))
Text(text = stringResource(id = R.string.feature_groups_cancel))
}

Spacer(modifier = Modifier.width(10.dp))
Expand All @@ -182,7 +182,7 @@ fun SyncGroupDialogContent(
onClick = { hideClicked() },
modifier = Modifier.weight(1f)
) {
Text(text = stringResource(id = R.string.hide))
Text(text = stringResource(id = R.string.feature_groups_hide))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.dialogfragments.syncgroupsdialog
package com.mifos.feature.groups.sync_group_dialog

import androidx.compose.ui.graphics.vector.ImageVector
import com.mifos.core.objects.group.Group
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.mifos.mifosxdroid.dialogfragments.syncgroupsdialog
package com.mifos.feature.groups.sync_group_dialog

import androidx.lifecycle.ViewModel
import com.mifos.core.common.utils.Constants
import com.mifos.core.common.utils.NetworkUtilsWrapper
import com.mifos.core.data.repository.SyncGroupsDialogRepository
import com.mifos.core.datastore.PrefManager
import com.mifos.core.designsystem.icon.MifosIcons
import com.mifos.core.objects.accounts.ClientAccounts
import com.mifos.core.objects.accounts.GroupAccounts
Expand All @@ -11,11 +15,7 @@ import com.mifos.core.objects.group.Group
import com.mifos.core.objects.group.GroupWithAssociations
import com.mifos.core.objects.zipmodels.LoanAndLoanRepayment
import com.mifos.core.objects.zipmodels.SavingsAccountAndTransactionTemplate
import com.mifos.mifosxdroid.R
import com.mifos.utils.Constants
import com.mifos.utils.NetworkUtilsWrapper
import com.mifos.utils.PrefManager
import com.mifos.utils.Utils
import com.mifos.feature.groups.R
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -34,7 +34,8 @@ import javax.inject.Inject
@HiltViewModel
class SyncGroupsDialogViewModel @Inject constructor(
private val repository: SyncGroupsDialogRepository,
private val networkUtilsWrapper: NetworkUtilsWrapper
private val networkUtilsWrapper: NetworkUtilsWrapper,
private val prefManager: PrefManager
) : ViewModel() {

private var mGroupList: List<Group> = ArrayList()
Expand Down Expand Up @@ -67,7 +68,7 @@ class SyncGroupsDialogViewModel @Inject constructor(
* This Method checking network connection before starting group synchronization
*/
fun syncGroups() {
if(PrefManager.userStatus == Constants.USER_ONLINE) {
if(prefManager.userStatus == Constants.USER_ONLINE) {
checkNetworkConnection {
syncGroupAndUpdateUI()
}
Expand Down Expand Up @@ -198,10 +199,10 @@ class SyncGroupsDialogViewModel @Inject constructor(
}

override fun onNext(groupAccounts: GroupAccounts) {
mLoanAccountList = Utils.getActiveLoanAccounts(
mLoanAccountList = getActiveLoanAccounts(
groupAccounts.loanAccounts
)
mSavingsAccountList = Utils.getActiveSavingsAccounts(
mSavingsAccountList = getActiveSavingsAccounts(
groupAccounts.savingsAccounts
)

Expand Down Expand Up @@ -384,11 +385,11 @@ class SyncGroupsDialogViewModel @Inject constructor(
}

override fun onNext(clientAccounts: ClientAccounts) {
mLoanAccountList = Utils.getActiveLoanAccounts(
mLoanAccountList = getActiveLoanAccounts(
clientAccounts
.loanAccounts
)
mSavingsAccountList = Utils.getSyncableSavingsAccounts(
mSavingsAccountList = getSyncableSavingsAccounts(
clientAccounts
.savingsAccounts
)
Expand Down Expand Up @@ -554,9 +555,40 @@ class SyncGroupsDialogViewModel @Inject constructor(
taskWhenOnline.invoke()
} else {
_syncGroupsDialogUiState.value = SyncGroupsDialogUiState.Error(
messageResId = R.string.error_network_not_available,
messageResId = R.string.feature_groups_error_not_connected_internet,
imageVector = MifosIcons.WifiOff
)
}
}

fun getActiveLoanAccounts(loanAccountList: List<LoanAccount>?): List<LoanAccount> {
val loanAccounts: MutableList<LoanAccount> = ArrayList()
Observable.from(loanAccountList)
.filter { loanAccount -> loanAccount.status?.active }
.subscribe { loanAccount -> loanAccounts.add(loanAccount) }
return loanAccounts
}

fun getActiveSavingsAccounts(savingsAccounts: List<SavingsAccount>?): List<SavingsAccount> {
val accounts: MutableList<SavingsAccount> = ArrayList()
Observable.from(savingsAccounts)
.filter { savingsAccount ->
savingsAccount.status?.active == true &&
!savingsAccount.depositType!!.isRecurring
}
.subscribe { savingsAccount -> accounts.add(savingsAccount) }
return accounts
}

fun getSyncableSavingsAccounts(savingsAccounts: List<SavingsAccount>?): List<SavingsAccount> {
val accounts: MutableList<SavingsAccount> = ArrayList()
Observable.from(savingsAccounts)
.filter { savingsAccount ->
savingsAccount.depositType?.value == "Savings" &&
savingsAccount.status?.active == true &&
!savingsAccount.depositType!!.isRecurring
}
.subscribe { savingsAccount -> accounts.add(savingsAccount) }
return accounts
}
}
16 changes: 16 additions & 0 deletions feature/groups/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,20 @@
<string name="feature_groups_error_group_sync_failed">Group sync failed</string>
<string name="feature_groups_error_failed_to_load_groupPayload">Failed to load GroupPayload</string>
<string name="feature_groups_error_failed_to_update_list">Failed to Update List</string>
<string name="feature_groups_something_went_wrong">Something went wrong</string>
<string name="feature_groups_sync_groups_full_information">Sync Groups All Information</string>
<string name="feature_groups_total">Total</string>
<string name="feature_groups_space" translatable="false">" "</string>
<string name="feature_groups_syncing_group">Syncing Group</string>
<string name="feature_groups_syncing_client">Syncing Client</string>
<string name="feature_groups_total_sync_progress">Total Sync Progress</string>
<string name="feature_groups_slash" translatable="false">/</string>
<string name="feature_groups_failed_sync">Sync Failed</string>
<string name="feature_groups_dialog_action_ok">OK</string>
<string name="feature_groups_cancel">Cancel</string>
<string name="feature_groups_hide">Hide</string>
<string name="feature_groups_error_network_not_available">Network is not Available</string>



</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.DialogFragment
import com.mifos.core.objects.group.Group
import com.mifos.feature.groups.sync_group_dialog.SyncGroupDialogScreen
import com.mifos.feature.groups.sync_group_dialog.SyncGroupsDialogViewModel
import com.mifos.utils.Constants
import dagger.hilt.android.AndroidEntryPoint

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import com.mifos.mifosxdroid.dialogfragments.synccenterdialog.SyncCentersDialogR
import com.mifos.mifosxdroid.dialogfragments.synccenterdialog.SyncCentersDialogRepositoryImp
import com.mifos.mifosxdroid.dialogfragments.syncclientsdialog.SyncClientsDialogRepository
import com.mifos.mifosxdroid.dialogfragments.syncclientsdialog.SyncClientsDialogRepositoryImp
import com.mifos.mifosxdroid.dialogfragments.syncgroupsdialog.SyncGroupsDialogRepository
import com.mifos.mifosxdroid.dialogfragments.syncgroupsdialog.SyncGroupsDialogRepositoryImp
import com.mifos.core.data.repository.SyncGroupsDialogRepository
import com.mifos.core.data.repository_imp.SyncGroupsDialogRepositoryImp
import com.mifos.mifosxdroid.offline.offlinedashbarod.OfflineDashboardRepository
import com.mifos.mifosxdroid.offline.offlinedashbarod.OfflineDashboardRepositoryImp
import com.mifos.mifosxdroid.offline.synccenterpayloads.SyncCenterPayloadsRepository
Expand Down

0 comments on commit 35f1d5c

Please sign in to comment.