Skip to content

Commit

Permalink
MIFOSAC-282 (#2256)
Browse files Browse the repository at this point in the history
Apply Spotless and Detekt to the "feature-datatable" module.
  • Loading branch information
Aditya3815 authored Dec 12, 2024
1 parent cf3c70c commit 72142da
Show file tree
Hide file tree
Showing 27 changed files with 526 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions feature/data-table/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 @@
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.
*
Expand All @@ -21,4 +28,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.mifos.feature.data_table.test", appContext.packageName)
}
}
}
9 changes: 9 additions & 0 deletions feature/data-table/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,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
Expand Down Expand Up @@ -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
Expand All @@ -67,7 +76,7 @@ fun DataTableScreen(
isRefreshing = isRefreshing,
onClick = {
onClick(tableName, entityId, it)
}
},
)
}

Expand All @@ -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()
Expand All @@ -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,
)
}

Expand All @@ -110,7 +120,8 @@ fun DataTableScreen(

is DataTableUiState.ShowError -> {
MifosSweetError(
message = stringResource(id = uiState.message), onclick = onRefresh
message = stringResource(id = uiState.message),
onclick = onRefresh,
)
}

Expand All @@ -126,8 +137,9 @@ fun DataTableScreen(
}

LaunchedEffect(key1 = isRefreshing) {
if (isRefreshing)
if (isRefreshing) {
pullRefreshState.startRefresh()
}
}

LaunchedEffect(key1 = pullRefreshState.isRefreshing) {
Expand All @@ -150,13 +162,16 @@ fun DataTableScreen(
@Composable
fun DataTableContent(
dataTable: List<DataTable>,
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,
)
}
}
Expand All @@ -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,
)
}
}
Expand All @@ -199,40 +215,39 @@ class DataTablePreviewProvider : PreviewParameterProvider<DataTableUiState> {
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<DataTableUiState>
get() = sequenceOf(
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 = { },
)
}

Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 =
Expand Down Expand Up @@ -67,6 +76,4 @@ class DataTableViewModel @Inject constructor(
}
})
}

}

Loading

0 comments on commit 72142da

Please sign in to comment.