Example #1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            HelperMethods.HideSplitView();
            if (Frame.BackStack.Count > 0)
            {
                if (Frame.BackStack[Frame.BackStack.Count - 1].SourcePageType == typeof(FinalConfirmation))
                {
                    HelperMethods.DisableBackButton();
                }
            }
            if (AppConstants.users.Count == 0)
            {
                proceedTextBlock.Text = "Login to Twitch";
            }
            else
            {
                proceedTextBlock.Text = "Choose an account";
            }

            StorageFile usersFile = await roamingFolder.GetFileAsync("Users.json");

            string usersDataString = await FileIO.ReadTextAsync(usersFile);

            if (!string.IsNullOrEmpty(usersDataString))
            {
                JArray usersA = JArray.Parse(usersDataString);
                foreach (JObject userO in usersA)
                {
                    User    tmpUser     = null;
                    string  name        = (string)userO["name"];
                    string  accessToken = (string)userO["access_token"];
                    Channel userChannel = await AppConstants.Twixel.RetrieveChannel(name);

                    AccountListViewBinding binding = new AccountListViewBinding();
                    binding.DisplayName = userChannel.displayName;
                    binding.Name        = userChannel.name;
                    if (userChannel.logo != null)
                    {
                        binding.Image = userChannel.logo.ToString();
                    }
                    try
                    {
                        tmpUser = await AppConstants.Twixel.RetrieveUserWithAccessToken(accessToken);

                        binding.Invalid = false;
                        accounts.Add(binding);
                        validUsers.Add(binding.Name, tmpUser);
                    }
                    catch (TwixelException ex)
                    {
                        if (ex.Message == $"{accessToken} is not a valid access token")
                        {
                            binding.Invalid = true;
                            accounts.Add(binding);
                        }
                    }
                }
            }
            base.OnNavigatedTo(e);
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     HelperMethods.HideSplitView();
     HelperMethods.DisableBackButton();
     base.OnNavigatedTo(e);
 }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (Frame.BackStack.Count > 0)
            {
                if (Frame.BackStack[Frame.BackStack.Count - 1].SourcePageType == typeof(LoadingPage) ||
                    Frame.BackStack[Frame.BackStack.Count - 1].SourcePageType == typeof(FinalConfirmation))
                {
                    HelperMethods.DisableBackButton();
                }
            }

            progressRing.IsActive = true;

            try
            {
                streams = await AppConstants.Twixel.RetrieveFeaturedStreams(0, 10);
            }
            catch (TwixelException ex)
            {
                await HelperMethods.ShowErrorDialog(ex);
            }
            foreach (FeaturedStream stream in streams)
            {
                stream.CleanTextString();
                stream.text = stream.text.Replace('\n', ' ').Trim();
                Dictionary <AppConstants.StreamQuality, Uri> q = null;
                try
                {
                    q = await HelperMethods.RetrieveHlsStream(stream.stream.channel.name);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                if (q != null)
                {
                    qualities.Add(q);
                }
                else
                {
                    qualities.Add(q);
                }
            }

            if (streams.Count > 0)
            {
                SetUpFeaturedStream();
                streamButton.IsEnabled = true;
                playButton.IsEnabled   = true;
                nextButton.IsEnabled   = true;
            }

            Total <List <Game> > topGames = null;

            try
            {
                topGames = await AppConstants.Twixel.RetrieveTopGames(0, 10);
            }
            catch (TwixelException ex)
            {
                await HelperMethods.ShowErrorDialog(ex);
            }
            if (topGames != null)
            {
                foreach (Game game in topGames.wrapped)
                {
                    topGamesCollection.Add(new GameGridViewBinding(game));
                }
            }
            progressRing.IsActive = false;
            base.OnNavigatedTo(e);
        }