make sure to save the note at creating a new one, or opening another one

This commit is contained in:
tibbi 2016-10-23 18:13:46 +02:00
parent 4aea8e42d1
commit d765177e6b
1 changed files with 5 additions and 0 deletions

View File

@ -101,6 +101,7 @@ public class MainActivity extends SimpleActivity {
}
private void updateSelectedNote(int index) {
saveText();
mConfig.setCurrentNoteIndex(index);
mCurrentNote = mNotes.get(index);
mNotesView.setText(mCurrentNote.getValue());
@ -134,6 +135,7 @@ public class MainActivity extends SimpleActivity {
} else if (mDb.doesTitleExist(title)) {
Utils.showToast(getApplicationContext(), R.string.title_taken);
} else {
saveText();
final Note newNote = new Note(0, title, "");
final int id = mDb.insertNote(newNote);
newNote.setId(id);
@ -205,6 +207,9 @@ public class MainActivity extends SimpleActivity {
}
private void saveText() {
if (mCurrentNote == null)
return;
final String newText = getCurrentNote();
final String oldText = mCurrentNote.getValue();
if (!newText.equals(oldText)) {