Skip to content

Commit

Permalink
refactor: refactor Activate fragment to compose (openMF#2123)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 authored Jul 13, 2024
1 parent c1e7d2c commit 6074317
Show file tree
Hide file tree
Showing 20 changed files with 649 additions and 98 deletions.
5 changes: 5 additions & 0 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,7 @@
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
import com.mifos.core.data.repository.CheckerInboxRepository
Expand All @@ -17,6 +18,7 @@ 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.CenterDetailsRepositoryImp
import com.mifos.core.data.repository_imp.CenterListRepositoryImp
Expand Down Expand Up @@ -82,6 +84,9 @@ abstract class DataModule {
@Binds
internal abstract fun bindClientIdentifiersRepository(impl: ClientIdentifiersRepositoryImp): ClientIdentifiersRepository

@Binds
internal abstract fun bindActivateRepository(impl: ActivateRepositoryImp): ActivateRepository

@Binds
internal abstract fun bindReportDetailRepository(impl: ReportDetailRepositoryImp): ReportDetailRepository

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mifos.core.data.repository

import com.mifos.core.network.GenericResponse
import com.mifos.core.objects.client.ActivatePayload
import org.apache.fineract.client.models.PostCentersCenterIdResponse
import org.apache.fineract.client.models.PostClientsClientIdResponse
import rx.Observable

/**
* Created by Aditya Gupta on 06/08/23.
*/

interface ActivateRepository {

fun activateClient(
clientId: Int,
clientActivate: ActivatePayload?
): Observable<PostClientsClientIdResponse>

fun activateCenter(
centerId: Int,
activatePayload: ActivatePayload?
): Observable<PostCentersCenterIdResponse>

fun activateGroup(
groupId: Int,
activatePayload: ActivatePayload?
): Observable<GenericResponse>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.mifos.core.data.repository_imp

import com.mifos.core.data.repository.ActivateRepository
import com.mifos.core.network.GenericResponse
import com.mifos.core.network.datamanager.DataManagerCenter
import com.mifos.core.network.datamanager.DataManagerClient
import com.mifos.core.network.datamanager.DataManagerGroups
import com.mifos.core.objects.client.ActivatePayload
import org.apache.fineract.client.models.PostCentersCenterIdResponse
import org.apache.fineract.client.models.PostClientsClientIdResponse
import rx.Observable
import javax.inject.Inject

/**
* Created by Aditya Gupta on 06/08/23.
*/
class ActivateRepositoryImp @Inject constructor(
private val dataManagerClient: DataManagerClient,
private val dataManagerCenter: DataManagerCenter,
private val dataManagerGroups: DataManagerGroups
) : ActivateRepository {

override fun activateClient(
clientId: Int,
clientActivate: ActivatePayload?
): Observable<PostClientsClientIdResponse> {
return dataManagerClient.activateClient(clientId, clientActivate)
}

override fun activateCenter(
centerId: Int,
activatePayload: ActivatePayload?
): Observable<PostCentersCenterIdResponse> {
return dataManagerCenter.activateCenter(centerId, activatePayload)
}

override fun activateGroup(
groupId: Int,
activatePayload: ActivatePayload?
): Observable<GenericResponse> {
return dataManagerGroups.activateGroup(groupId, activatePayload)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.ActivateRepository
import com.mifos.core.objects.client.ActivatePayload
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import org.apache.fineract.client.models.PostCentersCenterIdResponse
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

class ActivateCenterUseCase @Inject constructor(private val activateRepository: ActivateRepository) {

suspend operator fun invoke(
centerId: Int,
centerPayload: ActivatePayload
): Flow<Resource<PostCentersCenterIdResponse>> = callbackFlow {
try {

trySend(Resource.Loading())
activateRepository.activateCenter(centerId, centerPayload)
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(Schedulers.io())
.subscribe(object : Subscriber<PostCentersCenterIdResponse>() {
override fun onCompleted() {}

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

override fun onNext(response: PostCentersCenterIdResponse) {
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,43 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.ActivateRepository
import com.mifos.core.objects.client.ActivatePayload
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import org.apache.fineract.client.models.PostClientsClientIdResponse
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

class ActivateClientUseCase @Inject constructor(private val activateRepository: ActivateRepository) {

suspend operator fun invoke(
clientId: Int,
clientPayload: ActivatePayload
): Flow<Resource<PostClientsClientIdResponse>> = callbackFlow {
try {

trySend(Resource.Loading())
activateRepository.activateClient(clientId, clientPayload)
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(Schedulers.io())
.subscribe(object : Subscriber<PostClientsClientIdResponse>() {
override fun onCompleted() {}

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

override fun onNext(response: PostClientsClientIdResponse) {
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,42 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.ActivateRepository
import com.mifos.core.network.GenericResponse
import com.mifos.core.objects.client.ActivatePayload
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 ActivateGroupUseCase @Inject constructor(private val activateRepository: ActivateRepository) {

suspend operator fun invoke(
groupId: Int,
groupPayload: ActivatePayload
): Flow<Resource<GenericResponse>> = callbackFlow {
try {
trySend(Resource.Loading())
activateRepository.activateGroup(groupId, groupPayload)
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(Schedulers.io())
.subscribe(object : Subscriber<GenericResponse>() {
override fun onCompleted() {}

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

override fun onNext(response: GenericResponse) {
trySend(Resource.Success(response))
}
})
awaitClose { channel.close() }
} catch (exception: Exception) {
trySend(Resource.Error(exception.message.toString()))
}
}
}
1 change: 1 addition & 0 deletions feature/activate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
23 changes: 23 additions & 0 deletions feature/activate/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
alias(libs.plugins.mifos.android.library.jacoco)
}

android {
namespace = "com.mifos.feature.activate"
}

dependencies {

implementation(projects.core.domain)

//DBFlow dependencies
kapt(libs.dbflow.processor)
implementation(libs.dbflow)
kapt(libs.github.dbflow.processor)
testImplementation(libs.hilt.android.testing)
testImplementation(projects.core.testing)

androidTestImplementation(projects.core.testing)
}
Empty file.
21 changes: 21 additions & 0 deletions feature/activate/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mifos.feature.activate

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.mifos.feature.activate.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions feature/activate/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Loading

0 comments on commit 6074317

Please sign in to comment.