use of de.tum.in.tumcampusapp.component.ui.news.NewsController 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.component.ui.news.NewsController 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.ui.news.NewsController in project TumCampusApp by TCA-Team.
the class DownloadService method downloadNews.
private boolean downloadNews(boolean force) {
try {
NewsController nm = new NewsController(this);
nm.downloadFromExternal(force);
return true;
} catch (JSONException e) {
Utils.log(e);
return false;
}
}
use of de.tum.in.tumcampusapp.component.ui.news.NewsController in project TumCampusApp by TCA-Team.
the class SettingsFragment method populateNewsSources.
private void populateNewsSources() {
PreferenceCategory newsSourcesPreference = (PreferenceCategory) findPreference("card_news_sources");
NewsController newsController = new NewsController(mContext);
List<NewsSources> newsSources = newsController.getNewsSources();
final NetUtils net = new NetUtils(mContext);
for (NewsSources newsSource : newsSources) {
final CheckBoxPreference pref = new CheckBoxPreference(mContext);
pref.setKey("card_news_source_" + newsSource.getId());
pref.setDefaultValue(true);
// Load news source icon in background and set it
final String url = newsSource.getIcon();
if (url != null) {
// Skip News that do not have a image
new Thread(() -> {
final Optional<Bitmap> bmp = net.downloadImageToBitmap(url);
mContext.runOnUiThread(() -> {
if (bmp.isPresent()) {
pref.setIcon(new BitmapDrawable(getResources(), bmp.get()));
}
});
}).start();
}
pref.setTitle(newsSource.getTitle());
if (newsSourcesPreference != null) {
newsSourcesPreference.addPreference(pref);
}
}
}
Aggregations