Search in sources :

Example 1 with News

use of de.tum.in.tumcampusapp.component.ui.news.model.News 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 News

use of de.tum.in.tumcampusapp.component.ui.news.model.News in project TumCampusApp by TCA-Team.

the class NewsDaoTest method getBySourcesLatestTest.

/**
 * Closest to today items retrieved single per source.
 * Expected output: All items are retrieved
 */
@Test
public void getBySourcesLatestTest() {
    DateTime now = DateTime.now();
    dao.insert(createNewsItem("123", now.minusDays(1).toDate()));
    dao.insert(createNewsItem("124", now.minusMonths(1).toDate()));
    dao.insert(createNewsItem("125", now.minusYears(1).toDate()));
    dao.insert(createNewsItem("126", now.minusHours(1).toDate()));
    List<News> news = dao.getBySources(new Integer[] { 123, 124, 125, 126 });
    assertThat(news).hasSize(4);
}
Also used : News(de.tum.in.tumcampusapp.component.ui.news.model.News) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with News

use of de.tum.in.tumcampusapp.component.ui.news.model.News in project TumCampusApp by TCA-Team.

the class NewsDaoTest method createNewsItem.

private News createNewsItem(String source, Date date) {
    News news = new News(Integer.toString(newsIdx), Integer.toString(newsIdx), "dummy link", source, "dummy image", date, date, 0);
    newsIdx++;
    return news;
}
Also used : News(de.tum.in.tumcampusapp.component.ui.news.model.News)

Example 4 with News

use of de.tum.in.tumcampusapp.component.ui.news.model.News in project TumCampusApp by TCA-Team.

the class NewsDaoTest method getLastTest.

/**
 * Several news items and "biggest" id one is retrieved
 * Expected output: item with biggest id is retrieved
 */
@Test
public void getLastTest() {
    DateTime now = DateTime.now();
    dao.insert(createNewsItem("123", now.minusDays(1).toDate()));
    dao.insert(createNewsItem("123", now.minusMonths(1).toDate()));
    dao.insert(createNewsItem("123", now.minusYears(1).toDate()));
    dao.insert(createNewsItem("123", now.minusHours(1).toDate()));
    News last = dao.getLast();
    assertThat(last.getId()).isEqualTo("3");
}
Also used : News(de.tum.in.tumcampusapp.component.ui.news.model.News) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with News

use of de.tum.in.tumcampusapp.component.ui.news.model.News in project TumCampusApp by TCA-Team.

the class NewsActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    // Gets all news from database
    nm = new NewsController(this);
    List<News> news = nm.getAllFromDb(this);
    if (news.size() > 0) {
        NewsAdapter adapter = new NewsAdapter(this, news);
        lv = findViewById(R.id.activity_news_list_view);
        lv.setLayoutManager(new LinearLayoutManager(this));
        lv.setAdapter(adapter);
        /* Restore previous state (including selected item index and scroll position) */
        if (state == -1) {
            lv.scrollToPosition(nm.getTodayIndex());
        } else {
            lv.scrollToPosition(state);
        }
    } else if (NetUtils.isConnected(this)) {
        showErrorLayout();
    } else {
        showNoInternetLayout();
    }
}
Also used : News(de.tum.in.tumcampusapp.component.ui.news.model.News) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

News (de.tum.in.tumcampusapp.component.ui.news.model.News)8 DateTime (org.joda.time.DateTime)3 Test (org.junit.Test)3 NewsSources (de.tum.in.tumcampusapp.component.ui.news.model.NewsSources)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 AccessTokenManager (de.tum.in.tumcampusapp.api.tumonline.AccessTokenManager)1 TUMOnlineRequest (de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest)1 OrgItemList (de.tum.in.tumcampusapp.component.other.departments.model.OrgItemList)1 TuitionList (de.tum.in.tumcampusapp.component.tumui.tutionfees.model.TuitionList)1 NewsController (de.tum.in.tumcampusapp.component.ui.news.NewsController)1 FilmCard (de.tum.in.tumcampusapp.component.ui.tufilm.FilmCard)1 Kino (de.tum.in.tumcampusapp.component.ui.tufilm.model.Kino)1 NetUtils (de.tum.in.tumcampusapp.utils.NetUtils)1 SyncManager (de.tum.in.tumcampusapp.utils.sync.SyncManager)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1