Skip to content

Commit

Permalink
refactor: refactor add loan account fragment to compose (openMF#2126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 authored Jul 6, 2024
1 parent 3f9f33d commit fb969f6
Show file tree
Hide file tree
Showing 26 changed files with 1,237 additions and 732 deletions.
11 changes: 8 additions & 3 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 @@ -5,23 +5,25 @@ import com.mifos.core.data.repository.CenterDetailsRepository
import com.mifos.core.data.repository.CenterListRepository
import com.mifos.core.data.repository.CheckerInboxRepository
import com.mifos.core.data.repository.CheckerInboxTasksRepository
import com.mifos.core.data.repository.ClientIdentifiersRepository
import com.mifos.core.data.repository.ClientChargeRepository
import com.mifos.core.data.repository.ClientIdentifiersRepository
import com.mifos.core.data.repository.CreateNewCenterRepository
import com.mifos.core.data.repository.GroupDetailsRepository
import com.mifos.core.data.repository.GroupsListRepository
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.CenterDetailsRepositoryImp
import com.mifos.core.data.repository_imp.CenterListRepositoryImp
import com.mifos.core.data.repository_imp.CheckerInboxRepositoryImp
import com.mifos.core.data.repository_imp.CheckerInboxTasksRepositoryImp
import com.mifos.core.data.repository_imp.ClientIdentifiersRepositoryImp
import com.mifos.core.data.repository_imp.ClientChargeRepositoryImp
import com.mifos.core.data.repository_imp.ClientIdentifiersRepositoryImp
import com.mifos.core.data.repository_imp.CreateNewCenterRepositoryImp
import com.mifos.core.data.repository_imp.GroupDetailsRepositoryImp
import com.mifos.core.data.repository_imp.GroupsListRepositoryImpl
import com.mifos.core.data.repository_imp.LoanAccountRepositoryImp
import com.mifos.core.data.repository_imp.NewIndividualCollectionSheetRepositoryImp
import com.mifos.core.data.repository_imp.PathTrackingRepositoryImp
import com.mifos.core.data.repository_imp.ReportCategoryRepositoryImp
Expand Down Expand Up @@ -65,10 +67,13 @@ abstract class DataModule {

@Binds
internal abstract fun bindClientChargeRepository(impl: ClientChargeRepositoryImp): ClientChargeRepository

@Binds
internal abstract fun bindCreateNewCenterRepository(impl: CreateNewCenterRepositoryImp): CreateNewCenterRepository

@Binds
internal abstract fun bindClientIdentifiersRepository(impl: ClientIdentifiersRepositoryImp): ClientIdentifiersRepository

@Binds
internal abstract fun bindLoanAccountRepository(impl: LoanAccountRepositoryImp): LoanAccountRepository
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.online.loanaccount
package com.mifos.core.data.repository

import com.mifos.core.data.LoansPayload
import com.mifos.core.objects.accounts.loan.Loans
Expand All @@ -11,11 +11,9 @@ import rx.Observable
*/
interface LoanAccountRepository {

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

fun getLoansAccountTemplate(clientId: Int, productId: Int): Observable<LoanTemplate>

fun createLoansAccount(loansPayload: LoansPayload?): Observable<Loans>
suspend fun allLoans(): Observable<List<LoanProducts>>

suspend fun getLoansAccountTemplate(clientId: Int, productId: Int): Observable<LoanTemplate>

suspend fun createLoansAccount(loansPayload: LoansPayload): Observable<Loans>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mifos.mifosxdroid.online.loanaccount
package com.mifos.core.data.repository_imp

import com.mifos.core.data.LoansPayload
import com.mifos.core.data.repository.LoanAccountRepository
import com.mifos.core.network.datamanager.DataManagerLoan
import com.mifos.core.objects.accounts.loan.Loans
import com.mifos.core.objects.organisation.LoanProducts
Expand All @@ -14,15 +15,18 @@ import javax.inject.Inject
class LoanAccountRepositoryImp @Inject constructor(private val dataManagerLoan: DataManagerLoan) :
LoanAccountRepository {

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

override fun getLoansAccountTemplate(clientId: Int, productId: Int): Observable<LoanTemplate> {
override suspend fun getLoansAccountTemplate(
clientId: Int,
productId: Int
): Observable<LoanTemplate> {
return dataManagerLoan.getLoansAccountTemplate(clientId, productId)
}

override fun createLoansAccount(loansPayload: LoansPayload?): Observable<Loans> {
override suspend fun createLoansAccount(loansPayload: LoansPayload): Observable<Loans> {
return dataManagerLoan.createLoansAccount(loansPayload)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fun MifosOutlinedTextField(
modifier: Modifier = Modifier,
value: String,
label: String,
leadingIcon: ImageVector,
leadingIcon: ImageVector? = null,
maxLines: Int = 1,
isError: Boolean = false,
errorText: String? = null,
Expand Down Expand Up @@ -205,7 +205,7 @@ fun MifosOutlinedTextField(
)
},
leadingIcon = {
Icon(imageVector = leadingIcon, contentDescription = "leadingIcon")
leadingIcon?.let { Icon(imageVector = it, contentDescription = "leadingIcon") }
},
trailingIcon = @Composable {
if (isPasswordToggleDisplayed) {
Expand Down Expand Up @@ -261,6 +261,62 @@ fun MifosOutlinedTextField(
)
}

@Composable
fun MifosOutlinedTextField(
modifier: Modifier = Modifier.fillMaxWidth().padding(start = 16.dp, end = 16.dp),
value: String,
onValueChange: (String) -> Unit,
maxLines: Int = 1,
singleLine: Boolean = true,
icon: ImageVector? = null,
label: String,
visualTransformation: VisualTransformation = VisualTransformation.None,
trailingIcon: @Composable (() -> Unit)? = null,
keyboardType: KeyboardType = KeyboardType.Text,
error: Int?
) {

OutlinedTextField(
value = value,
onValueChange = onValueChange,
label = { Text(label) },
modifier = modifier,
leadingIcon = if (icon != null) {
{
Icon(
imageVector = icon,
contentDescription = null,
tint = if (isSystemInDarkTheme()) White else DarkGray
)
}
} else null,
trailingIcon = trailingIcon,
maxLines = maxLines,
singleLine = singleLine,
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary,
focusedLabelColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary
),
textStyle = LocalDensity.current.run {
TextStyle(fontSize = 18.sp)
},
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next,keyboardType = keyboardType),
visualTransformation = visualTransformation,
isError = error != null,
supportingText = if (error != null) {
{
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(id = error),
color = MaterialTheme.colorScheme.error
)
}
} else {
null
}
)
}

@Composable
private fun PasswordToggleIcon(
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -309,7 +365,7 @@ private fun ClearIconButton(
)
}
}

}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import com.mifos.core.designsystem.theme.BluePrimaryDark

@Composable
fun MifosTextFieldDropdown(
modifier: Modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp),
value: String,
onValueChanged: (String) -> Unit,
onOptionSelected: (Int, String) -> Unit,
Expand All @@ -47,10 +50,7 @@ fun MifosTextFieldDropdown(
value = value,
onValueChange = { onValueChanged(it) },
label = { Text(text = stringResource(id = label)) },
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp)
.menuAnchor(),
modifier = modifier.menuAnchor(),
maxLines = 1,
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.LoansPayload
import com.mifos.core.data.repository.LoanAccountRepository
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 CreateLoanAccountUseCase @Inject constructor(private val loanAccountRepository: LoanAccountRepository) {

suspend operator fun invoke(loansPayload: LoansPayload): Flow<Resource<Loans>> = callbackFlow {
try {
trySend(Resource.Loading())
loanAccountRepository.createLoansAccount(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(loans: Loans) {
trySend(Resource.Success(loans))
}
})

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,38 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.LoanAccountRepository
import com.mifos.core.objects.organisation.LoanProducts
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 GetAllLoanUseCase @Inject constructor(private val loanAccountRepository: LoanAccountRepository) {

suspend operator fun invoke(): Flow<Resource<List<LoanProducts>>> = callbackFlow {
try {
trySend(Resource.Loading())
loanAccountRepository.allLoans()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<List<LoanProducts>>() {
override fun onCompleted() {}

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

override fun onNext(products: List<LoanProducts>) {
trySend(Resource.Success(products))
}
})
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,41 @@
package com.mifos.core.domain.use_cases

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

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

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

override fun onNext(loanTemplate: LoanTemplate?) {
trySend(Resource.Success(loanTemplate))
}
})

awaitClose { channel.close() }

} catch (exception: Exception) {
trySend(Resource.Error(exception.message.toString()))
}
}
}
1 change: 1 addition & 0 deletions feature/loan/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
23 changes: 23 additions & 0 deletions feature/loan/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.loan"
}

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 added feature/loan/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions feature/loan/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
Loading

0 comments on commit fb969f6

Please sign in to comment.