Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [database.center] dbFlow to room migration #2307

Merged
merged 7 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ complexity:
ignoreArgumentsMatchingNames: false
NestedBlockDepth:
active: true
threshold: 5
threshold: 6
NestedScopeFunctions:
active: false
threshold: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
*/
package com.mifos.core.data.pagingSource

import android.graphics.pdf.LoadParams
import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.mifos.core.entity.group.Center
import com.mifos.core.network.datamanager.DataManagerCenter
import com.mifos.core.objects.clients.Page
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
import com.mifos.room.entities.group.Center
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map

class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) :
PagingSource<Int, Center>() {
Expand Down Expand Up @@ -55,26 +51,10 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) :
return Pair(pagedClient.pageItems, pagedClient.totalFilteredRecords)
}

private suspend fun getCenterDbList(): List<Center> = suspendCoroutine { continuation ->
try {
dataManagerCenter.allDatabaseCenters
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<Page<Center>>() {
override fun onCompleted() {
}

override fun onError(error: Throwable) {
continuation.resumeWithException(error)
}

override fun onNext(centers: Page<Center>) {
continuation.resume(centers.pageItems)
}
})
} catch (exception: Exception) {
continuation.resumeWithException(exception)
}
private suspend fun getCenterDbList(): List<Center> {
return dataManagerCenter.allDatabaseCenters
.map { it.pageItems }
.first()
}

private fun getCenterListWithSync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
package com.mifos.core.data.repository

import androidx.paging.PagingData
import com.mifos.core.entity.group.Center
import com.mifos.core.objects.clients.Page
import com.mifos.core.model.objects.clients.Page
import com.mifos.room.entities.group.Center
import com.mifos.room.entities.group.CenterWithAssociations
import kotlinx.coroutines.flow.Flow
import rx.Observable

/**
* Created by Aditya Gupta on 06/08/23.
Expand All @@ -25,5 +24,5 @@ interface CenterListRepository {

suspend fun getCentersGroupAndMeeting(id: Int): CenterWithAssociations

fun allDatabaseCenters(): Observable<Page<Center>>
fun allDatabaseCenters(): Flow<Page<Center>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
*/
package com.mifos.core.data.repository

import com.mifos.core.entity.center.CenterPayload
import com.mifos.core.objects.responses.SaveResponse
import rx.Observable
import com.mifos.room.entities.center.CenterPayload

