Skip to content

feat: report migrate to cmp #2367

New issue

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

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

Already on GitHub? # to your account

Closed
wants to merge 5 commits into from
Closed
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
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
25 changes: 12 additions & 13 deletions feature/report/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@
* 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.report"
}

dependencies {
kotlin {
sourceSets {
commonMain.dependencies {
implementation(compose.material3)
implementation(compose.components.resources)
implementation(compose.ui)
api(projects.core.common)
api(projects.core.model)

implementation(projects.core.domain)

//DBFlow dependencies
testImplementation(libs.hilt.android.testing)
testImplementation(projects.core.testing)

implementation(libs.kotlinx.serialization.json)
}
}
}

androidTestImplementation(projects.core.testing)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
*/
package com.mifos.feature.report.report

import android.Manifest
import android.os.Build
import android.os.Environment
import android.widget.Toast
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyRow
Expand All @@ -34,21 +30,19 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color.Companion.Black
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
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.core.content.ContextCompat.getString
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.designsystem.component.PermissionBox
import com.mifos.core.model.objects.runreport.FullParameterListResponse
import com.mifos.feature.report.R
import core.designsystem.generated.resources.Res
import kotlinx.coroutines.launch
import org.koin.androidx.compose.koinViewModel
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.viewmodel.koinViewModel

@Composable
internal fun ReportScreen(
Expand All @@ -66,7 +60,7 @@ internal fun ReportScreen(
exportReport = {
val reportDirectoryPath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.toString() + getString(context, R.string.feature_report_export_csv_directory)
.toString() + getString(context, Res.string.feature_report_export_csv_directory)
viewModel.exportCsv(
report = report,
reportDirectoryPath = reportDirectoryPath,
Expand All @@ -91,7 +85,7 @@ internal fun ReportScreen(
when (state) {
is ReportUiState.Initial -> Unit
is ReportUiState.Message -> {
Toast.makeText(context, stringResource(id = state.message), Toast.LENGTH_SHORT).show()
Toast.makeText(context, stringResource(state.message), Toast.LENGTH_SHORT).show()
}
}

Expand All @@ -105,10 +99,10 @@ internal fun ReportScreen(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
)
},
title = stringResource(R.string.feature_report_permission_required),
description = stringResource(R.string.feature_report_external_approve_permission_description),
confirmButtonText = stringResource(R.string.feature_report_proceed),
dismissButtonText = stringResource(R.string.feature_report_dismiss),
title = stringResource(Res.string.feature_report_permission_required),
description = stringResource(Res.string.feature_report_external_approve_permission_description),
confirmButtonText = stringResource(Res.string.feature_report_proceed),
dismissButtonText = stringResource(Res.string.feature_report_dismiss),
onGranted = {
LaunchedEffect(key1 = Unit) {
scope.launch {
Expand All @@ -121,7 +115,7 @@ internal fun ReportScreen(

MifosScaffold(
modifier = modifier,
title = stringResource(R.string.feature_report_title),
title = stringResource(Res.string.feature_report_title),
onBackPressed = onBackPressed,
actions = {
TextButton(
Expand All @@ -130,7 +124,7 @@ internal fun ReportScreen(
},
colors = ButtonDefaults.textButtonColors(White),
) {
Text(text = stringResource(id = R.string.feature_report_export_csv), color = Black)
Text(text = stringResource(Res.string.feature_report_export_csv), color = Black)
}
},
snackbarHostState = snackbarHostState,
Expand Down Expand Up @@ -166,7 +160,7 @@ private class ReportUiStateProvider : PreviewParameterProvider<ReportUiState> {
override val values: Sequence<ReportUiState>
get() = sequenceOf(
ReportUiState.Initial,
ReportUiState.Message(R.string.feature_report_export_csv),
ReportUiState.Message(Res.string.feature_report_export_csv),
)
}

Expand All @@ -182,3 +176,6 @@ private fun ReportScreenPreview(
exportReport = { },
)
}



Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.common.utils.Constants
import com.mifos.core.model.objects.runreport.FullParameterListResponse
import com.mifos.feature.report.R
import core.designsystem.generated.resources.Res
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand All @@ -37,7 +37,7 @@ class ReportViewModel(

fun exportCsv(report: FullParameterListResponse, reportDirectoryPath: String) =
viewModelScope.launch(Dispatchers.IO) {
_reportUiState.value = ReportUiState.Message(R.string.feature_report_export_started)
_reportUiState.value = ReportUiState.Message(Res.string.feature_report_export_started)
val timestamp = System.currentTimeMillis()
val reportPath = "$reportDirectoryPath$timestamp.csv"
val reportDirectory = File(reportDirectoryPath)
Expand All @@ -46,7 +46,7 @@ class ReportViewModel(
val makeRequiredDirectories = reportDirectory.mkdirs()
if (!makeRequiredDirectories) {
_reportUiState.value =
ReportUiState.Message(R.string.feature_report_unable_to_create_directory)
ReportUiState.Message(Res.string.feature_report_unable_to_create_directory)
}
}

Expand Down Expand Up @@ -75,9 +75,9 @@ class ReportViewModel(
fileWriter.close()
} catch (e: Exception) {
_reportUiState.value =
ReportUiState.Message(R.string.feature_report_unable_to_export)
ReportUiState.Message(Res.string.feature_report_unable_to_export)
}
_reportUiState.value =
ReportUiState.Message(R.string.feature_report_exported_successfully)
ReportUiState.Message(Res.string.feature_report_exported_successfully)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,9 @@ import androidx.compose.ui.graphics.Color.Companion.Black
import androidx.compose.ui.graphics.Color.Companion.Blue
import androidx.compose.ui.graphics.Color.Companion.Gray
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
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 @@ -65,8 +60,9 @@ import com.mifos.core.designsystem.component.MifosTextFieldDropdown
import com.mifos.core.model.objects.runreport.DataRow
import com.mifos.core.model.objects.runreport.FullParameterListResponse
import com.mifos.core.model.objects.runreport.client.ClientReportTypeItem
import com.mifos.feature.report.R
import org.koin.androidx.compose.koinViewModel
import core.designsystem.generated.resources.Res
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.viewmodel.koinViewModel

@Composable
internal fun ReportDetailScreen(
Expand Down Expand Up @@ -210,21 +206,21 @@ internal fun ReportDetailScreen(

MifosScaffold(
modifier = modifier,
title = stringResource(id = R.string.feature_report_details),
title = stringResource(Res.string.feature_report_details),
onBackPressed = onBackPressed,
actions = {
TextButton(
onClick = { runReport(runReportDetail) },
colors = ButtonDefaults.textButtonColors(White),
) {
Text(text = stringResource(id = R.string.feature_report_run_report), color = Black)
Text(text = stringResource(Res.string.feature_report_run_report), color = Black)
}
},
snackbarHostState = snackbarHostState,
) { paddingValues ->
Box(modifier = Modifier.padding(paddingValues)) {
when (state) {
is ReportDetailUiState.Error -> MifosSweetError(message = stringResource(id = state.message)) {
is ReportDetailUiState.Error -> MifosSweetError(message = stringResource(state.message)) {
onRetry()
}

Expand Down Expand Up @@ -368,7 +364,7 @@ private fun RunReportContent(
.background(Blue, CircleShape),
) {
Icon(
painter = painterResource(id = R.drawable.feature_report_ic_report_item),
painter = painterResource(Res.drawable.feature_report_ic_report_item),
contentDescription = null,
tint = Black,
)
Expand Down Expand Up @@ -430,7 +426,7 @@ private fun RunReportContent(
selectedOffice = value
selectedOfficeId = officeList[index].row.first()
},
label = R.string.feature_report_office,
label = Res.string.feature_report_office,
options = officeList.map { it.row[1] },
readOnly = true,
)
Expand All @@ -447,7 +443,7 @@ private fun RunReportContent(
selectedLoanPurpose = value
selectedLoanPurposeId = loanPurposeList[index].row.first()
},
label = R.string.feature_report_loan_purpose,
label = Res.string.feature_report_loan_purpose,
options = loanPurposeList.map { it.row[1] },
readOnly = true,
)
Expand All @@ -464,7 +460,7 @@ private fun RunReportContent(
selectedLoanOfficer = value
selectedLoanOfficerId = reportOffices[index].row.first()
},
label = R.string.feature_report_loan_officer,
label = Res.string.feature_report_loan_officer,
options = reportOffices.map { it.row[1] },
readOnly = true,
)
Expand All @@ -481,7 +477,7 @@ private fun RunReportContent(
selectedProducts = value
selectedProductsId = reportProducts[index].row.first()
},
label = R.string.feature_report_product,
label = Res.string.feature_report_product,
options = reportProducts.map { it.row[1] },
readOnly = true,
)
Expand All @@ -498,7 +494,7 @@ private fun RunReportContent(
selectedFund = value
selectedFundId = fundList[index].row.first()
},
label = R.string.feature_report_fund,
label = Res.string.feature_report_fund,
options = fundList.map { it.row[1] },
readOnly = true,
)
Expand All @@ -515,7 +511,7 @@ private fun RunReportContent(
selectedCurrency = value
selectedCurrencyId = currencyList[index].row.first()
},
label = R.string.feature_report_currency,
label = Res.string.feature_report_currency,
options = currencyList.map { it.row[1] },
readOnly = true,
)
Expand All @@ -532,7 +528,7 @@ private fun RunReportContent(
selectedParCalculator = value
selectedParCalculatorId = parCalculatorList[index].row.first()
},
label = R.string.feature_report_par_type,
label = Res.string.feature_report_par_type,
options = parCalculatorList.map { it.row[1] },
readOnly = true,
)
Expand All @@ -549,7 +545,7 @@ private fun RunReportContent(
selectedSavingsAccountDeposit = value
selectedSavingsAccountDepositId = savingsAccountDepositList[index].row.first()
},
label = R.string.feature_report_saving_account,
label = Res.string.feature_report_saving_account,
options = savingsAccountDepositList.map { it.row[1] },
readOnly = true,
)
Expand All @@ -566,7 +562,7 @@ private fun RunReportContent(
selectedGlAccount = value
selectedGlAccountId = glAccountList[index].row.first()
},
label = R.string.feature_report_gl_account,
label = Res.string.feature_report_gl_account,
options = glAccountList.map { it.row[1] },
readOnly = true,
)
Expand All @@ -583,7 +579,7 @@ private fun RunReportContent(
selectedObligationDate = value
selectedObligationDateId = obligationDateList[index].row.first()
},
label = R.string.feature_report_obligation_date,
label = Res.string.feature_report_obligation_date,
options = obligationDateList.map { it.row[1] },
readOnly = true,
)
Expand All @@ -592,36 +588,4 @@ private fun RunReportContent(
}
}

private class ReportDetailUiStateProvider : PreviewParameterProvider<ReportDetailUiState> {

override val values: Sequence<ReportDetailUiState>
get() = sequenceOf(
ReportDetailUiState.Error(R.string.feature_report_failed_to_load_report_details),
ReportDetailUiState.Loading,
ReportDetailUiState.ParameterDetailsSuccess,
)
}

@Preview(showBackground = true)
@Composable
private fun ReportDetailScreenPreview(
@PreviewParameter(ReportDetailUiStateProvider::class) state: ReportDetailUiState,
) {
ReportDetailScreen(
reportItem = ClientReportTypeItem(),
state = state,
onBackPressed = {},
onRetry = {},
officeList = emptyList(),
loanPurposeList = emptyList(),
fundList = emptyList(),
currencyList = emptyList(),
parCalculatorList = emptyList(),
savingsAccountDepositList = emptyList(),
glAccountList = emptyList(),
obligationDateList = emptyList(),
reportOffices = emptyList(),
reportProducts = emptyList(),
runReport = {},
)
}
Loading
Loading