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