@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(KEY_ITEM_SELECTED, mItemSelected); outState.putString(KEY_WHERE_CLAUSE, getWhereClause()); if (mDateFrom != null) { // outState.putSerializable(KEY_FROM_DATE, mDateFrom); outState.putString(KEY_FROM_DATE, mDateFrom.toString()); } if (mDateTo != null) outState.putSerializable(KEY_TO_DATE, mDateTo); }
@Override public boolean onOptionsItemSelected(MenuItem item) { // todo: replace this complex way of querying and find the start/end dates for // ViewMobileData.Date. CalendarUtils calendar = new CalendarUtils(); // int currentMonth = Calendar.getInstance().get(Calendar.MONTH) + 1; // int currentYear = Calendar.getInstance().get(Calendar.YEAR); switch (item.getItemId()) { case R.id.menu_current_month: // whereClause = ViewMobileData.Month + "=" + Integer.toString(currentMonth) // + " AND " + // ViewMobileData.Year + "=" + Integer.toString(currentYear); // DateTime startDate = DateTime.today(TimeZone.getDefault()); // mDateFrom = // calendar.setFirstDayOfMonth().setTimeToBeginningOfDay().getTime(); mDateFrom = DateTimeUtils.today().getStartOfMonth(); mDateTo = calendar.setLastDayOfMonth().setTimeToEndOfDay().getTime(); break; case R.id.menu_last_month: // if (currentMonth == 1) { // whereClause = ViewMobileData.Month + "=" + Integer.toString(12) + " // AND " + ViewMobileData.Year + "=" + Integer.toString(currentYear - 1); // } else { // whereClause = ViewMobileData.Month + "=" + // Integer.toString(currentMonth - 1) + " AND " + ViewMobileData.Year + "=" + // Integer.toString(currentYear); // } // Calendar dateFrom = // calendar.setNow().addMonth(-1).setFirstDayOfMonth().setTimeToBeginningOfDay().getTime(); Calendar dateFrom = calendar .setNow() .addMonth(-1) .setFirstDayOfMonth() .setTimeToBeginningOfDay() .getCalendar(); mDateFrom = DateTimeUtils.from(dateFrom); mDateTo = calendar.setLastDayOfMonth().setTimeToEndOfDay().getTime(); break; case R.id.menu_last_30_days: // whereClause = "(julianday(date('now')) - julianday(" + ViewMobileData.Date // + ") <= 30)"; dateFrom = calendar.setNow().addDays(-30).setTimeToBeginningOfDay().getCalendar(); mDateFrom = DateTimeUtils.from(dateFrom); mDateTo = calendar.setNow().setTimeToEndOfDay().getTime(); break; case R.id.menu_current_year: // whereClause = ViewMobileData.Year + "=" + Integer.toString(currentYear); dateFrom = calendar.setNow().setMonth(Calendar.JANUARY).setFirstDayOfMonth().getCalendar(); mDateFrom = DateTimeUtils.from(dateFrom); mDateTo = calendar.setMonth(Calendar.DECEMBER).setLastDayOfMonth().getTime(); break; case R.id.menu_last_year: // whereClause = ViewMobileData.Year + "=" + Integer.toString(currentYear - // 1); dateFrom = calendar .setNow() .addYear(-1) .setMonth(Calendar.JANUARY) .setFirstDayOfMonth() .getCalendar(); mDateFrom = DateTimeUtils.from(dateFrom); mDateTo = calendar.setMonth(Calendar.DECEMBER).setLastDayOfMonth().getTime(); break; case R.id.menu_all_time: mDateFrom = null; mDateTo = null; break; case R.id.menu_custom_dates: // check item item.setChecked(true); mItemSelected = item.getItemId(); // show dialog showDialogCustomDates(); return true; // break; default: return super.onOptionsItemSelected(item); } String whereClause = null; if (mDateFrom != null && mDateTo != null) { // todo: mDateFrom.format(Constants.ISO_DATE_FORMAT) ? whereClause = ViewMobileData.Date + " >= '" + mDateFrom.toString() + "' AND " + ViewMobileData.Date + " <= '" + DateUtils.getIsoStringDate(mDateTo) + "'"; } // check item item.setChecked(true); mItemSelected = item.getItemId(); // compose bundle Bundle args = new Bundle(); args.putString(KEY_WHERE_CLAUSE, whereClause); // starts loader startLoader(args); return true; }