Search in sources :

Example 1 with MediaRank

use of com.mxt.anitrend.model.entity.anilist.MediaRank 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)

Aggregations

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 ExternalLink (com.mxt.anitrend.model.entity.anilist.ExternalLink)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