forked from openMF/android-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor Activate fragment to compose (openMF#2123)
- Loading branch information
1 parent
c1e7d2c
commit 6074317
Showing
20 changed files
with
649 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/data/src/main/java/com/mifos/core/data/repository/ActivateRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
core/data/src/main/java/com/mifos/core/data/repository_imp/ActivateRepositoryImp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
core/domain/src/main/java/com/mifos/core/domain/use_cases/ActivateCenterUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
core/domain/src/main/java/com/mifos/core/domain/use_cases/ActivateClientUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
core/domain/src/main/java/com/mifos/core/domain/use_cases/ActivateGroupUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 24 additions & 0 deletions
24
feature/activate/src/androidTest/java/com/mifos/feature/activate/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.