Skip to content

Commit

Permalink
Merge branch 'master' into activate
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 authored Jul 7, 2024
2 parents 46023e5 + fb969f6 commit 2f378c9
Show file tree
Hide file tree
Showing 40 changed files with 3,060 additions and 1,076 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
Expand Up @@ -11,6 +11,7 @@ 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
Expand All @@ -24,6 +25,7 @@ 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 @@ -76,4 +78,7 @@ abstract class DataModule {

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

@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
@@ -1,6 +1,7 @@
package com.mifos.core.designsystem.component

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.Image
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsFocusedAsState
import androidx.compose.foundation.isSystemInDarkTheme
Expand All @@ -23,9 +24,12 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.ImeAction
Expand Down Expand Up @@ -98,13 +102,68 @@ fun MifosOutlinedTextField(
)
}

@Composable
fun MifosOutlinedTextField(
value: String,
onValueChange: (String) -> Unit,
maxLines: Int = 1,
singleLine: Boolean = true,
icon: ImageVector? = null,
label: String,
visualTransformation: VisualTransformation = VisualTransformation.None,
trailingIcon: @Composable (() -> Unit)? = null,
error: Int?
) {

OutlinedTextField(
value = value,
onValueChange = onValueChange,
label = { Text(label) },
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp),
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),
visualTransformation = visualTransformation,
isError = error != null,
supportingText = if (error != null) {
{
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(id = error),
color = MaterialTheme.colorScheme.error
)
}
} else {
null
}
)
}

@Composable
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 @@ -146,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 @@ -202,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 @@ -250,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()))
}
}
}
Loading

0 comments on commit 2f378c9

Please sign in to comment.