Search in sources :

Example 1 with NewsSources

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

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

Example 3 with NewsSources

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

Example 4 with NewsSources

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);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) NewsSources(de.tum.in.tumcampusapp.component.ui.news.model.NewsSources) ArrayList(java.util.ArrayList)

Example 5 with NewsSources

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

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