Search in sources :

Example 1 with NewsController

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

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;
}
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 NewsController

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;
    }
}
Also used : JSONException(org.json.JSONException) NewsController(de.tum.in.tumcampusapp.component.ui.news.NewsController)

Example 4 with NewsController

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);
        }
    }
}
Also used : NewsSources(de.tum.in.tumcampusapp.component.ui.news.model.NewsSources) NetUtils(de.tum.in.tumcampusapp.utils.NetUtils) Optional(com.google.common.base.Optional) PreferenceCategory(android.support.v7.preference.PreferenceCategory) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) NewsController(de.tum.in.tumcampusapp.component.ui.news.NewsController) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Aggregations

NewsController (de.tum.in.tumcampusapp.component.ui.news.NewsController)4 AccessTokenManager (de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager)2 NewsSources (de.tum.in.tumcampusapp.component.ui.news.model.NewsSources)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)1 PreferenceCategory (android.support.v7.preference.PreferenceCategory)1 Optional (com.google.common.base.Optional)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 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