Search in sources :

Example 1 with CalendarItem

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

the class CreateEventActivity method createEvent.

private void createEvent() {
    event = new CalendarItem();
    event.setDtstart(DateUtils.getDateTimeString(start.getTime()));
    event.setDtend(DateUtils.getDateTimeString(end.getTime()));
    String title = titleView.getText().toString();
    if (title.length() > 255) {
        title = title.substring(0, 255);
    }
    event.setTitle(title);
    String description = descriptionView.getText().toString();
    if (description.length() > 4000) {
        description = description.substring(0, 4000);
    }
    event.setDescription(description);
    requestHandler.setParameter(Const.EVENT_TITLE, title);
    requestHandler.setParameter(Const.EVENT_COMMENT, description);
    requestHandler.setParameter(Const.EVENT_START, event.getDtstart());
    requestHandler.setParameter(Const.EVENT_END, event.getDtend());
    requestFetch();
}
Also used : CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem)

Example 2 with CalendarItem

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

the class CalendarActivity method onEventClick.

@Override
public void onEventClick(WeekViewEvent weekViewEvent, RectF rectF) {
    detailsFragment = new CalendarDetailsFragment();
    Bundle bundle = new Bundle();
    CalendarItem item = calendarController.getCalendarItemByStartAndEndTime(weekViewEvent.getStartTime(), weekViewEvent.getEndTime());
    bundle.putString(CALENDAR_ID_PARAM, item.getNr());
    detailsFragment.setArguments(bundle);
    detailsFragment.show(getSupportFragmentManager(), null);
}
Also used : CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem) Bundle(android.os.Bundle)

Example 3 with CalendarItem

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

the class CalendarController method getLecturesForWidget.

/**
 * get all lectures and the information whether they are on the blacklist for the given widget
 *
 * @param widgetId the Id of the widget
 * @return A cursor containing a list of lectures and the is_on_blacklist flag
 */
public List<CalendarItem> getLecturesForWidget(int widgetId) {
    List<CalendarItem> lectures = calendarDao.getLecturesInBlacklist(Integer.toString(widgetId));
    for (CalendarItem blacklistedLecture : lectures) {
        blacklistedLecture.setBlacklisted(true);
    }
    lectures.addAll(calendarDao.getLecturesNotInBlacklist(Integer.toString(widgetId)));
    return lectures;
}
Also used : CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem)

Example 4 with CalendarItem

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

the class SilenceService method onHandleWork.

@Override
protected void onHandleWork(@NonNull Intent intent) {
    // Abort, if the settings changed
    if (!Utils.getSettingBool(this, Const.SILENCE_SERVICE, false)) {
        // Don't schedule a new run, since the service is disabled
        return;
    }
    if (!hasPermissions(this)) {
        Utils.setSetting(this, Const.SILENCE_SERVICE, false);
        return;
    }
    AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    if (alarmManager == null) {
        return;
    }
    Intent newIntent = new Intent(this, SilenceService.class);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    long startTime = System.currentTimeMillis();
    long waitDuration = CHECK_INTERVAL;
    Utils.log("SilenceService enabled, checking for lectures …");
    CalendarController calendarController = new CalendarController(this);
    if (!calendarController.hasLectures()) {
        Utils.logv("No lectures available");
        alarmManager.set(AlarmManager.RTC, startTime + waitDuration, pendingIntent);
        return;
    }
    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    if (am == null) {
        return;
    }
    List<CalendarItem> currentLectures = calendarController.getCurrentFromDb();
    Utils.log("Current lectures: " + currentLectures.size());
    if (currentLectures.isEmpty() || isDoNotDisturbMode()) {
        if (Utils.getSettingBool(this, Const.SILENCE_ON, false) && !isDoNotDisturbMode()) {
            // default: old state
            Utils.log("set ringer mode to old state");
            am.setRingerMode(Integer.parseInt(Utils.getSetting(this, Const.SILENCE_OLD_STATE, Integer.toString(AudioManager.RINGER_MODE_NORMAL))));
            Utils.setSetting(this, Const.SILENCE_ON, false);
            List<CalendarItem> nextCalendarItems = calendarController.getNextCalendarItems();
            // update the refresh interval until then. Otherwise use default interval.
            if (!nextCalendarItems.isEmpty()) {
                // refresh when next event has started
                waitDuration = getWaitDuration(nextCalendarItems.get(0).getDtstart());
            }
        }
    } else {
        // remember old state if just activated ; in doubt dont change
        if (!Utils.getSettingBool(this, Const.SILENCE_ON, true)) {
            Utils.setSetting(this, Const.SILENCE_OLD_STATE, am.getRingerMode());
        }
        // if current lecture(s) found, silence the mobile
        Utils.setSetting(this, Const.SILENCE_ON, true);
        // Set into silent mode
        String mode = Utils.getSetting(this, "silent_mode_set_to", "0");
        if ("0".equals(mode)) {
            Utils.log("set ringer mode: vibration");
            am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
        } else {
            Utils.log("set ringer mode: silent");
            am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        }
        // refresh when event has ended
        waitDuration = getWaitDuration(currentLectures.get(0).getDtstart());
    }
    alarmManager.set(AlarmManager.RTC, startTime + waitDuration, pendingIntent);
}
Also used : CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem) AudioManager(android.media.AudioManager) CalendarController(de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController) AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 5 with CalendarItem

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

the class CalendarDaoTest method getNextCalendarItem.

/**
 * Get all next items
 * Expected output: all items are returned
 */
@Test
public void getNextCalendarItem() {
    DateTime now = DateTime.now();
    CalendarItem expected = createCalendarItem("GOOD", now.plusHours(1));
    dao.insert(expected);
    dao.insert(createCalendarItem("OK", now.plusDays(5)));
    dao.insert(createCalendarItem("DUNNO", now.plusDays(1)));
    dao.insert(createCalendarItem("YES", now.plusDays(2)));
    List<CalendarItem> results = dao.getNextCalendarItems();
    assertThat(results).hasSize(1);
    assertThat(results.get(0)).isEqualToComparingFieldByField(expected);
}
Also used : CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

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