use of de.tum.in.tumcampusapp.component.ui.news.model.NewsSources 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.NewsSources in project TumCampusApp by TCA-Team.
the class NewsSourcesDaoTest method getNewsSourceTest.
/**
* Test that specific id item is returned
* Expected output: actual item is returned
*/
@Test
public void getNewsSourceTest() {
dao.insert(new NewsSources(8, "8", "8"));
dao.insert(new NewsSources(9, "9", "9"));
dao.insert(new NewsSources(10, "10", "10"));
dao.insert(new NewsSources(11, "11", "11"));
NewsSources item = dao.getNewsSource(9);
assertThat(item.getId()).isEqualTo(9);
assertThat(item.getTitle()).isEqualTo("9");
assertThat(item.getIcon()).isEqualTo("9");
}
use of de.tum.in.tumcampusapp.component.ui.news.model.NewsSources in project TumCampusApp by TCA-Team.
the class NewsSourcesDaoTest method getNewsSourcesNoneTest.
/**
* Test that all that are in excluded range are not returned
* Expected output: no items returned
*/
@Test
public void getNewsSourcesNoneTest() {
dao.insert(new NewsSources(8, "0", ""));
dao.insert(new NewsSources(9, "1", ""));
dao.insert(new NewsSources(10, "2", ""));
dao.insert(new NewsSources(11, "3", ""));
assertThat(dao.getNewsSources("1")).hasSize(0);
}
use of de.tum.in.tumcampusapp.component.ui.news.model.NewsSources in project TumCampusApp by TCA-Team.
the class NewsActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_disable_sources) {
Collection<CharSequence> itemsList = new ArrayList<>();
Collection<Boolean> checkedList = new ArrayList<>();
List<NewsSources> newsSources = nm.getNewsSources();
// Populate the settings dialog from the NewsController sources
for (NewsSources newsSource : newsSources) {
itemsList.add(newsSource.getTitle());
checkedList.add(Utils.getSettingBool(this, "news_source_" + newsSource.getId(), true));
}
CharSequence[] items = Iterables.toArray(itemsList, CharSequence.class);
boolean[] checkedItems = Booleans.toArray(checkedList);
new AlertDialog.Builder(this).setMultiChoiceItems(items, checkedItems, this).create().show();
return true;
}
return super.onOptionsItemSelected(item);
}
use of de.tum.in.tumcampusapp.component.ui.news.model.NewsSources in project TumCampusApp by TCA-Team.
the class NewsCard method fillNotification.
@Override
protected Notification fillNotification(NotificationCompat.Builder notificationBuilder) {
NewsSourcesDao newsSourcesDao = TcaDb.getInstance(mContext).newsSourcesDao();
NewsSources newsSource = newsSourcesDao.getNewsSource(Integer.parseInt(mNews.getSrc()));
notificationBuilder.setContentTitle(mContext.getString(R.string.news));
notificationBuilder.setContentText(mNews.getTitle());
notificationBuilder.setContentInfo(newsSource.getTitle());
notificationBuilder.setTicker(mNews.getTitle());
notificationBuilder.setSmallIcon(R.drawable.ic_notification);
Optional<Bitmap> img = net.downloadImageToBitmap(mNews.getImage());
if (img.isPresent()) {
notificationBuilder.extend(new NotificationCompat.WearableExtender().setBackground(img.get()));
}
return notificationBuilder.build();
}
Aggregations