use of gov.whitehouse.data.model.FeedItem 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();
}
use of gov.whitehouse.data.model.FeedItem in project wh-app-android by WhiteHouse.
the class DataTest method mapFavoritesToJson.
@Test
public void mapFavoritesToJson() {
final Gson gson = createGson();
String json;
FeedItem item = generateFeedItem();
FavoritesMap convertedMap;
FavoritesMap map = FavoritesMap.create(new ArrayList<>(1), new ArrayList<>(), new ArrayList<>());
map.articles().add(item);
System.out.println("Map toString():\n" + map.toString() + "\n");
json = gson.toJson(map);
System.out.println("Map JSON:\n" + json + "\n");
convertedMap = gson.fromJson(json, FavoritesMap.class);
System.out.println("Converted Map toString():\n" + convertedMap.toString() + "\n");
System.out.println("Item hashCode(): " + item.hashCode());
printFeedItemFieldHashes(item);
System.out.println("Converted Item hashCode(): " + convertedMap.articles().get(0).hashCode());
printFeedItemFieldHashes(convertedMap.articles().get(0));
assertThat(convertedMap.articles()).hasSameSizeAs(map.articles());
assertThat(convertedMap.photos()).hasSameSizeAs(map.photos());
assertThat(convertedMap.videos()).hasSameSizeAs(map.videos());
assertThat(convertedMap.articles()).contains(item);
}
use of gov.whitehouse.data.model.FeedItem in project wh-app-android by WhiteHouse.
the class DataTest method createFavoritesMap.
@Test
public void createFavoritesMap() {
FeedItem item = generateFeedItem();
FavoritesMap map = FavoritesMap.create(new ArrayList<>(1), new ArrayList<>(), new ArrayList<>());
map.articles().add(item);
assertThat(map.articles()).hasSize(1);
assertThat(map.photos()).hasSize(0);
assertThat(map.videos()).hasSize(0);
}
use of gov.whitehouse.data.model.FeedItem in project wh-app-android by WhiteHouse.
the class GalleryPhotoFragment method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Bundle args = getArguments();
mFeedItem = GsonUtils.fromJson(args.getString(EXTRA_FEED_ITEM), FeedItem.class);
/* TODO: Make FeedItem Parcelable */
mIndexInGallery = args.getInt(EXTRA_INDEX, -1);
}
use of gov.whitehouse.data.model.FeedItem in project wh-app-android by WhiteHouse.
the class LiveService method processEvents.
private void processEvents() {
final Set<String> newNotifs = new HashSet<>();
final Set<String> oldNotifs = getStoredNotificationKeys();
final Date now = new Date();
Date pubDate;
Date notifDate;
String key;
for (FeedItem item : mLiveEvents) {
pubDate = item.pubDate();
notifDate = new Date();
notifDate.setTime(pubDate.getTime() - (30 * MILLIS_IN_MINUTE));
key = String.format("%s+%tQ", item.guid(), pubDate);
if (pubDate.after(now)) {
if (!oldNotifs.contains(key)) {
scheduleNotification(key, buildLiveNotification(item), notifDate.getTime());
}
newNotifs.add(key);
}
}
saveNotifications(newNotifs);
}
Aggregations