Skip to content

Commit

Permalink
MIFOSAC-282 (#2272)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya3815 authored Dec 23, 2024
1 parent 52db705 commit fee8541
Show file tree
Hide file tree
Showing 26 changed files with 487 additions and 208 deletions.
2 changes: 1 addition & 1 deletion config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ complexity:
LongParameterList:
active: true
# Updating Common values based on current scenario
functionThreshold: 20 #6
functionThreshold: 30 #6
constructorThreshold: 30 #7
ignoreDefaultParameters: false
ignoreDataClasses: true
Expand Down
9 changes: 9 additions & 0 deletions core/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.library)
alias(libs.plugins.mifos.android.library.compose)
Expand Down
9 changes: 9 additions & 0 deletions core/designsystem/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 Mifos Initiative
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/.
See https://github.com/openMF/android-client/blob/master/LICENSE.md
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path

class DrawingState {
var usedColors: MutableState<Set<Color>> = mutableStateOf(setOf())
private set
var paths: SnapshotStateList<PathState> = mutableStateListOf()
private set
var currentPath: MutableState<Path> = mutableStateOf(Path())
private set

fun addUsedColor(color: Color) {
usedColors.value = usedColors.value + color
}

fun addPath(pathState: PathState) {
paths.add(pathState)
}

fun updateCurrentPath(action: (Path) -> Unit) {
currentPath.value = currentPath.value.also(action)
}

fun resetCurrentPath() {
currentPath.value = Path()
}
}

data class PathState(
val path: Path,
val color: Color,
val stroke: Float,
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.designsystem.component

import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -34,10 +43,10 @@ fun MifosDialogBox(
showDialogState: Boolean,
onDismiss: () -> Unit,
title: Int,
message: Int? = null,
confirmButtonText: Int,
onConfirm: () -> Unit,
dismissButtonText: Int
dismissButtonText: Int,
message: Int? = null,
) {
if (showDialogState) {
AlertDialog(
Expand All @@ -52,7 +61,7 @@ fun MifosDialogBox(
TextButton(
onClick = {
onConfirm()
}
},
) {
Text(stringResource(id = confirmButtonText))
}
Expand All @@ -61,30 +70,30 @@ fun MifosDialogBox(
TextButton(onClick = onDismiss) {
Text(stringResource(id = dismissButtonText))
}
}
},
)
}
}


