Skip to content

Commit

Permalink
MIFOSAC-295 applied spotless and detekt on core:data (#2251)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsPronay authored Dec 6, 2024
1 parent 657a930 commit b460b21
Show file tree
Hide file tree
Showing 132 changed files with 1,620 additions and 497 deletions.
6 changes: 3 additions & 3 deletions 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: 4
threshold: 5
NestedScopeFunctions:
active: false
threshold: 1
Expand Down Expand Up @@ -230,7 +230,7 @@ complexity:
]
# Modifying default values 11 to 20
thresholdInFiles: 20
thresholdInClasses: 30
thresholdInClasses: 45
thresholdInInterfaces: 20
thresholdInObjects: 20
thresholdInEnums: 20
Expand Down Expand Up @@ -323,7 +323,7 @@ exceptions:
PrintStackTrace:
active: true
RethrowCaughtException:
active: true
active: false
ReturnFromFinally:
active: true
ignoreLabeled: false
Expand Down
9 changes: 9 additions & 0 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.library)
alias(libs.plugins.mifos.android.hilt)
Expand Down
9 changes: 9 additions & 0 deletions core/data/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 Mifos Initiative
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/.
See https://github.com/openMF/android-client/blob/master/LICENSE.md
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
92 changes: 50 additions & 42 deletions core/data/src/main/java/com/mifos/core/data/di/DataModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.data.di


