use of de.tum.in.tumcampusapp.component.ui.news.model.NewsSources in project TumCampusApp by TCA-Team.
the class NewsSourcesDaoTest method getNewsSourcesAllTest.
/**
* Test that all news sources are returned
* Expected output: all items are returned
*/
@Test
public void getNewsSourcesAllTest() {
dao.insert(new NewsSources(0, "0", ""));
dao.insert(new NewsSources(1, "1", ""));
dao.insert(new NewsSources(14, "2", ""));
dao.insert(new NewsSources(15, "3", ""));
assertThat(dao.getNewsSources("1")).hasSize(4);
}
use of de.tum.in.tumcampusapp.component.ui.news.model.NewsSources in project TumCampusApp by TCA-Team.
the class NewsSourcesDaoTest method getNewsSourcesSelectedSourceTest.
/**
* Test that selected source from excluded range is returned
* Expected output: single item
*/
@Test
public void getNewsSourcesSelectedSourceTest() {
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("9")).hasSize(1);
}
use of de.tum.in.tumcampusapp.component.ui.news.model.NewsSources in project TumCampusApp by TCA-Team.
the class NewsSourcesDaoTest method getNewsSourcesSomeTest.
/**
* Test that only in "allowed" range sources are returned
* Expected output: some items are returned
*/
@Test
public void getNewsSourcesSomeTest() {
dao.insert(new NewsSources(0, "0", ""));
// should be excluded
dao.insert(new NewsSources(9, "1", ""));
// should be excluded
dao.insert(new NewsSources(10, "2", ""));
dao.insert(new NewsSources(15, "3", ""));
assertThat(dao.getNewsSources("1")).hasSize(2);
}
use of de.tum.in.tumcampusapp.component.ui.news.model.NewsSources 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