@Composable
fun MifosRadioButtonDialog(
titleResId: Int,
selectedItem: String,
items: Array<String>,
selectItem: (item: String, index: Int) -> Unit,
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
) {
Dialog(
onDismissRequest = { onDismissRequest.invoke() }
onDismissRequest = { onDismissRequest.invoke() },
) {
Card {
Card(modifier = modifier) {
Column(modifier = Modifier.padding(20.dp)) {
Text(text = stringResource(id = titleResId))
LazyColumn(
modifier = Modifier
.fillMaxWidth()
.heightIn(max = 500.dp)
.heightIn(max = 500.dp),
) {
itemsIndexed(items = items) { index, item ->
Row(
Expand All @@ -94,18 +103,18 @@ fun MifosRadioButtonDialog(
onDismissRequest.invoke()
selectItem.invoke(item, index)
}
.fillMaxWidth()
.fillMaxWidth(),
) {
RadioButton(
selected = (item == selectedItem),
onClick = {
onDismissRequest.invoke()
selectItem.invoke(item, index)
}
},
)
Text(
text = item,
modifier = Modifier.padding(start = 4.dp)
modifier = Modifier.padding(start = 4.dp),
)
}
}
Expand All @@ -120,17 +129,18 @@ fun UpdateEndpointDialogScreen(
initialBaseURL: String?,
initialTenant: String?,
onDismissRequest: () -> Unit,
handleEndpointUpdate: (baseURL: String, tenant: String) -> Unit
handleEndpointUpdate: (baseURL: String, tenant: String) -> Unit,
modifier: Modifier = Modifier,
) {
var baseURL by rememberSaveable { mutableStateOf(initialBaseURL) }
var tenant by rememberSaveable { mutableStateOf(initialTenant) }

Dialog(
onDismissRequest = { onDismissRequest.invoke() }
onDismissRequest = { onDismissRequest.invoke() },
) {
Card {
Column(
modifier = Modifier
modifier = modifier
.fillMaxWidth()
.padding(20.dp),
) {
Expand All @@ -141,7 +151,7 @@ fun UpdateEndpointDialogScreen(
OutlinedTextField(
value = it,
onValueChange = { baseURL = it },
label = { Text(text = stringResource(id = R.string.core_designsystem_enter_base_url)) }
label = { Text(text = stringResource(id = R.string.core_designsystem_enter_base_url)) },
)
}

Expand All @@ -151,30 +161,30 @@ fun UpdateEndpointDialogScreen(
OutlinedTextField(
value = it,
onValueChange = { tenant = it },
label = { Text(text = stringResource(id = R.string.core_designsystem_enter_tenant)) }
label = { Text(text = stringResource(id = R.string.core_designsystem_enter_tenant)) },
)
}

Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End
horizontalArrangement = Arrangement.End,
) {
TextButton(
onClick = { onDismissRequest.invoke() }) {
onClick = { onDismissRequest.invoke() },
) {
Text(text = stringResource(id = R.string.core_designsystem_cancel))
}
TextButton(
onClick = {
if (baseURL != null && tenant != null) {
handleEndpointUpdate.invoke(baseURL ?: "", tenant ?: "")
}
}
)
{
},
) {
Text(text = stringResource(id = R.string.core_designsystem_dialog_action_ok))
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.designsystem.component

import androidx.compose.foundation.Image
Expand All @@ -12,12 +21,10 @@ import androidx.compose.ui.unit.dp
*/

@Composable
fun MifosAndroidClientIcon(id: Int) {

fun MifosAndroidClientIcon(id: Int, modifier: Modifier = Modifier) {
Image(
painter = painterResource(id = id),
contentDescription = null,
modifier = Modifier
.size(200.dp, 100.dp)
modifier = modifier.then(Modifier.size(200.dp, 100.dp)),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
@file:OptIn(ExperimentalMaterial3Api::class)

package com.mifos.core.designsystem.component
Expand Down Expand Up @@ -31,7 +40,6 @@ fun MifosBottomSheet(
val modalSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
var showBottomSheet by remember { mutableStateOf(true) }


fun dismissSheet() {
coroutineScope.launch { modalSheetState.hide() }.invokeOnCompletion {
if (!modalSheetState.isVisible) {
Expand Down Expand Up @@ -73,4 +81,4 @@ fun MifosBottomSheetPreview() {
},
{},
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.designsystem.component

import DrawingState
import PathState
import android.view.MotionEvent
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -12,27 +23,28 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.input.pointer.pointerInteropFilter
import com.mifos.core.designsystem.utility.PathState

@ExperimentalComposeUiApi
@Composable
fun MifosDrawingCanvas(
drawColor: Color,
drawBrush: Float,
usedColors: MutableSet<Color>,
paths: MutableList<PathState>
modifier: Modifier = Modifier,
drawingState: DrawingState = remember { DrawingState() },
) {
val currentPath = paths.last().path
val movePath = remember { mutableStateOf<Offset?>(null) }

Canvas(
modifier = Modifier
modifier = modifier
.fillMaxSize()
.pointerInteropFilter {
when (it.action) {
MotionEvent.ACTION_DOWN -> {
currentPath.moveTo(it.x, it.y)
usedColors.add(drawColor)
drawingState.updateCurrentPath { path ->
path.moveTo(it.x, it.y)
}
drawingState.addUsedColor(drawColor)
drawingState.addPath(PathState(drawingState.currentPath.value, drawColor, drawBrush))
}

MotionEvent.ACTION_MOVE -> {
Expand All @@ -41,26 +53,29 @@ fun MifosDrawingCanvas(

else -> {
movePath.value = null
drawingState.resetCurrentPath()
}
}
true
}
},
) {
movePath.value?.let {
currentPath.lineTo(it.x, it.y)
drawingState.updateCurrentPath { path ->
path.lineTo(it.x, it.y)
}
drawPath(
path = currentPath,
path = drawingState.currentPath.value,
color = drawColor,
style = Stroke(drawBrush)
style = Stroke(drawBrush),
)
}

paths.forEach {
drawingState.paths.forEach {
drawPath(
path = it.path,
color = Color.Red,
style = Stroke(it.stroke)
color = it.color,
style = Stroke(it.stroke),
)
}
}
}
}
Loading

0 comments on commit fee8541

Please sign in to comment.