import com.mifos.core.data.repository.ActivateRepository
import com.mifos.core.data.repository.CenterDetailsRepository
import com.mifos.core.data.repository.CenterListRepository
Expand Down Expand Up @@ -41,46 +49,46 @@ import com.mifos.core.data.repository.SearchRepository
import com.mifos.core.data.repository.SignatureRepository
import com.mifos.core.data.repository.SurveyListRepository
import com.mifos.core.data.repository.SurveySubmitRepository
import com.mifos.core.data.repository_imp.ActivateRepositoryImp
import com.mifos.core.data.repository_imp.CenterDetailsRepositoryImp
import com.mifos.core.data.repository_imp.CenterListRepositoryImp
import com.mifos.core.data.repository_imp.ChargeDialogRepositoryImp
import com.mifos.core.data.repository_imp.CheckerInboxRepositoryImp
import com.mifos.core.data.repository_imp.CheckerInboxTasksRepositoryImp
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.DataTableListRepositoryImp
import com.mifos.core.data.repository_imp.DataTableRepositoryImp
import com.mifos.core.data.repository_imp.DataTableRowDialogRepositoryImp
import com.mifos.core.data.repository_imp.DocumentListRepositoryImp
import com.mifos.core.data.repository_imp.GenerateCollectionSheetRepositoryImp
import com.mifos.core.data.repository_imp.GroupDetailsRepositoryImp
import com.mifos.core.data.repository_imp.GroupListRepositoryImp
import com.mifos.core.data.repository_imp.GroupLoanAccountRepositoryImp
import com.mifos.core.data.repository_imp.GroupsListRepositoryImpl
import com.mifos.core.data.repository_imp.IndividualCollectionSheetDetailsRepositoryImp
import com.mifos.core.data.repository_imp.LoanAccountApprovalRepositoryImp
import com.mifos.core.data.repository_imp.LoanAccountDisbursementRepositoryImp
import com.mifos.core.data.repository_imp.LoanAccountRepositoryImp
import com.mifos.core.data.repository_imp.LoanAccountSummaryRepositoryImp
import com.mifos.core.data.repository_imp.LoanChargeDialogRepositoryImp
import com.mifos.core.data.repository_imp.LoanChargeRepositoryImp
import com.mifos.core.data.repository_imp.LoanRepaymentRepositoryImp
import com.mifos.core.data.repository_imp.LoanRepaymentScheduleRepositoryImp
import com.mifos.core.data.repository_imp.LoanTransactionsRepositoryImp
import com.mifos.core.data.repository_imp.NewIndividualCollectionSheetRepositoryImp
import com.mifos.core.data.repository_imp.PathTrackingRepositoryImp
import com.mifos.core.data.repository_imp.PinPointClientRepositoryImp
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.SurveyListRepositoryImp
import com.mifos.core.data.repository_imp.SurveySubmitRepositoryImp
import com.mifos.core.data.repositoryImp.ActivateRepositoryImp
import com.mifos.core.data.repositoryImp.CenterDetailsRepositoryImp
import com.mifos.core.data.repositoryImp.CenterListRepositoryImp
import com.mifos.core.data.repositoryImp.ChargeDialogRepositoryImp
import com.mifos.core.data.repositoryImp.CheckerInboxRepositoryImp
import com.mifos.core.data.repositoryImp.CheckerInboxTasksRepositoryImp
import com.mifos.core.data.repositoryImp.ClientChargeRepositoryImp
import com.mifos.core.data.repositoryImp.ClientIdentifierDialogRepositoryImp
import com.mifos.core.data.repositoryImp.ClientIdentifiersRepositoryImp
import com.mifos.core.data.repositoryImp.CreateNewCenterRepositoryImp
import com.mifos.core.data.repositoryImp.CreateNewGroupRepositoryImp
import com.mifos.core.data.repositoryImp.DataTableDataRepositoryImp
import com.mifos.core.data.repositoryImp.DataTableListRepositoryImp
import com.mifos.core.data.repositoryImp.DataTableRepositoryImp
import com.mifos.core.data.repositoryImp.DataTableRowDialogRepositoryImp
import com.mifos.core.data.repositoryImp.DocumentListRepositoryImp
import com.mifos.core.data.repositoryImp.GenerateCollectionSheetRepositoryImp
import com.mifos.core.data.repositoryImp.GroupDetailsRepositoryImp
import com.mifos.core.data.repositoryImp.GroupListRepositoryImp
import com.mifos.core.data.repositoryImp.GroupLoanAccountRepositoryImp
import com.mifos.core.data.repositoryImp.GroupsListRepositoryImpl
import com.mifos.core.data.repositoryImp.IndividualCollectionSheetDetailsRepositoryImp
import com.mifos.core.data.repositoryImp.LoanAccountApprovalRepositoryImp
import com.mifos.core.data.repositoryImp.LoanAccountDisbursementRepositoryImp
import com.mifos.core.data.repositoryImp.LoanAccountRepositoryImp
import com.mifos.core.data.repositoryImp.LoanAccountSummaryRepositoryImp
import com.mifos.core.data.repositoryImp.LoanChargeDialogRepositoryImp
import com.mifos.core.data.repositoryImp.LoanChargeRepositoryImp
import com.mifos.core.data.repositoryImp.LoanRepaymentRepositoryImp
import com.mifos.core.data.repositoryImp.LoanRepaymentScheduleRepositoryImp
import com.mifos.core.data.repositoryImp.LoanTransactionsRepositoryImp
import com.mifos.core.data.repositoryImp.NewIndividualCollectionSheetRepositoryImp
import com.mifos.core.data.repositoryImp.PathTrackingRepositoryImp
import com.mifos.core.data.repositoryImp.PinPointClientRepositoryImp
import com.mifos.core.data.repositoryImp.ReportCategoryRepositoryImp
import com.mifos.core.data.repositoryImp.ReportDetailRepositoryImp
import com.mifos.core.data.repositoryImp.SearchRepositoryImp
import com.mifos.core.data.repositoryImp.SignatureRepositoryImp
import com.mifos.core.data.repositoryImp.SurveyListRepositoryImp
import com.mifos.core.data.repositoryImp.SurveySubmitRepositoryImp
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -209,4 +217,4 @@ abstract class DataModule {

@Binds
internal abstract fun bindDataTableListRepository(impl: DataTableListRepositoryImp): DataTableListRepository
}
}
17 changes: 13 additions & 4 deletions core/data/src/main/java/com/mifos/core/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.data.di

import com.mifos.core.data.repository.ClientDetailsRepository
import com.mifos.core.data.repository.ClientListRepository
import com.mifos.core.data.repository.LoginRepository
import com.mifos.core.data.repository_imp.ClientDetailsRepositoryImp
import com.mifos.core.data.repository_imp.ClientListRepositoryImp
import com.mifos.core.data.repository_imp.LoginRepositoryImp
import com.mifos.core.data.repositoryImp.ClientDetailsRepositoryImp
import com.mifos.core.data.repositoryImp.ClientListRepositoryImp
import com.mifos.core.data.repositoryImp.LoginRepositoryImp
import com.mifos.core.network.datamanager.DataManagerClient
import com.mifos.core.network.datamanger.DataManagerAuth
import dagger.Module
Expand All @@ -30,4 +39,4 @@ object RepositoryModule {
@Provides
fun providesLoginRepository(dataManagerAuth: DataManagerAuth): LoginRepository =
LoginRepositoryImp(dataManagerAuth)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package com.mifos.core.data.paging_source
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.data.pagingSource

import androidx.paging.PagingSource
import androidx.paging.PagingState
Expand All @@ -18,7 +27,7 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) :
override fun getRefreshKey(state: PagingState<Int, Center>): Int? {
return state.anchorPosition?.let { position ->
state.closestPageToPosition(position)?.prevKey?.plus(10) ?: state.closestPageToPosition(
position
position,
)?.nextKey?.minus(10)
}
}
Expand All @@ -34,7 +43,7 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) :
LoadResult.Page(
data = centerListWithSync,
prevKey = if (position <= 0) null else position - 10,
nextKey = if (position >= totalCenters) null else position + 10
nextKey = if (position >= totalCenters) null else position + 10,
)
} catch (e: Exception) {
LoadResult.Error(e)
Expand All @@ -59,8 +68,8 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) :
continuation.resume(
Pair(
center.pageItems,
center.totalFilteredRecords
)
center.totalFilteredRecords,
),
)
}
})
Expand All @@ -71,7 +80,6 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) :

