Esempio n. 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);
        }
Esempio n. 2
0
        public FinalConfirmation()
        {
            this.InitializeComponent();

            HelperMethods.HideSplitView();
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     HelperMethods.HideSplitView();
     HelperMethods.DisableBackButton();
     base.OnNavigatedTo(e);
 }
Esempio n. 4
0
        private async void page_Loaded(object sender, RoutedEventArgs e)
        {
            HelperMethods.HideSplitView();
            try
            {
                AppConstants.NetworkConnectionType connection = await HelperMethods.DetermineInternetConnection();
            }
            catch (Exception)
            {
                loadingText.Text = "no internet connection found";
                return;
            }
            ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
            StorageFolder            roamingFolder   = ApplicationData.Current.RoamingFolder;
            StorageFolder            localFolder     = ApplicationData.Current.LocalFolder;

            await DoEmotesStuff(localFolder);

            loadingText.Text = "loading settings";
            if (!roamingSettings.Values.ContainsKey("wifiStreamQuality"))
            {
                roamingSettings.Values["wifiStreamQuality"] = "Medium";
            }
            if (!roamingSettings.Values.ContainsKey("cellStreamQuality"))
            {
                roamingSettings.Values["cellStreamQuality"] = "Mobile";
            }
            AppConstants.WifiStreamQuality = HelperMethods.GetStreamQuality((string)roamingSettings.Values["wifiStreamQuality"]);
            AppConstants.CellStreamQuality = HelperMethods.GetStreamQuality((string)roamingSettings.Values["cellStreamQuality"]);
            StorageFile usersFile = await roamingFolder.CreateFileAsync("Users.json", CreationCollisionOption.OpenIfExists);

            string usersData = await FileIO.ReadTextAsync(usersFile);

            if (string.IsNullOrEmpty(usersData))
            {
                roamingSettings.Values["activeUser"] = string.Empty;
                AppConstants.activeUser = null;
                HelperMethods.ShowSplitView();
                Frame.Navigate(typeof(HomePage));
            }
            else
            {
                JArray usersA = JArray.Parse(usersData);
                Dictionary <string, User> tmpUsers = new Dictionary <string, User>();
                foreach (JObject userO in usersA)
                {
                    User   tmpUser     = null;
                    string name        = (string)userO["name"];
                    string accessToken = (string)userO["access_token"];
                    loadingText.Text = "loading " + name;
                    try
                    {
                        tmpUser = await AppConstants.Twixel.RetrieveUserWithAccessToken(accessToken);
                    }
                    catch (TwixelException ex)
                    {
                        if (ex.Message == $"{accessToken} is not a valid access token")
                        {
                            await HelperMethods.ShowMessageDialog($"The access token for {name} isn't currently valid.\nYou can fix this later in the settings menu.");
                        }
                        else
                        {
                            await HelperMethods.ShowMessageDialog($"Something went wrong when trying to talk to Twitch. You should probably try again later. Here's the error:\n{ex.Message}");
                        }
                    }
                    if (tmpUser == null)
                    {
                        AppConstants.users.Add(name, string.Empty);
                    }
                    else
                    {
                        tmpUsers.Add(name, tmpUser);
                        AppConstants.users.Add(name, accessToken);
                    }
                }
                if (!roamingSettings.Values.ContainsKey("activeUser"))
                {
                    roamingSettings.Values["activeUser"] = string.Empty;
                }
                string activeUser = (string)roamingSettings.Values["activeUser"];
                if (!string.IsNullOrEmpty(activeUser))
                {
                    if (AppConstants.users.ContainsKey(activeUser))
                    {
                        if (!string.IsNullOrEmpty(AppConstants.users[activeUser]))
                        {
                            AppConstants.activeUser = tmpUsers[activeUser];
                            Frame.Navigate(typeof(HomePage));
                        }
                        else
                        {
                            // need to choose a new active user
                            roamingSettings.Values["activeUser"] = string.Empty;
                            Frame.Navigate(typeof(HomePage));
                        }
                    }
                    else
                    {
                        // need to choose a new active user
                        roamingSettings.Values["activeUser"] = string.Empty;
                        Frame.Navigate(typeof(HomePage));
                    }
                }
                else
                {
                    // need to choose a new active user
                    roamingSettings.Values["activeUser"] = string.Empty;
                    Frame.Navigate(typeof(HomePage));
                }
            }
        }