Skip to content

feat: about migrate to cmp #2377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -17,8 +17,8 @@ class CMPFeatureConventionPlugin : Plugin<Project> {
dependencies {
add("commonMainImplementation", project(":core:ui"))
add("commonMainImplementation", project(":core:designsystem"))
add("commonMainImplementation", project(":core:testing"))
add("commonMainImplementation", project(":core:data"))
//add("commonMainImplementation", project(":core:testing"))
// add("commonMainImplementation", project(":core:data"))

add("commonMainImplementation", libs.findLibrary("koin.compose").get())
add("commonMainImplementation", libs.findLibrary("koin.compose.viewmodel").get())
Expand Down
19 changes: 12 additions & 7 deletions feature/about/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@
* 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)
alias(libs.plugins.mifos.android.library.jacoco)
alias(libs.plugins.mifos.cmp.feature)
}

android {
namespace = "com.mifos.feature.about"
}

dependencies {
// testImplementation(libs.hilt.android.testing)
// testImplementation(projects.core.testing)
// androidTestImplementation(projects.core.testing)
kotlin {
sourceSets {
commonMain.dependencies {
implementation(compose.material3)
implementation(compose.components.resources)
implementation(compose.ui)
api(projects.core.common)
api(projects.core.model)
api(projects.core.domain)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
package com.mifos.feature.about

import androidx.compose.ui.graphics.Color
import org.jetbrains.compose.resources.DrawableResource
import org.jetbrains.compose.resources.StringResource

data class AboutItem(
val icon: Int?,
val title: Int,
val subtitle: Int?,
val color: Color,
val icon: DrawableResource? = null,
val title: StringResource,
val subtitle: StringResource? = null,
val color: Color? = null,
val id: AboutItems,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
*/
package com.mifos.feature.about

import androidclient.feature.about.generated.resources.Res
import androidclient.feature.about.generated.resources.feature_about
import androidclient.feature.about.generated.resources.feature_about_app
import androidclient.feature.about.generated.resources.feature_about_ic_launcher
import androidclient.feature.about.generated.resources.feature_about_mifos
import androidclient.feature.about.generated.resources.feature_about_mifos_x_droid
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
Expand All @@ -21,6 +27,7 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -30,16 +37,9 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Color.Companion.Black
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
Expand All @@ -48,7 +48,10 @@ import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.designsystem.component.MifosSweetError
import com.mifos.core.designsystem.theme.aboutItemTextStyle
import com.mifos.core.designsystem.theme.aboutItemTextStyleBold
import org.koin.androidx.compose.koinViewModel
import com.mifos.core.ui.util.ShareUtils
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.viewmodel.koinViewModel

@Composable
internal fun AboutScreen(
Expand All @@ -68,17 +71,17 @@ internal fun AboutScreen(
onRetry = { viewModel.getAboutOptions() },
onOptionClick = {
when (it) {
AboutItems.CONTRIBUTIONS -> uriHandler.openUri("https://github.com/openMF/android-client/graphs/contributors")
AboutItems.CONTRIBUTIONS -> ShareUtils.openUrl("https://github.com/openMF/android-client/graphs/contributors")

AboutItems.APP_VERSION -> Unit

AboutItems.OFFICIAL_WEBSITE -> uriHandler.openUri("https://openmf.github.io/mobileapps.github.io/")
AboutItems.OFFICIAL_WEBSITE -> ShareUtils.openUrl("https://openmf.github.io/mobileapps.github.io/")

AboutItems.TWITTER -> uriHandler.openUri("https://twitter.com/mifos")
AboutItems.TWITTER -> ShareUtils.openUrl("https://twitter.com/mifos")

AboutItems.SOURCE_CODE -> uriHandler.openUri("https://github.com/openMF/android-client")
AboutItems.SOURCE_CODE -> ShareUtils.openUrl("https://github.com/openMF/android-client")

AboutItems.LICENSE -> uriHandler.openUri("https://github.com/openMF/android-client/blob/master/LICENSE.md")
AboutItems.LICENSE -> ShareUtils.openUrl("https://github.com/openMF/android-client/blob/master/LICENSE.md")
}
},
)
Expand All @@ -94,7 +97,7 @@ internal fun AboutScreen(
val snackbarHostState = remember { SnackbarHostState() }

MifosScaffold(
title = stringResource(R.string.feature_about),
title = stringResource(Res.string.feature_about),
onBackPressed = onBackPressed,
snackbarHostState = snackbarHostState,
) { paddingValues ->
Expand All @@ -110,7 +113,9 @@ internal fun AboutScreen(
)
}

is AboutUiState.Error -> MifosSweetError(message = stringResource(id = state.message)) {
is AboutUiState.Error -> MifosSweetError(
message = stringResource(state.message),
) {
onRetry()
}

Expand All @@ -128,21 +133,21 @@ private fun AboutScreenContent(
Column {
Image(
modifier = Modifier.size(100.dp),
painter = painterResource(id = R.drawable.feature_about_ic_launcher),
painter = painterResource(Res.drawable.feature_about_ic_launcher),
contentDescription = null,
)
Text(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
text = stringResource(id = R.string.feature_about_mifos_x_droid),
text = stringResource(Res.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),
text = stringResource(Res.string.feature_about_app),
style = aboutItemTextStyle,
)
Text(
Expand All @@ -152,7 +157,7 @@ private fun AboutScreenContent(
.clickable {
onOptionClick(AboutItems.CONTRIBUTIONS)
},
text = stringResource(id = R.string.feature_about_mifos),
text = stringResource(Res.string.feature_about_mifos),
style = TextStyle(
fontSize = 16.sp,
),
Expand Down Expand Up @@ -180,7 +185,7 @@ private fun AboutCardItem(
bottom = 8.dp,
),
elevation = CardDefaults.elevatedCardElevation(0.dp),
colors = CardDefaults.elevatedCardColors(about.color),
// colors = CardDefaults.elevatedCardColors(about.color),
onClick = {
onOptionClick(about.id)
},
Expand All @@ -200,58 +205,55 @@ private fun AboutCardItem(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp),
text = stringResource(id = about.title),
style = TextStyle(
fontSize = 16.sp,
),
color = Black,
text = stringResource(about.title),
style = MaterialTheme.typography.titleMedium,
// color = Black,
)
about.subtitle?.let {
Text(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp),
text = stringResource(id = it),
style = TextStyle(
fontSize = 16.sp,
),
color = Black,
text = stringResource(it),
style = MaterialTheme.typography.bodyMedium,

// color = Black,
)
}
}
}
}
}

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),
)
}
// 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),
// )
// }

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

val sampleAboutItem = List(4) {
AboutItem(
icon = R.drawable.feature_about_icon_twitter,
title = R.string.feature_about_support_twitter,
subtitle = R.string.feature_about_license_sub,
color = White,
id = AboutItems.TWITTER,
)
}
// @Preview(showBackground = true)
// @Composable
// private fun AboutScreenPreview(
// @PreviewParameter(AboutUiStateProvider::class) state: AboutUiState,
// ) {
// AboutScreen(
// state = state,
// onBackPressed = {},
// onRetry = {},
// onOptionClick = {},
// )
// }
//
// val sampleAboutItem = List(4) {
// AboutItem(
// icon = Res.drawable.feature_about_icon_twitter,
// title = Res.string.feature_about_support_twitter,
// subtitle = Res.string.feature_about_license_sub,
// color = White,
// id = AboutItems.TWITTER,
// )
// }
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
*/
package com.mifos.feature.about

import org.jetbrains.compose.resources.StringResource

sealed class AboutUiState {

data object Loading : AboutUiState()

data class Error(val message: Int) : AboutUiState()
data class Error(val message: StringResource) : AboutUiState()

data class AboutOptions(val aboutOptions: List<AboutItem>) : AboutUiState()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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 androidclient.feature.about.generated.resources.feature_about_app_version
import androidclient.feature.about.generated.resources.feature_about_failed_to_load
import androidclient.feature.about.generated.resources.feature_about_ic_source_code
import androidclient.feature.about.generated.resources.feature_about_ic_website
import androidclient.feature.about.generated.resources.feature_about_icon_twitter
import androidclient.feature.about.generated.resources.feature_about_license
import androidclient.feature.about.generated.resources.feature_about_license_sub
import androidclient.feature.about.generated.resources.feature_about_support_github
import androidclient.feature.about.generated.resources.feature_about_support_twitter
import androidclient.feature.about.generated.resources.feature_about_website
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch

class AboutViewModel : ViewModel() {

private val _aboutUiState = MutableStateFlow<AboutUiState>(AboutUiState.Loading)
val aboutUiState = _aboutUiState.asStateFlow()

fun getAboutOptions() = viewModelScope.launch {
try {
val options = listOf(
AboutItem(
icon = null,
title = androidclient.feature.about.generated.resources.Res.string.feature_about_app_version,
subtitle = null,
// color = Color.Blue,
id = AboutItems.APP_VERSION,
),
AboutItem(
icon = androidclient.feature.about.generated.resources.Res.drawable.feature_about_ic_website,
title = androidclient.feature.about.generated.resources.Res.string.feature_about_website,
subtitle = null,
// color = White,
id = AboutItems.OFFICIAL_WEBSITE,
),
AboutItem(
icon = androidclient.feature.about.generated.resources.Res.drawable.feature_about_icon_twitter,
title = androidclient.feature.about.generated.resources.Res.string.feature_about_support_twitter,
subtitle = null,
color = White,
id = AboutItems.TWITTER,
),
AboutItem(
icon = androidclient.feature.about.generated.resources.Res.drawable.feature_about_ic_source_code,
title = androidclient.feature.about.generated.resources.Res.string.feature_about_support_github,
subtitle = null,
// color = White,
id = AboutItems.SOURCE_CODE,
),
AboutItem(
icon = null,
title = androidclient.feature.about.generated.resources.Res.string.feature_about_license,
subtitle = androidclient.feature.about.generated.resources.Res.string.feature_about_license_sub,
// color = Color.Blue,
id = AboutItems.LICENSE,
),
)
_aboutUiState.value = AboutUiState.AboutOptions(options)
} catch (exception: Exception) {
_aboutUiState.value = AboutUiState.Error(androidclient.feature.about.generated.resources.Res.string.feature_about_failed_to_load)
}
}
}

enum class AboutItems {
CONTRIBUTIONS,
APP_VERSION,
OFFICIAL_WEBSITE,
TWITTER,
SOURCE_CODE,
LICENSE,
}
Loading