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();
}
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);
}
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;
}
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);
}
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);
}
Aggregations