From 345a950d2ddabcbf51c604bd4cb4347478c25735 Mon Sep 17 00:00:00 2001 From: Darkeye14 Date: Fri, 29 Nov 2024 23:01:46 +0530 Subject: [PATCH] applying spotless and detekt to note module (JIRA 279) --- feature/note/build.gradle.kts | 9 +++ .../feature/note/ExampleInstrumentedTest.kt | 17 +++-- feature/note/src/main/AndroidManifest.xml | 9 +++ .../java/com/mifos/feature/note/NoteScreen.kt | 75 +++++++++++-------- .../com/mifos/feature/note/NoteUiState.kt | 10 ++- .../com/mifos/feature/note/NoteViewModel.kt | 15 +++- .../feature/note/navigation/NoteNavigation.kt | 21 ++++-- .../feature/note/navigation/NoteScreens.kt | 9 +++ feature/note/src/main/res/values/res.xml | 9 +++ .../com/mifos/feature/note/ExampleUnitTest.kt | 14 +++- 10 files changed, 137 insertions(+), 51 deletions(-) diff --git a/feature/note/build.gradle.kts b/feature/note/build.gradle.kts index c6c22d46383..f9200a24dbb 100644 --- a/feature/note/build.gradle.kts +++ b/feature/note/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/note/src/androidTest/java/com/mifos/feature/note/ExampleInstrumentedTest.kt b/feature/note/src/androidTest/java/com/mifos/feature/note/ExampleInstrumentedTest.kt index 8e8d4f763f1..cb99e6dbe98 100644 --- a/feature/note/src/androidTest/java/com/mifos/feature/note/ExampleInstrumentedTest.kt +++ b/feature/note/src/androidTest/java/com/mifos/feature/note/ExampleInstrumentedTest.kt @@ -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.note -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.note.test", appContext.packageName) } -} \ No newline at end of file +} diff --git a/feature/note/src/main/AndroidManifest.xml b/feature/note/src/main/AndroidManifest.xml index a5918e68abc..1dc76da0f7e 100644 --- a/feature/note/src/main/AndroidManifest.xml +++ b/feature/note/src/main/AndroidManifest.xml @@ -1,4 +1,13 @@ + \ No newline at end of file diff --git a/feature/note/src/main/java/com/mifos/feature/note/NoteScreen.kt b/feature/note/src/main/java/com/mifos/feature/note/NoteScreen.kt index d728026ca1d..d05277cf553 100644 --- a/feature/note/src/main/java/com/mifos/feature/note/NoteScreen.kt +++ b/feature/note/src/main/java/com/mifos/feature/note/NoteScreen.kt @@ -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.note import android.widget.Toast @@ -41,32 +50,33 @@ import com.mifos.core.objects.noncore.Note import com.mifos.core.ui.components.MifosEmptyUi @Composable -fun NoteScreen( - onBackPressed: () -> Unit +internal fun NoteScreen( + onBackPressed: () -> Unit, + viewModel: NoteViewModel = hiltViewModel(), ) { - val viewModel: NoteViewModel = hiltViewModel() val uiState by viewModel.noteUiState.collectAsStateWithLifecycle() val isRefreshing by viewModel.isRefreshing.collectAsStateWithLifecycle() LaunchedEffect(key1 = Unit) { - viewModel.loadNote() + viewModel.loadNote() } NoteScreen( uiState = uiState, onBackPressed = onBackPressed, refresh = { viewModel.refresh() }, - isRefreshing = isRefreshing + isRefreshing = isRefreshing, ) } @OptIn(ExperimentalMaterial3Api::class) @Composable -fun NoteScreen( +internal fun NoteScreen( isRefreshing: Boolean, refresh: () -> Unit, uiState: NoteUiState, onBackPressed: () -> Unit, + modifier: Modifier = Modifier, ) { val snackBarHostState = remember { SnackbarHostState() } val pullRefreshState = rememberPullToRefreshState() @@ -76,13 +86,14 @@ fun NoteScreen( icon = MifosIcons.arrowBack, title = stringResource(id = R.string.feature_note_Note), onBackPressed = onBackPressed, - snackbarHostState = snackBarHostState + snackbarHostState = snackBarHostState, + modifier = modifier ) { paddingValues -> Box( modifier = Modifier .fillMaxSize() .padding(paddingValues) - .nestedScroll(pullRefreshState.nestedScrollConnection) + .nestedScroll(pullRefreshState.nestedScrollConnection), ) { when (uiState) { NoteUiState.ShowProgressbar -> { @@ -96,7 +107,7 @@ fun NoteScreen( is NoteUiState.ShowError -> { MifosSweetError( message = stringResource(id = uiState.message), - onclick = refresh + onclick = refresh, ) } @@ -107,13 +118,14 @@ fun NoteScreen( PullToRefreshContainer( state = pullRefreshState, - modifier = Modifier.align(Alignment.TopCenter) + modifier = Modifier.align(Alignment.TopCenter), ) } LaunchedEffect(key1 = isRefreshing) { - if (isRefreshing) + if (isRefreshing) { pullRefreshState.startRefresh() + } } LaunchedEffect(key1 = pullRefreshState.isRefreshing) { @@ -130,16 +142,15 @@ fun NoteScreen( pullRefreshState.endRefresh() } } - } } - @Composable -fun NoteContent( - notes: List +private fun NoteContent( + notes: List, + modifier: Modifier = Modifier, ) { - LazyColumn { + LazyColumn (modifier = modifier) { items(notes) { note -> note.noteContent?.let { NoteItem(noteTitle = it) } } @@ -147,34 +158,34 @@ fun NoteContent( } @Composable -fun NoteItem( - noteTitle: String +private fun NoteItem( + noteTitle: String, ) { Card( 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, + ), ) { Text( modifier = Modifier.padding( horizontal = 12.dp, - vertical = 16.dp + vertical = 16.dp, ), style = MaterialTheme.typography.bodyLarge, - text = noteTitle + text = noteTitle, ) } } -class NoteScreenPreviewProvider : PreviewParameterProvider { +private class NoteScreenPreviewProvider : PreviewParameterProvider { val demoNotes = listOf( Note( id = 1, @@ -185,7 +196,7 @@ class NoteScreenPreviewProvider : PreviewParameterProvider { createdOn = System.currentTimeMillis(), updatedById = 1002, updatedByUsername = "updater_1", - updatedOn = System.currentTimeMillis() + updatedOn = System.currentTimeMillis(), ), Note( id = 2, @@ -196,7 +207,7 @@ class NoteScreenPreviewProvider : PreviewParameterProvider { createdOn = System.currentTimeMillis(), updatedById = 1004, updatedByUsername = "updater_2", - updatedOn = System.currentTimeMillis() + updatedOn = System.currentTimeMillis(), ), Note( id = 3, @@ -207,8 +218,8 @@ class NoteScreenPreviewProvider : PreviewParameterProvider { createdOn = System.currentTimeMillis(), updatedById = 1006, updatedByUsername = "updater_3", - updatedOn = System.currentTimeMillis() - ) + updatedOn = System.currentTimeMillis(), + ), ) override val values: Sequence @@ -216,19 +227,19 @@ class NoteScreenPreviewProvider : PreviewParameterProvider { NoteUiState.ShowEmptyNotes, NoteUiState.ShowNote(demoNotes), NoteUiState.ShowProgressbar, - NoteUiState.ShowError(R.string.feature_note_failed_to_fetch_notes) + NoteUiState.ShowError(R.string.feature_note_failed_to_fetch_notes), ) } @Composable @Preview(showSystemUi = true) -fun PreviewNoteScreen( - @PreviewParameter(NoteScreenPreviewProvider::class) noteUiState: NoteUiState +private fun PreviewNoteScreen( + @PreviewParameter(NoteScreenPreviewProvider::class) noteUiState: NoteUiState, ) { NoteScreen( isRefreshing = false, refresh = { }, uiState = noteUiState, - onBackPressed = {} + onBackPressed = {}, ) } diff --git a/feature/note/src/main/java/com/mifos/feature/note/NoteUiState.kt b/feature/note/src/main/java/com/mifos/feature/note/NoteUiState.kt index 98fd07be63a..9d6d2ef76da 100644 --- a/feature/note/src/main/java/com/mifos/feature/note/NoteUiState.kt +++ b/feature/note/src/main/java/com/mifos/feature/note/NoteUiState.kt @@ -1,8 +1,16 @@ +/* + * 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.note import com.mifos.core.objects.noncore.Note - /** * Created by Aditya Gupta on 08/08/23. */ diff --git a/feature/note/src/main/java/com/mifos/feature/note/NoteViewModel.kt b/feature/note/src/main/java/com/mifos/feature/note/NoteViewModel.kt index 62ca89d51b2..2a9de5f7d67 100644 --- a/feature/note/src/main/java/com/mifos/feature/note/NoteViewModel.kt +++ b/feature/note/src/main/java/com/mifos/feature/note/NoteViewModel.kt @@ -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.note import android.util.Log @@ -18,11 +27,11 @@ import javax.inject.Inject @HiltViewModel class NoteViewModel @Inject constructor( private val repository: NoteRepositoryImp, - savedStateHandle: SavedStateHandle + savedStateHandle: SavedStateHandle, ) : ViewModel() { val entityId = savedStateHandle.getStateFlow(key = Constants.ENTITY_ID, initialValue = 0) - val entityType : StateFlow = savedStateHandle.getStateFlow(key = Constants.ENTITY_TYPE, initialValue = null) + val entityType: StateFlow = savedStateHandle.getStateFlow(key = Constants.ENTITY_TYPE, initialValue = null) private val _noteUiState = MutableStateFlow(NoteUiState.ShowProgressbar) val noteUiState: StateFlow get() = _noteUiState @@ -40,7 +49,7 @@ class NoteViewModel @Inject constructor( /** * This method load the Notes. * Response: List - */ + */ fun loadNote() { Log.d("NoteScreendebug1", "id ${entityId.value} type ${entityType.value}") viewModelScope.launch { diff --git a/feature/note/src/main/java/com/mifos/feature/note/navigation/NoteNavigation.kt b/feature/note/src/main/java/com/mifos/feature/note/navigation/NoteNavigation.kt index 3fa9435b56d..7fcc1e906f8 100644 --- a/feature/note/src/main/java/com/mifos/feature/note/navigation/NoteNavigation.kt +++ b/feature/note/src/main/java/com/mifos/feature/note/navigation/NoteNavigation.kt @@ -1,7 +1,14 @@ +/* + * 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.note.navigation -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.NavType @@ -14,21 +21,21 @@ import com.mifos.feature.note.NoteScreen * Created by Pronay Sarker on 17/08/2024 (12:05 AM) */ fun NavGraphBuilder.noteScreen( - onBackPressed: () -> Unit + onBackPressed: () -> Unit, ) { composable( route = NoteScreens.NoteScreen.route, arguments = listOf( navArgument(name = Constants.ENTITY_ID, builder = { NavType.IntType }), - navArgument(name = Constants.ENTITY_TYPE, builder = { NavType.StringType }) - ) + navArgument(name = Constants.ENTITY_TYPE, builder = { NavType.StringType }), + ), ) { NoteScreen( - onBackPressed = onBackPressed + onBackPressed = onBackPressed, ) } } fun NavController.navigateToNoteScreen(entityId: Int, entityType: String?) { navigate(NoteScreens.NoteScreen.argument(entityId, entityType)) -} \ No newline at end of file +} diff --git a/feature/note/src/main/java/com/mifos/feature/note/navigation/NoteScreens.kt b/feature/note/src/main/java/com/mifos/feature/note/navigation/NoteScreens.kt index a31c234206e..c474342aef5 100644 --- a/feature/note/src/main/java/com/mifos/feature/note/navigation/NoteScreens.kt +++ b/feature/note/src/main/java/com/mifos/feature/note/navigation/NoteScreens.kt @@ -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.note.navigation import com.mifos.core.common.utils.Constants diff --git a/feature/note/src/main/res/values/res.xml b/feature/note/src/main/res/values/res.xml index 4a2fcd705fd..85568293567 100644 --- a/feature/note/src/main/res/values/res.xml +++ b/feature/note/src/main/res/values/res.xml @@ -1,4 +1,13 @@ + Notes No notes found diff --git a/feature/note/src/test/java/com/mifos/feature/note/ExampleUnitTest.kt b/feature/note/src/test/java/com/mifos/feature/note/ExampleUnitTest.kt index 1ead3771dbc..6ca0aecb7ec 100644 --- a/feature/note/src/test/java/com/mifos/feature/note/ExampleUnitTest.kt +++ b/feature/note/src/test/java/com/mifos/feature/note/ExampleUnitTest.kt @@ -1,9 +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.note +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * @@ -14,4 +22,4 @@ class ExampleUnitTest { fun addition_isCorrect() { assertEquals(4, 2 + 2) } -} \ No newline at end of file +}