use of de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController 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.CalendarController in project TumCampusApp by TCA-Team.
the class CacheManager method syncCalendar.
public void syncCalendar() {
TUMOnlineRequest<CalendarRowSet> requestHandler = new TUMOnlineRequest<>(TUMOnlineConst.Companion.getCALENDER(), mContext);
requestHandler.setParameter("pMonateVor", "2");
requestHandler.setParameter("pMonateNach", "3");
if (shouldRefresh(requestHandler.getRequestURL())) {
Optional<CalendarRowSet> set = requestHandler.fetch();
if (set.isPresent()) {
CalendarController calendarController = new CalendarController(mContext);
calendarController.importCalendar(set.get());
CalendarController.QueryLocationsService.loadGeo(mContext);
}
}
}
use of de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController in project TumCampusApp by TCA-Team.
the class CardManager method update.
/**
* Refreshes or initialises all cards.
* WARNING: Must not be called from UI thread.
* <p/>
* HOW TO ADD A NEW CARD:
* 1. Let the manager class implement {@link Card.ProvidesCard}
* 2. Create a new class extending {@link Card}
* 3. Implement the getCardView method in this class
* 4. Create a new instance of this card in the
* {@link Card.ProvidesCard#onRequestCard(Context)} method of the manager
* 5. Add this card to the CardManager by calling {@link Card#apply()} from
* {@link Card.ProvidesCard#onRequestCard(Context)}
* 6. Add an instance of the manager class to the managers list below
*/
public static synchronized void update(Context context) {
// Use temporary array to avoid that the main thread is trying to access an empty array
newCards.clear();
new NoInternetCard(context).apply();
new LoginPromtCard(context).apply();
new SupportCard(context).apply();
new EduroamCard(context).apply();
new EduroamFixCard(context).apply();
Collection<Card.ProvidesCard> managers = new ArrayList<>();
// Add those managers only if valid access token is available
if (new AccessTokenManager(context).hasValidAccessToken()) {
managers.add(new CalendarController(context));
managers.add(new TuitionFeeManager());
managers.add(new ChatRoomController(context));
}
// Those don't need TUMOnline access
managers.add(new CafeteriaManager(context));
managers.add(new TransportController(context));
managers.add(new NewsController(context));
for (Card.ProvidesCard manager : managers) {
manager.onRequestCard(context);
}
// Always append the restore card at the end of our list
new RestoreCard(context).apply();
shouldRefresh = false;
}
use of de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController in project TumCampusApp by TCA-Team.
the class TimetableWidgetConfigureActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timetable_widget_configure);
// Setup toolbar and save button
setSupportActionBar(findViewById(R.id.main_toolbar));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_check);
// Get appWidgetId from intent
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
ListView listViewLectures = findViewById(R.id.activity_timetable_lectures);
// Initialize stations adapter
CalendarController calendarController = new CalendarController(this);
List<CalendarItem> lectures = calendarController.getLecturesForWidget(this.appWidgetId);
listViewLectures.setAdapter(new LectureListSelectionAdapter(this, lectures, this.appWidgetId));
listViewLectures.requestFocus();
}
Aggregations