/**
* Created by Aditya Gupta on 10/08/23.
*/
interface CreateNewCenterRepository {
fun createCenter(centerPayload: CenterPayload): Observable<SaveResponse>
suspend fun createCenter(centerPayload: CenterPayload)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
package com.mifos.core.data.repository

import com.mifos.core.entity.accounts.savings.SavingsAccountTransactionRequest
import com.mifos.core.entity.center.CenterPayload
import com.mifos.core.entity.client.ClientPayload
import com.mifos.core.entity.group.GroupPayload
import com.mifos.room.entities.accounts.loans.LoanRepaymentRequest
import com.mifos.room.entities.center.CenterPayload
import kotlinx.coroutines.flow.Flow
import rx.Observable

Expand All @@ -26,7 +26,7 @@ interface OfflineDashboardRepository {

fun allDatabaseGroupPayload(): Observable<List<GroupPayload>>

fun allDatabaseCenterPayload(): Observable<List<CenterPayload>>
fun allDatabaseCenterPayload(): Flow<List<CenterPayload>>

fun databaseLoanRepayments(): Flow<List<LoanRepaymentRequest>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@
*/
package com.mifos.core.data.repository

import com.mifos.core.entity.center.CenterPayload
import com.mifos.core.objects.responses.SaveResponse
import rx.Observable
import com.mifos.room.entities.center.CenterPayload
import kotlinx.coroutines.flow.Flow

/**
* Created by Aditya Gupta on 16/08/23.
*/
interface SyncCenterPayloadsRepository {

fun allDatabaseCenterPayload(): Observable<List<CenterPayload>>
fun allDatabaseCenterPayload(): Flow<List<CenterPayload>>

fun createCenter(centerPayload: CenterPayload): Observable<SaveResponse>
suspend fun createCenter(centerPayload: CenterPayload?)

fun deleteAndUpdateCenterPayloads(id: Int): Observable<List<CenterPayload>>
fun deleteAndUpdateCenterPayloads(id: Int): Flow<List<CenterPayload>>

fun updateCenterPayload(centerPayload: CenterPayload): Observable<CenterPayload>
suspend fun updateCenterPayload(centerPayload: CenterPayload)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ package com.mifos.core.data.repository

import com.mifos.core.entity.accounts.savings.SavingsAccountWithAssociations
import com.mifos.core.entity.client.Client
import com.mifos.core.entity.group.Center
import com.mifos.core.entity.group.Group
import com.mifos.core.entity.templates.savings.SavingsAccountTransactionTemplate
import com.mifos.room.entities.accounts.CenterAccounts
import com.mifos.room.entities.accounts.ClientAccounts
import com.mifos.room.entities.accounts.GroupAccounts
import com.mifos.room.entities.accounts.loans.LoanWithAssociations
import com.mifos.room.entities.group.Center
import com.mifos.room.entities.group.CenterWithAssociations
import com.mifos.room.entities.group.GroupWithAssociations
import com.mifos.room.entities.templates.loans.LoanRepaymentTemplate
Expand All @@ -29,13 +29,13 @@ import rx.Observable
*/
interface SyncCentersDialogRepository {

fun syncCenterAccounts(centerId: Int): Observable<CenterAccounts>
fun syncCenterAccounts(centerId: Int): Flow<CenterAccounts>

fun syncLoanById(loanId: Int): Flow<LoanWithAssociations>

fun syncLoanRepaymentTemplate(loanId: Int): Flow<LoanRepaymentTemplate>

fun getCenterWithAssociations(centerId: Int): Observable<CenterWithAssociations>
fun getCenterWithAssociations(centerId: Int): Flow<CenterWithAssociations>

fun getGroupWithAssociations(groupId: Int): Observable<GroupWithAssociations>

Expand All @@ -47,7 +47,7 @@ interface SyncCentersDialogRepository {

fun syncClientInDatabase(client: Client): Observable<Client>

fun syncCenterInDatabase(center: Center): Observable<Center>
suspend fun syncCenterInDatabase(center: Center)

fun syncSavingsAccount(
type: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.mifos.core.data.pagingSource.CenterListPagingSource
import com.mifos.core.data.repository.CenterListRepository
import com.mifos.core.entity.group.Center
import com.mifos.core.model.objects.clients.Page
import com.mifos.core.network.datamanager.DataManagerCenter
import com.mifos.core.objects.clients.Page
import com.mifos.room.entities.group.Center
import com.mifos.room.entities.group.CenterWithAssociations
import kotlinx.coroutines.flow.Flow
import rx.Observable
import javax.inject.Inject

/**
Expand All @@ -43,7 +42,7 @@ class CenterListRepositoryImp @Inject constructor(private val dataManagerCenter:
return dataManagerCenter.getCentersGroupAndMeeting(id)
}

override fun allDatabaseCenters(): Observable<Page<Center>> {
override fun allDatabaseCenters(): Flow<Page<Center>> {
return dataManagerCenter.allDatabaseCenters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
package com.mifos.core.data.repositoryImp

import com.mifos.core.data.repository.CreateNewCenterRepository
import com.mifos.core.entity.center.CenterPayload
import com.mifos.core.network.datamanager.DataManagerCenter
import com.mifos.core.objects.responses.SaveResponse
import rx.Observable
import com.mifos.room.entities.center.CenterPayload
import javax.inject.Inject

/**
Expand All @@ -22,7 +20,7 @@ import javax.inject.Inject
class CreateNewCenterRepositoryImp @Inject constructor(private val dataManagerCenter: DataManagerCenter) :
CreateNewCenterRepository {

override fun createCenter(centerPayload: CenterPayload): Observable<SaveResponse> {
return dataManagerCenter.createCenter(centerPayload)
override suspend fun createCenter(centerPayload: CenterPayload) {
dataManagerCenter.createCenter(centerPayload)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package com.mifos.core.data.repositoryImp

import com.mifos.core.data.repository.OfflineDashboardRepository
import com.mifos.core.entity.accounts.savings.SavingsAccountTransactionRequest
import com.mifos.core.entity.center.CenterPayload
import com.mifos.core.entity.client.ClientPayload
import com.mifos.core.entity.group.GroupPayload
import com.mifos.core.network.datamanager.DataManagerCenter
Expand All @@ -20,6 +19,7 @@ import com.mifos.core.network.datamanager.DataManagerGroups
import com.mifos.core.network.datamanager.DataManagerLoan
import com.mifos.core.network.datamanager.DataManagerSavings
import com.mifos.room.entities.accounts.loans.LoanRepaymentRequest
import com.mifos.room.entities.center.CenterPayload
import kotlinx.coroutines.flow.Flow
import rx.Observable
import javax.inject.Inject
Expand All @@ -43,7 +43,7 @@ class OfflineDashboardRepositoryImp @Inject constructor(
return dataManagerGroups.allDatabaseGroupPayload
}

override fun allDatabaseCenterPayload(): Observable<List<CenterPayload>> {
override fun allDatabaseCenterPayload(): Flow<List<CenterPayload>> {
return dataManagerCenter.allDatabaseCenterPayload
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
package com.mifos.core.data.repositoryImp

import com.mifos.core.data.repository.SyncCenterPayloadsRepository
import com.mifos.core.entity.center.CenterPayload
import com.mifos.core.network.datamanager.DataManagerCenter
import com.mifos.core.objects.responses.SaveResponse
import rx.Observable
import com.mifos.room.entities.center.CenterPayload
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

/**
Expand All @@ -22,19 +21,19 @@ import javax.inject.Inject
class SyncCenterPayloadsRepositoryImp @Inject constructor(private val dataManagerCenter: DataManagerCenter) :
SyncCenterPayloadsRepository {

override fun allDatabaseCenterPayload(): Observable<List<CenterPayload>> {
override fun allDatabaseCenterPayload(): Flow<List<CenterPayload>> {
return dataManagerCenter.allDatabaseCenterPayload
}

override fun createCenter(centerPayload: CenterPayload): Observable<SaveResponse> {
return dataManagerCenter.createCenter(centerPayload)
override suspend fun createCenter(centerPayload: CenterPayload?) {
dataManagerCenter.createCenter(centerPayload)
}

override fun deleteAndUpdateCenterPayloads(id: Int): Observable<List<CenterPayload>> {
override fun deleteAndUpdateCenterPayloads(id: Int): Flow<List<CenterPayload>> {
return dataManagerCenter.deleteAndUpdateCenterPayloads(id)
}

override fun updateCenterPayload(centerPayload: CenterPayload): Observable<CenterPayload> {
return dataManagerCenter.updateCenterPayload(centerPayload)
override suspend fun updateCenterPayload(centerPayload: CenterPayload) {
dataManagerCenter.updateCenterPayload(centerPayload)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package com.mifos.core.data.repositoryImp
import com.mifos.core.data.repository.SyncCentersDialogRepository
import com.mifos.core.entity.accounts.savings.SavingsAccountWithAssociations
import com.mifos.core.entity.client.Client
import com.mifos.core.entity.group.Center
import com.mifos.core.entity.group.Group
import com.mifos.core.entity.templates.savings.SavingsAccountTransactionTemplate
import com.mifos.core.network.datamanager.DataManagerCenter
Expand All @@ -24,6 +23,7 @@ import com.mifos.room.entities.accounts.CenterAccounts
import com.mifos.room.entities.accounts.ClientAccounts
import com.mifos.room.entities.accounts.GroupAccounts
import com.mifos.room.entities.accounts.loans.LoanWithAssociations
import com.mifos.room.entities.group.Center
import com.mifos.room.entities.group.CenterWithAssociations
import com.mifos.room.entities.group.GroupWithAssociations
import com.mifos.room.entities.templates.loans.LoanRepaymentTemplate
Expand All @@ -42,7 +42,7 @@ class SyncCentersDialogRepositoryImp @Inject constructor(
private val dataManagerClient: DataManagerClient,
) : SyncCentersDialogRepository {

override fun syncCenterAccounts(centerId: Int): Observable<CenterAccounts> {
override fun syncCenterAccounts(centerId: Int): Flow<CenterAccounts> {
return dataManagerCenter.syncCenterAccounts(centerId)
}

Expand All @@ -54,7 +54,7 @@ class SyncCentersDialogRepositoryImp @Inject constructor(
return dataManagerLoan.syncLoanRepaymentTemplate(loanId)
}

override fun getCenterWithAssociations(centerId: Int): Observable<CenterWithAssociations> {
override fun getCenterWithAssociations(centerId: Int): Flow<CenterWithAssociations> {
return dataManagerCenter.getCenterWithAssociations(centerId)
}

Expand All @@ -78,8 +78,8 @@ class SyncCentersDialogRepositoryImp @Inject constructor(
return dataManagerClient.syncClientInDatabase(client)
}

override fun syncCenterInDatabase(center: Center): Observable<Center> {
return dataManagerCenter.syncCenterInDatabase(center)
override suspend fun syncCenterInDatabase(center: Center) {
dataManagerCenter.syncCenterInDatabase(center)
}

override fun syncSavingsAccount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import com.mifos.core.entity.group.Center
import com.mifos.core.entity.group.CenterDate
import com.mifos.core.entity.group.Group
import com.mifos.core.entity.group.Group_Table
import com.mifos.core.objects.clients.Page
import com.mifos.core.objects.responses.SaveResponse
import com.mifos.core.model.objects.clients.Page
import com.mifos.core.model.objects.responses.SaveResponse
import com.mifos.room.entities.accounts.CenterAccounts
import com.mifos.room.entities.group.CenterWithAssociations
import com.raizlabs.android.dbflow.sql.language.Delete
Expand Down
Loading
Loading