Skip to content

Commit

Permalink
applying spotless and detekt to note module (JIRA 279) (#2243)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkeye14 authored Nov 29, 2024
1 parent 79db9b2 commit 3a3ebe7
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 51 deletions.
9 changes: 9 additions & 0 deletions feature/note/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.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.
*
Expand All @@ -21,4 +28,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.mifos.feature.note.test", appContext.packageName)
}
}
}
9 changes: 9 additions & 0 deletions feature/note/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>
75 changes: 43 additions & 32 deletions feature/note/src/main/java/com/mifos/feature/note/NoteScreen.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.note

import android.widget.Toast
Expand Down Expand Up @@ -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()
Expand All @@ -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 -> {
Expand All @@ -96,7 +107,7 @@ fun NoteScreen(
is NoteUiState.ShowError -> {
MifosSweetError(
message = stringResource(id = uiState.message),
onclick = refresh
onclick = refresh,
)
}

Expand All @@ -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) {
Expand All @@ -130,51 +142,50 @@ fun NoteScreen(
pullRefreshState.endRefresh()
}
}

}
}


@Composable
fun NoteContent(
notes: List<Note>
private fun NoteContent(
notes: List<Note>,
modifier: Modifier = Modifier,
) {
LazyColumn {
LazyColumn (modifier = modifier) {
items(notes) { note ->
note.noteContent?.let { NoteItem(noteTitle = it) }
}
}
}

@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<NoteUiState> {
private class NoteScreenPreviewProvider : PreviewParameterProvider<NoteUiState> {
val demoNotes = listOf(
Note(
id = 1,
Expand All @@ -185,7 +196,7 @@ class NoteScreenPreviewProvider : PreviewParameterProvider<NoteUiState> {
createdOn = System.currentTimeMillis(),
updatedById = 1002,
updatedByUsername = "updater_1",
updatedOn = System.currentTimeMillis()
updatedOn = System.currentTimeMillis(),
),
Note(
id = 2,
Expand All @@ -196,7 +207,7 @@ class NoteScreenPreviewProvider : PreviewParameterProvider<NoteUiState> {
createdOn = System.currentTimeMillis(),
updatedById = 1004,
updatedByUsername = "updater_2",
updatedOn = System.currentTimeMillis()
updatedOn = System.currentTimeMillis(),
),
Note(
id = 3,
Expand All @@ -207,28 +218,28 @@ class NoteScreenPreviewProvider : PreviewParameterProvider<NoteUiState> {
createdOn = System.currentTimeMillis(),
updatedById = 1006,
updatedByUsername = "updater_3",
updatedOn = System.currentTimeMillis()
)
updatedOn = System.currentTimeMillis(),
),
)

override val values: Sequence<NoteUiState>
get() = sequenceOf(
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 = {},
)
}
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down
15 changes: 12 additions & 3 deletions feature/note/src/main/java/com/mifos/feature/note/NoteViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.note

import android.util.Log
Expand All @@ -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<String?> = savedStateHandle.getStateFlow(key = Constants.ENTITY_TYPE, initialValue = null)
val entityType: StateFlow<String?> = savedStateHandle.getStateFlow(key = Constants.ENTITY_TYPE, initialValue = null)

private val _noteUiState = MutableStateFlow<NoteUiState>(NoteUiState.ShowProgressbar)
val noteUiState: StateFlow<NoteUiState> get() = _noteUiState
Expand All @@ -40,7 +49,7 @@ class NoteViewModel @Inject constructor(
/**
* This method load the Notes.
* Response: List<Note>
</Note> */
</Note> */
fun loadNote() {
Log.d("NoteScreendebug1", "id ${entityId.value} type ${entityType.value}")
viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.note.navigation

import com.mifos.core.common.utils.Constants
Expand Down
9 changes: 9 additions & 0 deletions feature/note/src/main/res/values/res.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
-->
<resources>
<string name="feature_note_Note">Notes</string>
<string name="feature_note_no_notes_found">No notes found</string>
Expand Down
Loading

0 comments on commit 3a3ebe7

Please sign in to comment.