Skip to content

Commit

Permalink
[High Pri Bug Fix] Creation of new notes broken
Browse files Browse the repository at this point in the history
  • Loading branch information
BijoySingh committed Dec 17, 2017
1 parent 354c2ce commit 1a79de5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdkVersion 17
targetSdkVersion 26
versionCode 26
versionName "3.7.0"
versionName "3.7.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ protected void onCreate(Bundle savedInstanceState) {
if (noteId == 0 && savedInstanceState != null) {
noteId = savedInstanceState.getInt(NOTE_ID, 0);
}
note = Note.db(this).getByID(noteId);

if (noteId != 0) {
note = Note.db(this).getByID(noteId);
}
note = note == null ? Note.gen() : note;

holder = new SimpleNoteViewHolder(this);
Expand Down Expand Up @@ -171,7 +174,7 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
if (savedInstanceState == null) {
return;
}
savedInstanceState.putInt(NOTE_ID, note == null ? 0 : note.uid);
savedInstanceState.putInt(NOTE_ID, note == null || note.uid == null ? 0 : note.uid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

public class MainActivity extends ThemedActivity {

private static final String MIGRATE_ZERO_NOTES = "MIGRATE_ZERO_NOTES";

RecyclerView recyclerView;
NoteAppAdapter adapter;
HomeNavigationState mode;
Expand All @@ -60,6 +62,10 @@ protected void onCreate(Bundle savedInstanceState) {
store = DataStore.get(this);
executor = new SimpleThreadExecutor(1);

if(!store.get(MIGRATE_ZERO_NOTES, false)) {
migrateZeroNotes();
}

setupRecyclerView();
setListeners();
requestSetNightMode(store.get(ThemedActivity.Companion.getKey(), false));
Expand Down Expand Up @@ -420,4 +426,27 @@ public void notifyNightModeChange() {
getColor(R.color.material_grey_50, R.color.material_grey_850));
}

private void migrateZeroNotes() {
MultiAsyncTask.execute(this, new MultiAsyncTask.Task<Boolean>() {
@Override
public Boolean run() {
Note note = Note.db(MainActivity.this).getByID(0);
if (note != null) {
Note.db(MainActivity.this).delete(note);
note.uid = null;
note.save(MainActivity.this);
return true;
}
return false;
}

@Override
public void handle(Boolean result) {
if (result) {
setupData();
}
store.put(MIGRATE_ZERO_NOTES, true);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ protected void onCreate(Bundle savedInstanceState) {
if (noteId == 0 && savedInstanceState != null) {
noteId = savedInstanceState.getInt(NOTE_ID, 0);
}
note = Note.db(this).getByID(noteId);
if (noteId != 0) {
note = Note.db(this).getByID(noteId);
}
note = note == null ? Note.gen() : note;

setNightMode(getIntent().getBooleanExtra(
Expand Down Expand Up @@ -359,6 +361,6 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
if (savedInstanceState == null) {
return;
}
savedInstanceState.putInt(NOTE_ID, note == null ? 0 : note.uid);
savedInstanceState.putInt(NOTE_ID, note == null || note.uid == null ? 0 : note.uid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ public static NoteDao db(Context context) {

public static Note gen() {
Note note = new Note();
note.uid = 0;
note.state = NoteState.DEFAULT.name();
note.timestamp = Calendar.getInstance().getTimeInMillis();
note.displayTimestamp = DateFormatter.getDate(Calendar.getInstance());
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
We endeavour to build beautiful, carefully designed free, ad-free or minimal ads apps which serve great utility to everyone!</string>


<string name="tag_sheet_create_title">Add New Tag&#8230;</string>
<string name="tag_sheet_edit_title">Edit Tag&#8230;</string>
<string name="tag_sheet_enter_tag_hint">enter tag</string>
<string name="tag_sheet_create_title" translatable="false">Add New Tag&#8230;</string>
<string name="tag_sheet_edit_title" translatable="false">Edit Tag&#8230;</string>
<string name="tag_sheet_enter_tag_hint" translatable="false">enter tag</string>

</resources>

0 comments on commit 1a79de5

Please sign in to comment.