diff --git a/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientNavigation.kt b/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientNavigation.kt index 30165b93c2a..79929d84cfe 100644 --- a/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientNavigation.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientNavigation.kt @@ -30,7 +30,7 @@ import com.mifos.feature.client.clientSignature.SignatureScreen import com.mifos.feature.client.clientSurveyList.SurveyListScreen import com.mifos.feature.client.clientSurveyQuestion.SurveyQuestionScreen import com.mifos.feature.client.createNewClient.CreateNewClientScreen -import com.mifos.feature.data_table.dataTableList.FormWidget +import com.mifos.feature.dataTable.dataTableList.FormWidget import kotlin.reflect.KFunction4 fun NavGraphBuilder.clientNavGraph( diff --git a/feature/data-table/build.gradle.kts b/feature/data-table/build.gradle.kts index a59c75d6c3c..1e65fe8f2d0 100644 --- a/feature/data-table/build.gradle.kts +++ b/feature/data-table/build.gradle.kts @@ -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) diff --git a/feature/data-table/src/androidTest/java/com/mifos/feature/data_table/ExampleInstrumentedTest.kt b/feature/data-table/src/androidTest/java/com/mifos/feature/dataTable/ExampleInstrumentedTest.kt similarity index 61% rename from feature/data-table/src/androidTest/java/com/mifos/feature/data_table/ExampleInstrumentedTest.kt rename to feature/data-table/src/androidTest/java/com/mifos/feature/dataTable/ExampleInstrumentedTest.kt index a92c745615a..1c5a02acbdf 100644 --- a/feature/data-table/src/androidTest/java/com/mifos/feature/data_table/ExampleInstrumentedTest.kt +++ b/feature/data-table/src/androidTest/java/com/mifos/feature/dataTable/ExampleInstrumentedTest.kt @@ -1,13 +1,20 @@ -package com.mifos.feature.data_table +/* + * 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.dataTable -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * @@ -21,4 +28,4 @@ class ExampleInstrumentedTest { val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.mifos.feature.data_table.test", appContext.packageName) } -} \ No newline at end of file +} diff --git a/feature/data-table/src/main/AndroidManifest.xml b/feature/data-table/src/main/AndroidManifest.xml index a5918e68abc..1dc76da0f7e 100644 --- a/feature/data-table/src/main/AndroidManifest.xml +++ b/feature/data-table/src/main/AndroidManifest.xml @@ -1,4 +1,13 @@ + \ No newline at end of file diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableScreen.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableScreen.kt similarity index 82% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableScreen.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableScreen.kt index 9551bd17d54..7d631a0888b 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableScreen.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableScreen.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.data_table.dataTable +/* + * 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.dataTable.dataTable import android.widget.Toast import androidx.compose.foundation.layout.Box @@ -47,9 +56,9 @@ import com.mifos.feature.data_table.R @Composable fun DataTableScreen( - viewModel: DataTableViewModel = hiltViewModel(), navigateBack: () -> Unit, - onClick: (table: String, entityId: Int, dataTable: DataTable) -> Unit + viewModel: DataTableViewModel = hiltViewModel(), + onClick: (table: String, entityId: Int, dataTable: DataTable) -> Unit, ) { val tableName = viewModel.args.tableName val entityId = viewModel.args.entityId @@ -67,7 +76,7 @@ fun DataTableScreen( isRefreshing = isRefreshing, onClick = { onClick(tableName, entityId, it) - } + }, ) } @@ -78,7 +87,8 @@ fun DataTableScreen( navigateBack: () -> Unit, onRefresh: () -> Unit, isRefreshing: Boolean, - onClick: (dataTable: DataTable) -> Unit + onClick: (dataTable: DataTable) -> Unit, + modifier: Modifier = Modifier, ) { val snackbarHostState = remember { SnackbarHostState() } val pullRefreshState = rememberPullToRefreshState() @@ -88,19 +98,19 @@ fun DataTableScreen( icon = MifosIcons.arrowBack, title = stringResource(id = R.string.feature_data_table_title), onBackPressed = navigateBack, - snackbarHostState = snackbarHostState + snackbarHostState = snackbarHostState, ) { Box( - modifier = Modifier + modifier = modifier // Pass the modifier here .fillMaxSize() .padding(it) - .nestedScroll(pullRefreshState.nestedScrollConnection) + .nestedScroll(pullRefreshState.nestedScrollConnection), ) { when (uiState) { is DataTableUiState.ShowDataTables -> { DataTableContent( dataTable = uiState.dataTables, - onClick = onClick + onClick = onClick, ) } @@ -110,7 +120,8 @@ fun DataTableScreen( is DataTableUiState.ShowError -> { MifosSweetError( - message = stringResource(id = uiState.message), onclick = onRefresh + message = stringResource(id = uiState.message), + onclick = onRefresh, ) } @@ -126,8 +137,9 @@ fun DataTableScreen( } LaunchedEffect(key1 = isRefreshing) { - if (isRefreshing) + if (isRefreshing) { pullRefreshState.startRefresh() + } } LaunchedEffect(key1 = pullRefreshState.isRefreshing) { @@ -150,13 +162,16 @@ fun DataTableScreen( @Composable fun DataTableContent( dataTable: List, - onClick: (dataTable: DataTable) -> Unit + onClick: (dataTable: DataTable) -> Unit, + modifier: Modifier = Modifier, ) { - LazyColumn { + LazyColumn( + modifier = modifier, + ) { items(dataTable) { dataTable -> DataTableItem( dataTable = dataTable, - onClick = onClick + onClick = onClick, ) } } @@ -165,30 +180,31 @@ fun DataTableContent( @Composable fun DataTableItem( dataTable: DataTable, - onClick: (dataTable: DataTable) -> Unit + onClick: (dataTable: DataTable) -> Unit, + modifier: Modifier = Modifier, ) { Card( - modifier = Modifier + modifier = modifier .fillMaxWidth() .padding( horizontal = 4.dp, - vertical = 4.dp + vertical = 4.dp, ), shape = RoundedCornerShape(0.dp), elevation = CardDefaults.cardElevation(defaultElevation = 2.dp), colors = CardDefaults.cardColors( - containerColor = Color.White + containerColor = Color.White, ), - onClick = { onClick.invoke(dataTable) } + onClick = { onClick.invoke(dataTable) }, ) { dataTable.registeredTableName?.let { Text( modifier = Modifier.padding( horizontal = 16.dp, - vertical = 18.dp + vertical = 18.dp, ), style = MaterialTheme.typography.bodyLarge, - text = it + text = it, ) } } @@ -199,18 +215,18 @@ class DataTablePreviewProvider : PreviewParameterProvider { DataTable( applicationTableName = "AppTable1", columnHeaderData = listOf(), - registeredTableName = "registered Table Name" + registeredTableName = "registered Table Name", ), DataTable( applicationTableName = "AppTable1", columnHeaderData = listOf(), - registeredTableName = "registered Table Name" + registeredTableName = "registered Table Name", ), DataTable( applicationTableName = "AppTable1", columnHeaderData = listOf(), - registeredTableName = "registered Table Name" - ) + registeredTableName = "registered Table Name", + ), ) override val values: Sequence @@ -218,21 +234,20 @@ class DataTablePreviewProvider : PreviewParameterProvider { DataTableUiState.ShowEmptyDataTables, DataTableUiState.ShowProgressbar, DataTableUiState.ShowDataTables(dataTable), - DataTableUiState.ShowError(R.string.feature_data_table_failed_to_fetch_data_table) + DataTableUiState.ShowError(R.string.feature_data_table_failed_to_fetch_data_table), ) } @Composable @Preview(showSystemUi = true) -fun PreviewDataTable( - @PreviewParameter(DataTablePreviewProvider::class) dataTableUiState: DataTableUiState +private fun PreviewDataTable( + @PreviewParameter(DataTablePreviewProvider::class) dataTableUiState: DataTableUiState, ) { DataTableScreen( uiState = dataTableUiState, navigateBack = { }, onRefresh = { }, isRefreshing = false, - onClick = { } + onClick = { }, ) } - diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableUiState.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableUiState.kt similarity index 51% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableUiState.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableUiState.kt index 01910946523..dcf688bd0ac 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableUiState.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableUiState.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.data_table.dataTable +/* + * 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.dataTable.dataTable import com.mifos.core.objects.noncore.DataTable diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableViewModel.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableViewModel.kt similarity index 86% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableViewModel.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableViewModel.kt index 9d075bd6fcc..196056d9e2b 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableViewModel.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableViewModel.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.data_table.dataTable +/* + * 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.dataTable.dataTable import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel @@ -25,7 +34,7 @@ import javax.inject.Inject @HiltViewModel class DataTableViewModel @Inject constructor( private val repository: DataTableRepository, - private val savedStateHandle: SavedStateHandle + private val savedStateHandle: SavedStateHandle, ) : ViewModel() { private val arg = @@ -67,6 +76,4 @@ class DataTableViewModel @Inject constructor( } }) } - } - diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableData/DataTableDataScreen.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableData/DataTableDataScreen.kt similarity index 81% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableData/DataTableDataScreen.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableData/DataTableDataScreen.kt index 9b8a56b189a..4563f78ea2e 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableData/DataTableDataScreen.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableData/DataTableDataScreen.kt @@ -1,6 +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/android-client/blob/master/LICENSE.md + */ @file:OptIn(ExperimentalMaterialApi::class) -package com.mifos.feature.data_table.dataTableData +package com.mifos.feature.dataTable.dataTableData import android.widget.Toast import androidx.compose.foundation.clickable @@ -66,23 +75,22 @@ import com.mifos.core.designsystem.theme.DarkGray import com.mifos.core.designsystem.theme.White import com.mifos.core.objects.noncore.DataTable import com.mifos.core.ui.components.MifosEmptyUi +import com.mifos.feature.dataTable.dataTableRowDialog.DataTableRowDialogScreen import com.mifos.feature.data_table.R -import com.mifos.feature.data_table.dataTableRowDialog.DataTableRowDialogScreen @Composable fun DataTableDataScreen( - onBackPressed: () -> Unit + viewModel: DataTableDataViewModel = hiltViewModel(), + onBackPressed: () -> Unit, ) { - - val viewmodel: DataTableDataViewModel = hiltViewModel() - val dataTable = viewmodel.arg.dataTable - val entityId = viewmodel.arg.entityId - val table = viewmodel.arg.tableName - val state by viewmodel.tableDataUiState.collectAsStateWithLifecycle() - val isRefreshing by viewmodel.isRefreshing.collectAsStateWithLifecycle() + val dataTable = viewModel.arg.dataTable + val entityId = viewModel.arg.entityId + val table = viewModel.arg.tableName + val state by viewModel.dataTableDataUiState.collectAsStateWithLifecycle() + val isRefreshing by viewModel.isRefreshing.collectAsStateWithLifecycle() LaunchedEffect(Unit) { - viewmodel.loadDataTableInfo(table, entityId) + viewModel.loadDataTableInfo(table, entityId) } DataTableDataScreen( @@ -91,17 +99,16 @@ fun DataTableDataScreen( state = state, onBackPressed = onBackPressed, onRetry = { - viewmodel.loadDataTableInfo(table, entityId) + viewModel.loadDataTableInfo(table, entityId) }, onRefresh = { - viewmodel.refreshDataTableData(table, entityId) + viewModel.refreshDataTableData(table, entityId) }, refreshState = isRefreshing, deleteDataTable = { - viewmodel.deleteDataTableEntry(table, entityId, it) - } + viewModel.deleteDataTableEntry(table, entityId, it) + }, ) - } @Composable @@ -113,18 +120,18 @@ fun DataTableDataScreen( onRetry: () -> Unit, onRefresh: () -> Unit, refreshState: Boolean, - deleteDataTable: (Int) -> Unit + deleteDataTable: (Int) -> Unit, + modifier: Modifier = Modifier, ) { val snackbarHostState = remember { SnackbarHostState() } val pullRefreshState = rememberPullRefreshState( refreshing = refreshState, - onRefresh = onRefresh + onRefresh = onRefresh, ) var showOptionDialog by rememberSaveable { mutableStateOf(false) } var deleteDataTableId by rememberSaveable { mutableIntStateOf(0) } var showAddDataTableRowDialog by rememberSaveable { mutableStateOf(false) } - if (showAddDataTableRowDialog) { DataTableRowDialogScreen( dataTable = dataTable, @@ -135,7 +142,7 @@ fun DataTableDataScreen( onSuccess = { showAddDataTableRowDialog = false onRetry() - } + }, ) } @@ -146,11 +153,10 @@ fun DataTableDataScreen( deleteDataTable(deleteDataTableId) showOptionDialog = false onRetry() - } + }, ) } - MifosScaffold( icon = MifosIcons.arrowBack, title = stringResource(id = R.string.feature_data_table_title), @@ -162,17 +168,16 @@ fun DataTableDataScreen( Icon(imageVector = MifosIcons.Add, contentDescription = null) } }, - snackbarHostState = snackbarHostState + snackbarHostState = snackbarHostState, ) { paddingValues -> - Column(modifier = Modifier.padding(paddingValues)) { + Column(modifier = modifier.padding(paddingValues)) { // Use the passed Modifier here Box(modifier = Modifier.pullRefresh(pullRefreshState)) { - when (state) { is DataTableDataUiState.DataTableDeletedSuccessfully -> { Toast.makeText( LocalContext.current, stringResource(id = R.string.feature_data_table_data_table_created_successfully), - Toast.LENGTH_SHORT + Toast.LENGTH_SHORT, ).show() onBackPressed() } @@ -183,7 +188,7 @@ fun DataTableDataScreen( onDataClicked = { showOptionDialog = true deleteDataTableId = it - } + }, ) } @@ -197,7 +202,7 @@ fun DataTableDataScreen( PullRefreshIndicator( refreshing = refreshState, state = pullRefreshState, - modifier = Modifier.align(Alignment.TopCenter) + modifier = Modifier.align(Alignment.TopCenter), ) } } @@ -207,23 +212,20 @@ fun DataTableDataScreen( @Composable fun DataTableDataContent( jsonElements: JsonArray, - onDataClicked: (Int) -> Unit + onDataClicked: (Int) -> Unit, + modifier: Modifier = Modifier, ) { - val jsonElementIterator: Iterator = jsonElements.iterator() var dataList by rememberSaveable { mutableStateOf>(emptyList()) } - if (jsonElements.size() == 0) { MifosEmptyUi( text = stringResource(id = R.string.feature_data_table_no_data_table_details_to_show), + modifier = modifier, ) } else { - while (jsonElementIterator.hasNext()) { - val dataTableDataItem = DataTableDataItem() - val jsonElement: JsonElement = jsonElementIterator.next() if (jsonElement.asJsonObject.has("client_id")) { @@ -235,13 +237,11 @@ fun DataTableDataContent( dataList = dataList + dataTableDataItem } - - - LazyColumn { + LazyColumn(modifier = modifier) { items(dataList) { dataItem -> DataTableDataCardItem( dataItem = dataItem, - onDataClicked = onDataClicked + onDataClicked = onDataClicked, ) } } @@ -251,33 +251,33 @@ fun DataTableDataContent( @Composable fun DataTableDataCardItem( dataItem: DataTableDataItem, - onDataClicked: (Int) -> Unit + onDataClicked: (Int) -> Unit, + modifier: Modifier = Modifier, ) { OutlinedCard( - modifier = Modifier + modifier = modifier .padding(8.dp) .clickable { onDataClicked(dataItem.clientId?.toInt() ?: dataItem.id?.toInt() ?: 0) }, - colors = CardDefaults.cardColors(White) + colors = CardDefaults.cardColors(White), ) { Row( modifier = Modifier .fillMaxWidth() - .padding( - 16.dp - ), - verticalAlignment = Alignment.CenterVertically + .padding(16.dp), + verticalAlignment = Alignment.CenterVertically, ) { Column( modifier = Modifier .weight(1f) - .padding(start = 16.dp) + .padding(start = 16.dp), ) { Row( modifier = Modifier .fillMaxWidth() - .padding(top = 8.dp), horizontalArrangement = Arrangement.SpaceBetween + .padding(top = 8.dp), + horizontalArrangement = Arrangement.SpaceBetween, ) { Text( modifier = Modifier.weight(1f), @@ -286,8 +286,8 @@ fun DataTableDataCardItem( fontSize = 14.sp, fontWeight = FontWeight.Normal, fontStyle = FontStyle.Normal, - color = Black - ) + color = Black, + ), ) Text( modifier = Modifier.weight(1f), @@ -296,14 +296,14 @@ fun DataTableDataCardItem( fontSize = 14.sp, fontWeight = FontWeight.Normal, fontStyle = FontStyle.Normal, - color = DarkGray - ) + color = DarkGray, + ), ) } Row( modifier = Modifier .fillMaxWidth() - .padding(top = 8.dp) + .padding(top = 8.dp), ) { Text( modifier = Modifier.weight(1f), @@ -312,8 +312,8 @@ fun DataTableDataCardItem( fontSize = 14.sp, fontWeight = FontWeight.Normal, fontStyle = FontStyle.Normal, - color = Black - ) + color = Black, + ), ) Text( modifier = Modifier.weight(1f), @@ -322,8 +322,8 @@ fun DataTableDataCardItem( fontSize = 14.sp, fontWeight = FontWeight.Normal, fontStyle = FontStyle.Normal, - color = DarkGray - ) + color = DarkGray, + ), ) } } @@ -331,7 +331,6 @@ fun DataTableDataCardItem( } } - data class DataTableDataItem( var id: String? = null, var clientId: String? = null, @@ -343,33 +342,33 @@ class DataTableDataUiStateProvider : PreviewParameterProvider Unit, deleteDataTable: () -> Unit, + modifier: Modifier = Modifier, ) { - Dialog( onDismissRequest = { onDismissRequest() }, properties = DialogProperties( dismissOnBackPress = true, - dismissOnClickOutside = true - ) + dismissOnClickOutside = true, + ), ) { Card( colors = CardDefaults.cardColors(White), - shape = RoundedCornerShape(20.dp) + shape = RoundedCornerShape(20.dp), + modifier = modifier, ) { Column( modifier = Modifier .padding(30.dp), verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally + horizontalAlignment = Alignment.CenterHorizontally, ) { Text( text = stringResource(id = R.string.feature_data_table_select_options), @@ -377,16 +376,16 @@ fun SelectOptionsDialog( style = TextStyle( fontSize = 18.sp, fontWeight = FontWeight.Normal, - fontStyle = FontStyle.Normal + fontStyle = FontStyle.Normal, ), color = Color.Black, - textAlign = TextAlign.Center + textAlign = TextAlign.Center, ) Spacer(modifier = Modifier.height(20.dp)) Button( onClick = { deleteDataTable() }, - colors = ButtonDefaults.buttonColors(BlueSecondary) + colors = ButtonDefaults.buttonColors(BlueSecondary), ) { Text( text = stringResource(id = R.string.feature_data_table_delete_data_table), @@ -394,10 +393,10 @@ fun SelectOptionsDialog( style = TextStyle( fontSize = 18.sp, fontWeight = FontWeight.Normal, - fontStyle = FontStyle.Normal + fontStyle = FontStyle.Normal, ), color = Color.Black, - textAlign = TextAlign.Center + textAlign = TextAlign.Center, ) } } @@ -408,7 +407,7 @@ fun SelectOptionsDialog( @Preview(showBackground = true) @Composable private fun DataTableDataScreenPreview( - @PreviewParameter(DataTableDataUiStateProvider::class) state: DataTableDataUiState + @PreviewParameter(DataTableDataUiStateProvider::class) state: DataTableDataUiState, ) { DataTableDataScreen( dataTable = DataTable(), @@ -418,6 +417,6 @@ private fun DataTableDataScreenPreview( onRetry = {}, onRefresh = {}, refreshState = false, - deleteDataTable = {} + deleteDataTable = {}, ) -} \ No newline at end of file +} diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableData/DataTableDataUiState.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableData/DataTableDataUiState.kt similarity index 50% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableData/DataTableDataUiState.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableData/DataTableDataUiState.kt index bf25030d5de..e44b9d02a6a 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableData/DataTableDataUiState.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableData/DataTableDataUiState.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.data_table.dataTableData +/* + * 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.dataTable.dataTableData import com.google.gson.JsonArray @@ -14,4 +23,4 @@ sealed class DataTableDataUiState { data class DataTableInfo(val jsonElements: JsonArray) : DataTableDataUiState() data object DataTableDeletedSuccessfully : DataTableDataUiState() -} \ No newline at end of file +} diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableData/DataTableDataViewModel.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableData/DataTableDataViewModel.kt similarity index 57% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableData/DataTableDataViewModel.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableData/DataTableDataViewModel.kt index b4daf8ed4ed..2337c309de8 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableData/DataTableDataViewModel.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableData/DataTableDataViewModel.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.data_table.dataTableData +/* + * 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.dataTable.dataTableData import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel @@ -22,7 +31,7 @@ import javax.inject.Inject class DataTableDataViewModel @Inject constructor( private val getDataTableInfoUseCase: GetDataTableInfoUseCase, private val deleteDataTableEntryUseCase: DeleteDataTableEntryUseCase, - private val savedStateHandle: SavedStateHandle + private val savedStateHandle: SavedStateHandle, ) : ViewModel() { private val args = @@ -32,9 +41,8 @@ class DataTableDataViewModel @Inject constructor( private val _dataTableDataUiState = MutableStateFlow(DataTableDataUiState.Loading) - val tableDataUiState = _dataTableDataUiState.asStateFlow() + val dataTableDataUiState = _dataTableDataUiState.asStateFlow() - // for refresh feature private val _isRefreshing = MutableStateFlow(false) val isRefreshing = _isRefreshing.asStateFlow() @@ -48,14 +56,17 @@ class DataTableDataViewModel @Inject constructor( viewModelScope.launch(Dispatchers.IO) { getDataTableInfoUseCase(table, entityId).collect { result -> when (result) { - is Resource.Error -> _dataTableDataUiState.value = - DataTableDataUiState.Error(R.string.feature_data_table_failed_to_load_data_table_details) + is Resource.Error -> + _dataTableDataUiState.value = + DataTableDataUiState.Error(R.string.feature_data_table_failed_to_load_data_table_details) - is Resource.Loading -> _dataTableDataUiState.value = - DataTableDataUiState.Loading + is Resource.Loading -> + _dataTableDataUiState.value = + DataTableDataUiState.Loading - is Resource.Success -> _dataTableDataUiState.value = - DataTableDataUiState.DataTableInfo(result.data ?: JsonArray()) + is Resource.Success -> + _dataTableDataUiState.value = + DataTableDataUiState.DataTableInfo(result.data ?: JsonArray()) } } } @@ -64,15 +75,18 @@ class DataTableDataViewModel @Inject constructor( viewModelScope.launch(Dispatchers.IO) { deleteDataTableEntryUseCase(table, entity, rowId).collect { result -> when (result) { - is Resource.Error -> _dataTableDataUiState.value = - DataTableDataUiState.Error(R.string.feature_data_table_failed_to_delete_data_table) + is Resource.Error -> + _dataTableDataUiState.value = + DataTableDataUiState.Error(R.string.feature_data_table_failed_to_delete_data_table) - is Resource.Loading -> _dataTableDataUiState.value = - DataTableDataUiState.Loading + is Resource.Loading -> + _dataTableDataUiState.value = + DataTableDataUiState.Loading - is Resource.Success -> _dataTableDataUiState.value = - DataTableDataUiState.DataTableDeletedSuccessfully + is Resource.Success -> + _dataTableDataUiState.value = + DataTableDataUiState.DataTableDeletedSuccessfully } } } -} \ No newline at end of file +} diff --git a/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListNavArgs.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListNavArgs.kt new file mode 100644 index 00000000000..1b24d4270c4 --- /dev/null +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListNavArgs.kt @@ -0,0 +1,23 @@ +/* + * 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.dataTable.dataTableList + +import com.mifos.core.objects.noncore.DataTable + +data class DataTableListNavArgs( + + val dataTableList: List, + + val requestType: Int, + + val payload: Any?, + + val formWidget: MutableList>, +) diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListScreen.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListScreen.kt similarity index 85% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListScreen.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListScreen.kt index 2944149fee6..6df875f3102 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListScreen.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListScreen.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.data_table.dataTableList +/* + * 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.dataTable.dataTableList import android.app.DatePickerDialog import androidx.compose.foundation.layout.Box @@ -50,9 +59,9 @@ import java.time.format.DateTimeFormatter @Composable fun DataTableListScreen( - viewModel: DataTableListViewModel = hiltViewModel(), onBackPressed: () -> Unit, - clientCreated: (Client, Boolean) -> Unit + clientCreated: (Client, Boolean) -> Unit, + viewModel: DataTableListViewModel = hiltViewModel(), ) { val dataTables = viewModel.arg.dataTableList val requestType = viewModel.arg.requestType @@ -69,8 +78,8 @@ fun DataTableListScreen( uiState = uiState, dataTableList = dataTableList ?: listOf(), onBackPressed = onBackPressed, - clientCreated = { client -> clientCreated(client, viewModel.getUserStatus() ) }, - onSaveClicked = { viewModel.processDataTable() } + clientCreated = { client -> clientCreated(client, viewModel.getUserStatus()) }, + onSaveClicked = { viewModel.processDataTable() }, ) } @@ -80,7 +89,8 @@ fun DataTableListScreen( dataTableList: List, onBackPressed: () -> Unit, clientCreated: (Client) -> Unit, - onSaveClicked: () -> Unit + onSaveClicked: () -> Unit, + modifier: Modifier = Modifier, ) { val snackBarHostState = remember { SnackbarHostState() } @@ -88,16 +98,17 @@ fun DataTableListScreen( icon = MifosIcons.arrowBack, title = stringResource(id = R.string.feature_data_table_associated_datatables), onBackPressed = onBackPressed, - snackbarHostState = snackBarHostState + snackbarHostState = snackBarHostState, ) { paddingValues -> Box( - modifier = Modifier + modifier = modifier .padding(paddingValues) - .fillMaxSize() + .fillMaxSize(), ) { DataTableListContent( dataTableList = dataTableList, - onSaveClicked = onSaveClicked + onSaveClicked = onSaveClicked, + modifier = Modifier.fillMaxWidth(), ) when (uiState) { @@ -135,14 +146,15 @@ fun DataTableListScreen( @Composable fun DataTableListContent( dataTableList: List, - onSaveClicked: () -> Unit + onSaveClicked: () -> Unit, + modifier: Modifier = Modifier, ) { val scrollState = rememberScrollState() Column( - modifier = Modifier + modifier = modifier .fillMaxSize() - .verticalScroll(state = scrollState) + .verticalScroll(state = scrollState), ) { for (table in dataTableList) { Text( @@ -150,7 +162,7 @@ fun DataTableListContent( fontWeight = FontWeight.Bold, fontSize = 18.sp, textAlign = TextAlign.Center, - modifier = Modifier.fillMaxWidth() + modifier = Modifier.fillMaxWidth(), ) Spacer(modifier = Modifier.height(16.dp)) @@ -163,7 +175,7 @@ fun DataTableListContent( modifier = Modifier .fillMaxWidth() .padding(16.dp), - colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary) + colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary), ) { Text(text = stringResource(id = R.string.feature_data_table_save), color = Color.White) } @@ -173,9 +185,10 @@ fun DataTableListContent( @Composable fun TableColumnHeader( table: DataTable, + modifier: Modifier = Modifier, ) { val context = LocalContext.current - Column { + Column(modifier = modifier) { table.columnHeaderData.filter { it.columnPrimaryKey != null }.forEach { columnHeader -> when (columnHeader.columnDisplayType) { FormWidget.SCHEMA_KEY_STRING, FormWidget.SCHEMA_KEY_TEXT -> { @@ -183,7 +196,7 @@ fun TableColumnHeader( value = "", onValueChange = {}, label = columnHeader.dataTableColumnName ?: "", - modifier = Modifier.fillMaxWidth() + modifier = Modifier.fillMaxWidth(), ) Spacer(modifier = Modifier.height(16.dp)) @@ -197,7 +210,7 @@ fun TableColumnHeader( keyboardType = KeyboardType.Number, modifier = Modifier .fillMaxWidth() - .padding(vertical = 8.dp) + .padding(vertical = 8.dp), ) Spacer(modifier = Modifier.height(16.dp)) @@ -205,13 +218,12 @@ fun TableColumnHeader( FormWidget.SCHEMA_KEY_CODELOOKUP, FormWidget.SCHEMA_KEY_CODEVALUE -> { var selectedValue by remember { mutableStateOf("") } - val columnValueStrings = - columnHeader.columnValues.map { it.value.orEmpty() } + val columnValueStrings = columnHeader.columnValues.map { it.value.orEmpty() } Box( modifier = Modifier .fillMaxWidth() - .padding(vertical = 8.dp) + .padding(vertical = 8.dp), ) { MifosTextFieldDropdown( value = selectedValue, @@ -220,7 +232,7 @@ fun TableColumnHeader( modifier = Modifier.fillMaxWidth(), readOnly = true, options = columnValueStrings, - onOptionSelected = { _, item -> selectedValue = item } + onOptionSelected = { _, item -> selectedValue = item }, ) } @@ -230,9 +242,7 @@ fun TableColumnHeader( FormWidget.SCHEMA_KEY_DATE -> { val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") var selectedDate by remember { - mutableStateOf( - LocalDate.now().format(dateFormatter) - ) + mutableStateOf(LocalDate.now().format(dateFormatter)) } fun openDatePicker() { @@ -244,7 +254,7 @@ fun TableColumnHeader( }, LocalDate.now().year, LocalDate.now().monthValue - 1, - LocalDate.now().dayOfMonth + LocalDate.now().dayOfMonth, ) datePickerDialog.show() } @@ -252,7 +262,7 @@ fun TableColumnHeader( MifosDatePickerTextField( value = selectedDate, labelString = columnHeader.dataTableColumnName ?: "", - openDatePicker = ::openDatePicker + openDatePicker = ::openDatePicker, ) Spacer(modifier = Modifier.height(16.dp)) @@ -262,16 +272,16 @@ fun TableColumnHeader( var checked by remember { mutableStateOf(false) } Row( verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.padding(vertical = 8.dp) + modifier = Modifier.padding(vertical = 8.dp), ) { Text( text = columnHeader.dataTableColumnName ?: "", - modifier = Modifier.weight(1f) + modifier = Modifier.weight(1f), ) Switch( checked = checked, - onCheckedChange = { checked = it } + onCheckedChange = { checked = it }, ) } } @@ -288,22 +298,21 @@ fun DataTableListScreenPreview() { dataTableList = listOf(), onBackPressed = { }, clientCreated = { }, - onSaveClicked = { } + onSaveClicked = { }, ) } - -//private fun createFormWidgetList(): MutableList> { +// private fun createFormWidgetList(): MutableList> { // return dataTables?.map { createForm(it) }?.toMutableList() ?: mutableListOf() -//} +// } // -//private fun createForm(table: DataTable): List { +// private fun createForm(table: DataTable): List { // return table.columnHeaderData // .filterNot { it.columnPrimaryKey == true } // .map { createFormWidget(it) } -//} +// } // -//private fun createFormWidget(columnHeader: ColumnHeader): FormWidget { +// private fun createFormWidget(columnHeader: ColumnHeader): FormWidget { // return when (columnHeader.columnDisplayType) { // FormWidget.SCHEMA_KEY_STRING, FormWidget.SCHEMA_KEY_TEXT -> FormEditText( // activity, @@ -336,9 +345,9 @@ fun DataTableListScreenPreview() { // // else -> FormEditText(activity, columnHeader.dataTableColumnName) // } -//} +// } // -//private fun createFormSpinner(columnHeader: ColumnHeader): FormSpinner { +// private fun createFormSpinner(columnHeader: ColumnHeader): FormSpinner { // val columnValueStrings = columnHeader.columnValues.mapNotNull { it.value } // val columnValueIds = columnHeader.columnValues.mapNotNull { it.id } // return FormSpinner( @@ -349,9 +358,9 @@ fun DataTableListScreenPreview() { // ).apply { // returnType = FormWidget.SCHEMA_KEY_CODEVALUE // } -//} +// } // -//private fun showClientCreatedSuccessfully(client: Client) { +// private fun showClientCreatedSuccessfully(client: Client) { // requireActivity().supportFragmentManager.popBackStack() // requireActivity().supportFragmentManager.popBackStack() // Toast.makeText( @@ -363,4 +372,4 @@ fun DataTableListScreenPreview() { // clientActivityIntent.putExtra(Constants.CLIENT_ID, client.clientId) // startActivity(clientActivityIntent) // } -//} +// } diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListUiState.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListUiState.kt similarity index 52% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListUiState.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListUiState.kt index 2429f998b97..d5034b15584 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListUiState.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListUiState.kt @@ -1,7 +1,15 @@ -package com.mifos.feature.data_table.dataTableList +/* + * 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.dataTable.dataTableList import com.mifos.core.objects.client.Client -import com.mifos.core.objects.noncore.DataTable /** * Created by Aditya Gupta on 10/08/23. @@ -15,4 +23,4 @@ sealed class DataTableListUiState { data class Success(val messageResId: Int? = null, val client: Client? = null) : DataTableListUiState() -} \ No newline at end of file +} diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListViewModel.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListViewModel.kt similarity index 92% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListViewModel.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListViewModel.kt index 66380a3747f..b0ba91e3806 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListViewModel.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/DataTableListViewModel.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.data_table.dataTableList +/* + * 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.dataTable.dataTableList import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel @@ -50,7 +59,7 @@ class DataTableListViewModel @Inject constructor( private var clientPayload: ClientPayload? = null private var formWidgetsList: MutableList> = ArrayList() - fun getUserStatus() : Boolean { + fun getUserStatus(): Boolean { return prefManager.userStatus } @@ -58,7 +67,7 @@ class DataTableListViewModel @Inject constructor( dataTables: List, requestType: Int, formWidgetsList: MutableList>, - payload: Any? + payload: Any?, ) { _dataTableList.value = dataTables this.requestType = requestType @@ -135,7 +144,6 @@ class DataTableListViewModel @Inject constructor( DataTableListUiState.ShowMessage(R.string.feature_data_table_loan_creation_success) } }) - } private fun createClient(clientPayload: ClientPayload) { @@ -172,7 +180,11 @@ class DataTableListViewModel @Inject constructor( FormWidget.SCHEMA_KEY_INT -> { payload[formWidget.propertyName] = if (formWidget.value == "" - ) "0" else formWidget.value.toInt() + ) { + "0" + } else { + formWidget.value.toInt() + } } FormWidget.SCHEMA_KEY_DECIMAL -> { @@ -193,4 +205,4 @@ class DataTableListViewModel @Inject constructor( } return payload } -} \ No newline at end of file +} diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormSpinner.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/FormSpinner.kt similarity index 78% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormSpinner.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/FormSpinner.kt index 7505986b22d..50ce2c01715 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormSpinner.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/FormSpinner.kt @@ -1,8 +1,13 @@ /* - * This project is licensed under the open source MPL V2. + * 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.data_table.dataTableList +package com.mifos.feature.dataTable.dataTableList import android.R import android.content.Context @@ -17,7 +22,7 @@ class FormSpinner( context: Context?, name: String?, columnValues: List, - columnValueIds: List + columnValueIds: List, ) : FormWidget(context, name) { private val label: TextView private val spinner: Spinner @@ -44,4 +49,4 @@ class FormSpinner( fun getIdOfSelectedItem(key: String): Int { return spinnerValueIdMap[key]!! } -} \ No newline at end of file +} diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormWidget.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/FormWidget.kt similarity index 90% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormWidget.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/FormWidget.kt index 4ee8c561cf9..5436f65ba2b 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormWidget.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableList/FormWidget.kt @@ -1,10 +1,16 @@ /* - * This project is licensed under the open source MPL V2. + * 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.data_table.dataTableList +package com.mifos.feature.dataTable.dataTableList import android.content.Context +import android.util.Log import android.view.View import android.widget.LinearLayout import org.json.JSONObject @@ -15,7 +21,6 @@ import java.util.Locale */ abstract class FormWidget(context: Context?, name: String?) { - /** * returns the un-modified name of the property this widget represents */ @@ -60,7 +65,7 @@ abstract class FormWidget(context: Context?, name: String?) { /** * return LinearLayout containing this widget's view elements */ - val view : View + val view: View get() = layout /** @@ -78,7 +83,8 @@ abstract class FormWidget(context: Context?, name: String?) { // ----------------------------------------------- /** * returns value of this widget as String - */// -- override + */ + // -- override /** * sets value of this widget, method should be overridden in sub-class * @@ -107,6 +113,7 @@ abstract class FormWidget(context: Context?, name: String?) { * @param modifiers */ fun setModifiers(modifiers: JSONObject?) { + Log.d("Modifier", modifiers.toString()) // -- override } // ----------------------------------------------- @@ -142,7 +149,7 @@ abstract class FormWidget(context: Context?, name: String?) { companion object { val defaultLayoutParams = LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT + LinearLayout.LayoutParams.WRAP_CONTENT, ) const val SCHEMA_KEY_TYPE = "type" const val SCHEMA_KEY_BOOL = "BOOLEAN" @@ -159,4 +166,4 @@ abstract class FormWidget(context: Context?, name: String?) { const val SCHEMA_KEY_META = "meta" const val SCHEMA_KEY_HINT = "hint" } -} \ No newline at end of file +} diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableRowDialog/DataTableRowDialogScreen.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableRowDialog/DataTableRowDialogScreen.kt similarity index 85% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableRowDialog/DataTableRowDialogScreen.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableRowDialog/DataTableRowDialogScreen.kt index 94f43d4fa03..d376eeb787f 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableRowDialog/DataTableRowDialogScreen.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTableRowDialog/DataTableRowDialogScreen.kt @@ -1,5 +1,15 @@ -package com.mifos.feature.data_table.dataTableRowDialog +/* + * 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.dataTable.dataTableRowDialog +import android.util.Log import android.widget.Toast import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -45,11 +55,10 @@ fun DataTableRowDialogScreen( dataTable: DataTable, entityId: Int, onDismiss: () -> Unit, - onSuccess: () -> Unit + onSuccess: () -> Unit, + viewModel: DataTableRowDialogViewModel = hiltViewModel(), ) { - - val viewmodel: DataTableRowDialogViewModel = hiltViewModel() - val state by viewmodel.dataTableRowDialogUiState.collectAsStateWithLifecycle() + val state by viewModel.dataTableRowDialogUiState.collectAsStateWithLifecycle() DataTableRowDialogScreen( dataTable = dataTable, @@ -58,16 +67,15 @@ fun DataTableRowDialogScreen( onSuccess = onSuccess, onRetry = { }, onCreate = { - dataTable.registeredTableName?.let { it1 -> - viewmodel.addDataTableEntry( - table = it1, + dataTable.registeredTableName?.let { tableName -> + viewModel.addDataTableEntry( + table = tableName, payload = it, - entityId = entityId + entityId = entityId, ) } - } + }, ) - } @Composable @@ -77,32 +85,34 @@ fun DataTableRowDialogScreen( onDismiss: () -> Unit, onSuccess: () -> Unit, onRetry: () -> Unit, - onCreate: (HashMap) -> Unit + onCreate: (HashMap) -> Unit, + modifier: Modifier = Modifier, ) { - - Dialog(onDismissRequest = { onDismiss() } + Dialog( + onDismissRequest = { onDismiss() }, ) { Surface( + modifier = modifier, shape = RoundedCornerShape(16.dp), - color = Color.White + color = Color.White, ) { Box( - contentAlignment = Alignment.Center + contentAlignment = Alignment.Center, ) { when (state) { is DataTableRowDialogUiState.DataTableEntrySuccessfully -> { Toast.makeText( LocalContext.current, stringResource(id = R.string.feature_data_table_added_data_table_successfully), - Toast.LENGTH_SHORT + Toast.LENGTH_SHORT, ).show() onSuccess() } is DataTableRowDialogUiState.Error -> MifosSweetError( message = stringResource( - id = state.message - ) + id = state.message, + ), ) { onRetry() } @@ -114,12 +124,12 @@ fun DataTableRowDialogScreen( .fillMaxWidth() .padding(bottom = 16.dp), horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically + verticalAlignment = Alignment.CenterVertically, ) { Text( text = stringResource(id = R.string.feature_data_table_add_data_table), fontSize = MaterialTheme.typography.titleLarge.fontSize, - color = BluePrimary + color = BluePrimary, ) IconButton(onClick = { onDismiss() }) { Icon( @@ -128,13 +138,14 @@ fun DataTableRowDialogScreen( tint = colorResource(android.R.color.darker_gray), modifier = Modifier .width(30.dp) - .height(30.dp) + .height(30.dp), ) } } DataTableRowDialogContent( table = dataTable, - onCreate = onCreate + onCreate = onCreate, + modifier = Modifier.fillMaxWidth(), ) } } @@ -149,8 +160,11 @@ fun DataTableRowDialogScreen( @Composable fun DataTableRowDialogContent( table: DataTable, - onCreate: (HashMap) -> Unit + onCreate: (HashMap) -> Unit, + modifier: Modifier = Modifier, ) { + Log.d("DataTable", table.toString()) + Log.d("DataTable", onCreate.toString()) // TODO dataTable is now returning null for columnHeaderData, so we will correct this and then construct a form to implement. @@ -158,22 +172,21 @@ fun DataTableRowDialogContent( onClick = { // TODO call onCreate with using addDataTableInput }, - modifier = Modifier + modifier = modifier .fillMaxWidth() .height(50.dp), colors = ButtonColors( containerColor = BluePrimary, contentColor = White, disabledContainerColor = BluePrimary, - disabledContentColor = Color.Gray - ) + disabledContentColor = Color.Gray, + ), ) { Text(text = stringResource(id = R.string.feature_data_table_submit)) } } - -//private fun createForm(table: DataTable?) { +// private fun createForm(table: DataTable?) { // val formWidgets: MutableList = ArrayList() // if (table != null) { // for (columnHeader in table.columnHeaderData) { @@ -233,10 +246,9 @@ fun DataTableRowDialogContent( // } // } // listFormWidgets.addAll(formWidgets) -//} - +// } -//private fun addDataTableInput(): HashMap { +// private fun addDataTableInput(): HashMap { // val formWidgets: List = listFormWidgets // val payload = HashMap() // payload[Constants.DATE_FORMAT] = "dd-mm-YYYY" @@ -261,7 +273,7 @@ fun DataTableRowDialogContent( // } // } // return payload -//} +// } class DataTableRowDialogUiStateProvider : PreviewParameterProvider { @@ -270,15 +282,14 @@ class DataTableRowDialogUiStateProvider : PreviewParameterProvider(DataTableRowDialogUiState.Initial) val dataTableRowDialogUiState = _dataTableRowDialogUiState.asStateFlow() - fun addDataTableEntry(table: String, entityId: Int, payload: Map) = viewModelScope.launch(Dispatchers.IO) { addDataTableEntryUseCase(table, entityId, payload).collect { result -> when (result) { - is Resource.Error -> _dataTableRowDialogUiState.value = - DataTableRowDialogUiState.Error( - R.string.feature_data_table_failed_to_add_data_table - ) + is Resource.Error -> + _dataTableRowDialogUiState.value = + DataTableRowDialogUiState.Error( + R.string.feature_data_table_failed_to_add_data_table, + ) - is Resource.Loading -> _dataTableRowDialogUiState.value = - DataTableRowDialogUiState.Loading + is Resource.Loading -> + _dataTableRowDialogUiState.value = + DataTableRowDialogUiState.Loading - is Resource.Success -> _dataTableRowDialogUiState.value = - DataTableRowDialogUiState.DataTableEntrySuccessfully + is Resource.Success -> + _dataTableRowDialogUiState.value = + DataTableRowDialogUiState.DataTableEntrySuccessfully } } } -} \ No newline at end of file +} diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/navigation/DataTableNavigation.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/navigation/DataTableNavigation.kt similarity index 62% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/navigation/DataTableNavigation.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/navigation/DataTableNavigation.kt index a347f4f97a3..66ca1bcf13c 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/navigation/DataTableNavigation.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/navigation/DataTableNavigation.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.data_table.navigation +/* + * 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.dataTable.navigation import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder @@ -12,114 +21,117 @@ import com.mifos.core.objects.client.Client import com.mifos.core.objects.navigation.DataTableDataNavigationArg import com.mifos.core.objects.navigation.DataTableNavigationArg import com.mifos.core.objects.noncore.DataTable -import com.mifos.feature.data_table.dataTable.DataTableScreen -import com.mifos.feature.data_table.dataTableData.DataTableDataScreen -import com.mifos.feature.data_table.dataTableList.DataTableListNavArgs -import com.mifos.feature.data_table.dataTableList.DataTableListScreen -import com.mifos.feature.data_table.dataTableList.FormWidget +import com.mifos.feature.dataTable.dataTable.DataTableScreen +import com.mifos.feature.dataTable.dataTableData.DataTableDataScreen +import com.mifos.feature.dataTable.dataTableList.DataTableListNavArgs +import com.mifos.feature.dataTable.dataTableList.DataTableListScreen +import com.mifos.feature.dataTable.dataTableList.FormWidget fun NavGraphBuilder.dataTableNavGraph( navController: NavController, - clientCreated: (Client, Boolean) -> Unit + clientCreated: (Client, Boolean) -> Unit, ) { navigation( startDestination = DataTableScreens.DataTableScreen.route, - route = DataTableScreens.DataTableScreenRoute.route + route = DataTableScreens.DataTableScreenRoute.route, ) { dataTableRoute( onBackPressed = navController::popBackStack, - onClick = navController::navigateDataTableData + onClick = navController::navigateDataTableData, ) dataTableDataRoute( - onBackPressed = navController::popBackStack + onBackPressed = navController::popBackStack, ) dataTableListRoute( onBackPressed = navController::popBackStack, - clientCreated = clientCreated + clientCreated = clientCreated, ) } } fun NavGraphBuilder.dataTableRoute( onBackPressed: () -> Unit, - onClick: (table: String, entityId: Int, dataTable: DataTable) -> Unit + onClick: (table: String, entityId: Int, dataTable: DataTable) -> Unit, ) { composable( route = DataTableScreens.DataTableScreen.route, arguments = listOf( navArgument( name = Constants.DATA_TABLE_NAV_DATA, - builder = { type = NavType.StringType }) - ) + builder = { type = NavType.StringType }, + ), + ), ) { DataTableScreen( navigateBack = onBackPressed, - onClick = onClick + onClick = onClick, ) } } fun NavGraphBuilder.dataTableDataRoute( - onBackPressed: () -> Unit + onBackPressed: () -> Unit, ) { composable( route = DataTableScreens.DataTableDataScreen.route, arguments = listOf( navArgument( name = Constants.DATA_TABLE_DATA_NAV_DATA, - builder = { type = NavType.StringType } - ) - ) + builder = { type = NavType.StringType }, + ), + ), ) { DataTableDataScreen( - onBackPressed = onBackPressed + onBackPressed = onBackPressed, ) } } fun NavGraphBuilder.dataTableListRoute( onBackPressed: () -> Unit, - clientCreated: (Client, Boolean) -> Unit + clientCreated: (Client, Boolean) -> Unit, ) { composable( route = DataTableScreens.DataTableListScreen.route, arguments = listOf( navArgument( name = Constants.DATA_TABLE_LIST_NAV_DATA, - builder = { type = NavType.StringType } - ) - ) + builder = { type = NavType.StringType }, + ), + ), ) { DataTableListScreen( onBackPressed = onBackPressed, - clientCreated = clientCreated + clientCreated = clientCreated, ) } } fun NavController.navigateToDataTable( - tableName: String, entityId: Int + tableName: String, + entityId: Int, ) { val arg = Gson().toJson(DataTableNavigationArg(tableName, entityId)) navigate(DataTableScreens.DataTableScreen.argument(arg)) } fun NavController.navigateDataTableData( - tableName: String, entityId: Int, dataTable: DataTable + tableName: String, + entityId: Int, + dataTable: DataTable, ) { val arg = Gson().toJson(DataTableDataNavigationArg(tableName, entityId, dataTable)) navigate(DataTableScreens.DataTableDataScreen.argument(arg)) - } fun NavController.navigateDataTableList( dataTableList: List, payload: Any?, requestType: Int, - formWidget: MutableList> + formWidget: MutableList>, ) { val arg = Gson().toJson(DataTableListNavArgs(dataTableList, requestType, payload, formWidget)) navigate(DataTableScreens.DataTableListScreen.argument(arg)) -} \ No newline at end of file +} diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/navigation/DataTableScreens.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/navigation/DataTableScreens.kt similarity index 50% rename from feature/data-table/src/main/java/com/mifos/feature/data_table/navigation/DataTableScreens.kt rename to feature/data-table/src/main/java/com/mifos/feature/dataTable/navigation/DataTableScreens.kt index f3464cb8d63..2c297b6ea1e 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/navigation/DataTableScreens.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/navigation/DataTableScreens.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.data_table.navigation +/* + * 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.dataTable.navigation import com.mifos.core.common.utils.Constants @@ -8,16 +17,16 @@ sealed class DataTableScreens(val route: String) { data object DataTableScreen : DataTableScreens("data_table_screen/{${Constants.DATA_TABLE_NAV_DATA}}") { - fun argument(data: String) = "data_table_screen/${data}" + fun argument(data: String) = "data_table_screen/$data" } data object DataTableListScreen : DataTableScreens("data_table_list_screen/{${Constants.DATA_TABLE_LIST_NAV_DATA}}") { - fun argument(data: String) = "data_table_list_screen/${data}" + fun argument(data: String) = "data_table_list_screen/$data" } data object DataTableDataScreen : DataTableScreens("data_table_data_screen/{${Constants.DATA_TABLE_DATA_NAV_DATA}}") { - fun argument(data: String) = "data_table_data_screen/${data}" + fun argument(data: String) = "data_table_data_screen/$data" } -} \ No newline at end of file +} diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListNavArgs.kt b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListNavArgs.kt deleted file mode 100644 index 2562673573e..00000000000 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListNavArgs.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.mifos.feature.data_table.dataTableList - -import com.mifos.core.objects.noncore.DataTable - -data class DataTableListNavArgs( - - val dataTableList: List, - - val requestType: Int, - - val payload: Any?, - - val formWidget: MutableList> -) diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableRowDialog/DataTableRowDialogUiState.kt b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableRowDialog/DataTableRowDialogUiState.kt deleted file mode 100644 index dc8fc51f7cc..00000000000 --- a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableRowDialog/DataTableRowDialogUiState.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.mifos.feature.data_table.dataTableRowDialog - -/** - * Created by Aditya Gupta on 13/08/23. - */ -sealed class DataTableRowDialogUiState { - - data object Initial : DataTableRowDialogUiState() - - data object Loading : DataTableRowDialogUiState() - - data class Error(val message: Int) : DataTableRowDialogUiState() - - data object DataTableEntrySuccessfully : DataTableRowDialogUiState() -} diff --git a/feature/data-table/src/main/res/values/strings.xml b/feature/data-table/src/main/res/values/strings.xml index 77a9746522c..e6e5dc43428 100644 --- a/feature/data-table/src/main/res/values/strings.xml +++ b/feature/data-table/src/main/res/values/strings.xml @@ -1,4 +1,13 @@ + Data Table Client ID diff --git a/feature/data-table/src/test/java/com/mifos/feature/dataTable/ExampleUnitTest.kt b/feature/data-table/src/test/java/com/mifos/feature/dataTable/ExampleUnitTest.kt new file mode 100644 index 00000000000..ace5769aa04 --- /dev/null +++ b/feature/data-table/src/test/java/com/mifos/feature/dataTable/ExampleUnitTest.kt @@ -0,0 +1,25 @@ +/* + * 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.dataTable + +import org.junit.Assert.assertEquals +import org.junit.Test + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} diff --git a/feature/data-table/src/test/java/com/mifos/feature/data_table/ExampleUnitTest.kt b/feature/data-table/src/test/java/com/mifos/feature/data_table/ExampleUnitTest.kt deleted file mode 100644 index f92c67ec88c..00000000000 --- a/feature/data-table/src/test/java/com/mifos/feature/data_table/ExampleUnitTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.mifos.feature.data_table - -import org.junit.Test - -import org.junit.Assert.* - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt index 7d5bcc52bd4..7fc6f9af688 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt @@ -21,9 +21,9 @@ import com.mifos.feature.client.navigation.navigateClientDetailsScreen import com.mifos.feature.client.navigation.navigateCreateClientScreen import com.mifos.feature.client.navigation.navigateToClientListScreen -import com.mifos.feature.data_table.navigation.dataTableNavGraph -import com.mifos.feature.data_table.navigation.navigateDataTableList -import com.mifos.feature.data_table.navigation.navigateToDataTable +import com.mifos.feature.dataTable.navigation.dataTableNavGraph +import com.mifos.feature.dataTable.navigation.navigateDataTableList +import com.mifos.feature.dataTable.navigation.navigateToDataTable import com.mifos.feature.document.navigation.documentListScreen