Skip to content

Commit

Permalink
MIFOSAC-301 applied spotless and detekt on core:ui
Browse files Browse the repository at this point in the history
  • Loading branch information
itsPronay committed Dec 6, 2024
1 parent 7cbe06d commit b2bc30f
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 91 deletions.
9 changes: 9 additions & 0 deletions core/ui/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
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
/*
* 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.ui

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import junit.framework.TestCase.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand All @@ -21,4 +28,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.mifos.core.ui.test", appContext.packageName)
}
}
}
9 changes: 9 additions & 0 deletions core/ui/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>
23 changes: 16 additions & 7 deletions core/ui/src/main/java/com/mifos/core/ui/components/MifosEmptyUi.kt
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.ui.components

import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -26,8 +35,8 @@ import com.mifos.core.designsystem.theme.DarkGray

@Composable
fun MifosEmptyUi(
modifier: Modifier = Modifier,
text: String,
modifier: Modifier = Modifier,
icon: ImageVector = Icons.Default.Info,
) {
Box(
Expand All @@ -36,21 +45,21 @@ fun MifosEmptyUi(
.semantics {
contentDescription = "MifosEmptyUi"
},
contentAlignment = Alignment.Center
contentAlignment = Alignment.Center,
) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(18.dp)
.align(Alignment.Center),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(20.dp, Alignment.CenterVertically)
verticalArrangement = Arrangement.spacedBy(20.dp, Alignment.CenterVertically),
) {
Icon(
imageVector = icon,
contentDescription = text + icon.name,
tint = Color.Gray,
modifier = Modifier.size(70.dp)
modifier = Modifier.size(70.dp),
)

Text(
Expand All @@ -59,9 +68,9 @@ fun MifosEmptyUi(
fontSize = 14.sp,
fontWeight = FontWeight.Normal,
fontStyle = FontStyle.Normal,
color = DarkGray
)
color = DarkGray,
),
)
}
}
}
}
19 changes: 14 additions & 5 deletions core/ui/src/main/java/com/mifos/core/ui/components/MifosFAB.kt
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.ui.components

import androidx.compose.foundation.layout.Box
Expand All @@ -12,23 +21,23 @@ import com.mifos.core.designsystem.theme.BlueSecondary

@Composable
fun MifosFAB(
modifier: Modifier = Modifier,
icon: ImageVector,
onClick: () -> Unit,
modifier: Modifier = Modifier,
containerColor: Color = BlueSecondary,
) {
Box(
modifier = modifier,
contentAlignment = Alignment.BottomEnd
contentAlignment = Alignment.BottomEnd,
) {
FloatingActionButton(
onClick = onClick,
containerColor = containerColor
containerColor = containerColor,
) {
Icon(
imageVector = icon,
contentDescription = "MifosFab"
contentDescription = "MifosFab",
)
}
}
}
}
21 changes: 14 additions & 7 deletions core/ui/src/main/java/com/mifos/core/ui/components/MifosToolbar.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
/*
* 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.ui.components

import androidx.compose.foundation.layout.RowScope
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material.icons.rounded.Sync
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
Expand All @@ -19,16 +26,16 @@ import com.mifos.core.designsystem.theme.BlueSecondary
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SelectionModeTopAppBar(
modifier: Modifier = Modifier,
itemCount: Int,
resetSelectionMode: () -> Unit,
modifier: Modifier = Modifier,
containerColor: Color = BlueSecondary,
actions : @Composable RowScope.() -> Unit = {}
actions: @Composable RowScope.() -> Unit = {},
) {
TopAppBar(
modifier = modifier,
colors = TopAppBarDefaults.topAppBarColors(
containerColor = containerColor
containerColor = containerColor,
),
title = {
Text(text = "$itemCount selected")
Expand All @@ -43,6 +50,6 @@ fun SelectionModeTopAppBar(
)
}
},
actions = actions
actions = actions,
)
}
}
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.ui.components

import androidx.compose.animation.AnimatedVisibility
Expand All @@ -23,7 +32,9 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp

enum class FabType {
CLIENT, CENTER, GROUP
CLIENT,
CENTER,
GROUP,
}

sealed class FabButtonState {
Expand All @@ -47,53 +58,55 @@ data class FabButton(

@Composable
fun FabItem(
modifier: Modifier = Modifier,
fabButton: FabButton,
onFabClick: (FabType) -> Unit
modifier: Modifier = Modifier,
onFabClick: (FabType) -> Unit,
) {
FloatingActionButton(
onClick = {
onFabClick(fabButton.fabType)
},
modifier = modifier
.size(48.dp)
.size(48.dp),
) {
Icon(
painter = painterResource(id = fabButton.iconRes),
contentDescription = fabButton.fabType.name
contentDescription = fabButton.fabType.name,
)
}
}

@Composable
fun MultiFloatingActionButton(
modifier: Modifier = Modifier,
fabButtons: List<FabButton>,
fabButtonState: FabButtonState,
onFabButtonStateChange: (FabButtonState) -> Unit,
modifier: Modifier = Modifier,
onFabClick: (FabType) -> Unit,
) {
val rotation by animateFloatAsState(
if (fabButtonState.isExpanded())
if (fabButtonState.isExpanded()) {
45f
else
0f, label = "mainFabRotation"
} else {
0f
},
label = "mainFabRotation",
)

Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally
horizontalAlignment = Alignment.CenterHorizontally,
) {
AnimatedVisibility(
visible = fabButtonState.isExpanded(),
enter = fadeIn() + expandVertically(),
exit = fadeOut() + shrinkVertically()
exit = fadeOut() + shrinkVertically(),
) {
Column {
fabButtons.forEach {
FabItem(
fabButton = it,
onFabClick = onFabClick
onFabClick = onFabClick,
)
Spacer(modifier = Modifier.height(24.dp))
}
Expand All @@ -105,12 +118,12 @@ fun MultiFloatingActionButton(
onFabButtonStateChange(fabButtonState.toggleValue())
},
modifier = Modifier
.rotate(rotation)
.rotate(rotation),
) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = "mainFabIcon"
contentDescription = "mainFabIcon",
)
}
}
}
}
11 changes: 10 additions & 1 deletion core/ui/src/main/java/com/mifos/core/ui/util/DevicePreviews.kt
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.ui.util

import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -10,4 +19,4 @@ import androidx.compose.ui.tooling.preview.Preview
@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480")
@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480")
@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480")
annotation class DevicePreviews
annotation class DevicePreviews
Loading

0 comments on commit b2bc30f

Please sign in to comment.