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

refactor: Applied spotless and detekt to the report module #2242

Merged
merged 1 commit into from
Nov 29, 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
9 changes: 9 additions & 0 deletions feature/report/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.report

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

import androidx.test.platform.app.InstrumentationRegistry
import junit.framework.TestCase.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.report.test", appContext.packageName)
}
}
}
9 changes: 9 additions & 0 deletions feature/report/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,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.report.navigation

import androidx.navigation.NavController
Expand All @@ -11,68 +20,68 @@ import com.mifos.core.common.utils.Constants
import com.mifos.core.objects.runreports.FullParameterListResponse
import com.mifos.core.objects.runreports.client.ClientReportTypeItem
import com.mifos.feature.report.report.ReportScreen
import com.mifos.feature.report.report_detail.ReportDetailScreen
import com.mifos.feature.report.run_report.RunReportScreen
import com.mifos.feature.report.reportDetail.ReportDetailScreen
import com.mifos.feature.report.runReport.RunReportScreen

fun NavGraphBuilder.reportNavGraph(
navController: NavController
navController: NavController,
) {
navigation(
startDestination = ReportScreens.RunReportScreen.route,
route = "run_report_route"
route = "run_report_route",
) {
runReportScreenRoute(
onBackPressed = navController::popBackStack,
onReportSelected = navController::navigateReportDetailsScreen
onReportSelected = navController::navigateReportDetailsScreen,
)
reportDetailsScreenRoute(
onBackPressed = navController::popBackStack,
runReport = navController::navigateReportScreens
runReport = navController::navigateReportScreens,
)
reportScreenRoute(
onBackPressed = navController::popBackStack
onBackPressed = navController::popBackStack,
)
}
}

fun NavGraphBuilder.runReportScreenRoute(
onBackPressed: () -> Unit,
onReportSelected: (ClientReportTypeItem) -> Unit
onReportSelected: (ClientReportTypeItem) -> Unit,
) {
composable(
route = ReportScreens.RunReportScreen.route
route = ReportScreens.RunReportScreen.route,
) {
RunReportScreen(
onBackPressed = onBackPressed,
onReportClick = onReportSelected
onReportClick = onReportSelected,
)
}
}

fun NavGraphBuilder.reportDetailsScreenRoute(
onBackPressed: () -> Unit,
runReport: (FullParameterListResponse) -> Unit
runReport: (FullParameterListResponse) -> Unit,
) {
composable(
route = ReportScreens.ReportDetailScreen.route,
arguments = listOf(navArgument(Constants.REPORT_TYPE_ITEM, builder = {type = NavType.StringType}))
arguments = listOf(navArgument(Constants.REPORT_TYPE_ITEM, builder = { type = NavType.StringType })),
) {
ReportDetailScreen(
onBackPressed = onBackPressed,
runReport = runReport
runReport = runReport,
)
}
}

fun NavGraphBuilder.reportScreenRoute(
onBackPressed: () -> Unit
onBackPressed: () -> Unit,
) {
composable(
route = ReportScreens.ReportScreen.route,
arguments = listOf(navArgument(Constants.REPORT_PARAMETER_RESPONSE, builder = {type = NavType.StringType}))
arguments = listOf(navArgument(Constants.REPORT_PARAMETER_RESPONSE, builder = { type = NavType.StringType })),
) {
ReportScreen(
onBackPressed = onBackPressed
onBackPressed = onBackPressed,
)
}
}
Expand All @@ -85,4 +94,4 @@ fun NavController.navigateReportDetailsScreen(clientReportTypeItem: ClientReport
fun NavController.navigateReportScreens(fullParameterListResponse: FullParameterListResponse) {
val arg = Gson().toJson(fullParameterListResponse)
navigate(ReportScreens.ReportScreen.argument(arg))
}
}
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.report.navigation

import com.mifos.core.common.utils.Constants
Expand All @@ -8,11 +17,11 @@ sealed class ReportScreens(val route: String) {

data object ReportDetailScreen :
ReportScreens(route = "report_detail_screen/{${Constants.REPORT_TYPE_ITEM}}") {
fun argument(reportTypeItem: String) = "report_detail_screen/${reportTypeItem}"
fun argument(reportTypeItem: String) = "report_detail_screen/$reportTypeItem"
}

data object ReportScreen :
ReportScreens(route = "report_screen/{${Constants.REPORT_PARAMETER_RESPONSE}}") {
fun argument(reportParameter: String) = "report_screen/${reportParameter}"
fun argument(reportParameter: String) = "report_screen/$reportParameter"
}
}
}
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.report.report

