Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.an.notesapp.composetexteditor.editor

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -60,7 +61,7 @@ fun ComposeTextEditor(
},
textStyle = TextStyle(fontSize = 16.sp, color = Color.Black),
cursorBrush = SolidColor(Color.Black),
modifier = modifier
modifier = modifier.fillMaxSize()
)
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/an/notesapp/intent/NoteIntent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ sealed class NoteIntent {
data class DeleteNote(val note: Note) : NoteIntent()
data class OpenNoteClicked(val note: Note): NoteIntent()
data class ValidatePassword(val password: String): NoteIntent()
data object DismissPasswordSheet : NoteIntent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ fun NoteDetailScreen(viewModel: NoteDetailViewModel) {
// Note title
TextField(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 20.dp),
.fillMaxWidth(),
value = noteDetailViewState.value.note.title,
onValueChange = { viewModel.handleIntent(NoteIntent.UpdateNoteTitle(it)) },
placeholder = { Text(stringResource(id = R.string.add_note_title)) },
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/com/an/notesapp/view/ui/screen/NotesScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Lock
Expand All @@ -27,6 +29,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.blur
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -77,8 +80,9 @@ fun NotesScreen(
} else {
// Show notes screen
LazyVerticalStaggeredGrid(
modifier = Modifier.padding(top = 10.dp, bottom = 10.dp, start = 12.dp, end = 12.dp),
modifier = Modifier.fillMaxSize().padding(top = 10.dp, bottom = 10.dp, start = 12.dp, end = 12.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalItemSpacing = 16.dp,
columns = StaggeredGridCells.Adaptive(minSize = 140.dp),
) {
val notes = noteUiState.value.notes
Expand All @@ -97,7 +101,9 @@ fun NotesScreen(
PasswordBottomSheet(
isNoteLocked = true,
errorMessageId = noteUiState.value.passwordErrorResId,
onDismissRequest = { noteUiState.value.copy(showPasswordSheet = false) },
onDismissRequest = {
viewModel.handleIntent(NoteIntent.DismissPasswordSheet)
},
onDoneRequest = {
viewModel.handleIntent(NoteIntent.ValidatePassword(it))
}
Expand All @@ -118,9 +124,9 @@ fun NoteItem(
) {
Card (
modifier = Modifier
.padding(bottom = 12.dp)
.clip(RoundedCornerShape(8.dp))
.clickable { onNoteItemClicked(note) },
shape = RectangleShape,
shape = RoundedCornerShape(8.dp),
elevation = CardDefaults.cardElevation(10.dp),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.onPrimary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class NoteDetailViewModel @Inject constructor(
fun addNote() {
viewModelScope.launch(IO) {
val note = _noteDetailViewState.value.note.copy(
title = _noteDetailViewState.value.note.title.trim(),
createdAt = OffsetDateTime.now(),
modifiedAt = OffsetDateTime.now()
)
Expand All @@ -103,6 +104,7 @@ class NoteDetailViewModel @Inject constructor(
fun saveNote() {
viewModelScope.launch(IO) {
val updatedNote = _noteDetailViewState.value.note.copy(
title = _noteDetailViewState.value.note.title.trim(),
modifiedAt = OffsetDateTime.now()
)
repository.updateNote(updatedNote)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class NoteViewModel @Inject constructor(
is NoteIntent.DeleteNote -> deleteNote(intent.note)
is NoteIntent.OpenNoteClicked -> onNoteClicked(intent.note)
is NoteIntent.ValidatePassword -> validatePassword(intent.password)
is NoteIntent.DismissPasswordSheet -> {
_notesViewState.value = _notesViewState.value.copy(showPasswordSheet = false)
}
else -> { }
}
}
Expand Down