private void fillList() { try { // Sets the calendar for today without considering time, only the date is important. I also // set a default timezone, the timezone isn't important // so I set a default one so when you change the timezone on your phone, all your things will // still appear. Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); calendar.set(mYear, mMonth, mDay, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); // Parse the date to show it nicely SimpleDateFormat formatFecha = new SimpleDateFormat("EEEE dd/MM/yyyy"); String fParseada = formatFecha.format(calendar.getTime()); todayDate.setText(fParseada); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 2; if (dayOfWeek == -1) dayOfWeek = 6; // Get all the lists of stuff from the database and put them all together to pass them to the // adapter classes = db.getEntityList( "class", "day = '" + String.valueOf(dayOfWeek) + "'", "starttimehour asc"); dueHw = db.getEntityList( "homework", "due = '" + String.valueOf(calendar.getTimeInMillis()) + "'", "done asc"); dueAssignments = db.getEntityList( "assignment", "due = '" + String.valueOf(calendar.getTimeInMillis()) + "'", "done asc"); dueExams = db.getEntityList("exam", "due = '" + String.valueOf(calendar.getTimeInMillis()) + "'"); children = new ArrayList<ArrayList<Entity>>(); children.add(dueHw); children.add(dueAssignments); children.add(dueExams); children.add(classes); mListView.setAdapter(new AgendaSubjectsAdapter()); // Expand every group so make everything look like a unified list for (int x = 0; x < groups.size(); x++) { mListView.expandGroup(x); } } catch (Exception e) { e.printStackTrace(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.agendaday); context = this; getSupportActionBar(); // Start the database try { DataFramework.getInstance().open(this, "com.albertoelias.aplusplusgenda"); } catch (Exception e) { e.printStackTrace(); } settings = getSharedPreferences("com.albertoelias.aplusplusgenda", MODE_PRIVATE); version = settings.getString("version", "0"); // Check if the user has just updated the app. If so, do some changes. if (!version.equalsIgnoreCase("072") && !version.equalsIgnoreCase("073")) { try { List<Entity> classesToUpdate = db.getEntityList("class"); Iterator<Entity> iter = classesToUpdate.iterator(); while (iter.hasNext()) { Entity ent = (Entity) iter.next(); int newvalue = ent.getInt("day") - 2; if (newvalue == -1) newvalue = 6; ent.setValue("day", newvalue); ent.save(); } // Set that the changes has been done and the user has the latest version. SharedPreferences.Editor edit = settings.edit(); edit.putString("version", "072"); edit.commit(); } catch (Exception e) { e.printStackTrace(); } } if (!version.equalsIgnoreCase("073")) { try { ArrayList<Entity> dueHwToUpdate = db.getEntityList("homework"); Iterator<Entity> iter2 = dueHwToUpdate.iterator(); while (iter2.hasNext()) { Entity ent = (Entity) iter2.next(); Calendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(ent.getLong("setDate")); calendar = cambiarAGMT(calendar); ent.setValue("setDate", calendar.getTimeInMillis()); Calendar due = new GregorianCalendar(); due.setTimeInMillis(ent.getLong("due")); due = cambiarAGMT(due); ent.setValue("due", due.getTimeInMillis()); ent.save(); } ArrayList<Entity> dueAssignToUpdate = db.getEntityList("assignment"); Iterator<Entity> iter3 = dueAssignToUpdate.iterator(); while (iter3.hasNext()) { Entity ent = (Entity) iter3.next(); Calendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(ent.getLong("setDate")); calendar = cambiarAGMT(calendar); ent.setValue("setDate", calendar.getTimeInMillis()); Calendar due = new GregorianCalendar(); due.setTimeInMillis(ent.getLong("due")); due = cambiarAGMT(due); ent.setValue("due", due.getTimeInMillis()); ent.save(); } ArrayList<Entity> dueExamsToUpdate = db.getEntityList("exam"); Iterator<Entity> iter4 = dueExamsToUpdate.iterator(); while (iter4.hasNext()) { Entity ent = (Entity) iter4.next(); Calendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(ent.getLong("setDate")); calendar = cambiarAGMT(calendar); ent.setValue("setDate", calendar.getTimeInMillis()); Calendar due = new GregorianCalendar(); due.setTimeInMillis(ent.getLong("due")); due = cambiarAGMT(due); ent.setValue("due", due.getTimeInMillis()); ent.save(); } ArrayList<Entity> termsToUpdate = db.getEntityList("term"); Iterator<Entity> iter5 = termsToUpdate.iterator(); while (iter5.hasNext()) { Entity ent = (Entity) iter5.next(); Calendar start = new GregorianCalendar(); start.setTimeInMillis(ent.getLong("start_date")); start = cambiarAGMT(start); ent.setValue("start_date", start.getTimeInMillis()); Calendar end = new GregorianCalendar(); end.setTimeInMillis(ent.getLong("end_date")); end = cambiarAGMT(end); ent.setValue("end_date", end.getTimeInMillis()); ent.save(); } } catch (Exception e) { e.printStackTrace(); } // Set that the changes has been done and the user has the latest version. SharedPreferences.Editor edit = settings.edit(); edit.putString("version", "073"); edit.commit(); } String[] groupArray = getResources().getStringArray(R.array.parentGroup); groups = new ArrayList<String>(Arrays.asList(groupArray)); todayDate = (TextView) findViewById(R.id.date); mListView = (ExpandableListView) findViewById(android.R.id.list); mListView.setEmptyView(findViewById(android.R.id.empty)); mListView.setGroupIndicator(null); mListView.setOnGroupCollapseListener( new ExpandableListView.OnGroupCollapseListener() { @Override public void onGroupCollapse(int collapseIndex) { // Now allow groups to collapse fillList(); mListView.expandGroup(collapseIndex); } }); // Get the date of the day the user's viewing Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH); }