Skip to content
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

Center Module clean up #2226

Merged
merged 16 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions build-logic/convention/src/main/kotlin/org/mifos/Detekt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.gradle.kotlin.dsl.named

internal fun Project.configureDetekt(extension: DetektExtension) = extension.apply {
tasks.named<Detekt>("detekt") {
jvmTarget = "1.8"
config.from(rootProject.file("config/detekt/detekt.yml"))
reports {
xml.required.set(true)
Expand Down
9 changes: 9 additions & 0 deletions feature/center/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.center

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

import androidx.test.platform.app.InstrumentationRegistry
import junit.framework.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.center.test", appContext.packageName)
}
}
}
9 changes: 9 additions & 0 deletions feature/center/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>
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
@file:OptIn(ExperimentalMaterial3Api::class)

package com.mifos.feature.center.center_details
/*
* 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.center.centerDetails

import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
Expand All @@ -17,7 +24,6 @@ import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand Down Expand Up @@ -60,13 +66,12 @@ import com.mifos.core.objects.group.CenterWithAssociations
import com.mifos.feature.center.R

@Composable
fun CenterDetailsScreen(
internal fun CenterDetailsScreen(
onBackPressed: () -> Unit,
onActivateCenter: (Int) -> Unit,
addSavingsAccount: (Int) -> Unit,
groupList: (Int) -> Unit
groupList: (Int) -> Unit,
) {

val viewModel: CenterDetailsViewModel = hiltViewModel()
val centerId by viewModel.centerId.collectAsStateWithLifecycle()
val state by viewModel.centerDetailsUiState.collectAsStateWithLifecycle()
Expand All @@ -88,19 +93,18 @@ fun CenterDetailsScreen(
onRetryClick = {
viewModel.loadClientDetails(centerId)
},
onActivateCenter = { onActivateCenter(centerId) }
onActivateCenter = { onActivateCenter(centerId) },
)
}

@Composable
fun CenterDetailsScreen(
internal fun CenterDetailsScreen(
state: CenterDetailsUiState,
onBackPressed: () -> Unit,
onMenuClick: (MenuItems) -> Unit,
onRetryClick: () -> Unit,
onActivateCenter: () -> Unit
onActivateCenter: () -> Unit,
) {

val snackbarHostState = remember { SnackbarHostState() }
var showMenu by remember { mutableStateOf(false) }
var centerActive by remember { mutableStateOf(true) }
Expand All @@ -116,7 +120,7 @@ fun CenterDetailsScreen(
DropdownMenu(
modifier = Modifier.background(White),
expanded = showMenu,
onDismissRequest = { showMenu = false }
onDismissRequest = { showMenu = false },
) {
MifosMenuDropDownItem(option = stringResource(id = R.string.feature_center_add_savings_account)) {
onMenuClick(MenuItems.ADD_SAVINGS_ACCOUNT)
Expand All @@ -138,20 +142,19 @@ fun CenterDetailsScreen(
.heightIn(44.dp)
.padding(start = 16.dp, end = 16.dp),
colors = ButtonDefaults.buttonColors(
containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary
)
containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary,
),
) {
Text(
text = stringResource(id = R.string.feature_center_activate_center),
fontSize = 16.sp
fontSize = 16.sp,
)
}

}
}
},
) { paddingValues ->
Column(
modifier = Modifier.padding(paddingValues)
modifier = Modifier.padding(paddingValues),
) {
when (state) {
is CenterDetailsUiState.Error -> {
Expand All @@ -166,7 +169,7 @@ fun CenterDetailsScreen(
CenterDetailsContent(
centerWithAssociations = state.centerWithAssociations,
centerInfo = state.centerInfo,
activateCenter = { centerActive = false }
activateCenter = { centerActive = false },
)
}
}
Expand All @@ -175,10 +178,10 @@ fun CenterDetailsScreen(
}

@Composable
fun CenterDetailsContent(
private fun CenterDetailsContent(
centerWithAssociations: CenterWithAssociations,
centerInfo: CenterInfo,
activateCenter: () -> Unit
activateCenter: () -> Unit,
) {
if (centerWithAssociations.active == false) {
activateCenter()
Expand All @@ -195,34 +198,42 @@ fun CenterDetailsContent(
fontWeight = FontWeight.SemiBold,
),
color = Black,
textAlign = TextAlign.Center
textAlign = TextAlign.Center,
)
}
MifosCenterDetailsText(
icon = MifosIcons.date,
field = stringResource(id = R.string.feature_center_activation_date),
value = Utils.getStringOfDate(centerWithAssociations.activationDate)
value = Utils.getStringOfDate(centerWithAssociations.activationDate),
)
MifosCenterDetailsText(
icon = MifosIcons.date,
field = stringResource(id = R.string.feature_center_next_meeting_on),
value = if (centerWithAssociations.collectionMeetingCalendar.calendarInstanceId == null) stringResource(
id = R.string.feature_center_unassigned
) else Utils.getStringOfDate(centerWithAssociations.collectionMeetingCalendar.nextTenRecurringDates[0])
value = if (centerWithAssociations.collectionMeetingCalendar.calendarInstanceId == null) {
stringResource(
id = R.string.feature_center_unassigned,
)
} else {
Utils.getStringOfDate(centerWithAssociations.collectionMeetingCalendar.nextTenRecurringDates[0])
},
)
centerWithAssociations.collectionMeetingCalendar.humanReadable?.let {
MifosCenterDetailsText(
icon = MifosIcons.eventRepeat,
field = stringResource(id = R.string.feature_center_meeting_frequency),
value = it
value = it,
)
}
MifosCenterDetailsText(
icon = MifosIcons.person,
field = stringResource(id = R.string.feature_center_staff_name),
value = if (centerWithAssociations.staffName != null) centerWithAssociations.staffName.toString() else stringResource(
R.string.feature_center_no_staff
)
value = if (centerWithAssociations.staffName != null) {
centerWithAssociations.staffName.toString()
} else {
stringResource(
R.string.feature_center_no_staff,
)
},
)

Spacer(modifier = Modifier.height(16.dp))
Expand All @@ -238,60 +249,60 @@ fun CenterDetailsContent(
fontWeight = FontWeight.SemiBold,
),
color = Black,
textAlign = TextAlign.Center
textAlign = TextAlign.Center,
)

MifosCenterDetailsText(
icon = MifosIcons.person,
field = stringResource(id = R.string.feature_center_active_client),
value = centerInfo.activeClients.toString()
value = centerInfo.activeClients.toString(),
)
MifosCenterDetailsText(
icon = MifosIcons.group,
field = stringResource(id = R.string.feature_center_active_group_loan),
value = centerInfo.activeGroupLoans.toString()
value = centerInfo.activeGroupLoans.toString(),
)
MifosCenterDetailsText(
icon = MifosIcons.person,
field = stringResource(id = R.string.feature_center_active_client_loans),
value = centerInfo.activeClientLoans.toString()
value = centerInfo.activeClientLoans.toString(),
)
MifosCenterDetailsText(
icon = MifosIcons.group,
field = stringResource(id = R.string.feature_center_active_group_borrowers),
value = centerInfo.activeGroupBorrowers.toString()
value = centerInfo.activeGroupBorrowers.toString(),
)
MifosCenterDetailsText(
icon = MifosIcons.person,
field = stringResource(id = R.string.feature_center_active_client_borrowers),
value = centerInfo.activeClientBorrowers.toString()
value = centerInfo.activeClientBorrowers.toString(),
)
MifosCenterDetailsText(
icon = MifosIcons.group,
field = stringResource(id = R.string.feature_center_active_overdue_group_loans),
value = centerInfo.overdueGroupLoans.toString()
value = centerInfo.overdueGroupLoans.toString(),
)
MifosCenterDetailsText(
icon = MifosIcons.person,
field = stringResource(id = R.string.feature_center_active_group_loan),
value = centerInfo.overdueClientLoans.toString()
value = centerInfo.overdueClientLoans.toString(),
)
}
}

@Composable
fun MifosCenterDetailsText(icon: ImageVector, field: String, value: String) {
private fun MifosCenterDetailsText(icon: ImageVector, field: String, value: String) {
Row(
modifier = Modifier
.padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 8.dp)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
modifier = Modifier.size(18.dp),
imageVector = icon,
contentDescription = null,
tint = DarkGray
tint = DarkGray,
)
Text(
modifier = Modifier
Expand All @@ -301,51 +312,50 @@ fun MifosCenterDetailsText(icon: ImageVector, field: String, value: String) {
style = TextStyle(
fontSize = 18.sp,
fontWeight = FontWeight.Normal,
fontStyle = FontStyle.Normal
fontStyle = FontStyle.Normal,
),
color = Black,
textAlign = TextAlign.Start
textAlign = TextAlign.Start,
)
Text(

text = value,
style = TextStyle(
fontSize = 18.sp,
fontWeight = FontWeight.Normal,
fontStyle = FontStyle.Normal
fontStyle = FontStyle.Normal,
),
color = DarkGray,
textAlign = TextAlign.Start
textAlign = TextAlign.Start,
)
}
}

class CenterDetailsUiStateProvider : PreviewParameterProvider<CenterDetailsUiState> {
private class CenterDetailsUiStateProvider : PreviewParameterProvider<CenterDetailsUiState> {

override val values: Sequence<CenterDetailsUiState>
get() = sequenceOf(
CenterDetailsUiState.Loading,
CenterDetailsUiState.Error(R.string.feature_center_error_loading_centers),
CenterDetailsUiState.CenterDetails(CenterWithAssociations(), CenterInfo())
CenterDetailsUiState.CenterDetails(CenterWithAssociations(), CenterInfo()),
)
}


@Preview(showBackground = true)
@Composable
private fun CenterDetailsScreenPreview(
@PreviewParameter(CenterDetailsUiStateProvider::class) state: CenterDetailsUiState
@PreviewParameter(CenterDetailsUiStateProvider::class) state: CenterDetailsUiState,
) {
CenterDetailsScreen(
state = state,
onBackPressed = {},
onMenuClick = {},
onRetryClick = {},
onActivateCenter = {}
onActivateCenter = {},
)
}

enum class MenuItems {
ADD_SAVINGS_ACCOUNT,
GROUP_LIST
}
GROUP_LIST,
}
Loading
Loading