Search in sources :

Example 1 with ExternalLink

use of com.mxt.anitrend.model.entity.anilist.ExternalLink in project anitrend-app by AniTrend.

the class HubPageAdapter method getItem.

/**
 * Return the Fragment associated with a specified position.
 *
 * @param position
 */
@Override
public Fragment getItem(int position) {
    switch(position) {
        case 0:
            return SuggestionListFragment.newInstance(getParams());
        case 1:
            List<ExternalLink> externalLinks = new ArrayList<>(1);
            externalLinks.add(new ExternalLink(BuildConfig.FEEDS_LINK, null));
            return WatchListFragment.newInstance(externalLinks, true);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) ExternalLink(com.mxt.anitrend.model.entity.anilist.ExternalLink)

Example 2 with ExternalLink

use of com.mxt.anitrend.model.entity.anilist.ExternalLink in project anitrend-app by AniTrend.

the class MediaStatsFragment method updateUI.

/**
 * Is automatically called in the @onStart Method if overridden in list implementation
 */
@Override
protected void updateUI() {
    binding.setModel(model);
    if (rankAdapter == null) {
        rankAdapter = new RankAdapter(getContext());
        rankAdapter.onItemsInserted(model.getRankings());
        rankAdapter.setClickListener(new ItemClickListener<MediaRank>() {

            @Override
            public void onItemClick(View target, IntPair<MediaRank> data) {
                Intent intent = new Intent(getActivity(), MediaBrowseActivity.class);
                Bundle args = new Bundle();
                QueryContainerBuilder queryContainer = GraphUtil.INSTANCE.getDefaultQuery(true).putVariable(KeyUtil.arg_type, mediaType).putVariable(KeyUtil.arg_format, data.getSecond().getFormat());
                if (MediaUtil.isAnimeType(model))
                    queryContainer.putVariable(KeyUtil.arg_season, data.getSecond().getSeason());
                if (!data.getSecond().isAllTime()) {
                    if (MediaUtil.isAnimeType(model))
                        queryContainer.putVariable(KeyUtil.arg_seasonYear, data.getSecond().getYear());
                    else
                        queryContainer.putVariable(KeyUtil.arg_startDateLike, String.format(Locale.getDefault(), "%d%%", data.getSecond().getYear()));
                }
                switch(data.getSecond().getType()) {
                    case KeyUtil.RATED:
                        queryContainer.putVariable(KeyUtil.arg_sort, KeyUtil.SCORE + KeyUtil.DESC);
                        break;
                    case KeyUtil.POPULAR:
                        queryContainer.putVariable(KeyUtil.arg_sort, KeyUtil.POPULARITY + KeyUtil.DESC);
                        break;
                }
                args.putParcelable(KeyUtil.arg_graph_params, queryContainer);
                args.putParcelable(KeyUtil.arg_media_util, new MediaBrowseUtil().setCompactType(true).setFilterEnabled(false));
                args.putString(KeyUtil.arg_activity_tag, data.getSecond().getTypeHtmlPlainTitle());
                intent.putExtras(args);
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View target, IntPair<MediaRank> data) {
            }
        });
    }
    if (linkAdapter == null) {
        linkAdapter = new LinkAdapter(getContext());
        linkAdapter.onItemsInserted(model.getExternalLinks());
        linkAdapter.setClickListener(new ItemClickListener<ExternalLink>() {

            @Override
            public void onItemClick(View target, IntPair<ExternalLink> data) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(data.getSecond().getUrl()));
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View target, IntPair<ExternalLink> data) {
            }
        });
    }
    binding.stateLayout.showContent();
    binding.linksRecycler.setAdapter(linkAdapter);
    binding.rankingRecycler.setAdapter(rankAdapter);
    showStatusDistribution();
    showScoreDistribution();
}
Also used : Bundle(android.os.Bundle) MediaBrowseUtil(com.mxt.anitrend.util.media.MediaBrowseUtil) Intent(android.content.Intent) View(android.view.View) ExternalLink(com.mxt.anitrend.model.entity.anilist.ExternalLink) MediaRank(com.mxt.anitrend.model.entity.anilist.MediaRank) LinkAdapter(com.mxt.anitrend.adapter.recycler.detail.LinkAdapter) RankAdapter(com.mxt.anitrend.adapter.recycler.detail.RankAdapter) MediaBrowseActivity(com.mxt.anitrend.view.activity.detail.MediaBrowseActivity) QueryContainerBuilder(io.github.wax911.library.model.request.QueryContainerBuilder)

