Skip to content

Commit

Permalink
Refactored details query for calendar view
Browse files Browse the repository at this point in the history
  • Loading branch information
arnowelzel committed Dec 26, 2020
1 parent 6283071 commit 5344a72
Showing 1 changed file with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -729,23 +729,39 @@ void loadCalculatedData() {
}

// Fill details for each day
fillDetailsFromResult("select eventdate, symptom from symptoms order by eventdate", false);
fillDetailsFromResult("select eventdate, content from notes order by eventdate", true);

System.gc();
}

/**
* Fill entry list with details
*
* @param query Query to get details
* @param isNotes Query is for notes or symptoms
*/
void fillDetailsFromResult(String query, boolean isNotes)
{
Cursor result = db.rawQuery(query, null);
int index = 0;
DayEntry entryTarget = null;
result = db.rawQuery("select notes.eventdate, content, symptom from " +
"notes " +
"left outer join symptoms on notes.eventdate=symptoms.eventdate " +
"order by notes.eventdate",
null);
while (result.moveToNext()) {
String dbdate = result.getString(0);
assert dbdate != null;
int eventyear = Integer.parseInt(dbdate.substring(0, 4), 10);
int eventmonth = Integer.parseInt(dbdate.substring(4, 6), 10);
int eventday = Integer.parseInt(dbdate.substring(6, 8), 10);
GregorianCalendar eventdate = new GregorianCalendar(eventyear, eventmonth - 1, eventday);
String notes = result.getString(1);
if (notes == null) notes = "";
int symptom = result.getInt(2);

String notes = "";
int symptom = 0;
if (isNotes) {
notes = result.getString(1);
if (notes == null) notes = "";
} else {
symptom = result.getInt(1);
}

if (dayEntries.size() == 0) {
// If we don't have any entries yet, create an empty entry for the details
Expand All @@ -755,7 +771,7 @@ void loadCalculatedData() {
} else {
// We have at least ony entry, but it may be in the future
if (dayEntries.size() > index) {
entry = dayEntries.get(index);
DayEntry entry = dayEntries.get(index);
if (entry.date.getTimeInMillis() > eventdate.getTimeInMillis()) {
// The existing entry is in the future, so create a new blank entry before
// this day to hold the details
Expand All @@ -780,16 +796,17 @@ void loadCalculatedData() {

// Add symptom to the current entry
if (null != entryTarget) {
if (symptom != 0) {
entryTarget.symptoms.add(symptom);
if (isNotes) {
entryTarget.notes = notes;
} else {
if (symptom != 0) {
entryTarget.symptoms.add(symptom);
}
}
entryTarget.notes = notes;
}
}
}
result.close();

System.gc();
}


Expand Down

0 comments on commit 5344a72

Please sign in to comment.