Ejemplo n.º 1
0
        public async Task CreateStatusActivity(string text)
        {
            var postResp = await AniListService.SaveTextActivity(text, null, default);

            postResp.Switch((IAniListError error) => View.DisplaySnackbarMessage("Error occurred while posting status", Snackbar.LengthLong))
            .Switch(activity => View.RefreshActivity());
        }
Ejemplo n.º 2
0
        public void SearchAniList(string searchType, string searchTerm)
        {
            switch (searchType)
            {
            case SearchResultsActivity.AniListSearchTypes.Anime:
                View.ShowMediaSearchResults(AniListService.SearchMedia(searchTerm, MediaType.Anime,
                                                                       PageSize));
                break;

            case SearchResultsActivity.AniListSearchTypes.Manga:
                View.ShowMediaSearchResults(AniListService.SearchMedia(searchTerm, MediaType.Manga,
                                                                       PageSize));
                break;

            case SearchResultsActivity.AniListSearchTypes.Characters:
                View.ShowCharacterSearchResults(AniListService.SearchCharacters(searchTerm, PageSize));
                break;

            case SearchResultsActivity.AniListSearchTypes.Staff:
                View.ShowStaffSearchResults(AniListService.SearchStaff(searchTerm, PageSize));
                break;

            case SearchResultsActivity.AniListSearchTypes.Studios:
                View.ShowStudioSearchResults(AniListService.SearchStudios(searchTerm, PageSize));
                break;

            case SearchResultsActivity.AniListSearchTypes.Users:
                View.ShowUserSearchResults(AniListService.SearchUsers(searchTerm, PageSize));
                break;

            case SearchResultsActivity.AniListSearchTypes.Forum:
                View.ShowForumThreadSearchResults(AniListService.SearchForumThreads(searchTerm, PageSize));
                break;
            }
        }
Ejemplo n.º 3
0
        public async Task PostActivityReplyAsync(AniListActivity activity, int activityPosition, string text)
        {
            var postResp = await AniListService.PostActivityReply(activity.Id, text, default);

            postResp.Switch((IAniListError error) =>
            {
                View.UpdateActivity(activityPosition, activity);
                View.DisplaySnackbarMessage("Error occurred while posting reply", Snackbar.LengthLong);
            })
            .Switch(async reply =>
            {
                var refreshResp = await AniListService.GetAniListActivityById(activity.Id, default);

                refreshResp.Switch((IAniListError error) =>
                {
                    View.UpdateActivity(activityPosition, activity);
                    View.DisplaySnackbarMessage("Error occurred while refreshing activity", Snackbar.LengthLong);
                })
                .Switch(activityResp =>
                {
                    View.UpdateActivity(activityPosition, activityResp);
                    View.DisplaySnackbarMessage("Reply posted successfully", Snackbar.LengthShort);
                });
            });
        }
Ejemplo n.º 4
0
        public async Task UpdateActivityAsync(AniListActivity activity, int activityPosition)
        {
            var activityResp = await AniListService.GetAniListActivityById(activity.Id, default);

            activityResp.Switch((IAniListError error) => View.DisplaySnackbarMessage("Error occurred while refreshing activity", Snackbar.LengthLong))
            .Switch(updatedAct => View.UpdateActivity(activityPosition, updatedAct));
        }
Ejemplo n.º 5
0
 public IAsyncEnumerable <OneOf <IPagedData <AniListActivity>, IAniListError> > GetAniListActivity(bool isFollowingOnly)
 {
     AniDroidSettings.ShowAllAniListActivity = !isFollowingOnly;
     return(AniListService.GetAniListActivity(new AniListActivityDto {
         IsFollowing = isFollowingOnly
     }, 20));
 }
Ejemplo n.º 6
0
        public override async Task Init()
        {
            View.SetLoadingShown();
            var userId   = View.GetUserId();
            var userName = View.GetUserName();

            Logger.Debug("UserPresenter", $"Init started (userId: {userId}, userName: {userName})");

            var userResp = await AniListService.GetUser(userName, userId, default(CancellationToken));

            userResp.Switch(user =>
            {
                if (AniDroidSettings.IsUserAuthenticated && user.Id != AniDroidSettings.LoggedInUser.Id)
                {
                    View.SetCanFollow();
                    View.SetCanMessage();
                    View.SetIsFollowing(user.IsFollowing, false);
                }

                View.SetShareText(user.Name, user.SiteUrl);
                View.SetContentShown(false);     // TODO: change this to switch based on banner presence
                View.SetupToolbar(user.Name);
                View.SetupUserView(user);
            })
            .Switch(error => View.OnError(error));
        }
