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