- if(viewDayplan)
- showDates = AppContext.getDatabaseManager().getDaysWithPlanData(now - (30 * 86400), now + (30 * 86400));
- else
- showDates = AppContext.getDatabaseManager().getDaysWithPlanData(now - (365 * 86400), now + (30 * 86400));
+ if(viewDate < now)
+ now = viewDate;
+
+ int weekdayResIds[] = new int[] { R.string.week_monday_short, R.string.week_tuesday_short, R.string.week_wednesday_short, R.string.week_thursday_short, R.string.week_friday_short, R.string.week_saturday_short, R.string.week_sunday_short };
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(new Date(now * 1000));
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+ long midnight = cal.getTimeInMillis() / 1000;
+ int dow = cal.get(Calendar.DAY_OF_WEEK);
+ dow -= 2;
+ if(dow < 0) // monday should be 0!
+ dow += 7;
+ long subTimeToWeekStart = (86400 * dow);
+ long showDateFrom = midnight - subTimeToWeekStart;
+
+ showDates = AppContext.getDatabaseManager().getDaysWithPlanData(showDateFrom, now + (30 * 86400));