Ejemplo n.º 7
0
        public async Task Login(CancellationToken token)
        {
            AniDroidSettings.ClearUserAuthentication();
            var authCode = View.GetAuthCode();

            if (string.IsNullOrWhiteSpace(authCode))
            {
                View.OnErrorAuthorizing();
                return;
            }

            var authResp = await AniListService.AuthenticateUser(_authConfig, authCode, token);

            authResp.Switch((IAniListError error) => View.OnErrorAuthorizing())
            .Switch(async auth =>
            {
                AniDroidSettings.UserAccessCode = auth.AccessToken;

                var currentUser = await AniListService.GetCurrentUser(token);

                currentUser.Switch((IAniListError error) =>
                {
                    AniDroidSettings.ClearUserAuthentication();
                    View.OnErrorAuthorizing();
                }).Switch(user =>
                {
                    AniDroidSettings.LoggedInUser = user;
                    View.OnAuthorized();
                });
            });
        }
Ejemplo n.º 8
0
        public async Task EditStatusActivityAsync(AniListActivity activity, int activityPosition, string updateText)
        {
            var postResp = await AniListService.SaveTextActivity(updateText, activity.Id, default);

            postResp.Switch((IAniListError error) => View.DisplaySnackbarMessage("Error occurred while saving status", Snackbar.LengthLong))
            .Switch(updatedAct => View.UpdateActivity(activityPosition, updatedAct));
        }
Ejemplo n.º 9
0
        public async Task ToggleFollowUser(int userId)
        {
            var toggleResp = await AniListService.ToggleFollowUser(userId, default(CancellationToken));

            toggleResp.Switch((IAniListError error) =>
                              View.DisplaySnackbarMessage("Error occurred while trying to toggle following status",
                                                          Snackbar.LengthLong))
            .Switch(user => View.SetIsFollowing(user.IsFollowing, true));
        }
Ejemplo n.º 10
0
        public async Task ToggleFavorite()
        {
            var characterId = View.GetCharacterId();
            var favResp     = await AniListService.ToggleFavorite(new FavoriteDto { CharacterId = characterId },
                                                                  default(CancellationToken));

            favResp.Switch(error => View.OnError(error))
            .Switch(favorites => View.SetIsFavorite(favorites.Characters?.Nodes?.Any(x => x.Id == characterId) == true, true));
        }
Ejemplo n.º 11
0
        public async Task SaveMediaListEntry(MediaListEditDto editDto, Action onSuccess, Action onError)
        {
            var mediaUpdateResp = await AniListService.UpdateMediaListEntry(editDto, default);

            mediaUpdateResp.Switch(mediaList =>
            {
                onSuccess();
                View.DisplaySnackbarMessage("Saved", Snackbar.LengthShort);
                View.UpdateMediaListItem(mediaList);
            }).Switch(error => onError());
        }
Ejemplo n.º 12
0
        public async Task DeleteMediaListEntry(int mediaListId, Action onSuccess, Action onError)
        {
            var mediaDeleteResp = await AniListService.DeleteMediaListEntry(mediaListId, default);

            mediaDeleteResp.Switch((bool success) =>
            {
                onSuccess();
                View.DisplaySnackbarMessage("Deleted", Snackbar.LengthShort);
                View.RemoveMediaListItem(mediaListId);
            }).Switch(error =>
                      onError());
        }
Ejemplo n.º 13
0
        public async Task PostUserMessage(int userId, string message)
        {
            var postResp = await AniListService.PostUserMessage(userId, message, default(CancellationToken));

            postResp.Switch((IAniListError error) =>
                            View.DisplaySnackbarMessage("Error occurred while posting message", Snackbar.LengthLong))
            .Switch(activity =>
            {
                View.RefreshUserActivity();
                View.DisplaySnackbarMessage("Message posted successfully", Snackbar.LengthShort);
            });
        }
Ejemplo n.º 14
0
        public async Task <bool> DeleteActivityReplyAsync(ActivityReply activityReply,
                                                          int activityPosition)
        {
            var editResp = await AniListService.DeleteActivityReply(activityReply.Id, default);

            return(editResp.Match((IAniListError error) =>
            {
                View.DisplaySnackbarMessage("Error occurred while deleting reply", Snackbar.LengthLong);

                return false;
            })
                   .Match(deletedResponse => deletedResponse.Deleted));
        }
