Search in sources :

Example 6 with CalendarItem

use of de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem in project TumCampusApp by TCA-Team.

the class CalendarDaoTest method createCalendarItem.

private CalendarItem createCalendarItem(String status, DateTime startDate, DateTime endDate) {
    CalendarItem item = new CalendarItem(Integer.toString(nr), status, "dummy url", "title " + Integer.toString(nr), "dummy description", DateUtils.getDateTimeString(startDate.toDate()), DateUtils.getDateTimeString(endDate.toDate()), "dummy location", false);
    nr++;
    return item;
}
Also used : CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem)

Example 7 with CalendarItem

use of de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem in project TumCampusApp by TCA-Team.

the class RoomLocationsDaoTest method createCalendarItem.

private CalendarItem createCalendarItem(DateTime startDate, String location) {
    CalendarItem item = new CalendarItem(Integer.toString(nr), "good", "dummy url", "title " + Integer.toString(nr), "dummy description", DateUtils.getDateTimeString(startDate.toDate()), DateUtils.getDateTimeString(startDate.toDate()), location, false);
    nr++;
    return item;
}
Also used : CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem)

Example 8 with CalendarItem

use of de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem in project TumCampusApp by TCA-Team.

the class CalendarActivity method onMonthChange.

@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
    // Populate the week view with the events of the month to display
    List<WeekViewEvent> events = new ArrayList<>();
    Calendar calendar = Calendar.getInstance();
    // Note the (-1), since the calendar starts with month 0, but we get months starting with 1
    calendar.set(newYear, newMonth - 1, 1);
    int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    // Probably refactor this to a good SQL query
    for (int curDay = 1; curDay <= daysInMonth; curDay++) {
        calendar.set(Calendar.DAY_OF_MONTH, curDay);
        List<CalendarItem> calendarItems = calendarController.getFromDbForDate(new Date(calendar.getTimeInMillis()));
        for (CalendarItem calendarItem : calendarItems) {
            events.add(new IntegratedCalendarEvent(calendarItem, this));
        }
    }
    return events;
}
Also used : CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) WeekViewEvent(com.alamkanak.weekview.WeekViewEvent) Date(java.util.Date)

Example 9 with CalendarItem

use of de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem in project TumCampusApp by TCA-Team.

the class CalendarController method getNextDaysFromDb.

/**
 * Returns all stored events in the next days from db.
 * If there is a valid widget id (> 0) the events are filtered by the widgets blacklist
 *
 * @param dayCount The number of days
 * @param widgetId The id of the widget
 * @return List<IntegratedCalendarEvent> List of Events
 */
public List<IntegratedCalendarEvent> getNextDaysFromDb(int dayCount, int widgetId) {
    Calendar calendar = Calendar.getInstance();
    String from = DateUtils.getDateTimeString(calendar.getTime());
    calendar.add(Calendar.DAY_OF_YEAR, dayCount);
    String to = DateUtils.getDateTimeString(calendar.getTime());
    List<IntegratedCalendarEvent> calendarEvents = new ArrayList<>();
    List<CalendarItem> calendarItems = calendarDao.getNextDays(from, to, String.valueOf(widgetId));
    for (CalendarItem calendarItem : calendarItems) {
        calendarEvents.add(new IntegratedCalendarEvent(calendarItem, mContext));
    }
    return calendarEvents;
}
Also used : CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList)

Example 10 with CalendarItem

use of de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem in project TumCampusApp by TCA-Team.

the class CalendarController method addEvents.

private static void addEvents(Context c, Uri uri) {
    if (ContextCompat.checkSelfPermission(c, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    // Get ID
    ContentResolver contentResolver = c.getContentResolver();
    String id = "0";
    try (Cursor cursor = contentResolver.query(uri, PROJECTION, null, null, null)) {
        while (cursor.moveToNext()) {
            id = cursor.getString(0);
        }
    }
    CalendarDao calendarDao = TcaDb.getInstance(c).calendarDao();
    List<CalendarItem> calendarItems = calendarDao.getAllNotCancelled();
    for (CalendarItem calendarItem : calendarItems) {
        ContentValues values = calendarItem.toContentValues();
        values.put(CalendarContract.Events.CALENDAR_ID, id);
        values.put(CalendarContract.Events.EVENT_TIMEZONE, R.string.calendarTimeZone);
        contentResolver.insert(CalendarContract.Events.CONTENT_URI, values);
    }
}
Also used : CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem) ContentValues(android.content.ContentValues) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver)

Aggregations

CalendarItem (de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem)11 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 CalendarController (de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 ContentResolver (android.content.ContentResolver)1 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 AudioManager (android.media.AudioManager)1 ListView (android.widget.ListView)1 WeekViewEvent (com.alamkanak.weekview.WeekViewEvent)1 LectureListSelectionAdapter (de.tum.in.tumcampusapp.component.tumui.lectures.adapter.LectureListSelectionAdapter)1 Date (java.util.Date)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1