Beispiel #1
0
        private View CreateMediaUserDataView(AniList.Models.MediaModels.Media media)
        {
            var retView       = LayoutInflater.Inflate(Resource.Layout.View_NestedScrollLayout, null);
            var containerView = retView.FindViewById <LinearLayout>(Resource.Id.Scroll_Container);

            if (media.Rankings?.Any() == true)
            {
                containerView.AddView(CreateUserRankingView(media.Rankings));
            }

            if (media.Stats?.ScoreDistribution?.Count(x => x.Amount > 0) >= 3 && !MediaStatus.NotYetReleased.Equals(media.Status))
            {
                containerView.AddView(CreateUserScoresView(media.Stats.ScoreDistribution));
            }

            if (media.Stats?.StatusDistribution?.Any() == true)
            {
                containerView.AddView(CreateUserListStatusView(media.Stats.StatusDistribution));
            }

            return(retView);
        }
Beispiel #2
0
        private View CreateMediaDetailsView(AniList.Models.MediaModels.Media media)
        {
            var retView = LayoutInflater.Inflate(Resource.Layout.View_MediaDetails, null);

            retView.FindViewById <TextView>(Resource.Id.Media_Title).Text        = media.Title?.UserPreferred;
            retView.FindViewById <TextView>(Resource.Id.Media_AiringStatus).Text = media.Status?.DisplayValue;
            retView.FindViewById <ExpandableText>(Resource.Id.Media_Description).TextFormatted = FromHtml(media.Description ?? "No Description");
            retView.FindViewById <ImageView>(Resource.Id.Media_TitleIcon).Click +=
                (sender, args) => MediaTitlesDialog.Create(this, media.Title, media.Synonyms);

            var imageView = retView.FindViewById <ImageView>(Resource.Id.Media_Image);

            ImageLoader.LoadImage(imageView, media.CoverImage.ExtraLarge ?? media.CoverImage.Large);

            var formatView = retView.FindViewById <TextView>(Resource.Id.Media_Format);

            formatView.Text = (media.Format?.DisplayValue ?? "Unknown Format") +
                              (media.Episodes > 1 ? $" ({media.Episodes} episodes)" : "");

            var nextAiringView = retView.FindViewById <TextView>(Resource.Id.Media_NextEpisode);

            if (media.NextAiringEpisode?.AiringAt > 0)
            {
                nextAiringView.Visibility = ViewStates.Visible;

                var airingString = !Settings.DisplayUpcomingEpisodeTimeAsCountdown
                    ? media.NextAiringEpisode.GetAiringAtDateTime().ToShortDateString()
                    : media.NextAiringEpisode.GetTimeUntilAiringTimeSpan().ToString("%d'd '%h'h '%m'm'");

                nextAiringView.Text = $"Episode {media.NextAiringEpisode?.Episode}:  {airingString}";
            }

            var listStatusView = retView.FindViewById <TextView>(Resource.Id.Media_ListStatus);

            if (media.MediaListEntry != null)
            {
                listStatusView.Visibility = ViewStates.Visible;
                listStatusView.Text       = media.MediaListEntry?.Status?.DisplayValue;
            }

            var genreContainer = retView.FindViewById <FlexboxLayout>(Resource.Id.Media_Genres);

            foreach (var genre in media.Genres)
            {
                var genreView = LayoutInflater.Inflate(Resource.Layout.Item_Category, null);
                genreView.FindViewById <TextView>(Resource.Id.Category_Text).Text = genre;
                genreView.Clickable = true;
                genreView.Click    += (sender, eventArgs) => BrowseActivity.StartActivity(this,
                                                                                          new BrowseMediaDto
                {
                    Type           = media.Type,
                    IncludedGenres = new List <string> {
                        genre
                    },
                    Sort = new List <MediaSort> {
                        MediaSort.PopularityDesc
                    }
                }, ObjectBrowseRequestCode);
                genreContainer.AddView(genreView);
            }

            // media list summary
            var mediaListSummaryView = retView.FindViewById <DataRow>(Resource.Id.Media_MediaListSummary);

            if (media.MediaListEntry != null && _mediaListOptions != null)
            {
                mediaListSummaryView.Visibility = ViewStates.Visible;
                mediaListSummaryView.TextOne    = $"Rating:  {media.MediaListEntry.GetScoreString(_mediaListOptions.ScoreFormat)}";

                if (media.Type == MediaType.Anime)
                {
                    mediaListSummaryView.TextTwo =
                        media.MediaListEntry.GetFormattedProgressString(media.Type, media.Episodes);
                }
                else if (media.Type == MediaType.Manga)
                {
                    mediaListSummaryView.TextTwo =
                        media.MediaListEntry.GetFormattedProgressString(media.Type, media.Chapters);
                }
            }

            var dateRangeView = retView.FindViewById <DataRow>(Resource.Id.Media_DateRange);

            if (media.StartDate?.IsValid() == true || media.EndDate?.IsValid() == true)
            {
                dateRangeView.Visibility = ViewStates.Visible;
                dateRangeView.TextOne    = media.GetFormattedDateRangeString();

                var startDate = media.StartDate?.GetDate();

                if (MediaStatus.NotYetReleased.Equals(media.Status) && startDate.HasValue &&
                    startDate.Value > DateTime.Now.Date)
                {
                    dateRangeView.ButtonVisible   = true;
                    dateRangeView.ButtonClickable = true;
                    dateRangeView.ButtonClick    += (sender, eventArgs) =>
                    {
                        var calIntent = new Intent(Intent.ActionEdit);
                        calIntent.SetType("vnd.android.cursor.item/event");
                        calIntent.PutExtra("beginTime", new DateTimeOffset(startDate.Value).ToUnixTimeMilliseconds());
                        calIntent.PutExtra("allDay", true);
                        calIntent.PutExtra("title", $"{media.Title?.UserPreferred} starts");
                        StartActivity(calIntent);
                    };
                }
            }

            if (media.Season != null)
            {
                dateRangeView.TextTwo   = media.Season.DisplayValue + (media.StartDate?.Year > 0 ? $" {media.StartDate.Year}" : "");
                dateRangeView.Clickable = true;
                dateRangeView.Click    += (sender, args) => BrowseActivity.StartActivity(this,
                                                                                         new BrowseMediaDto
                {
                    Season     = media.Season,
                    SeasonYear = media.StartDate?.Year,
                    Type       = media.Type,
                    Sort       = new List <MediaSort> {
                        MediaSort.PopularityDesc
                    }
                }, ObjectBrowseRequestCode);
            }

            var episodesView = retView.FindViewById <DataRow>(Resource.Id.Media_Episodes);

            if (MediaType.Anime.Equals(media.Type))
            {
                episodesView.TextOne = media.Episodes > 0 ? (media.Episodes > 1 ? $"{media.Episodes} episodes" : "Single episode") : "";
                episodesView.TextTwo = media.Duration > 0 ? $"{media.Duration} minutes" : "";

                if ((media.Episodes ?? 0) == 0 && (media.Duration ?? 0) == 0)
                {
                    episodesView.Visibility = ViewStates.Gone;
                }

                if (media.StreamingEpisodes?.Any() == true)
                {
                    episodesView.ButtonVisible   = true;
                    episodesView.ButtonClickable = false;
                    episodesView.Clickable       = true;
                    episodesView.Click          += (sender, args) =>
                                                   MediaStreamingEpisodeListDialog.Create(this, media.StreamingEpisodes);
                }
            }
            else if (MediaType.Manga.Equals(media.Type))
            {
                episodesView.TextOne = media.Volumes > 0 ? $"{media.Volumes} Volumes" : "";
                episodesView.TextTwo = media.Chapters > 0 ? $"{media.Chapters} Chapters" : "";

                if ((media.Volumes ?? 0) == 0 && (media.Chapters ?? 0) == 0)
                {
                    episodesView.Visibility = ViewStates.Gone;
                }
            }

            var scoresView = retView.FindViewById(Resource.Id.Media_ScoresContainer);

            if (media.MeanScore > 30 || media.AverageScore > 30 || media.Popularity > 100)
            {
                retView.FindViewById <TextView>(Resource.Id.Media_MeanScore).Text     = $"{media.MeanScore}%";
                retView.FindViewById(Resource.Id.Media_MeanScoreContainer).Visibility = media.MeanScore > 30 ? ViewStates.Visible : ViewStates.Gone;

                var avgContainer = retView.FindViewById(Resource.Id.Media_AverageScoreContainer);
                retView.FindViewById <TextView>(Resource.Id.Media_AverageScore).Text = $"{media.AverageScore}%";
                avgContainer.Visibility = media.AverageScore > 30 ? ViewStates.Visible : ViewStates.Gone;
                avgContainer.Click     += (sender, args) => BrowseActivity.StartActivity(this,
                                                                                         new BrowseMediaDto
                {
                    Type = media.Type,
                    AverageGreaterThan = media.AverageScore,
                    Sort = new List <MediaSort> {
                        MediaSort.ScoreDesc
                    }
                }, ObjectBrowseRequestCode);

                var popContainer = retView.FindViewById(Resource.Id.Media_PopularityContainer);
                retView.FindViewById <TextView>(Resource.Id.Media_Popularity).Text = media.Popularity.ToString();
                popContainer.Visibility = media.Popularity > 100 ? ViewStates.Visible : ViewStates.Gone;
                popContainer.Click     += (sender, args) => BrowseActivity.StartActivity(this,
                                                                                         new BrowseMediaDto
                {
                    Type = media.Type,
                    PopularityGreaterThan = media.Popularity,
                    Sort = new List <MediaSort> {
                        MediaSort.PopularityDesc
                    }
                }, ObjectBrowseRequestCode);
            }
            else
            {
                scoresView.Visibility = ViewStates.Gone;
            }

            return(retView);
        }
