NoteViewModel

class NoteViewModel(noteDao: NoteDao) : ViewModel

ViewModel for managing UI-related data for notes in a lifecycle-conscious way. This class is responsible for preparing and managing the data for an Activity or a Fragment. It also handles communication with the data layer (NoteDao) for CRUD operations.

Constructors

Link copied to clipboard
constructor(noteDao: NoteDao)

Properties

Link copied to clipboard
val notes: StateFlow<List<Note>>

Functions

Link copied to clipboard
open fun addCloseable(closeable: AutoCloseable)
fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
fun deleteNote(note: Note)

Permanently deletes a note from the database. This operation is performed asynchronously in a coroutine.

Link copied to clipboard
Link copied to clipboard
fun insertNote(note: Note)

Inserts a new note into the database. This operation is performed asynchronously in a coroutine.

Link copied to clipboard
fun loadNotes(showDeleted: Boolean = false)

Loads notes from the database based on the 'showDeleted' flag. Updates the _notes StateFlow with the fetched notes.

Link copied to clipboard
fun restoreNote(note: Note): Job

Restores a soft-deleted note by setting its 'isDeleted' flag to false. The note is updated in the database. This operation is performed asynchronously in a coroutine.

Link copied to clipboard
fun softDeleteNote(note: Note): Job

Marks a note as "soft-deleted" by setting its 'isDeleted' flag to true. The note is updated in the database, not physically removed. This operation is performed asynchronously in a coroutine.