Skip to content

Commit b1ffd11

Browse files
kapmauryaitsPronay
andauthored
feat: about migrate to cmp (#2377)
Co-authored-by: itsPronay <[email protected]>
1 parent bc19d3a commit b1ffd11

File tree

20 files changed

+241
-369
lines changed

20 files changed

+241
-369
lines changed

build-logic/convention/src/main/kotlin/CMPFeatureConventionPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CMPFeatureConventionPlugin : Plugin<Project> {
1717
dependencies {
1818
add("commonMainImplementation", project(":core:ui"))
1919
add("commonMainImplementation", project(":core:designsystem"))
20-
add("commonMainImplementation", project(":core:data"))
20+
add("commonMainImplementation", project(":core:data"))
2121

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

cmp-navigation/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ kotlin {
3030
implementation(projects.core.database)
3131
implementation(projects.core.network)
3232

33-
// implementation(projects.feature.about)
33+
implementation(projects.feature.about)
3434
// implementation(projects.feature.activate)
3535
implementation(projects.feature.auth)
3636
// implementation(projects.feature.center)

cmp-navigation/src/commonMain/kotlin/cmp/navigation/navigation/FeatureNavHost.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.navigation.NavGraphBuilder
2222
import androidx.navigation.compose.NavHost
2323
import androidx.navigation.compose.composable
2424
import cmp.navigation.AppState
25+
import com.mifos.feature.about.navigation.aboutNavGraph
2526

2627
const val WELCOME_ROUTE = "home_route"
2728

@@ -38,6 +39,8 @@ internal fun FeatureNavHost(
3839
modifier = modifier,
3940
) {
4041
homeScreen()
42+
43+
aboutNavGraph(onBackPressed = appState.navController::popBackStack)
4144
}
4245
}
4346

feature/about/build.gradle.kts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
99
*/
1010
plugins {
11-
alias(libs.plugins.mifos.android.feature)
12-
alias(libs.plugins.mifos.android.library.compose)
13-
alias(libs.plugins.mifos.android.library.jacoco)
11+
alias(libs.plugins.mifos.cmp.feature)
1412
}
1513

1614
android {
1715
namespace = "com.mifos.feature.about"
1816
}
1917

20-
dependencies {
21-
// testImplementation(libs.hilt.android.testing)
22-
// testImplementation(projects.core.testing)
23-
// androidTestImplementation(projects.core.testing)
18+
kotlin {
19+
sourceSets {
20+
commonMain.dependencies {
21+
implementation(compose.material3)
22+
implementation(compose.components.resources)
23+
implementation(compose.ui)
24+
}
25+
}
2426
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.feature.about
11+
12+
import androidclient.feature.about.generated.resources.Res
13+
import androidclient.feature.about.generated.resources.feature_about_app_version
14+
import androidclient.feature.about.generated.resources.feature_about_ic_source_code
15+
import androidclient.feature.about.generated.resources.feature_about_ic_website
16+
import androidclient.feature.about.generated.resources.feature_about_icon_twitter
17+
import androidclient.feature.about.generated.resources.feature_about_license
18+
import androidclient.feature.about.generated.resources.feature_about_license_sub
19+
import androidclient.feature.about.generated.resources.feature_about_support_github
20+
import androidclient.feature.about.generated.resources.feature_about_support_twitter
21+
import androidclient.feature.about.generated.resources.feature_about_website
22+
23+
val aboutItems = listOf(
24+
AboutItem(
25+
icon = null,
26+
title = Res.string.feature_about_app_version,
27+
id = AboutItems.APP_VERSION,
28+
),
29+
AboutItem(
30+
icon = Res.drawable.feature_about_ic_website,
31+
title = Res.string.feature_about_website,
32+
id = AboutItems.OFFICIAL_WEBSITE,
33+
),
34+
AboutItem(
35+
icon = Res.drawable.feature_about_icon_twitter,
36+
title = Res.string.feature_about_support_twitter,
37+
id = AboutItems.TWITTER,
38+
),
39+
AboutItem(
40+
icon = Res.drawable.feature_about_ic_source_code,
41+
title = Res.string.feature_about_support_github,
42+
id = AboutItems.SOURCE_CODE,
43+
),
44+
AboutItem(
45+
icon = null,
46+
title = Res.string.feature_about_license,
47+
subtitle = Res.string.feature_about_license_sub,
48+
id = AboutItems.LICENSE,
49+
),
50+
)

feature/about/src/main/java/com/mifos/feature/about/AboutItem.kt renamed to feature/about/src/commonMain/kotlin/com/mifos/feature/about/AboutItem.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,22 @@
1010
package com.mifos.feature.about
1111

1212
import androidx.compose.ui.graphics.Color
13+
import org.jetbrains.compose.resources.DrawableResource
14+
import org.jetbrains.compose.resources.StringResource
1315

1416
data class AboutItem(
15-
val icon: Int?,
16-
val title: Int,
17-
val subtitle: Int?,
18-
val color: Color,
17+
val icon: DrawableResource? = null,
18+
val title: StringResource,
19+
val subtitle: StringResource? = null,
20+
val color: Color? = null,
1921
val id: AboutItems,
2022
)
23+
24+
enum class AboutItems {
25+
CONTRIBUTIONS,
26+
APP_VERSION,
27+
OFFICIAL_WEBSITE,
28+
TWITTER,
29+
SOURCE_CODE,
30+
LICENSE,
31+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.feature.about
11+
12+
import androidclient.feature.about.generated.resources.Res
13+
import androidclient.feature.about.generated.resources.feature_about
14+
import androidclient.feature.about.generated.resources.feature_about_app
15+
import androidclient.feature.about.generated.resources.feature_about_ic_launcher
16+
import androidclient.feature.about.generated.resources.feature_about_mifos
17+
import androidclient.feature.about.generated.resources.feature_about_mifos_x_droid
18+
import androidx.compose.foundation.Image
19+
import androidx.compose.foundation.clickable
20+
import androidx.compose.foundation.layout.Box
21+
import androidx.compose.foundation.layout.Column
22+
import androidx.compose.foundation.layout.Row
23+
import androidx.compose.foundation.layout.fillMaxWidth
24+
import androidx.compose.foundation.layout.padding
25+
import androidx.compose.foundation.layout.size
26+
import androidx.compose.foundation.lazy.LazyColumn
27+
import androidx.compose.foundation.lazy.items
28+
import androidx.compose.material3.CardDefaults
29+
import androidx.compose.material3.ElevatedCard
30+
import androidx.compose.material3.Icon
31+
import androidx.compose.material3.MaterialTheme
32+
import androidx.compose.material3.SnackbarHostState
33+
import androidx.compose.material3.Text
34+
import androidx.compose.runtime.Composable
35+
import androidx.compose.runtime.remember
36+
import androidx.compose.ui.Alignment
37+
import androidx.compose.ui.Modifier
38+
import androidx.compose.ui.text.style.TextAlign
39+
import androidx.compose.ui.unit.dp
40+
import com.mifos.core.designsystem.component.MifosScaffold
41+
import com.mifos.core.designsystem.theme.aboutItemTextStyle
42+
import com.mifos.core.designsystem.theme.aboutItemTextStyleBold
43+
import com.mifos.core.ui.util.ShareUtils
44+
import org.jetbrains.compose.resources.painterResource
45+
import org.jetbrains.compose.resources.stringResource
46+
47+
@Composable
48+
internal fun AboutScreen(
49+
onBackPressed: () -> Unit,
50+
) {
51+
MifosScaffold(
52+
title = stringResource(Res.string.feature_about),
53+
onBackPressed = onBackPressed,
54+
snackbarHostState = remember { SnackbarHostState() },
55+
) { paddingValues ->
56+
LazyColumn(
57+
modifier = Modifier
58+
.padding(paddingValues),
59+
horizontalAlignment = Alignment.CenterHorizontally,
60+
) {
61+
item {
62+
Box(modifier = Modifier.fillMaxWidth()) {
63+
Image(
64+
modifier = Modifier.size(100.dp).align(Alignment.Center),
65+
painter = painterResource(Res.drawable.feature_about_ic_launcher),
66+
contentDescription = "App icon",
67+
)
68+
}
69+
70+
Text(
71+
modifier = Modifier
72+
.fillMaxWidth()
73+
.padding(16.dp),
74+
text = stringResource(Res.string.feature_about_mifos_x_droid),
75+
style = aboutItemTextStyleBold,
76+
)
77+
Text(
78+
modifier = Modifier
79+
.fillMaxWidth()
80+
.padding(start = 16.dp, end = 16.dp),
81+
text = stringResource(Res.string.feature_about_app),
82+
style = aboutItemTextStyle,
83+
)
84+
Text(
85+
modifier = Modifier
86+
.fillMaxWidth()
87+
.padding(16.dp)
88+
.clickable {
89+
ShareUtils.openUrl("https://github.com/openMF/android-client/graphs/contributors")
90+
},
91+
text = stringResource(Res.string.feature_about_mifos),
92+
style = MaterialTheme.typography.bodyMedium,
93+
textAlign = TextAlign.Center,
94+
)
95+
}
96+
items(aboutItems) { about ->
97+
AboutCardItem(about = about) {
98+
when (it) {
99+
AboutItems.CONTRIBUTIONS -> ShareUtils.openUrl("https://github.com/openMF/android-client/graphs/contributors")
100+
AboutItems.APP_VERSION -> Unit
101+
AboutItems.OFFICIAL_WEBSITE -> ShareUtils.openUrl("https://openmf.github.io/mobileapps.github.io/")
102+
AboutItems.TWITTER -> ShareUtils.openUrl("https://twitter.com/mifos")
103+
AboutItems.SOURCE_CODE -> ShareUtils.openUrl("https://github.com/openMF/android-client")
104+
AboutItems.LICENSE -> ShareUtils.openUrl("https://github.com/openMF/android-client/blob/master/LICENSE.md")
105+
}
106+
}
107+
}
108+
}
109+
}
110+
}
111+
112+
@Composable
113+
private fun AboutCardItem(
114+
about: AboutItem,
115+
onOptionClick: (AboutItems) -> Unit,
116+
) {
117+
ElevatedCard(
118+
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
119+
elevation = CardDefaults.elevatedCardElevation(0.dp),
120+
onClick = { onOptionClick(about.id) },
121+
) {
122+
Row(
123+
modifier = Modifier.padding(16.dp),
124+
verticalAlignment = Alignment.CenterVertically,
125+
) {
126+
about.icon?.let {
127+
Icon(
128+
painter = painterResource(it),
129+
contentDescription = stringResource(about.title),
130+
)
131+
}
132+
Column {
133+
Text(
134+
modifier = Modifier
135+
.fillMaxWidth()
136+
.padding(horizontal = 16.dp),
137+
text = stringResource(about.title),
138+
style = MaterialTheme.typography.titleMedium,
139+
)
140+
about.subtitle?.let {
141+
Text(
142+
modifier = Modifier
143+
.fillMaxWidth()
144+
.padding(horizontal = 16.dp),
145+
text = stringResource(it),
146+
style = MaterialTheme.typography.bodyMedium,
147+
)
148+
}
149+
}
150+
}
151+
}
152+
}

feature/about/src/main/java/com/mifos/feature/about/AboutUiState.kt renamed to feature/about/src/commonMain/kotlin/com/mifos/feature/about/AboutUiState.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
*/
1010
package com.mifos.feature.about
1111

12+
import org.jetbrains.compose.resources.StringResource
13+
1214
sealed class AboutUiState {
1315

1416
data object Loading : AboutUiState()
1517

16-
data class Error(val message: Int) : AboutUiState()
18+
data class Error(val message: StringResource) : AboutUiState()
1719

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

feature/about/src/main/java/com/mifos/feature/about/navigation/AccountNavigation.kt renamed to feature/about/src/commonMain/kotlin/com/mifos/feature/about/navigation/AccountNavigation.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99
*/
1010
package com.mifos.feature.about.navigation
1111

12+
import androidx.navigation.NavController
1213
import androidx.navigation.NavGraphBuilder
1314
import androidx.navigation.compose.composable
1415
import com.mifos.feature.about.AboutScreen
1516

1617
/**
1718
* Created by Pronay Sarker on 10/08/2024 (7:56 AM)
1819
*/
19-
fun NavGraphBuilder.aboutScreen(
20+
fun NavController.navigateToAboutScreen() {
21+
navigate(AboutScreens.AboutScreen.route)
22+
}
23+
24+
fun NavGraphBuilder.aboutNavGraph(
2025
onBackPressed: () -> Unit,
2126
) {
2227
composable(AboutScreens.AboutScreen.route) {

0 commit comments

Comments
 (0)