allow changing the current note

This commit is contained in:
tibbi 2016-10-02 12:35:06 +02:00
parent 6d7746f66c
commit 2ea85dbb4a
1 changed files with 13 additions and 9 deletions

View File

@ -42,9 +42,8 @@ public class MainActivity extends SimpleActivity {
ButterKnife.bind(this);
mDb = DBHelper.newInstance(getApplicationContext());
mCurrentNote = mDb.getGeneralNote();
mNotesView.setText(mCurrentNote.getValue());
mCurrNoteTitle.setText(mCurrentNote.getTitle());
mNotes = mDb.getNotes();
updateCurrentNote(0);
}
@Override
@ -53,11 +52,7 @@ public class MainActivity extends SimpleActivity {
invalidateOptionsMenu();
mNotesView.setTextSize(TypedValue.COMPLEX_UNIT_PX, Utils.getTextSize(getApplicationContext()));
mNotes = mDb.getNotes();
invalidateOptionsMenu();
mCurrNoteLabel.setVisibility(mNotes.size() <= 1 ? View.GONE : View.VISIBLE);
mCurrNoteTitle.setVisibility(mNotes.size() <= 1 ? View.GONE : View.VISIBLE);
}
@Override
@ -107,6 +102,15 @@ public class MainActivity extends SimpleActivity {
}
}
private void updateCurrentNote(int index) {
mCurrentNote = mNotes.get(index);
mNotesView.setText(mCurrentNote.getValue());
mCurrNoteTitle.setText(mCurrentNote.getTitle());
mCurrNoteLabel.setVisibility(mNotes.size() <= 1 ? View.GONE : View.VISIBLE);
mCurrNoteTitle.setVisibility(mNotes.size() <= 1 ? View.GONE : View.VISIBLE);
}
@OnClick(R.id.notes_fab)
public void fabClicked(View view) {
final View newNoteView = getLayoutInflater().inflate(R.layout.new_note, null);
@ -169,7 +173,7 @@ public class MainActivity extends SimpleActivity {
builder.setItems(notes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
updateCurrentNote(which);
}
});
builder.show();