Skip to content

Commit

Permalink
Apply & Fix Detekt, Ktlint Rules in About Module (#2676)
Browse files Browse the repository at this point in the history
  • Loading branch information
niyajali authored Aug 30, 2024
1 parent 344c5d1 commit 1704351
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 95 deletions.
14 changes: 9 additions & 5 deletions feature/about/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/*
* 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/mobile-mobile/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
alias(libs.plugins.kotlin.parcelize)
}

android {
Expand All @@ -10,8 +18,4 @@ android {

dependencies {
implementation(projects.core.model)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
}

This file was deleted.

11 changes: 10 additions & 1 deletion 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"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!--
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/mobile-mobile/blob/master/LICENSE.md
-->
<manifest>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/*
* 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/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.feature.about.navigation

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
Expand All @@ -20,26 +28,28 @@ fun NavController.navigateToAboutUsScreen() {

fun NavGraphBuilder.aboutUsNavGraph(
navController: NavController,
navigateToOssLicense: () -> Unit
navigateToOssLicense: () -> Unit,
) {
navigation(
startDestination = AboutUsNavigation.AboutUsScreen.route,
route = AboutUsNavigation.AboutUsBase.route,
) {
aboutUsScreenRoute(
navigateToPrivacyPolicy = { navController.navigate(AboutUsNavigation.PrivacyPolicyScreen.route) },
navigateToOssLicense = navigateToOssLicense
navigateToPrivacyPolicy = {
navController.navigate(AboutUsNavigation.PrivacyPolicyScreen.route)
},
navigateToOssLicense = navigateToOssLicense,
)

privacyPolicyScreenRoute(
navigateBack = navController::popBackStack
navigateBack = navController::popBackStack,
)
}
}

fun NavGraphBuilder.aboutUsScreenRoute(
navigateToPrivacyPolicy: () -> Unit,
navigateToOssLicense: () -> Unit
navigateToOssLicense: () -> Unit,
) {
composable(
route = AboutUsNavigation.AboutUsScreen.route,
Expand All @@ -52,21 +62,21 @@ fun NavGraphBuilder.aboutUsScreenRoute(
context = context,
aboutUsItem = it.itemId,
navigateToOssLicense = navigateToOssLicense,
navigateToPrivacyPolicy = navigateToPrivacyPolicy
navigateToPrivacyPolicy = navigateToPrivacyPolicy,
)
}
},
)
}
}

fun NavGraphBuilder.privacyPolicyScreenRoute(
navigateBack: () -> Unit
navigateBack: () -> Unit,
) {
composable(
route = AboutUsNavigation.PrivacyPolicyScreen.route,
) {
PrivacyPolicyScreen(
navigateBack = navigateBack
navigateBack = navigateBack,
)
}
}
Expand All @@ -75,7 +85,7 @@ private fun navigateToItem(
context: Context,
aboutUsItem: AboutUsListItemId,
navigateToPrivacyPolicy: () -> Unit,
navigateToOssLicense: () -> Unit
navigateToOssLicense: () -> Unit,
) {
when (aboutUsItem) {
AboutUsListItemId.OFFICE_WEBSITE -> {
Expand Down Expand Up @@ -104,4 +114,4 @@ private fun navigateToItem(

fun startActivity(context: Context, uri: String) {
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(uri)))
}
}
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/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.feature.about.navigation

// Constants for Routes
Expand All @@ -10,4 +19,4 @@ sealed class AboutUsNavigation(val route: String) {
data object AboutUsBase : AboutUsNavigation(route = ABOUT_US_NAVIGATION_ROUTE_BASE)
data object AboutUsScreen : AboutUsNavigation(route = ABOUT_US_SCREEN_ROUTE)
data object PrivacyPolicyScreen : AboutUsNavigation(route = PRIVACY_POLICY_SCREEN_ROUTE)
}
}
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/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.feature.about.ui

import androidx.compose.foundation.Image
Expand All @@ -13,21 +22,23 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.mifos.mobile.core.ui.utils.DevicePreviews
import org.mifos.mobile.feature.about.R

@Preview
@DevicePreviews
@Composable
fun AboutUsHeader() {
Column {
fun AboutUsHeader(
modifier: Modifier = Modifier,
) {
Column(modifier) {
Image(
painter = painterResource(id = R.mipmap.core_common_mifos_icon),
contentDescription = null,
modifier = Modifier
.size(100.dp)
.fillMaxWidth()
.align(Alignment.CenterHorizontally)
.align(Alignment.CenterHorizontally),
)

Text(
Expand All @@ -37,7 +48,7 @@ fun AboutUsHeader() {
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 8.dp)
.padding(bottom = 8.dp),
)

Text(
Expand All @@ -47,7 +58,7 @@ fun AboutUsHeader() {
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 16.dp)
.padding(bottom = 16.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/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.feature.about.ui

import android.content.Context
Expand All @@ -10,23 +19,24 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
import org.mifos.mobile.core.model.entity.AboutUsItem
import org.mifos.mobile.core.model.enums.AboutUsListItemId
import org.mifos.mobile.core.ui.component.AboutUsItemCard
import org.mifos.mobile.core.ui.component.MifosItemCard
import org.mifos.mobile.core.ui.utils.DevicePreviews
import org.mifos.mobile.feature.about.R
import java.util.Calendar

@Composable
fun AboutUsScreen(
navigateToItem: (AboutUsItem) -> Unit
navigateToItem: (AboutUsItem) -> Unit,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
LazyColumn(
modifier = Modifier
modifier = modifier
.fillMaxSize()
.padding(16.dp),
) {
Expand All @@ -37,13 +47,13 @@ fun AboutUsScreen(
items(getAboutUsItem(context)) { item ->
MifosItemCard(
modifier = Modifier.padding(bottom = 8.dp),
onClick = { navigateToItem(item) }
onClick = { navigateToItem(item) },
) {
item.title?.let {
AboutUsItemCard(
title = it,
subtitle = item.subtitle,
iconUrl = item.iconUrl
iconUrl = item.iconUrl,
)
}
}
Expand All @@ -52,49 +62,48 @@ fun AboutUsScreen(
}

fun getAboutUsItem(context: Context): List<AboutUsItem> {

val currentYear = Calendar.getInstance().get(Calendar.YEAR)
val copyrightText = context.getString(R.string.copy_right_mifos).replace("%1\$s", currentYear.toString())

return listOf(
AboutUsItem(
title = context.getString(R.string.app_version_text),
itemId = AboutUsListItemId.APP_VERSION_TEXT
itemId = AboutUsListItemId.APP_VERSION_TEXT,
),
AboutUsItem(
title = context.getString(R.string.official_website),
iconUrl = R.drawable.ic_website,
itemId = AboutUsListItemId.OFFICE_WEBSITE
itemId = AboutUsListItemId.OFFICE_WEBSITE,
),
AboutUsItem(
title = context.getString(R.string.licenses),
iconUrl = R.drawable.ic_law_icon,
itemId = AboutUsListItemId.LICENSES
itemId = AboutUsListItemId.LICENSES,
),
AboutUsItem(
title = context.getString(R.string.privacy_policy),
iconUrl = R.drawable.ic_privacy_policy,
itemId = AboutUsListItemId.PRIVACY_POLICY
itemId = AboutUsListItemId.PRIVACY_POLICY,
),
AboutUsItem(
title = context.getString(R.string.sources),
iconUrl = R.drawable.ic_source_code,
itemId = AboutUsListItemId.SOURCE_CODE
itemId = AboutUsListItemId.SOURCE_CODE,
),
AboutUsItem(
title = copyrightText,
subtitle = R.string.license_string_with_value,
itemId = AboutUsListItemId.LICENSES_STRING_WITH_VALUE
)
itemId = AboutUsListItemId.LICENSES_STRING_WITH_VALUE,
),
)
}

@Preview(showSystemUi = true, device = "id:pixel_5")
@DevicePreviews
@Composable
fun AboutScreenPreview() {
MifosMobileTheme {
AboutUsScreen(
navigateToItem = {}
navigateToItem = {},
)
}
}
}
Loading

0 comments on commit 1704351

Please sign in to comment.