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