Пример #1
0
 private void maybeAddNowTab() {
   int currentTabCount = tabsAdapter.getCount();
   boolean shouldShowTraktTabs = TraktCredentials.get(this).hasCredentials();
   if (shouldShowTraktTabs && currentTabCount != TAB_COUNT_WITH_TRAKT) {
     tabsAdapter.addTab(R.string.now_tab, MoviesNowFragment.class, null);
     // update tabs
     tabsAdapter.notifyTabsChanged();
   }
 }
Пример #2
0
  private void setupViews() {
    // tabs
    tabsAdapter =
        new TabStripAdapter(
            getSupportFragmentManager(),
            this,
            (ViewPager) findViewById(R.id.viewPagerTabs),
            (SlidingTabLayout) findViewById(R.id.tabLayoutTabs));
    // search
    tabsAdapter.addTab(R.string.search, MoviesSearchFragment.class, null);
    // trakt-only tabs should only be visible if connected
    if (TraktCredentials.get(this).hasCredentials()) {
      // (what to watch) now
      tabsAdapter.addTab(R.string.now_tab, MoviesNowFragment.class, null);
    }
    // watchlist
    tabsAdapter.addTab(R.string.movies_watchlist, MoviesWatchListFragment.class, null);
    // collection
    tabsAdapter.addTab(R.string.movies_collection, MoviesCollectionFragment.class, null);

    tabsAdapter.notifyTabsChanged();
  }
  @Override
  public List<NowAdapter.NowItem> loadInBackground() {
    if (!TraktCredentials.get(getContext()).hasCredentials()) {
      return null;
    }

    // get all trakt friends
    List<Friend> friends =
        SgTrakt.executeAuthenticatedCall(
            getContext(), traktUsers.get().friends(UserSlug.ME, Extended.FULL), "get friends");
    if (friends == null) {
      return null;
    }

    int size = friends.size();
    if (size == 0) {
      return null; // no friends, done.
    }

    // estimate list size
    List<NowAdapter.NowItem> items = new ArrayList<>(size + 1);

    // add header
    items.add(new NowAdapter.NowItem().header(getContext().getString(R.string.friends_recently)));

    // add last watched movie for each friend
    for (int i = 0; i < size; i++) {
      Friend friend = friends.get(i);

      // at least need a userSlug
      if (friend.user == null) {
        continue;
      }
      String userSlug = friend.user.ids.slug;
      if (TextUtils.isEmpty(userSlug)) {
        continue;
      }

      // get last watched episode
      List<HistoryEntry> history =
          SgTrakt.executeCall(
              getContext(),
              traktUsers
                  .get()
                  .history(
                      new UserSlug(userSlug),
                      HistoryType.MOVIES,
                      1,
                      1,
                      Extended.DEFAULT_MIN,
                      null,
                      null),
              "get friend movie history");
      if (history == null || history.size() == 0) {
        continue; // no history
      }

      HistoryEntry entry = history.get(0);
      if (entry.watched_at == null || entry.movie == null) {
        // missing required values
        continue;
      }

      String avatar =
          (friend.user.images == null || friend.user.images.avatar == null)
              ? null
              : friend.user.images.avatar.full;
      // trakt has removed image support: currently displaying no image
      NowAdapter.NowItem nowItem =
          new NowAdapter.NowItem()
              .displayData(entry.watched_at.getMillis(), entry.movie.title, null, null)
              .tmdbId(entry.movie.ids == null ? null : entry.movie.ids.tmdb)
              .friend(friend.user.username, avatar, entry.action);
      items.add(nowItem);
    }

    // only have a header? return nothing
    if (items.size() == 1) {
      return Collections.emptyList();
    }

    return items;
  }
 private void onRateOnTrakt() {
   if (TraktCredentials.ensureCredentials(getActivity())) {
     onShareEpisode(ShareMethod.RATE_TRAKT);
   }
   fireTrackerEvent("Rate (trakt)");
 }