Search in sources :

Example 1 with AccessTokenManager

use of de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager in project TumCampusApp by TCA-Team.

the class CacheManager method fillCache.

/**
 * Download usual tumOnline requests
 */
public void fillCache() {
    NetUtils net = new NetUtils(mContext);
    // Cache news source images
    NewsController newsController = new NewsController(mContext);
    List<NewsSources> newsSources = newsController.getNewsSources();
    for (NewsSources newsSource : newsSources) {
        String imgUrl = newsSource.getIcon();
        if (!imgUrl.isEmpty() && !"null".equals(imgUrl)) {
            net.downloadImage(imgUrl);
        }
    }
    // Cache news images
    List<News> news = newsController.getAllFromDb(mContext);
    for (News n : news) {
        String imgUrl = n.getImage();
        if (!imgUrl.isEmpty() && !"null".equals(imgUrl)) {
            net.downloadImage(imgUrl);
        }
    }
    // Cache kino covers
    kinoDao.getAll().subscribe(it -> {
        for (Kino kino : it) {
            String imgUrl = kino.getCover();
            if (!imgUrl.isEmpty() && !"null".equals(imgUrl)) {
                net.downloadImage(imgUrl);
            }
        }
    });
    // acquire access token
    if (!new AccessTokenManager(mContext).hasValidAccessToken()) {
        return;
    }
    // ALL STUFF BELOW HERE NEEDS A VALID ACCESS TOKEN
    // Sync organisation tree
    TUMOnlineRequest<OrgItemList> requestHandler = new TUMOnlineRequest<>(TUMOnlineConst.Companion.getORG_TREE(), mContext);
    if (shouldRefresh(requestHandler.getRequestURL())) {
        requestHandler.fetch();
    }
    // Sync fee status
    TUMOnlineRequest<TuitionList> requestHandler2 = new TUMOnlineRequest<>(TUMOnlineConst.Companion.getTUITION_FEE_STATUS(), mContext);
    if (shouldRefresh(requestHandler2.getRequestURL())) {
        requestHandler2.fetch();
    }
    // Sync lectures, details and appointments
    importLecturesFromTUMOnline();
    // Sync calendar
    syncCalendar();
}
Also used : TUMOnlineRequest(de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest) AccessTokenManager(de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager) OrgItemList(de.tum.in.tumcampusapp.component.other.departments.model.OrgItemList) TuitionList(de.tum.in.tumcampusapp.component.tumui.tutionfees.model.TuitionList) NewsController(de.tum.in.tumcampusapp.component.ui.news.NewsController) NewsSources(de.tum.in.tumcampusapp.component.ui.news.model.NewsSources) News(de.tum.in.tumcampusapp.component.ui.news.model.News) Kino(de.tum.in.tumcampusapp.component.ui.tufilm.model.Kino)

Example 2 with AccessTokenManager

use of de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager 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 3 with AccessTokenManager

use of de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager in project TumCampusApp by TCA-Team.