private suspend fun getCenterDbList(): List<Center> = suspendCoroutine { continuation ->
try {

dataManagerCenter.allDatabaseCenters
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
Expand All @@ -92,10 +100,9 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) :
}
}


private fun getCenterListWithSync(
centerList: List<Center>,
centerDbList: List<Center>
centerDbList: List<Center>,
): List<Center> {
if (centerDbList.isNotEmpty()) {
centerList.forEach { center ->
Expand All @@ -108,4 +115,4 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) :
}
return centerList
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package com.mifos.core.data.paging_source
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.data.pagingSource

import androidx.paging.PagingSource
import androidx.paging.PagingState
Expand All @@ -14,14 +23,14 @@ import kotlin.coroutines.resumeWithException

class ClientChargesPagingSource(
private val clientId: Int,
private val dataManagerCharge: DataManagerCharge
private val dataManagerCharge: DataManagerCharge,
) :
PagingSource<Int, Charges>() {

override fun getRefreshKey(state: PagingState<Int, Charges>): Int? {
return state.anchorPosition?.let { position ->
state.closestPageToPosition(position)?.prevKey?.plus(10) ?: state.closestPageToPosition(
position
position,
)?.nextKey?.minus(10)
}
}
Expand All @@ -35,7 +44,7 @@ class ClientChargesPagingSource(
LoadResult.Page(
data = clientChargesList,
prevKey = if (position <= 0) null else position - 10,
nextKey = if (position >= totalCharges) null else position + 10
nextKey = if (position >= totalCharges) null else position + 10,
)
} catch (exception: Exception) {
LoadResult.Error(exception)
Expand All @@ -44,7 +53,7 @@ class ClientChargesPagingSource(

private suspend fun getClientChargeList(
clientId: Int,
position: Int
position: Int,
): Pair<List<Charges>, Int> {
return suspendCancellableCoroutine { continuation ->
dataManagerCharge.getClientCharges(clientId = clientId, offset = position, 10)
Expand All @@ -64,4 +73,4 @@ class ClientChargesPagingSource(
})
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package com.mifos.core.data.paging_source
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.data.pagingSource

import androidx.paging.PagingSource
import androidx.paging.PagingState
Expand All @@ -18,13 +27,13 @@ import kotlin.coroutines.suspendCoroutine
*/

class ClientListPagingSource(
private val dataManagerClient: DataManagerClient
private val dataManagerClient: DataManagerClient,
) : PagingSource<Int, Client>() {

override fun getRefreshKey(state: PagingState<Int, Client>): Int? {
return state.anchorPosition?.let { position ->
state.closestPageToPosition(position)?.prevKey?.plus(10) ?: state.closestPageToPosition(
position
position,
)?.nextKey?.minus(10)
}
}
Expand All @@ -40,7 +49,7 @@ class ClientListPagingSource(
LoadResult.Page(
data = clientListWithSync,
prevKey = if (position <= 0) null else position - 10,
nextKey = if (position >= totalClients) null else position + 10
nextKey = if (position >= totalClients) null else position + 10,
)
} catch (e: Exception) {
LoadResult.Error(e)
Expand All @@ -54,7 +63,6 @@ class ClientListPagingSource(
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<Page<Client>>() {
override fun onCompleted() {

}

override fun onError(e: Throwable) {
Expand Down Expand Up @@ -90,7 +98,7 @@ class ClientListPagingSource(

private fun getClientListWithSync(
clientList: List<Client>,
clientDbList: List<Client>
clientDbList: List<Client>,
): List<Client> {
if (clientDbList.isNotEmpty()) {
clientList.forEach { client ->
Expand All @@ -103,4 +111,4 @@ class ClientListPagingSource(
}
return clientList
}
}
}
Loading

0 comments on commit b460b21

Please sign in to comment.