Search in sources :

Example 1 with FeedItem

use of gov.whitehouse.data.model.FeedItem 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 FeedItem

use of gov.whitehouse.data.model.FeedItem 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)

Example 3 with FeedItem

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

the class GalleryFragment method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    Bundle args = getArguments();
    Collections.addAll(mFeedItems, (FeedItem[]) args.getParcelableArray(EXTRA_FEED));
    mIndex = args.getInt(EXTRA_INDEX, 0);
}
Also used : FeedItem(gov.whitehouse.data.model.FeedItem) Bundle(android.os.Bundle)

Example 4 with FeedItem

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

the class FavoritesUtils method removeFromFavorites.

public static void removeFromFavorites(final Context context, final String type, final FeedItem item) {
    FavoritesMap map;
    try {
        map = getGson().fromJson(new InputStreamReader(getInputStream(context)), FavoritesMap.class);
    } catch (FileNotFoundException e) {
        map = null;
    }
    if (map == null) {
        return;
    }
    if (FAVORITE_ARTICLES.equals(type) && (map.articles() == null || map.articles().size() < 1)) {
        return;
    } else if (FAVORITE_PHOTOS.equals(type) && (map.photos() == null || map.photos().size() < 1)) {
        return;
    } else if (FAVORITE_VIDEOS.equals(type) && (map.videos() == null || map.videos().size() < 1)) {
        return;
    }
    final LinkedList<FeedItem> llist;
    switch(type) {
        case FAVORITE_ARTICLES:
            llist = new LinkedList<>(map.articles());
            break;
        case FAVORITE_PHOTOS:
            llist = new LinkedList<>(map.photos());
            break;
        case FAVORITE_VIDEOS:
            llist = new LinkedList<>(map.videos());
            break;
        default:
            llist = new LinkedList<>();
            break;
    }
    for (Iterator itr = llist.iterator(); itr.hasNext(); ) {
        FeedItem i = (FeedItem) itr.next();
        if (i.pubDate().equals(item.pubDate()) && i.link().equals(item.link())) {
            itr.remove();
        }
    }
    switch(type) {
        case FAVORITE_ARTICLES:
            map.articles().clear();
            map.articles().addAll(llist);
            break;
        case FAVORITE_PHOTOS:
            map.photos().clear();
            map.photos().addAll(llist);
            break;
        case FAVORITE_VIDEOS:
            map.videos().clear();
            map.videos().addAll(llist);
            break;
    }
    OutputStreamWriter out = new OutputStreamWriter(getOutputStream(context));
    try {
        out.write(getGson().toJson(map));
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FeedItem(gov.whitehouse.data.model.FeedItem) FileNotFoundException(java.io.FileNotFoundException) Iterator(java.util.Iterator) FavoritesMap(gov.whitehouse.data.model.FavoritesMap) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException)

Example 5 with FeedItem

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

the class FeedManager method updateFavorites.

public static void updateFavorites(Context ctx) {
    sFavoritesSubject.onNext(Observable.create((Subscriber<? super List<FeedItem>> op) -> {
        final FavoritesMap map;
        final InputStreamReader isr;
        final List<FeedItem> favorites = new ArrayList<>();
        final Gson gson = GsonUtils.createGsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
        try {
            isr = new InputStreamReader(FavoritesUtils.getInputStream(ctx));
            map = gson.fromJson(isr, FavoritesMap.class);
            if (map.articles() != null) {
                processAndStoreFavorites(map.articles(), favorites, FeedType.TYPE_ARTICLE);
            }
            if (map.photos() != null) {
                processAndStoreFavorites(map.photos(), favorites, FeedType.TYPE_PHOTO);
            }
            if (map.videos() != null) {
                processAndStoreFavorites(map.videos(), favorites, FeedType.TYPE_VIDEO);
            }
            Collections.sort(favorites, (lhs, rhs) -> {
                if (lhs.feedTitle() != null && rhs.feedTitle() != null) {
                    return lhs.feedTitle().compareTo(rhs.feedTitle());
                }
                return 1;
            });
        } catch (FileNotFoundException ignored) {
        }
        op.onNext(favorites);
        op.onCompleted();
    }).subscribeOn(Schedulers.io()));
}
Also used : InputStreamReader(java.io.InputStreamReader) FeedItem(gov.whitehouse.data.model.FeedItem) Subscriber(rx.Subscriber) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FavoritesMap(gov.whitehouse.data.model.FavoritesMap) Gson(com.google.gson.Gson) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

FeedItem (gov.whitehouse.data.model.FeedItem)15 ArrayList (java.util.ArrayList)5 Bundle (android.os.Bundle)4 FavoritesMap (gov.whitehouse.data.model.FavoritesMap)4 Test (org.junit.Test)4 FileNotFoundException (java.io.FileNotFoundException)3 Intent (android.content.Intent)2 Fragment (android.support.v4.app.Fragment)2 FragmentManager (android.support.v4.app.FragmentManager)2 Gson (com.google.gson.Gson)2 BaseFragment (gov.whitehouse.app.BaseFragment)2 FeedItemData (gov.whitehouse.core.FeedItemData)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 List (java.util.List)2 Observable (rx.Observable)2 Subscriber (rx.Subscriber)2 Activity (android.app.Activity)1 Drawable (android.graphics.drawable.Drawable)1 Nullable (android.support.annotation.Nullable)1