Search in sources :

Example 11 with FeedItem

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

Example 12 with FeedItem

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);
}
Also used : FeedItem(gov.whitehouse.data.model.FeedItem) Gson(com.google.gson.Gson) FavoritesMap(gov.whitehouse.data.model.FavoritesMap) Test(org.junit.Test)

Example 13 with FeedItem

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);
}
Also used : FeedItem(gov.whitehouse.data.model.FeedItem) FavoritesMap(gov.whitehouse.data.model.FavoritesMap) Test(org.junit.Test)

Example 14 with FeedItem

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);
}
Also used : FeedItem(gov.whitehouse.data.model.FeedItem) Bundle(android.os.Bundle)

Example 15 with FeedItem

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);
}
Also used : FeedItem(gov.whitehouse.data.model.FeedItem) Date(java.util.Date) HashSet(java.util.HashSet)

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