Skip to content

Commit d765177

Browse files
committed
make sure to save the note at creating a new one, or opening another one
1 parent 4aea8e4 commit d765177

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

app/src/main/java/com/simplemobiletools/notes/activities/MainActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
101101
}
102102

103103
private void updateSelectedNote(int index) {
104+
saveText();
104105
mConfig.setCurrentNoteIndex(index);
105106
mCurrentNote = mNotes.get(index);
106107
mNotesView.setText(mCurrentNote.getValue());
@@ -134,6 +135,7 @@ public void onClick(View v) {
134135
} else if (mDb.doesTitleExist(title)) {
135136
Utils.showToast(getApplicationContext(), R.string.title_taken);
136137
} else {
138+
saveText();
137139
final Note newNote = new Note(0, title, "");
138140
final int id = mDb.insertNote(newNote);
139141
newNote.setId(id);
@@ -205,6 +207,9 @@ public void onClick(DialogInterface dialog, int which) {
205207
}
206208

207209
private void saveText() {
210+
if (mCurrentNote == null)
211+
return;
212+
208213
final String newText = getCurrentNote();
209214
final String oldText = mCurrentNote.getValue();
210215
if (!newText.equals(oldText)) {

0 commit comments

Comments
 (0)