Search in sources :

Example 11 with NewsSources

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);
}
Also used : NewsSources(de.tum.in.tumcampusapp.component.ui.news.model.NewsSources) Test(org.junit.Test)

Example 12 with NewsSources

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);
}
Also used : NewsSources(de.tum.in.tumcampusapp.component.ui.news.model.NewsSources) Test(org.junit.Test)

Example 13 with NewsSources

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);
}
Also used : NewsSources(de.tum.in.tumcampusapp.component.ui.news.model.NewsSources) Test(org.junit.Test)

Example 14 with NewsSources

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

NewsSources (de.tum.in.tumcampusapp.component.ui.news.model.NewsSources)14 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 NewsController (de.tum.in.tumcampusapp.component.ui.news.NewsController)2 News (de.tum.in.tumcampusapp.component.ui.news.model.News)2 NetUtils (de.tum.in.tumcampusapp.utils.NetUtils)2 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 AlertDialog (android.support.v7.app.AlertDialog)1 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)1 PreferenceCategory (android.support.v7.preference.PreferenceCategory)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Optional (com.google.common.base.Optional)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 Kino (de.tum.in.tumcampusapp.component.ui.tufilm.model.Kino)1 SyncManager (de.tum.in.tumcampusapp.utils.sync.SyncManager)1 DateFormat (java.text.DateFormat)1