Skip to content

Commit

Permalink
Applying spotless and detekt on about module (JIRA 280) (#2244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkeye14 authored Nov 29, 2024
1 parent 2fa724c commit 9c6958e
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 91 deletions.
9 changes: 9 additions & 0 deletions feature/about/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.feature)
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.feature.about

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

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.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.feature.about.test", appContext.packageName)
}
}
}
9 changes: 9 additions & 0 deletions feature/about/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>
13 changes: 11 additions & 2 deletions feature/about/src/main/java/com/mifos/feature/about/AboutItem.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.feature.about

import androidx.compose.ui.graphics.Color
Expand All @@ -7,5 +16,5 @@ data class AboutItem(
val title: Int,
val subtitle: Int?,
val color: Color,
val id: AboutItems
)
val id: AboutItems,
)
143 changes: 76 additions & 67 deletions feature/about/src/main/java/com/mifos/feature/about/AboutScreen.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.feature.about

import androidx.compose.foundation.Image
Expand Down Expand Up @@ -42,11 +51,11 @@ import com.mifos.core.designsystem.theme.White
import com.mifos.core.designsystem.theme.aboutItemTextStyle
import com.mifos.core.designsystem.theme.aboutItemTextStyleBold


@Composable
fun AboutScreen(onBackPressed: () -> Unit) {

val viewModel: AboutViewModel = hiltViewModel()
internal fun AboutScreen(
onBackPressed: () -> Unit,
viewModel: AboutViewModel = hiltViewModel()
) {
val state by viewModel.aboutUiState.collectAsStateWithLifecycle()
val uriHandler = LocalUriHandler.current

Expand All @@ -72,35 +81,34 @@ fun AboutScreen(onBackPressed: () -> Unit) {

AboutItems.LICENSE -> uriHandler.openUri("https://github.com/openMF/android-client/blob/master/LICENSE.md")
}
}
},
)
}

