Skip to content

Commit 187e788

Browse files
committed
avoid saving text if current notes view is null
1 parent 570b3c2 commit 187e788

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ class NoteFragment : Fragment() {
111111
}
112112

113113
if (menuVisible && noteId != 0) {
114-
(activity as MainActivity).currentNoteTextChanged(getCurrentNoteViewText())
114+
val currentText = getCurrentNoteViewText()
115+
if (currentText != null) {
116+
(activity as MainActivity).currentNoteTextChanged(currentText)
117+
}
115118
}
116119
}
117120

@@ -128,7 +131,7 @@ class NoteFragment : Fragment() {
128131

129132
val newText = getCurrentNoteViewText()
130133
val oldText = context!!.getNoteStoredValue(note)
131-
if (newText != oldText) {
134+
if (newText != null && newText != oldText) {
132135
note.value = newText
133136
saveNoteValue(note)
134137
context!!.updateWidget()
@@ -144,11 +147,14 @@ class NoteFragment : Fragment() {
144147
db.updateNoteValue(note)
145148
(activity as MainActivity).noteSavedSuccessfully(note.title)
146149
} else {
147-
(activity as MainActivity).exportNoteValueToFile(note.path, getCurrentNoteViewText(), true)
150+
val currentText = getCurrentNoteViewText()
151+
if (currentText != null) {
152+
(activity as MainActivity).exportNoteValueToFile(note.path, currentText, true)
153+
}
148154
}
149155
}
150156

151-
fun getCurrentNoteViewText() = view.notes_view?.text.toString()
157+
fun getCurrentNoteViewText() = view.notes_view?.text?.toString()
152158

153159
private fun getTextGravity() = when (context!!.config.gravity) {
154160
GRAVITY_CENTER -> Gravity.CENTER_HORIZONTAL

0 commit comments

Comments
 (0)