Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,24 @@ fun MifosOutlinedTextField(
value: String,
onValueChange: (String) -> Unit,
maxLines: Int = 1,
readOnly : Boolean = false,
singleLine: Boolean = true,
icon: ImageVector? = null,
label: String,
visualTransformation: VisualTransformation = VisualTransformation.None,
trailingIcon: @Composable (() -> Unit)? = null,
keyboardType: KeyboardType = KeyboardType.Text,
error: Int?
error: Int?,
enabled: Boolean = true
) {

OutlinedTextField(
value = value,
onValueChange = onValueChange,
label = { Text(label) },
modifier = modifier,
readOnly = readOnly,
enabled = enabled,
leadingIcon = if (icon != null) {
{
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.mifos.core.designsystem.theme.DarkGray
fun MifosSweetError(
message: String,
isRetryEnabled : Boolean = true,
buttonText : String = stringResource(id = R.string.core_designsystem_try_again),
onclick: () -> Unit
) {
Column(
Expand Down Expand Up @@ -87,7 +88,7 @@ fun MifosSweetError(
) {
Text(
modifier = Modifier.padding(start = 20.dp, end = 20.dp),
text = stringResource(id = R.string.core_designsystem_try_again),
text = buttonText,
fontSize = 15.sp
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ fun MifosTextFieldDropdown(
maxLines = 1,
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary,
),
focusedLabelColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary,
),
textStyle = LocalDensity.current.run {
TextStyle(fontSize = 18.sp)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mifos.mifosxdroid.online.savingsaccount
import com.mifos.core.objects.client.Savings
import com.mifos.core.objects.organisation.ProductSavings
import com.mifos.core.objects.templates.savings.SavingProductsTemplate
import com.mifos.core.objects.zipmodels.SavingProductsAndTemplate

/**
* Created by Aditya Gupta on 08/08/23.
Expand All @@ -13,10 +14,7 @@ sealed class SavingAccountUiState {

data class ShowFetchingError(val message: Int) : SavingAccountUiState()

data class ShowSavingsAccounts(val getProductSaving: List<ProductSavings>?) :
SavingAccountUiState()

data class ShowSavingsAccountTemplateByProduct(val savingProductsTemplate: SavingProductsTemplate) :
data class LoadAllSavings(val savingsTemplate: SavingProductsAndTemplate) :
SavingAccountUiState()

data class ShowSavingsAccountCreatedSuccessfully(val savings: Savings?) : SavingAccountUiState()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.mifos.mifosxdroid.online.savingsaccount

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.data.SavingsPayload
import com.mifos.core.objects.accounts.savings.FieldOfficerOptions
import com.mifos.core.objects.client.Savings
Expand All @@ -12,6 +12,11 @@ import com.mifos.core.objects.templates.savings.SavingProductsTemplate
import com.mifos.core.objects.zipmodels.SavingProductsAndTemplate
import com.mifos.mifosxdroid.R
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import rx.Observable
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
Expand All @@ -25,10 +30,23 @@ import javax.inject.Inject
class SavingAccountViewModel @Inject constructor(private val repository: SavingsAccountRepository) :
ViewModel() {

private val _savingAccountUiState = MutableLiveData<SavingAccountUiState>()
private val _savingAccountUiState = MutableStateFlow<SavingAccountUiState>(SavingAccountUiState.ShowProgress)
val savingAccountUiState: StateFlow<SavingAccountUiState> get() = _savingAccountUiState

val savingAccountUiState: LiveData<SavingAccountUiState>
get() = _savingAccountUiState
var clientId = 0
var groupId = 0
var isGroupAccount = false

private val _savingProductsTemplate = MutableStateFlow(SavingProductsTemplate())
val savingProductsTemplate = _savingProductsTemplate.asStateFlow()

fun loadLoanTemplateByProduct(productId: Int) {
if (isGroupAccount) {
loadGroupSavingAccountTemplateByProduct(groupId, productId)
} else {
loadClientSavingAccountTemplateByProduct(clientId, productId)
}
}

fun loadSavingsAccountsAndTemplate() {
_savingAccountUiState.value = SavingAccountUiState.ShowProgress
Expand All @@ -46,14 +64,15 @@ class SavingAccountViewModel @Inject constructor(private val repository: Savings
}

override fun onNext(productsAndTemplate: SavingProductsAndTemplate?) {
_savingAccountUiState.value =
SavingAccountUiState.ShowSavingsAccounts(productsAndTemplate?.getmProductSavings())
if (productsAndTemplate != null) {
_savingAccountUiState.value =
SavingAccountUiState.LoadAllSavings(productsAndTemplate)
}
}
})
}

fun loadClientSavingAccountTemplateByProduct(clientId: Int, productId: Int) {
_savingAccountUiState.value = SavingAccountUiState.ShowProgress
private fun loadClientSavingAccountTemplateByProduct(clientId: Int, productId: Int) {
repository.getClientSavingsAccountTemplateByProduct(clientId, productId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
Expand All @@ -67,17 +86,13 @@ class SavingAccountViewModel @Inject constructor(private val repository: Savings
}

override fun onNext(savingProductsTemplate: SavingProductsTemplate?) {
_savingAccountUiState.value = savingProductsTemplate?.let {
SavingAccountUiState.ShowSavingsAccountTemplateByProduct(
it
)
}
_savingProductsTemplate.value =
savingProductsTemplate ?: SavingProductsTemplate()
}
})
}

fun loadGroupSavingAccountTemplateByProduct(groupId: Int, productId: Int) {
_savingAccountUiState.value = SavingAccountUiState.ShowProgress
private fun loadGroupSavingAccountTemplateByProduct(groupId: Int, productId: Int) {
repository.getGroupSavingsAccountTemplateByProduct(groupId, productId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
Expand All @@ -91,11 +106,8 @@ class SavingAccountViewModel @Inject constructor(private val repository: Savings
}

override fun onNext(savingProductsTemplate: SavingProductsTemplate?) {
_savingAccountUiState.value = savingProductsTemplate?.let {
SavingAccountUiState.ShowSavingsAccountTemplateByProduct(
it
)
}
_savingProductsTemplate.value =
savingProductsTemplate ?: SavingProductsTemplate()
}
})
}
Expand All @@ -118,32 +130,4 @@ class SavingAccountViewModel @Inject constructor(private val repository: Savings
}
})
}

fun filterSpinnerOptions(interestTypes: List<InterestType>?): List<String> {
val interestNameList = ArrayList<String>()
Observable.from(interestTypes)
.subscribe { interestType -> interestType.value?.let { interestNameList.add(it) } }
return interestNameList
}

fun filterSavingProductsNames(productSavings: List<ProductSavings>?): List<String> {
val productsNames = ArrayList<String>()
Observable.from(productSavings)
.subscribe { product -> product.name?.let { productsNames.add(it) } }
return productsNames
}

fun filterFieldOfficerNames(fieldOfficerOptions: List<FieldOfficerOptions>?): List<String> {
val fieldOfficerNames = ArrayList<String>()
Observable.from(fieldOfficerOptions)
.subscribe { fieldOfficerOptions ->
fieldOfficerOptions.displayName?.let {
fieldOfficerNames.add(
it
)
}
}
return fieldOfficerNames
}

}
Loading