Skip to content

Commit

Permalink
MIFOSAC-247 Moved sync_center_dialog & sync_center_payloads to module (
Browse files Browse the repository at this point in the history
  • Loading branch information
itsPronay authored Aug 8, 2024
1 parent 787df6d commit 6ea49a7
Show file tree
Hide file tree
Showing 19 changed files with 479 additions and 211 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.offline.synccenterpayloads
package com.mifos.core.data.repository

import com.mifos.core.data.CenterPayload
import com.mifos.core.objects.response.SaveResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.dialogfragments.synccenterdialog
package com.mifos.core.data.repository

import com.mifos.core.objects.accounts.CenterAccounts
import com.mifos.core.objects.accounts.ClientAccounts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mifos.mifosxdroid.offline.synccenterpayloads
package com.mifos.core.data.repository_imp

import com.mifos.core.data.CenterPayload
import com.mifos.core.data.repository.SyncCenterPayloadsRepository
import com.mifos.core.network.datamanager.DataManagerCenter
import com.mifos.core.objects.response.SaveResponse
import rx.Observable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mifos.mifosxdroid.dialogfragments.synccenterdialog
package com.mifos.core.data.repository_imp

import com.mifos.core.data.repository.SyncCentersDialogRepository
import com.mifos.core.network.datamanager.DataManagerCenter
import com.mifos.core.network.datamanager.DataManagerClient
import com.mifos.core.network.datamanager.DataManagerGroups
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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.SyncCenterPayloadsRepository
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 08/08/2024 (2:22 PM)
*/
class AllDatabaseCenterPayloadUseCase @Inject constructor(private val repository: SyncCenterPayloadsRepository) {

suspend operator fun invoke(): Flow<Resource<List<CenterPayload>>> =
callbackFlow {
try {
trySend(Resource.Loading())

repository.allDatabaseCenterPayload()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<List<CenterPayload>>() {
override fun onCompleted() {}

override fun onError(e: Throwable) {
trySend(Resource.Error(e.message.toString()))
}

override fun onNext(centerPayloads: List<CenterPayload>) {
trySend(Resource.Success(centerPayloads))
}
})

awaitClose { channel.close() }
} catch (e: Exception) {
trySend(Resource.Error(e.message.toString()))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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.SyncCenterPayloadsRepository
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 08/08/2024 (2:08 PM)
*/
class CreateCenterUseCase @Inject constructor(private val repository: SyncCenterPayloadsRepository) {

suspend operator fun invoke(centerPayload: CenterPayload): Flow<Resource<SaveResponse?>> =
callbackFlow {
try {
trySend(Resource.Loading())

repository.createCenter(centerPayload)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<SaveResponse?>() {
override fun onCompleted() {}

override fun onError(e: Throwable) {
trySend(Resource.Error(e.message.toString()))
}

override fun onNext(center: SaveResponse?) {
trySend(Resource.Success(center))
}
})

awaitClose { channel.close() }
} catch (e: Exception) {
trySend(Resource.Error(e.message.toString()))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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.SyncCenterPayloadsRepository
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 08/08/2024 (1:37 PM)
*/
class DeleteAndUpdateCenterPayloadsUseCase @Inject constructor(private val repository: SyncCenterPayloadsRepository) {

suspend operator fun invoke(id: Int): Flow<Resource<List<CenterPayload>>> =
callbackFlow {
try {
trySend(Resource.Loading())

repository.deleteAndUpdateCenterPayloads(id)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<List<CenterPayload>>() {
override fun onCompleted() {}

override fun onError(e: Throwable) {
trySend(Resource.Error(e.message.toString()))
}

override fun onNext(centerPayloads: List<CenterPayload>) {
trySend(Resource.Success(centerPayloads))
}
})

awaitClose { channel.close() }
} catch (e: Exception) {
trySend(Resource.Error(e.message.toString()))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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.SyncCenterPayloadsRepository
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 08/08/2024 (1:43 PM)
*/
class UpdateCenterPayloadUseCase @Inject constructor(private val repository: SyncCenterPayloadsRepository) {

suspend operator fun invoke(centerPayload: CenterPayload): Flow<Resource<CenterPayload>> =
callbackFlow {
try {
trySend(Resource.Loading())

repository.updateCenterPayload(centerPayload)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<CenterPayload>() {
override fun onCompleted() {}

override fun onError(e: Throwable) {
trySend(Resource.Error(e.message.toString()))
}

override fun onNext(centerPayload: CenterPayload) {
trySend(Resource.Success(centerPayload))
}
})

awaitClose { channel.close() }
} catch (e: Exception) {
trySend(Resource.Error(e.message.toString()))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.offline.synccenterpayloads
package com.mifos.feature.center.sync_center_payloads

import android.content.Context
import android.widget.Toast
Expand All @@ -25,12 +25,11 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
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.data.CenterPayload
import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.designsystem.icon.MifosIcons
import com.mifos.mifosxdroid.R
import com.mifos.utils.Network
import com.mifos.utils.PrefManager.userStatus
import com.mifos.feature.center.R


@Composable
Expand All @@ -50,7 +49,8 @@ fun SyncCenterPayloadsScreenRoute(
onBackPressed = onBackPressed,
refreshing = refreshing,
onRefresh = { viewModel.refreshCenterPayloads() },
syncCenterPayloads = { viewModel.syncCenterPayload() }
syncCenterPayloads = { viewModel.syncCenterPayload() },
userStatus = viewModel.getUserStatus()
)
}

Expand All @@ -61,15 +61,16 @@ fun SyncCenterPayloadsScreen(
onBackPressed: () -> Unit,
refreshing: Boolean,
onRefresh: () -> Unit,
syncCenterPayloads: () -> Unit
syncCenterPayloads: () -> Unit,
userStatus : Boolean
) {
val context = LocalContext.current
val snackbarHostState = remember { SnackbarHostState() }
val pullRefreshState = rememberPullRefreshState(refreshing = refreshing, onRefresh = onRefresh)

MifosScaffold(
icon = MifosIcons.arrowBack,
title = stringResource(id = R.string.sync_centers_payloads),
title = stringResource(id = R.string.feature_center_sync_centers_payloads),
onBackPressed = onBackPressed,
actions = {
IconButton(onClick = {
Expand All @@ -80,7 +81,7 @@ fun SyncCenterPayloadsScreen(
}) {
Icon(
MifosIcons.sync,
contentDescription = stringResource(id = R.string.sync_centers)
contentDescription = stringResource(id = R.string.feature_center_sync_centers)
)
}
},
Expand Down Expand Up @@ -134,19 +135,19 @@ fun CenterPayloadItem(payload: CenterPayload) {
) {
Column(modifier = Modifier.padding(16.dp)) {
PayloadField(
label = stringResource(R.string.name),
label = stringResource(R.string.feature_center_name),
value = payload.name ?: ""
)
PayloadField(
label = stringResource(R.string.office_id),
label = stringResource(R.string.feature_center_office_id),
value = payload.officeId?.toString() ?: ""
)
PayloadField(
label = stringResource(R.string.activation_date),
label = stringResource(R.string.feature_center_activation_date),
value = payload.activationDate ?: ""
)
PayloadField(
label = stringResource(R.string.active),
label = stringResource(R.string.feature_center_active),
value = if (payload.active) true.toString() else false.toString()
)
payload.errorMessage?.let {
Expand Down Expand Up @@ -195,7 +196,7 @@ fun ErrorState(message: String, onRefresh: () -> Unit) {
)
Text(text = message, modifier = Modifier.padding(vertical = 16.dp))
Button(onClick = onRefresh) {
Text(stringResource(id = R.string.click_to_refresh))
Text(stringResource(id = R.string.feature_center_click_to_refresh))
}
}
}
Expand All @@ -213,7 +214,7 @@ fun EmptyState() {
modifier = Modifier.size(48.dp)
)
Text(
text = stringResource(id = R.string.no_center_payload_to_sync),
text = stringResource(id = R.string.feature_center_no_center_payload_to_sync),
modifier = Modifier.padding(top = 16.dp)
)
}
Expand All @@ -228,7 +229,7 @@ fun checkNetworkConnectionAndSync(
} else {
Toast.makeText(
context,
context.getString(R.string.error_not_connected_internet),
context.getString(R.string.feature_center_error_not_connected_internet),
Toast.LENGTH_SHORT
).show()
}
Expand All @@ -244,7 +245,8 @@ fun SyncCenterPayloadsScreenPreview(
onBackPressed = {},
refreshing = false,
onRefresh = {},
syncCenterPayloads = {}
syncCenterPayloads = {},
userStatus = true
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.offline.synccenterpayloads
package com.mifos.feature.center.sync_center_payloads

import com.mifos.core.data.CenterPayload

Expand Down
Loading

0 comments on commit 6ea49a7

Please sign in to comment.