Ejemplo n.º 15
0
        public async Task ToggleActivityReplyLikeAsync(ActivityReply activityReply, int activityPosition)
        {
            var toggleResp = await AniListService.ToggleLike(activityReply.Id, LikeableType.ActivityReply, default);

            toggleResp.Switch((IAniListError error) =>
            {
                View.DisplaySnackbarMessage("Error occurred while toggling like", Snackbar.LengthLong);
            })
            .Switch(userLikes =>
            {
                activityReply.Likes = userLikes;
            });
        }
Ejemplo n.º 16
0
 public void GetCurrentSeasonLists()
 {
     View.ShowCurrentTv(AniListService.BrowseMedia(new BrowseMediaDto
     {
         Season     = MediaSeason.Fall,
         SeasonYear = 2018,
         Type       = MediaType.Anime,
         Format     = MediaFormat.Tv,
         Sort       = new List <MediaSort> {
             _sortType
         }
     }, 5));
 }
Ejemplo n.º 17
0
        public async Task EditActivityReplyAsync(ActivityReply activityReply, int activityPosition, string updateText)
        {
            var editResp = await AniListService.SaveActivityReply(activityReply.Id, updateText, default);

            editResp.Switch((IAniListError error) =>
            {
                View.DisplaySnackbarMessage("Error occurred while updating reply", Snackbar.LengthLong);
            })
            .Switch(retReply =>
            {
                activityReply.Text  = retReply.Text;
                activityReply.Likes = retReply.Likes;
            });
        }
Ejemplo n.º 18
0
        public async Task DeleteActivityAsync(int activityId, int activityPosition)
        {
            var deleteResp = await AniListService.DeleteActivity(activityId, default);

            deleteResp.Switch((IAniListError error) => View.DisplaySnackbarMessage("Error occurred while deleting activity", Snackbar.LengthLong))
            .Switch(deleted => {
                if (deleted?.Deleted == true)
                {
                    View.RemoveActivity(activityPosition);
                }
                else
                {
                    View.DisplaySnackbarMessage("Error occurred while deleting activity", Snackbar.LengthLong);
                }
            });
        }
Ejemplo n.º 19
0
        public override async Task Init()
        {
            View.SetLoadingShown();
            var staffId   = View.GetStaffId();
            var staffResp = await AniListService.GetStaffById(staffId, default(CancellationToken));

            staffResp.Switch(staff =>
            {
                View.SetIsFavorite(staff.IsFavourite);
                View.SetShareText(staff.Name?.GetFormattedName(), staff.SiteUrl);
                View.SetContentShown(false);
                View.SetupToolbar($"{staff.Name?.First} {staff.Name?.Last}".Trim());
                View.SetupStaffView(staff);
            })
            .Switch(error => View.OnError(error));
        }
Ejemplo n.º 20
0
        public override async Task Init()
        {
            View.SetLoadingShown();
            var studioId   = View.GetStudioId();
            var studioResp = await AniListService.GetStudioById(studioId, default(CancellationToken));

            studioResp.Switch(studio =>
            {
                View.SetIsFavorite(studio.IsFavourite);
                View.SetShareText(studio.Name, studio.SiteUrl);
                View.SetContentShown(false);
                View.SetupToolbar(studio.Name);
                View.SetupStudioView(studio);
            })
            .Switch(error => View.OnError(error));
        }
Ejemplo n.º 21
0
        public override async Task Init()
        {
            View.SetLoadingShown();
            var characterId   = View.GetCharacterId();
            var characterResp = await AniListService.GetCharacterById(characterId, default(CancellationToken));

            characterResp.Switch(character =>
            {
                View.SetIsFavorite(character.IsFavourite);
                View.SetShareText(character.Name?.GetFormattedName(), character.SiteUrl);
                View.SetContentShown(false);
                View.SetupToolbar($"{character.Name?.First} {character.Name?.Last}".Trim());
                View.SetupCharacterView(character);
            })
            .Switch(error => View.OnError(error));
        }
Ejemplo n.º 22
0
        public async Task GetMediaLists(int userId)
        {
            var mediaListResp = await AniListService.GetUserMediaList(userId,
                                                                      View.GetMediaType(), AniDroidSettings.GroupCompletedLists, default);


            mediaListResp.Switch(error => View.OnError(error))
            .Switch(mediaLists =>
            {
                if (userId == AniDroidSettings.LoggedInUser?.Id)
                {
                    AniDroidSettings.UpdateLoggedInUser(mediaLists.User);
                }

                View.SetCollection(mediaLists);
            });
        }
