Search in sources :

Example 1 with CalendarController

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);
}
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 2 with CalendarController

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);
        }
    }
}
Also used : TUMOnlineRequest(de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest) CalendarController(de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController) CalendarRowSet(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarRowSet)

Example 3 with CalendarController

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;
}
Also used : CalendarController(de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController) CafeteriaManager(de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager) AccessTokenManager(de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager) EduroamFixCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard) LoginPromtCard(de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard) ArrayList(java.util.ArrayList) NewsController(de.tum.in.tumcampusapp.component.ui.news.NewsController) Card(de.tum.in.tumcampusapp.component.ui.overview.card.Card) LoginPromtCard(de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard) EduroamFixCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard) EduroamCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard) EduroamCard(de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard) TuitionFeeManager(de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeeManager) TransportController(de.tum.in.tumcampusapp.component.ui.transportation.TransportController) ChatRoomController(de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)

Example 4 with CalendarController

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();
}
Also used : CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem) CalendarController(de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController) ListView(android.widget.ListView) Bundle(android.os.Bundle) Intent(android.content.Intent) LectureListSelectionAdapter(de.tum.in.tumcampusapp.component.tumui.lectures.adapter.LectureListSelectionAdapter)

Aggregations

CalendarController (de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController)4 Intent (android.content.Intent)2 CalendarItem (de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem)2 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 AudioManager (android.media.AudioManager)1 Bundle (android.os.Bundle)1 ListView (android.widget.ListView)1 AccessTokenManager (de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager)1 TUMOnlineRequest (de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest)1 CalendarRowSet (de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarRowSet)1 LectureListSelectionAdapter (de.tum.in.tumcampusapp.component.tumui.lectures.adapter.LectureListSelectionAdapter)1 TuitionFeeManager (de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeeManager)1 CafeteriaManager (de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager)1 ChatRoomController (de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)1 EduroamCard (de.tum.in.tumcampusapp.component.ui.eduroam.EduroamCard)1 EduroamFixCard (de.tum.in.tumcampusapp.component.ui.eduroam.EduroamFixCard)1 NewsController (de.tum.in.tumcampusapp.component.ui.news.NewsController)1 LoginPromtCard (de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard)1 Card (de.tum.in.tumcampusapp.component.ui.overview.card.Card)1