Example 3 with ExternalLink

use of com.mxt.anitrend.model.entity.anilist.ExternalLink in project anitrend-app by AniTrend.

the class EpisodeUtilTests method episodeSupport_givenCrunchyrollUrl_shouldReturnTheFeedUrl.

@Test
public void episodeSupport_givenCrunchyrollUrl_shouldReturnTheFeedUrl() {
    String show = "my-hero-academia";
    ExternalLink link = mock(ExternalLink.class);
    when(link.getUrl()).thenReturn(BuildConfig.CRUNCHY_LINK + show);
    List<ExternalLink> links = Collections.singletonList(link);
    assertThat(EpisodeUtil.INSTANCE.episodeSupport(links), equalTo(show + ".rss"));
}
Also used : ExternalLink(com.mxt.anitrend.model.entity.anilist.ExternalLink) Test(org.junit.Test)

Example 4 with ExternalLink

use of com.mxt.anitrend.model.entity.anilist.ExternalLink in project anitrend-app by AniTrend.

the class EpisodeUtilTests method episodeSupport_notGivenASupportedLink_shouldReturnNull.

@Test
public void episodeSupport_notGivenASupportedLink_shouldReturnNull() {
    String website = "https://heroaca.com/";
    String twitter = "https://twitter.com/heroaca_anime";
    ExternalLink link1 = mock(ExternalLink.class);
    ExternalLink link2 = mock(ExternalLink.class);
    when(link1.getUrl()).thenReturn(website);
    when(link2.getUrl()).thenReturn(twitter);
    List<ExternalLink> links = Arrays.asList(link1, link2);
    assertThat(EpisodeUtil.INSTANCE.episodeSupport(links), nullValue());
}
Also used : ExternalLink(com.mxt.anitrend.model.entity.anilist.ExternalLink) Test(org.junit.Test)

Example 5 with ExternalLink

use of com.mxt.anitrend.model.entity.anilist.ExternalLink in project anitrend-app by AniTrend.

the class EpisodeUtilTests method episodeSupport_givenFeedUrl_shouldReturnTheSameLink.

@Test
public void episodeSupport_givenFeedUrl_shouldReturnTheSameLink() {
    String url = BuildConfig.FEEDS_LINK + "my-hero-academia.rss";
    ExternalLink link = mock(ExternalLink.class);
    when(link.getUrl()).thenReturn(url);
    List<ExternalLink> links = Collections.singletonList(link);
    assertThat(EpisodeUtil.INSTANCE.episodeSupport(links), equalTo(url));
}
Also used : ExternalLink(com.mxt.anitrend.model.entity.anilist.ExternalLink) Test(org.junit.Test)

Aggregations

ExternalLink (com.mxt.anitrend.model.entity.anilist.ExternalLink)7 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 View (android.view.View)1 LinkAdapter (com.mxt.anitrend.adapter.recycler.detail.LinkAdapter)1 RankAdapter (com.mxt.anitrend.adapter.recycler.detail.RankAdapter)1 MediaRank (com.mxt.anitrend.model.entity.anilist.MediaRank)1 MediaBrowseUtil (com.mxt.anitrend.util.media.MediaBrowseUtil)1 MediaBrowseActivity (com.mxt.anitrend.view.activity.detail.MediaBrowseActivity)1 QueryContainerBuilder (io.github.wax911.library.model.request.QueryContainerBuilder)1