Beispiel #3
0
        public void SetupMediaView(AniList.Models.MediaModels.Media media)
        {
            _media     = media;
            _mediaList = media.MediaListEntry;

            var adapter = new FragmentlessViewPagerAdapter();

            adapter.AddView(_mediaDetailsView = CreateMediaDetailsView(media), "Details");

            if (media.Characters?.PageInfo?.Total > 0)
            {
                adapter.AddView(CreateMediaCharactersView(media.Id), "Characters");
            }

            if (media.Staff?.PageInfo?.Total > 0)
            {
                adapter.AddView(CreateMediaStaffView(media.Id), "Staff");
            }

            if (media.Relations?.Data?.Any() == true)
            {
                adapter.AddView(CreateMediaRelationsView(media.Relations.Data.ToList()), "Relations");
            }

            if (media.Recommendations?.PageInfo?.Total > 0)
            {
                adapter.AddView(CreateMediaRecommendationsView(media.Id), "Recommendations");
            }

            if (media.Studios?.Data?.Any() == true)
            {
                adapter.AddView(CreateMediaStudiosView(media.Studios.Data.ToList()), "Studios");
            }

            if (media.Tags?.Any() == true)
            {
                adapter.AddView(CreateMediaTagsView(media.Tags, media.Type), "Tags");
            }

            if (media.Rankings?.Any() == true || media.Stats?.AreStatsValid() == true)
            {
                adapter.AddView(CreateMediaUserDataView(media), "User Data");
            }

            if (media.Trends?.PageInfo?.Total > 4 || media.AiringTrends?.PageInfo?.Total >= 2)
            {
                adapter.AddView(CreateMediaTrendsView(media.Trends?.Data?.ToList(), media.AiringTrends?.Data?.Where(x => x.Node.Episode.HasValue).DistinctBy(x => x.Node.Episode).ToList()), "Trends");
            }

            // TODO: see if there's a better way of determining whether to display this or not
            if (Settings.IsUserAuthenticated)
            {
                adapter.AddView(CreateMediaFollowingUsersMediaListStatusView(media.Id), "Following");
            }

            if (media.Reviews?.PageInfo?.Total > 0)
            {
                adapter.AddView(CreateMediaReviewsView(media.Id), "Reviews");
            }

            adapter.AddView(CreateMediaForumThreadsView(media.Id), "Forum Threads");

            ViewPager.OffscreenPageLimit = adapter.Count - 1;
            ViewPager.Adapter            = adapter;

            TabLayout.SetupWithViewPager(ViewPager);
        }