Esempio n. 1
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();
                });
            });
        }
Esempio n. 2
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);
            });
        }