the class WizNavExtrasActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.fadein, R.anim.fadeout);
    preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    // If called because app version changed remove "Step 4" and close on back pressed
    Intent i = getIntent();
    if (i != null && i.hasExtra(Const.TOKEN_IS_SETUP)) {
        // If coming from a 6X version we need to upload the public key to TUMO
        AuthenticationManager am = new AuthenticationManager(this);
        try {
            am.uploadPublicKey();
        } catch (NoPublicKey noPublicKey) {
            Utils.log(noPublicKey);
        }
        // Remember that we are only running through a limited setup
        tokenSetup = i.getBooleanExtra(Const.TOKEN_IS_SETUP, false);
    }
    // Get handles to all UI elements
    checkSilentMode = findViewById(R.id.chk_silent_mode);
    bugReport = findViewById(R.id.chk_bug_reports);
    bugReport.setChecked(preferences.getBoolean(Const.BUG_REPORTS, true));
    // Otherwise the app cannot load lectures so silence service makes no sense
    if (new AccessTokenManager(this).hasValidAccessToken()) {
        checkSilentMode.setChecked(preferences.getBoolean(Const.SILENCE_SERVICE, false));
        checkSilentMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (checkSilentMode.isChecked() && !SilenceService.hasPermissions(WizNavExtrasActivity.this)) {
                SilenceService.requestPermissions(WizNavExtrasActivity.this);
                checkSilentMode.setChecked(false);
            }
        });
    } else {
        checkSilentMode.setChecked(false);
        checkSilentMode.setEnabled(false);
    }
    // Get handles to all UI elements
    groupChatMode = findViewById(R.id.chk_group_chat);
    if (new AccessTokenManager(this).hasValidAccessToken()) {
        groupChatMode.setChecked(preferences.getBoolean(Const.GROUP_CHAT_ENABLED, true));
    } else {
        groupChatMode.setChecked(false);
        groupChatMode.setEnabled(false);
    }
}
Also used : AuthenticationManager(de.tum.in.tumcampusapp.api.app.AuthenticationManager) NoPublicKey(de.tum.in.tumcampusapp.api.app.exception.NoPublicKey) AccessTokenManager(de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager) Intent(android.content.Intent)

Example 4 with AccessTokenManager

use of de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager in project TumCampusApp by TCA-Team.

the class SettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    // Load the correct preference category
    setPreferencesFromResource(R.xml.settings, rootKey);
    mContext = getActivity();
    // Disables silence service if the app is used without TUMOnline access
    CheckBoxPreference silent = (CheckBoxPreference) findPreference("silent_mode");
    if (silent != null && !new AccessTokenManager(mContext).hasValidAccessToken()) {
        silent.setEnabled(false);
    }
    // Only do these things if we are in the root of the preferences
    if (rootKey == null) {
        // Click listener for preference list entries. Used to simulate a button
        // (since it is not possible to add a button to the preferences screen)
        findPreference(BUTTON_CLEAR_CACHE).setOnPreferenceClickListener(this);
        // Set summary for these preferences
        setSummary("card_cafeteria_default_G");
        setSummary("card_cafeteria_default_K");
        setSummary("card_cafeteria_default_W");
        setSummary("card_role");
        setSummary("card_stations_default_G");
        setSummary("card_stations_default_C");
        setSummary("card_stations_default_K");
        setSummary("card_default_campus");
        setSummary("silent_mode_set_to");
        setSummary("background_mode_set_to");
    } else if (rootKey.equals("card_eduroam")) {
        findPreference(SETUP_EDUROAM).setOnPreferenceClickListener(this);
    }
    // Register the change listener to react immediately on changes
    PreferenceManager.getDefaultSharedPreferences(mContext).registerOnSharedPreferenceChangeListener(this);
}
Also used : AccessTokenManager(de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference)

Aggregations

AccessTokenManager (de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager)4 NewsController (de.tum.in.tumcampusapp.component.ui.news.NewsController)2 Intent (android.content.Intent)1 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)1 AuthenticationManager (de.tum.in.tumcampusapp.api.app.AuthenticationManager)1 NoPublicKey (de.tum.in.tumcampusapp.api.app.exception.NoPublicKey)1 TUMOnlineRequest (de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest)1 OrgItemList (de.tum.in.tumcampusapp.component.other.departments.model.OrgItemList)1 CalendarController (de.tum.in.tumcampusapp.component.tumui.calendar.CalendarController)1 TuitionFeeManager (de.tum.in.tumcampusapp.component.tumui.tutionfees.TuitionFeeManager)1 TuitionList (de.tum.in.tumcampusapp.component.tumui.tutionfees.model.TuitionList)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 News (de.tum.in.tumcampusapp.component.ui.news.model.News)1 NewsSources (de.tum.in.tumcampusapp.component.ui.news.model.NewsSources)1 LoginPromtCard (de.tum.in.tumcampusapp.component.ui.onboarding.LoginPromtCard)1 Card (de.tum.in.tumcampusapp.component.ui.overview.card.Card)1 TransportController (de.tum.in.tumcampusapp.component.ui.transportation.TransportController)1