store the selected notes index

This commit is contained in:
tibbi 2016-10-02 18:02:32 +02:00
parent a1ad71adcc
commit ee8e8dd17c
3 changed files with 11 additions and 1 deletions

View File

@ -37,4 +37,12 @@ public class Config {
public void setFontSize(int size) {
mPrefs.edit().putInt(Constants.FONT_SIZE, size).apply();
}
public int getCurrentNoteIndex() {
return mPrefs.getInt(Constants.CURRENT_NOTE_INDEX, 0);
}
public void setCurrentNoteIndex(int index) {
mPrefs.edit().putInt(Constants.CURRENT_NOTE_INDEX, index).apply();
}
}

View File

@ -7,6 +7,7 @@ public class Constants {
public static final String PREFS_KEY = "Notes";
public static final String IS_FIRST_RUN = "is_first_run";
public static final String IS_DARK_THEME = "is_dark_theme";
public static final String CURRENT_NOTE_INDEX = "current_note_index";
public static final String FONT_SIZE = "font_size";
public static final String WIDGET_BG_COLOR = "widget_bg_color";
public static final String WIDGET_TEXT_COLOR = "widget_text_color";

View File

@ -43,7 +43,7 @@ public class MainActivity extends SimpleActivity {
mDb = DBHelper.newInstance(getApplicationContext());
mNotes = mDb.getNotes();
updateCurrentNote(0);
updateCurrentNote(mConfig.getCurrentNoteIndex());
}
@Override
@ -103,6 +103,7 @@ public class MainActivity extends SimpleActivity {
}
private void updateCurrentNote(int index) {
mConfig.setCurrentNoteIndex(index);
mCurrentNote = mNotes.get(index);
mNotesView.setText(mCurrentNote.getValue());
mCurrNoteTitle.setText(mCurrentNote.getTitle());