Ejemplo n.º 23
0
 public void GetDiscoverLists()
 {
     View.ShowCurrentlyAiringResults(AniListService.BrowseMedia(new BrowseMediaDto
     {
         Season     = MediaSeason.GetFromDate(DateTime.Now),
         SeasonYear = DateTime.Now.Year,
         Type       = MediaType.Anime,
         Sort       = new List <MediaSort> {
             MediaSort.PopularityDesc
         }
     }, 5));
     View.ShowTrendingAnimeResults(AniListService.BrowseMedia(new BrowseMediaDto
     {
         Type = MediaType.Anime,
         Sort = new List <MediaSort> {
             MediaSort.TrendingDesc
         }
     }, 5));
     View.ShowTrendingMangaResults(AniListService.BrowseMedia(new BrowseMediaDto
     {
         Type = MediaType.Manga,
         Sort = new List <MediaSort> {
             MediaSort.TrendingDesc
         }
     }, 5));
     View.ShowNewAnimeResults(AniListService.BrowseMedia(
                                  new BrowseMediaDto
     {
         Type = MediaType.Anime,
         Sort = new List <MediaSort> {
             MediaSort.IdDesc
         }
     }, 5));
     View.ShowNewMangaResults(AniListService.BrowseMedia(
                                  new BrowseMediaDto
     {
         Type = MediaType.Manga,
         Sort = new List <MediaSort> {
             MediaSort.IdDesc
         }
     }, 5));
 }
Ejemplo n.º 24
0
        public async Task IncreaseMediaProgress(AniList.Models.MediaModels.MediaList mediaListToUpdate)
        {
            var editDto = new MediaListEditDto
            {
                MediaId  = mediaListToUpdate.Media.Id,
                Progress = (mediaListToUpdate.Progress ?? 0) + 1
            };

            var mediaUpdateResp = await AniListService.UpdateMediaListEntry(editDto, default);

            mediaUpdateResp.Switch(mediaList =>
            {
                View.DisplaySnackbarMessage($"Updated progress for {mediaList.Media.Title.UserPreferred}", Snackbar.LengthShort);
                View.UpdateMediaListItem(mediaList);
            })
            .Switch(error =>
            {
                View.DisplaySnackbarMessage("Error occurred while saving list entry", Snackbar.LengthLong);
                View.ResetMediaListItem(mediaListToUpdate.Media.Id);
            });
        }
Ejemplo n.º 25
0
        public async Task CompleteMedia(AniList.Models.MediaModels.MediaList mediaListToComplete)
        {
            var editDto = new MediaListEditDto
            {
                MediaId  = mediaListToComplete.Media.Id,
                Progress = mediaListToComplete.Media.Episodes,
                Status   = MediaListStatus.Completed
            };

            var mediaUpdateResp = await AniListService.UpdateMediaListEntry(editDto, default);

            mediaUpdateResp.Switch(mediaList =>
            {
                View.DisplaySnackbarMessage($"Completed {mediaList.Media.Title.UserPreferred}", Snackbar.LengthShort);
                View.UpdateMediaListItem(mediaList);
            })
            .Switch(error =>
            {
                View.DisplaySnackbarMessage("Error occurred while saving list entry", Snackbar.LengthLong);
                View.ResetMediaListItem(mediaListToComplete.Media.Id);
            });
        }
Ejemplo n.º 26
0
 public IAsyncEnumerable <OneOf <IPagedData <MediaEdge>, IAniListError> > GetCharacterMediaEnumerable(int characterId, MediaType mediaType, int perPage)
 {
     return(AniListService.GetCharacterMedia(characterId, mediaType, perPage));
 }
Ejemplo n.º 27
0
 public IAsyncEnumerable <OneOf <IPagedData <Review>, IAniListError> > GetUserReviewsEnumerable(int userId,
                                                                                                int perPage)
 {
     return(AniListService.GetUserReviews(userId, perPage));
 }
Ejemplo n.º 28
0
 public IAsyncEnumerable <OneOf <IPagedData <MediaEdge>, IAniListError> > GetStudioMediaEnumerable(int studioId, int perPage)
 {
     return(AniListService.GetStudioMedia(studioId, perPage));
 }
Ejemplo n.º 29
0
 public IAsyncEnumerable <OneOf <IPagedData <AniList.Models.UserModels.User>, IAniListError> > GetUserFollowingEnumerable(int userId, int count)
 {
     return(AniListService.GetUserFollowing(userId, UserSort.Username, count));
 }
Ejemplo n.º 30
0
 public void BrowseAniListMedia(BrowseMediaDto browseDto)
 {
     _browseDto = browseDto;
     View.ShowMediaSearchResults(AniListService.BrowseMedia(browseDto, 20));
 }