Skip to content

Commit

Permalink
Merge pull request #135 from SecUSo/issue/#132
Browse files Browse the repository at this point in the history
Fixes: #132
  • Loading branch information
coderPaddyS authored Jan 15, 2023
2 parents d4c4f2e + 43af545 commit f67cd0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,19 @@ abstract class BaseNoteActivity(noteType: Int) : AppCompatActivity(), View.OnCli
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
createEditNoteViewModel.getNoteByID(id.toLong()).observe(
this
) { note: Note ->
etName.setText(note.name)
) { note ->
if (note != null) {
etName.setText(note.name)

//find the current category and set spinner to that
currentCat = note.category
savedCat = currentCat
//find the current category and set spinner to that
currentCat = note.category
savedCat = currentCat

//fill the notificationCursor
hasAlarm = notification!!._noteId >= 0
//fill the notificationCursor
hasAlarm = notification!!._noteId >= 0

onNoteLoadedFromDB(note)
onNoteLoadedFromDB(note)
}
}
} else {
onNewNote()
Expand Down Expand Up @@ -438,6 +440,11 @@ abstract class BaseNoteActivity(noteType: Int) : AppCompatActivity(), View.OnCli
private fun displayTrashDialog() {
val sp = getSharedPreferences(PreferenceKeys.SP_DATA, MODE_PRIVATE)
createEditNoteViewModel.getNoteByID(id.toLong()).observe(this) { note ->
if (note == null) {
shouldSave = false
finish()
return@observe
}
if (sp.getBoolean(PreferenceKeys.SP_DATA_DISPLAY_TRASH_MESSAGE, true)) {
//we never displayed the message before, so show it now
AlertDialog.Builder(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class CreateEditNoteViewModel(application: Application) : AndroidViewModel(appli
}
}

fun getNoteByID(id: Long): LiveData<Note> {
val note = MutableLiveData<Note>()
fun getNoteByID(id: Long): LiveData<Note?> {
val note = MutableLiveData<Note?>()
Log.d(TAG, "Fetching note $id from database")
viewModelScope.launch(Dispatchers.IO) {
note.postValue(database.noteDao().getNoteByID(id))
Expand Down

0 comments on commit f67cd0e

Please sign in to comment.