Skip to content

Commit

Permalink
make sure to save the note at creating a new one, or opening another one
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbi committed Oct 23, 2016
1 parent 4aea8e4 commit d765177
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

private void updateSelectedNote(int index) {
saveText();
mConfig.setCurrentNoteIndex(index);
mCurrentNote = mNotes.get(index);
mNotesView.setText(mCurrentNote.getValue());
Expand Down Expand Up @@ -134,6 +135,7 @@ public void onClick(View v) {
} 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);
Expand Down Expand Up @@ -205,6 +207,9 @@ public void onClick(DialogInterface dialog, int which) {
}

private void saveText() {
if (mCurrentNote == null)
return;

final String newText = getCurrentNote();
final String oldText = mCurrentNote.getValue();
if (!newText.equals(oldText)) {
Expand Down

0 comments on commit d765177

Please sign in to comment.