import android.Manifest
Expand Down Expand Up @@ -43,11 +52,10 @@ import com.mifos.feature.report.R
import kotlinx.coroutines.launch

@Composable
fun ReportScreen(
onBackPressed: () -> Unit
internal fun ReportScreen(
onBackPressed: () -> Unit,
viewModel: ReportViewModel = hiltViewModel(),
) {

val viewModel: ReportViewModel = hiltViewModel()
val report = viewModel.report
val state by viewModel.reportUiState.collectAsStateWithLifecycle()
val context = LocalContext.current
Expand All @@ -62,27 +70,25 @@ fun ReportScreen(
.toString() + getString(context, R.string.feature_report_export_csv_directory)
viewModel.exportCsv(
report = report,
reportDirectoryPath = reportDirectoryPath
reportDirectoryPath = reportDirectoryPath,
)
}
},
)
}


@Composable
fun ReportScreen(
internal fun ReportScreen(
state: ReportUiState,
report: FullParameterListResponse,
onBackPressed: () -> Unit,
exportReport: () -> Unit
modifier: Modifier = Modifier,
exportReport: () -> Unit,
) {

val context = LocalContext.current
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
var checkPermission by remember { mutableStateOf(false) }


when (state) {
is ReportUiState.Initial -> Unit
is ReportUiState.Message -> {
Expand All @@ -97,7 +103,7 @@ fun ReportScreen(
} else {
listOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
Manifest.permission.WRITE_EXTERNAL_STORAGE,
)
},
title = R.string.feature_report_permission_required,
Expand All @@ -110,11 +116,12 @@ fun ReportScreen(
exportReport()
}
}
}
},
)
}

MifosScaffold(
modifier = modifier,
icon = MifosIcons.arrowBack,
title = stringResource(R.string.feature_report_title),
onBackPressed = onBackPressed,
Expand All @@ -123,18 +130,18 @@ fun ReportScreen(
onClick = {
checkPermission = true
},
colors = ButtonDefaults.textButtonColors(White)
colors = ButtonDefaults.textButtonColors(White),
) {
Text(text = stringResource(id = R.string.feature_report_export_csv), color = Black)
}
},
snackbarHostState = snackbarHostState
snackbarHostState = snackbarHostState,
) { paddingValues ->

Column(
modifier = Modifier
.padding(paddingValues)
.verticalScroll(rememberScrollState())
.verticalScroll(rememberScrollState()),
) {
LazyRow {
itemsIndexed(report.columnHeaders.map { it.columnName }) { index, columnName ->
Expand All @@ -143,8 +150,8 @@ fun ReportScreen(
modifier = Modifier.padding(8.dp),
text = columnName,
style = TextStyle(
fontWeight = FontWeight.Bold
)
fontWeight = FontWeight.Bold,
),
)
report.data.map { it.row }.forEach {
Text(text = it[index], modifier = Modifier.padding(8.dp))
Expand All @@ -156,25 +163,24 @@ fun ReportScreen(
}
}

class ReportUiStateProvider : PreviewParameterProvider<ReportUiState> {
private class ReportUiStateProvider : PreviewParameterProvider<ReportUiState> {

override val values: Sequence<ReportUiState>
get() = sequenceOf(
ReportUiState.Initial,
ReportUiState.Message(R.string.feature_report_export_csv)
ReportUiState.Message(R.string.feature_report_export_csv),
)

}

@Preview(showBackground = true)
@Composable
private fun ReportScreenPreview(
@PreviewParameter(ReportUiStateProvider::class) state: ReportUiState
@PreviewParameter(ReportUiStateProvider::class) state: ReportUiState,
) {
ReportScreen(
state = state,
report = FullParameterListResponse(emptyList(), emptyList()),
onBackPressed = { },
exportReport = { }
exportReport = { },
)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
/*
* 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.report.report

sealed class ReportUiState {

data object Initial : ReportUiState()

data class Message(val message: Int) : ReportUiState()
}
}
Loading
Loading