Skip to content

Commit

Permalink
Merge branch 'kmm-impl' into migrate-settings-module-to-kmp
Browse files Browse the repository at this point in the history
  • Loading branch information
niyajali authored Oct 12, 2024
2 parents 79954e0 + a4360f2 commit 2e6680d
Show file tree
Hide file tree
Showing 41 changed files with 1,169 additions and 659 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class CMPFeatureConventionPlugin : Plugin<Project> {
add("commonMainImplementation", project(":core:designsystem"))
add("commonMainImplementation", project(":core:data"))

add("commonMainImplementation", libs.findLibrary("koin.compose").get())
add("commonMainImplementation", libs.findLibrary("koin.compose.viewmodel").get())

add("commonMainImplementation", libs.findLibrary("jb.composeRuntime").get())
add("commonMainImplementation", libs.findLibrary("jb.composeViewmodel").get())
add("commonMainImplementation", libs.findLibrary("jb.lifecycleViewmodel").get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ interface UserRepository {

suspend fun updateUser(userId: Int, updatedUser: NewUser): Flow<Result<GenericResponse>>

suspend fun updateUserPassword(userId: Long, password: String): Result<String>

suspend fun deleteUser(userId: Int): Result<CommonResponse>

suspend fun assignClientToUser(userId: Int, clientId: Int): Result<Unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.mifospay.core.network.FineractApiManager
import org.mifospay.core.network.model.CommonResponse
import org.mifospay.core.network.model.GenericResponse
import org.mifospay.core.network.model.entity.UserWithRole
import org.mifospay.core.network.model.entity.user.UpdateUserEntityPassword

class UserRepositoryImpl(
private val apiManager: FineractApiManager,
Expand Down Expand Up @@ -56,6 +57,19 @@ class UserRepositoryImpl(
.asResult().flowOn(ioDispatcher)
}

override suspend fun updateUserPassword(userId: Long, password: String): Result<String> {
return try {
apiManager.userApi.updateUserPassword(
userId = userId,
updateUserEntity = UpdateUserEntityPassword(password, password),
)

Result.Success("Password updated successfully")
} catch (e: Exception) {
Result.Error(e)
}
}

override suspend fun deleteUser(userId: Int): Result<CommonResponse> {
return try {
val result = withContext(ioDispatcher) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ package org.mifospay.core.designsystem.component
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
Expand All @@ -38,10 +35,10 @@ fun MifosOutlinedTextField(
trailingIcon: @Composable (() -> Unit)? = null,
keyboardOptions: KeyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
) {
OutlinedTextField(
MifosCustomTextField(
value = value,
onValueChange = onValueChange,
label = { Text(label) },
label = label,
modifier = modifier,
leadingIcon = if (icon != null) {
{
Expand All @@ -56,10 +53,6 @@ fun MifosOutlinedTextField(
trailingIcon = trailingIcon,
maxLines = maxLines,
singleLine = singleLine,
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = MaterialTheme.colorScheme.onSurface,
focusedLabelColor = MaterialTheme.colorScheme.onSurface,
),
textStyle = LocalDensity.current.run {
TextStyle(fontSize = 18.sp, color = MaterialTheme.colorScheme.onSurface)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,56 @@
package org.mifospay.core.designsystem.component

import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.mifospay.core.designsystem.theme.MifosTheme
import org.mifospay.core.designsystem.theme.NewUi

@Composable
fun MfOutlinedTextField(
Expand All @@ -50,11 +74,11 @@ fun MfOutlinedTextField(
trailingIcon: @Composable (() -> Unit)? = null,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
) {
OutlinedTextField(
MifosCustomTextField(
modifier = modifier,
value = value,
onValueChange = onValueChange,
label = { Text(label) },
label = label,
supportingText = {
if (isError) {
Text(text = errorMessage)
Expand All @@ -66,10 +90,6 @@ fun MfOutlinedTextField(
onKeyboardActions?.invoke()
},
keyboardOptions = keyboardOptions,
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = MaterialTheme.colorScheme.onSurface,
focusedLabelColor = MaterialTheme.colorScheme.onSurface,
),
textStyle = LocalDensity.current.run {
TextStyle(fontSize = 18.sp, color = MaterialTheme.colorScheme.onSurface)
},
Expand Down Expand Up @@ -158,6 +178,190 @@ fun MifosOutlinedTextField(
)
}

@Composable
fun MifosTextField(
value: String,
onValueChange: (String) -> Unit,
label: String,
modifier: Modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp),
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = LocalTextStyle.current,
visualTransformation: VisualTransformation = VisualTransformation.None,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = true,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
keyboardOptions: KeyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
trailingIcon: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
indicatorColor: Color? = null,
) {
var isFocused by rememberSaveable { mutableStateOf(false) }

BasicTextField(
value = value,
onValueChange = onValueChange,
textStyle = textStyle,
modifier = modifier
.fillMaxWidth()
.padding(top = 10.dp)
.onFocusChanged { focusState ->
isFocused = focusState.isFocused
}
.semantics(mergeDescendants = true) {},
enabled = enabled,
readOnly = readOnly,
visualTransformation = visualTransformation,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
interactionSource = interactionSource,
singleLine = singleLine,
maxLines = maxLines,
minLines = minLines,
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
decorationBox = { innerTextField ->
Column {
Text(
text = label,
color = MaterialTheme.colorScheme.primary,
style = MaterialTheme.typography.labelLarge,
modifier = Modifier.align(alignment = Alignment.Start),
)

Spacer(modifier = Modifier.height(5.dp))

Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth(),
) {
if (leadingIcon != null) {
leadingIcon()
}

Box(modifier = Modifier.weight(1f)) {
innerTextField()
}

if (trailingIcon != null) {
trailingIcon()
}
}
indicatorColor?.let { color ->
HorizontalDivider(
thickness = 1.dp,
color = if (isFocused) {
color
} else {
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.05f)
},
)
} ?: run {
HorizontalDivider(
thickness = 1.dp,
color = if (isFocused) {
MaterialTheme.colorScheme.primary
} else {
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.05f)
},
)
}
}
},
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MifosCustomTextField(
value: String,
onValueChange: (String) -> Unit,
label: String,
modifier: Modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp),
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = LocalTextStyle.current,
visualTransformation: VisualTransformation = VisualTransformation.None,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = true,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
isError: Boolean = false,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
keyboardOptions: KeyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
trailingIcon: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
supportingText:
@Composable()
(() -> Unit)? = null,
) {
val colors = TextFieldDefaults.colors().copy(
cursorColor = MaterialTheme.colorScheme.primary,
focusedContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent,
errorContainerColor = Color.Transparent,
focusedIndicatorColor = MaterialTheme.colorScheme.primary,
unfocusedIndicatorColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.05f),
focusedTrailingIconColor = NewUi.onSurface.copy(0.15f),
unfocusedTrailingIconColor = NewUi.onSurface.copy(0.15f),
)
BasicTextField(
value = value,
onValueChange = onValueChange,
modifier = modifier,
interactionSource = interactionSource,
enabled = enabled,
singleLine = singleLine,
readOnly = readOnly,
textStyle = textStyle,
visualTransformation = visualTransformation,
keyboardActions = keyboardActions,
maxLines = maxLines,
minLines = minLines,
keyboardOptions = keyboardOptions,
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
) {
TextFieldDefaults.DecorationBox(
value = value,
visualTransformation = VisualTransformation.None,
innerTextField = it,
singleLine = singleLine,
enabled = enabled,
interactionSource = interactionSource,
label = {
Text(
text = label,
color = MaterialTheme.colorScheme.primary,
style = MaterialTheme.typography.labelLarge,
modifier = Modifier.padding(bottom = 10.dp),
)
},
trailingIcon = trailingIcon,
leadingIcon = leadingIcon,
supportingText = supportingText,
colors = colors,
isError = isError,
contentPadding = PaddingValues(bottom = 10.dp),
container = {
TextFieldDefaults.Container(
enabled = enabled,
isError = isError,
colors = colors,
interactionSource = interactionSource,
shape = RectangleShape,
focusedIndicatorLineThickness = 1.dp,
unfocusedIndicatorLineThickness = 1.dp,
)
},
)
}
}

@Preview
@Composable
fun MfOutlinedTextFieldPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.outlined.Lock
import androidx.compose.material.icons.outlined.Notifications
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.Visibility
import androidx.compose.material.icons.outlined.VisibilityOff
import androidx.compose.material.icons.outlined.Wallet
import androidx.compose.material.icons.rounded.AccountBalance
import androidx.compose.material.icons.rounded.AccountCircle
Expand All @@ -67,6 +69,8 @@ object MifosIcons {
val QrCode: ImageVector = Icons.Filled.QrCode
val Close: ImageVector = Icons.Filled.Close
val AttachMoney: ImageVector = Icons.Filled.AttachMoney
val OutlinedVisibilityOff: ImageVector = Icons.Outlined.VisibilityOff
val OutlinedVisibility: ImageVector = Icons.Outlined.Visibility
val VisibilityOff: ImageVector = Icons.Filled.VisibilityOff
val Visibility: ImageVector = Icons.Filled.Visibility
val Check: ImageVector = Icons.Default.Check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ package org.mifospay.core.network.model.entity.user
import kotlinx.serialization.Serializable

@Serializable
data class UpdateUserEntityPassword(val password: String) {
val repeatPassword: String = password
}
data class UpdateUserEntityPassword(
val password: String,
val repeatPassword: String,
)

@Serializable
data class UpdateUserPasswordResponse(
val officeId: Long,
val resourceId: Long,
val changes: Changes,
)

@Serializable
data class Changes(
val passwordEncoded: String,
)
Loading

0 comments on commit 2e6680d

Please sign in to comment.