Skip to content

Commit

Permalink
refactor: refactor Group Loan Account Fragment to compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 committed Jul 14, 2024
1 parent 6074317 commit ef81cc3
Show file tree
Hide file tree
Showing 12 changed files with 846 additions and 722 deletions.
9 changes: 7 additions & 2 deletions core/data/src/main/java/com/mifos/core/data/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import com.mifos.core.data.repository.CreateNewCenterRepository
import com.mifos.core.data.repository.DocumentListRepository
import com.mifos.core.data.repository.GroupDetailsRepository
import com.mifos.core.data.repository.GroupListRepository
import com.mifos.core.data.repository.GroupLoanAccountRepository
import com.mifos.core.data.repository.GroupsListRepository
import com.mifos.core.data.repository.IndividualCollectionSheetDetailsRepository
import com.mifos.core.data.repository.LoanAccountRepository
import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
import com.mifos.core.data.repository.PathTrackingRepository
import com.mifos.core.data.repository.ReportCategoryRepository
import com.mifos.core.data.repository_imp.ActivateRepositoryImp
import com.mifos.core.data.repository.ReportDetailRepository
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.CheckerInboxRepositoryImp
Expand All @@ -30,6 +31,7 @@ import com.mifos.core.data.repository_imp.CreateNewCenterRepositoryImp
import com.mifos.core.data.repository_imp.DocumentListRepositoryImp
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.LoanAccountRepositoryImp
Expand Down Expand Up @@ -98,7 +100,10 @@ abstract class DataModule {

@Binds
internal abstract fun bindIndividualCollectionSheetDetailsRepositoryImp(impl: IndividualCollectionSheetDetailsRepositoryImp): IndividualCollectionSheetDetailsRepository

@Binds
internal abstract fun bindGroupListRepository(impl: GroupListRepositoryImp): GroupListRepository

@Binds
internal abstract fun bindGroupLoanAccountRepository(impl: GroupLoanAccountRepositoryImp): GroupLoanAccountRepository
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.mifos.mifosxdroid.online.grouploanaccount
package com.mifos.core.data.repository

import com.mifos.core.data.GroupLoanPayload
import com.mifos.core.objects.accounts.loan.Loans
import com.mifos.core.objects.organisation.LoanProducts
import com.mifos.core.objects.templates.loans.GroupLoanTemplate
import rx.Observable

Expand All @@ -11,9 +10,7 @@ import rx.Observable
*/
interface GroupLoanAccountRepository {

fun allLoans(): Observable<List<LoanProducts>>

fun getGroupLoansAccountTemplate(groupId: Int, productId: Int): Observable<GroupLoanTemplate>

fun createGroupLoansAccount(loansPayload: GroupLoanPayload?): Observable<Loans>
fun createGroupLoansAccount(loansPayload: GroupLoanPayload): Observable<Loans>
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.mifos.mifosxdroid.online.grouploanaccount
package com.mifos.core.data.repository_imp

import com.mifos.core.data.GroupLoanPayload
import com.mifos.core.data.repository.GroupLoanAccountRepository
import com.mifos.core.network.DataManager
import com.mifos.core.objects.accounts.loan.Loans
import com.mifos.core.objects.organisation.LoanProducts
import com.mifos.core.objects.templates.loans.GroupLoanTemplate
import rx.Observable
import javax.inject.Inject
Expand All @@ -14,18 +14,14 @@ import javax.inject.Inject
class GroupLoanAccountRepositoryImp @Inject constructor(private val dataManager: DataManager) :
GroupLoanAccountRepository {

override fun allLoans(): Observable<List<LoanProducts>> {
return dataManager.allLoans
}

override fun getGroupLoansAccountTemplate(
groupId: Int,
productId: Int
): Observable<GroupLoanTemplate> {
return dataManager.getGroupLoansAccountTemplate(groupId, productId)
}

override fun createGroupLoansAccount(loansPayload: GroupLoanPayload?): Observable<Loans> {
override fun createGroupLoansAccount(loansPayload: GroupLoanPayload): Observable<Loans> {
return dataManager.createGroupLoansAccount(loansPayload)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.GroupLoanPayload
import com.mifos.core.data.repository.GroupLoanAccountRepository
import com.mifos.core.objects.accounts.loan.Loans
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 CreateGroupLoansAccountUseCase @Inject constructor(private val repository: GroupLoanAccountRepository) {

suspend operator fun invoke(loansPayload: GroupLoanPayload): Flow<Resource<Loans>> =
callbackFlow {
try {
trySend(Resource.Loading())
repository.createGroupLoansAccount(loansPayload)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<Loans>() {
override fun onCompleted() {}

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

override fun onNext(response: Loans) {
trySend(Resource.Success(response))
}
})
awaitClose { channel.close() }
} catch (exception: Exception) {
trySend(Resource.Error(exception.message.toString()))
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.GroupLoanAccountRepository
import com.mifos.core.objects.templates.loans.GroupLoanTemplate
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 GetGroupLoansAccountTemplateUseCase @Inject constructor(private val repository: GroupLoanAccountRepository) {

suspend operator fun invoke(groupId: Int, productId: Int): Flow<Resource<GroupLoanTemplate>> =
callbackFlow {
try {
trySend(Resource.Loading())
repository.getGroupLoansAccountTemplate(groupId, productId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<GroupLoanTemplate>() {
override fun onCompleted() {}

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

override fun onNext(response: GroupLoanTemplate) {
trySend(Resource.Success(response))
}
})
awaitClose { channel.close() }
} catch (exception: Exception) {
trySend(Resource.Error(exception.message.toString()))
}
}
}
Loading

0 comments on commit ef81cc3

Please sign in to comment.