Search in sources :

Example 1 with FeedItemData

use of gov.whitehouse.core.FeedItemData in project wh-app-android by WhiteHouse.

the class FeedItemListFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    showList(false);
    showProgress(true);
    if (mFeedType == TYPE_FAVORITES) {
        bindSubscription(AndroidObservable.bindFragment(this, FeedManager.observeFavorites()).map(feedItems -> {
            List<FeedItemData> processed = new ArrayList<>(feedItems.size());
            FeedItemData data;
            for (FeedItem item : feedItems) {
                data = new FeedItemData();
                data.item = item;
                processed.add(data);
            }
            return processed;
        }).subscribe(this));
        FeedManager.updateFavorites(getActivity());
    } else {
        bindSubscription(fetchData());
        String viewType;
        switch(mFeedType) {
            default:
            case TYPE_ARTICLE:
                viewType = FeedCategoryItem.VIEW_TYPE_ARTICLE_LIST;
                break;
            case TYPE_LIVE:
                viewType = FeedCategoryItem.VIEW_TYPE_LIVE;
                break;
            case TYPE_PHOTOS:
                viewType = FeedCategoryItem.VIEW_TYPE_PHOTO_GALLERY;
                break;
            case TYPE_VIDEOS:
                viewType = FeedCategoryItem.VIEW_TYPE_VIDEO_GALLERY;
                break;
        }
        FeedManager.updateFeedFromServer(mFeedUrl, mFeedTitle, viewType);
    }
    if (mFeedType == TYPE_FAVORITES) {
        Drawable d = getResources().getDrawable(R.drawable.ic_action_bookmark_outline);
        String s = getString(R.string.empty_favorites_list);
        SpannableString ss = new SpannableString(s);
        ImageSpan is = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
        int index = s.indexOf("{icon}");
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        d.setColorFilter(Color.DKGRAY, PorterDuff.Mode.MULTIPLY);
        ss.setSpan(is, index, index + 6, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        getEmptyView().setText(ss);
    } else if (mFeedType == TYPE_LIVE) {
        getEmptyView().setText(R.string.empty_live_list);
    }
    if (getTracker() != null) {
        getTracker().setScreenName("FeedItemList");
        if (mFeedType == TYPE_FAVORITES) {
            getTracker().setPage("Favorites");
        } else {
            getTracker().setPage(mFeedUrl);
        }
    }
}
Also used : SpannableString(android.text.SpannableString) FeedItem(gov.whitehouse.data.model.FeedItem) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) SpannableString(android.text.SpannableString) FeedItemData(gov.whitehouse.core.FeedItemData) ImageSpan(android.text.style.ImageSpan)

Example 2 with FeedItemData

use of gov.whitehouse.core.FeedItemData in project wh-app-android by WhiteHouse.

the class MainActivity method onFeedItemSelected.

@Override
public void onFeedItemSelected(List<FeedItemData> items, int selectedPosition) {
    FeedItem item = items.get(selectedPosition).item;
    FragmentManager fm;
    FragmentTransaction ft;
    Fragment f;
    Intent intent;
    final List<FeedItem> feedItems;
    if (item.type().equals(FeedType.TYPE_LIVE)) {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(item.link()));
        startActivity(intent);
        return;
    }
    fm = getSupportFragmentManager();
    ft = fm.beginTransaction();
    if (item.type().equals(FeedType.TYPE_PHOTO)) {
        feedItems = new ArrayList<>(items.size());
        for (FeedItemData data : items) {
            feedItems.add(data.item);
        }
        f = GalleryFragment.newInstance(feedItems, selectedPosition);
    } else if (item.type().equals(FeedType.TYPE_VIDEO)) {
        if (item.isYouTubeVideo()) {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(item.videoLink()));
            startActivity(intent);
            return;
        } else {
            f = VideoPlayerFragment.newInstance(item);
        }
    } else {
        f = ArticleViewFragment.newInstance(item);
    }
    if (mSearchVisible && !mTogglingSearch) {
        toggleSearch();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    }
    Fragment old = fm.findFragmentByTag("contentFragment");
    if (old != null) {
        ft.remove(old);
    }
    ft.add(R.id.fragment_container, f, "contentFragment").addToBackStack(null).commit();
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) FeedItem(gov.whitehouse.data.model.FeedItem) Intent(android.content.Intent) BaseFragment(gov.whitehouse.app.BaseFragment) Fragment(android.support.v4.app.Fragment) FeedItemData(gov.whitehouse.core.FeedItemData)

Aggregations

FeedItemData (gov.whitehouse.core.FeedItemData)2 FeedItem (gov.whitehouse.data.model.FeedItem)2 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 Fragment (android.support.v4.app.Fragment)1 FragmentManager (android.support.v4.app.FragmentManager)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 SpannableString (android.text.SpannableString)1 ImageSpan (android.text.style.ImageSpan)1 BaseFragment (gov.whitehouse.app.BaseFragment)1 ArrayList (java.util.ArrayList)1