Search in sources :

Example 1 with CalendarWrapper

use of com.instructure.parentapp.models.CalendarWrapper in project instructure-android by instructure.

the class BootReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
        // set alarms here
        DatabaseHandler mDatabaseHandler = new DatabaseHandler(context);
        try {
            mDatabaseHandler.open();
            ArrayList<CalendarWrapper> calendars = mDatabaseHandler.getAllAlarms();
            if (calendars != null) {
                for (CalendarWrapper wrapper : calendars) {
                    alarm.setAlarm(context, wrapper.getCalendar(), wrapper.getAssignmentId(), wrapper.getTitle(), wrapper.getSubTitle());
                }
            }
            mDatabaseHandler.close();
        } catch (SQLException e) {
        // do nothing
        }
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseHandler(com.instructure.parentapp.database.DatabaseHandler) CalendarWrapper(com.instructure.parentapp.models.CalendarWrapper)

Example 2 with CalendarWrapper

use of com.instructure.parentapp.models.CalendarWrapper in project instructure-android by instructure.

the class DatabaseHandler method getAllAlarms.

public ArrayList<CalendarWrapper> getAllAlarms() {
    String[] columns = new String[] { KEY_ROWID, KEY_YEAR, KEY_MONTH, KEY_DAY, KEY_HOUR, KEY_MINUTE, KEY_ASSIGNMENT_ID, KEY_TITLE, KEY_SUBTITLE };
    ArrayList<CalendarWrapper> calendars = new ArrayList<>();
    Cursor cursor = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        if (cursor.getCount() == 0) {
            return null;
        }
        while (!cursor.isAfterLast()) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.YEAR, cursor.getInt(1));
            calendar.set(Calendar.MONTH, cursor.getInt(2));
            calendar.set(Calendar.DAY_OF_MONTH, cursor.getInt(3));
            calendar.set(Calendar.HOUR_OF_DAY, cursor.getInt(4));
            calendar.set(Calendar.MINUTE, cursor.getInt(5));
            long assignmentId = cursor.getInt(6);
            String title = cursor.getString(7);
            String subTitle = cursor.getString(8);
            // only add the calendar if the date is after today
            Calendar today = Calendar.getInstance();
            if (calendar.after(today)) {
                calendars.add(new CalendarWrapper(calendar, assignmentId, title, subTitle));
            }
            cursor.moveToNext();
        }
        cursor.close();
        return calendars;
    }
    return null;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) CalendarWrapper(com.instructure.parentapp.models.CalendarWrapper) Cursor(android.database.Cursor)

Aggregations

CalendarWrapper (com.instructure.parentapp.models.CalendarWrapper)2 Cursor (android.database.Cursor)1 DatabaseHandler (com.instructure.parentapp.database.DatabaseHandler)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1