@Composable
fun AboutScreen(
internal fun AboutScreen(
state: AboutUiState,
onBackPressed: () -> Unit,
onRetry: () -> Unit,
onOptionClick: (AboutItems) -> Unit
onOptionClick: (AboutItems) -> Unit,
) {

val snackbarHostState = remember { SnackbarHostState() }

MifosScaffold(
icon = MifosIcons.arrowBack,
title = stringResource(R.string.feature_about),
onBackPressed = onBackPressed,
snackbarHostState = snackbarHostState
snackbarHostState = snackbarHostState,
) { paddingValues ->
Column(
modifier = Modifier.padding(paddingValues),
horizontalAlignment = Alignment.CenterHorizontally
horizontalAlignment = Alignment.CenterHorizontally,
) {
when (state) {
is AboutUiState.AboutOptions -> {
AboutScreenContent(
aboutOptions = state.aboutOptions,
onOptionClick = onOptionClick
onOptionClick = onOptionClick,
)
}

Expand All @@ -115,76 +123,79 @@ fun AboutScreen(
}

@Composable
fun AboutScreenContent(
private fun AboutScreenContent(
aboutOptions: List<AboutItem>,
onOptionClick: (AboutItems) -> Unit
onOptionClick: (AboutItems) -> Unit,
) {
Image(
modifier = Modifier.size(100.dp),
painter = painterResource(id = R.drawable.feature_about_ic_launcher),
contentDescription = null
)
Text(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
text = stringResource(id = R.string.feature_about_mifos_x_droid),
style = aboutItemTextStyleBold
)
Text(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp),
text = stringResource(id = R.string.feature_about_app),
style = aboutItemTextStyle
)
Text(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.clickable {
onOptionClick(AboutItems.CONTRIBUTIONS)
},
text = stringResource(id = R.string.feature_about_mifos),
style = TextStyle(
fontSize = 16.sp
),
color = BluePrimary,
textAlign = TextAlign.Center
)
LazyColumn {
items(aboutOptions) { about ->
AboutCardItem(about = about, onOptionClick = onOptionClick)
Column {

Image(
modifier = Modifier.size(100.dp),
painter = painterResource(id = R.drawable.feature_about_ic_launcher),
contentDescription = null,
)
Text(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
text = stringResource(id = R.string.feature_about_mifos_x_droid),
style = aboutItemTextStyleBold,
)
Text(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp),
text = stringResource(id = R.string.feature_about_app),
style = aboutItemTextStyle,
)
Text(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.clickable {
onOptionClick(AboutItems.CONTRIBUTIONS)
},
text = stringResource(id = R.string.feature_about_mifos),
style = TextStyle(
fontSize = 16.sp,
),
color = BluePrimary,
textAlign = TextAlign.Center,
)
LazyColumn {
items(aboutOptions) { about ->
AboutCardItem(about = about, onOptionClick = onOptionClick)
}
}
}
}

@Composable
fun AboutCardItem(
private fun AboutCardItem(
about: AboutItem,
onOptionClick: (AboutItems) -> Unit
onOptionClick: (AboutItems) -> Unit,
) {
ElevatedCard(
modifier = Modifier.padding(
start = 16.dp,
end = 16.dp,
top = 8.dp,
bottom = 8.dp
bottom = 8.dp,
),
elevation = CardDefaults.elevatedCardElevation(0.dp),
colors = CardDefaults.elevatedCardColors(about.color),
onClick = {
onOptionClick(about.id)
}
},
) {
Row(
modifier = Modifier.padding(16.dp),
verticalAlignment = Alignment.CenterVertically
verticalAlignment = Alignment.CenterVertically,
) {
about.icon?.let {
Icon(
painter = painterResource(it),
contentDescription = null
contentDescription = null,
)
}
Column {
Expand All @@ -194,9 +205,9 @@ fun AboutCardItem(
.padding(start = 16.dp, end = 16.dp),
text = stringResource(id = about.title),
style = TextStyle(
fontSize = 16.sp
fontSize = 16.sp,
),
color = Black
color = Black,
)
about.subtitle?.let {
Text(
Expand All @@ -205,38 +216,36 @@ fun AboutCardItem(
.padding(start = 16.dp, end = 16.dp),
text = stringResource(id = it),
style = TextStyle(
fontSize = 16.sp
fontSize = 16.sp,
),
color = Black
color = Black,
)
}
}
}
}
}

class AboutUiStateProvider : PreviewParameterProvider<AboutUiState> {
private class AboutUiStateProvider : PreviewParameterProvider<AboutUiState> {

override val values: Sequence<AboutUiState>
get() = sequenceOf(
AboutUiState.Loading,
AboutUiState.Error(R.string.feature_about_failed_to_load),
AboutUiState.AboutOptions(sampleAboutItem)
AboutUiState.AboutOptions(sampleAboutItem),
)

}


@Preview(showBackground = true)
@Composable
private fun AboutScreenPreview(
@PreviewParameter(AboutUiStateProvider::class) state: AboutUiState
@PreviewParameter(AboutUiStateProvider::class) state: AboutUiState,
) {
AboutScreen(
state = state,
onBackPressed = {},
onRetry = {},
onOptionClick = {}
onOptionClick = {},
)
}

Expand All @@ -246,6 +255,6 @@ val sampleAboutItem = List(4) {
title = R.string.feature_about_support_twitter,
subtitle = R.string.feature_about_license_sub,
color = White,
id = AboutItems.TWITTER
id = AboutItems.TWITTER,
)
}
}
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.feature.about

sealed class AboutUiState {
Expand All @@ -7,4 +16,4 @@ sealed class AboutUiState {
data class Error(val message: Int) : AboutUiState()

data class AboutOptions(val aboutOptions: List<AboutItem>) : AboutUiState()
}
}
Loading

0 comments on commit 9c6958e

Please sign in to comment.