예제 #1
0
        private async void LoginButtonClicked()
        {
            if (IsLoggedIn)
            {
                _service.Logout();
                CurtainPrompt.Show("AuthLogoutSuccess".FromLanguageResource());
                LastFmUsername = null;
                LastFmPassword = null;
                IsLoggedIn     = false;
                Scrobble       = false;
                Insights.Track("Logged out from Last.FM");
            }
            else
            {
                if (string.IsNullOrEmpty(LastFmUsername) ||
                    string.IsNullOrEmpty(LastFmPassword))
                {
                    CurtainPrompt.ShowError("AuthLoginErrorForgot".FromLanguageResource());
                }

                else
                {
                    UiBlockerUtility.Block("GenericWait".FromLanguageResource());
                    if (await _service.AuthenticaAsync(LastFmUsername, LastFmPassword))
                    {
                        CurtainPrompt.Show("AuthLoginSuccess".FromLanguageResource());
                        IsLoggedIn = true;
                        Scrobble   = true;
                        Insights.Track("Logged in Last.FM");
                    }
                    else
                    {
                        CurtainPrompt.ShowError("AuthLoginError".FromLanguageResource());
                    }
                    UiBlockerUtility.Unblock();
                }

                // update the player also
                var msg = new ValueSet {
                    { PlayerConstants.LastFmLoginChanged, string.Empty }
                };
                BackgroundMediaPlayer.SendMessageToBackground(msg);
            }
        }