async Task LoadVideos()
        {
            videosLoader.StartLoading();
            DisableButtons();
            List <Video> videos = new List <Video>();

            try
            {
                if (selectedPeriod == Selected.Week)
                {
                    videos = await AppConstants.Twixel.RetrieveTopVideos(null, TwitchConstants.Period.Week, videosLoader.Offset, 100);
                }
                else if (selectedPeriod == Selected.Month)
                {
                    videos = await AppConstants.Twixel.RetrieveTopVideos(null, TwitchConstants.Period.Month, videosLoader.Offset, 100);
                }
                else if (selectedPeriod == Selected.AllTime)
                {
                    videos = await AppConstants.Twixel.RetrieveTopVideos(null, TwitchConstants.Period.All, videosLoader.Offset, 100);
                }
            }
            catch (TwixelException ex)
            {
                await HelperMethods.ShowMessageDialog(string.Format("Looks like there was an error. Here are the details:\nStatus Code: {0}\nError: {1}\nMessage: {2}", ex.Error.Status.ToString(), ex.Error.Error, ex.Error.Message), ex.Message);
            }
            if (!videosLoader.CheckForEnd(videos))
            {
                foreach (Video video in videos)
                {
                    videosCollection.Add(new VideosGridViewBinding(video));
                }
                videosLoader.EndLoading(100);
            }
            EnableButtons();
        }
        private async void userReadButton_Click(object sender, RoutedEventArgs e)
        {
            await HelperMethods.ShowMessageDialog(
                @"Lets us get your user information (this includes your email).
Lets us get the streams you follow.
You really should leave this enabled.
We promise not to do anything bad with this.");
        }
Example #3
0
        private async void gameStreamsGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            GameStreamsGridViewBinding streamItem = e.ClickedItem as GameStreamsGridViewBinding;
            List <object> parameters = new List <object>();

            parameters.Add(streamItem.stream);
            Dictionary <AppConstants.StreamQuality, Uri> qualities = null;

            try
            {
                qualities = await HelperMethods.RetrieveHlsStream(streamItem.stream.channel.name);
            }
            catch (Exception ex)
            {
                await HelperMethods.ShowMessageDialog(string.Format("Looks like {0} is offline. Sorry about that.", streamItem.stream.channel.displayName), string.Format("{0} is offline", streamItem.stream.channel.displayName));
            }
            parameters.Add(qualities);
            Frame.Navigate(typeof(StreamPage), parameters);
        }
Example #4
0
        private async void webView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
        {
            if (webView.Source.Host == "golf1052.com")
            {
                if (webView.Source.Query != "?error=access_denied&error_description=The+user+denied+you+access")
                {
                    webView.Visibility = Visibility.Collapsed;
                    string[] splitString       = webView.Source.Fragment.Split('=');
                    string[] secondSplitString = splitString[1].Split('&');
                    string[] scopes            = splitString[2].Split('+');
                    List <TwitchConstants.Scope> authorizedScopes = new List <TwitchConstants.Scope>();
                    foreach (string scope in scopes)
                    {
                        authorizedScopes.Add(TwitchConstants.StringToScope(scope));
                    }
                    User user = null;
                    try
                    {
                        user = await AppConstants.Twixel.RetrieveUserWithAccessToken(secondSplitString[0]);
                    }
                    catch (TwixelException ex)
                    {
                        if (ex.Message == TwitchConstants.twitchAPIErrorString)
                        {
                            await HelperMethods.ShowMessageDialog("There was a problem trying to authenticate. Here's the error:\n" + ex.Error.Error);
                        }
                        else
                        {
                            await HelperMethods.ShowMessageDialog(ex.Message);
                        }
                    }
                    catch (Exception ex)
                    {
                        await HelperMethods.ShowMessageDialog("There was a general error.\n" + ex.Message);
                    }
                    finally
                    {
                        Frame.Navigate(typeof(HomePage));
                    }

                    ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
                    StorageFolder            roamingFolder   = ApplicationData.Current.RoamingFolder;
                    StorageFile usersFile = await roamingFolder.GetFileAsync("Users.json");

                    string usersDataString = await FileIO.ReadTextAsync(usersFile);

                    JObject userO = new JObject();
                    userO["name"]         = user.name;
                    userO["access_token"] = user.accessToken;

                    if (string.IsNullOrEmpty(usersDataString))
                    {
                        JArray usersA = new JArray();
                        usersA.Add(userO);
                        await FileIO.WriteTextAsync(usersFile, usersA.ToString());
                    }
                    else
                    {
                        JArray usersA    = JArray.Parse(usersDataString);
                        bool   foundUser = false;
                        foreach (JObject fileUser in usersA)
                        {
                            if ((string)fileUser["name"] == user.name)
                            {
                                fileUser["access_token"] = user.accessToken;
                                foundUser = true;
                                break;
                            }
                        }
                        if (!foundUser)
                        {
                            usersA.Add(userO);
                        }
                        await FileIO.WriteTextAsync(usersFile, usersA.ToString());
                    }

                    roamingSettings.Values["activeUser"] = user.name;
                    AppConstants.activeUser = user;
                    Frame.Navigate(typeof(HomePage));
                }
                else
                {
                    Frame.Navigate(typeof(HomePage));
                }
            }
        }
 private async void chatLoginButton_Click(object sender, RoutedEventArgs e)
 {
     await HelperMethods.ShowMessageDialog("Ability to login to chat and send messages.");
 }
 private async void channelCheckSubscriptionButton_Click(object sender, RoutedEventArgs e)
 {
     await HelperMethods.ShowMessageDialog("Must be partnered on Twitch to use this.");
 }
 private async void userSubscriptionsButton_Click(object sender, RoutedEventArgs e)
 {
     await HelperMethods.ShowMessageDialog("Ability to view subscriptions.");
 }
 private async void channelStreamButton_Click(object sender, RoutedEventArgs e)
 {
     await HelperMethods.ShowMessageDialog("You can reset your stream key. We won't reset your stream key unless you really want to.");
 }
 private async void channelEditorButton_Click(object sender, RoutedEventArgs e)
 {
     await HelperMethods.ShowMessageDialog("You can update your status and what game you're playing.");
 }
        private async void channelReadButton_Click(object sender, RoutedEventArgs e)
        {
            await HelperMethods.ShowMessageDialog(
                @"Lets us view your email.
Lets us get your stream key.");
        }
 private async void userFollowsEditButton_Click(object sender, RoutedEventArgs e)
 {
     await HelperMethods.ShowMessageDialog("You can follow channels. You can unfollow channels.\nThese are all pretty straight forward.");
 }
 private async void userBlocksReadButton_Click(object sender, RoutedEventArgs e)
 {
     await HelperMethods.ShowMessageDialog("You can view your ignore list.");
 }
 private async void userBlocksEditButton_Click(object sender, RoutedEventArgs e)
 {
     await HelperMethods.ShowMessageDialog("You can block people. Then you can unblock them.");
 }
Example #14
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));
                }
            }
        }