Search in sources :

Example 1 with FeedCategoryItem

use of gov.whitehouse.data.model.FeedCategoryItem in project wh-app-android by WhiteHouse.

the class DrawerFragment method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mMenu = new MenuBuilder(getActivity());
    bindSubscription(AndroidObservable.bindFragment(this, FeedCategoryManager.get().getFeedCategoryConfig().first().subscribeOn(Schedulers.newThread())).subscribe(feedCategoryConfig -> {
        List<FeedCategoryItem> items = feedCategoryConfig.feeds();
        int i = 0;
        int group = 0;
        for (FeedCategoryItem c : items) {
            switch(c.viewType()) {
                case FeedCategoryItem.VIEW_TYPE_ARTICLE_LIST:
                    group = GROUP_ARTICLES;
                    break;
                case FeedCategoryItem.VIEW_TYPE_PHOTO_GALLERY:
                    group = GROUP_PHOTOS;
                    break;
                case FeedCategoryItem.VIEW_TYPE_VIDEO_GALLERY:
                    group = GROUP_VIDEOS;
                    break;
                case FeedCategoryItem.VIEW_TYPE_LIVE:
                    mLivePosition = i + 1;
                    group = GROUP_LIVE;
                    break;
            }
            mMenu.add(group, Menu.NONE, i++, c.title()).setIntent(new Intent().setData(Uri.parse(c.feedUrl())));
        }
        mMenu.add(GROUP_FAVORITES, Menu.NONE, i++, R.string.title_favorites);
        getAdapter().addHeader(new Object());
        getAdapter().fillWith(getMenuItems());
        getAdapter().selectOnly(mCheckedPosition);
        getProgressBar().setVisibility(View.GONE);
        getRecyclerView().setVisibility(View.VISIBLE);
        if (mDrawerCallbacks != null) {
            if (icicle == null) {
                mDrawerCallbacks.onRestoreSelectedItem(getAdapter().getItem(mCheckedPosition));
            }
            updateTitle();
        }
    }));
}
Also used : MenuBuilder(android.support.v7.internal.view.menu.MenuBuilder) Bundle(android.os.Bundle) Uri(android.net.Uri) Intent(android.content.Intent) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) BaseListFragment(gov.whitehouse.app.BaseListFragment) AndroidObservable(rx.android.observables.AndroidObservable) BaseAdapter(gov.whitehouse.widget.BaseAdapter) Menu(android.view.Menu) Schedulers(rx.schedulers.Schedulers) View(android.view.View) FeedCategoryManager(gov.whitehouse.core.manager.FeedCategoryManager) Icicle(icepick.Icicle) LayoutInflater(android.view.LayoutInflater) Collection(java.util.Collection) ViewGroup(android.view.ViewGroup) List(java.util.List) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar) FeedCategoryItem(gov.whitehouse.data.model.FeedCategoryItem) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) R(gov.whitehouse.R) DrawerItemAdapter(gov.whitehouse.widget.wh.DrawerItemAdapter) ArrayList(java.util.ArrayList) List(java.util.List) Intent(android.content.Intent) MenuBuilder(android.support.v7.internal.view.menu.MenuBuilder) FeedCategoryItem(gov.whitehouse.data.model.FeedCategoryItem)

Example 2 with FeedCategoryItem

use of gov.whitehouse.data.model.FeedCategoryItem in project wh-app-android by WhiteHouse.

the class LiveService method updateEvents.

private void updateEvents() {
    final FeedCategoryManager fcm = FeedCategoryManager.get();
    final FeedCategoryConfig config = fcm.getFeedCategoryConfig().toBlocking().first();
    final List<FeedItem> feedItems;
    final List<FeedItem> validItems = new ArrayList<>();
    FeedCategoryItem liveItem = null;
    for (FeedCategoryItem c : config.feeds()) {
        if (FeedCategoryItem.VIEW_TYPE_LIVE.equals(c.viewType())) {
            liveItem = c;
            break;
        }
    }
    if (liveItem == null) {
        return;
    }
    FeedManager.updateFeedFromServer(liveItem.feedUrl(), liveItem.title(), liveItem.viewType());
    feedItems = FeedManager.observeFeedItems(liveItem.feedUrl()).toBlocking().first();
    for (FeedItem item : feedItems) {
        if (item != null && item.pubDate() != null) {
            validItems.add(item);
        }
    }
    sLiveItemCountObservable.onNext(Observable.just(validItems.size()));
    mLiveEvents = validItems;
}
Also used : FeedCategoryConfig(gov.whitehouse.data.model.FeedCategoryConfig) FeedItem(gov.whitehouse.data.model.FeedItem) FeedCategoryManager(gov.whitehouse.core.manager.FeedCategoryManager) ArrayList(java.util.ArrayList) FeedCategoryItem(gov.whitehouse.data.model.FeedCategoryItem)

Aggregations

FeedCategoryManager (gov.whitehouse.core.manager.FeedCategoryManager)2 FeedCategoryItem (gov.whitehouse.data.model.FeedCategoryItem)2 ArrayList (java.util.ArrayList)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 MenuBuilder (android.support.v7.internal.view.menu.MenuBuilder)1 Toolbar (android.support.v7.widget.Toolbar)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 R (gov.whitehouse.R)1 BaseListFragment (gov.whitehouse.app.BaseListFragment)1 FeedCategoryConfig (gov.whitehouse.data.model.FeedCategoryConfig)1 FeedItem (gov.whitehouse.data.model.FeedItem)1