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