diff --git a/FoxTube/App.xaml.cs b/FoxTube/App.xaml.cs
index d5382f5..b2ba3c7 100644
--- a/FoxTube/App.xaml.cs
+++ b/FoxTube/App.xaml.cs
@@ -55,6 +55,8 @@ namespace FoxTube
/// Details about the launch request and process.
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
+ SecretsVault.CheckAuthorization();
+
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
diff --git a/FoxTube/Classes/Methods.cs b/FoxTube/Classes/Methods.cs
index 5141c13..2913870 100644
--- a/FoxTube/Classes/Methods.cs
+++ b/FoxTube/Classes/Methods.cs
@@ -3,6 +3,7 @@ using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
+using Windows.ApplicationModel.Core;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@@ -11,13 +12,18 @@ using Windows.UI.Xaml.Media;
namespace FoxTube
{
- class Methods
+ public static class Methods
{
public static MainPage MainPage
{
get { return (Window.Current.Content as Frame).Content as MainPage; }
}
+ public static void CloseApp()
+ {
+ CoreApplication.Exit();
+ }
+
public static string GetAgo(DateTime dateTime)
{
TimeSpan span = DateTime.Now - dateTime;
diff --git a/FoxTube/Classes/SecretsVault.cs b/FoxTube/Classes/SecretsVault.cs
index 842c6ad..20f395e 100644
--- a/FoxTube/Classes/SecretsVault.cs
+++ b/FoxTube/Classes/SecretsVault.cs
@@ -10,6 +10,7 @@ using Google.Apis.Services;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Windows.Storage;
+using Windows.UI.Popups;
namespace FoxTube
{
@@ -114,61 +115,82 @@ namespace FoxTube
catch { }
if(Credential != null)
{
- if (settings.Values["authorized"] == null)
- settings.Values.Add("authorized", true);
- else settings.Values["authorized"] = true;
+ try
+ {
+ if (settings.Values["authorized"] == null)
+ settings.Values.Add("authorized", true);
+ else settings.Values["authorized"] = true;
IsAuthorized = true;
- var request = Service.Channels.List("snippet,contentDetails");
- request.Mine = true;
- UserChannel = (await request.ExecuteAsync()).Items[0];
- AccountId = UserChannel.Id;
+ var request = Service.Channels.List("snippet,contentDetails");
+ request.Mine = true;
+ UserChannel = (await request.ExecuteAsync()).Items[0];
+ AccountId = UserChannel.Id;
- PlaylistItemsResource.ListRequest playlistRequest = Service.PlaylistItems.List("snippet");
- playlistRequest.PlaylistId = UserChannel.ContentDetails.RelatedPlaylists.WatchHistory;
- playlistRequest.MaxResults = 50;
- PlaylistItemListResponse playlistResponse = await playlistRequest.ExecuteAsync();
- UserHistory.Clear();
- foreach (PlaylistItem i in playlistResponse.Items)
- UserHistory.Add(i);
+ PlaylistItemsResource.ListRequest playlistRequest = Service.PlaylistItems.List("snippet");
+ playlistRequest.PlaylistId = UserChannel.ContentDetails.RelatedPlaylists.WatchHistory;
+ playlistRequest.MaxResults = 50;
+ PlaylistItemListResponse playlistResponse = await playlistRequest.ExecuteAsync();
+ UserHistory.Clear();
+ foreach (PlaylistItem i in playlistResponse.Items)
+ UserHistory.Add(i);
- playlistRequest = Service.PlaylistItems.List("snippet");
- playlistRequest.PlaylistId = UserChannel.ContentDetails.RelatedPlaylists.WatchLater;
- playlistRequest.MaxResults = 50;
- playlistResponse = await playlistRequest.ExecuteAsync();
- WatchLater.Clear();
-
- foreach (PlaylistItem i in playlistResponse.Items)
- WatchLater.Add(i);
-
- string nextToken = playlistResponse.NextPageToken;
- while (nextToken != null)
- {
- playlistRequest.PageToken = nextToken;
+ playlistRequest = Service.PlaylistItems.List("snippet");
+ playlistRequest.PlaylistId = UserChannel.ContentDetails.RelatedPlaylists.WatchLater;
+ playlistRequest.MaxResults = 50;
playlistResponse = await playlistRequest.ExecuteAsync();
+ WatchLater.Clear();
+
foreach (PlaylistItem i in playlistResponse.Items)
WatchLater.Add(i);
- nextToken = playlistResponse.NextPageToken;
- }
+ string nextToken = playlistResponse.NextPageToken;
+ while (nextToken != null)
+ {
+ playlistRequest.PageToken = nextToken;
+ playlistResponse = await playlistRequest.ExecuteAsync();
+ foreach (PlaylistItem i in playlistResponse.Items)
+ WatchLater.Add(i);
- SubscriptionsResource.ListRequest subRequest = Service.Subscriptions.List("snippet");
- subRequest.Mine = true;
- subRequest.MaxResults = 50;
- subRequest.Order = SubscriptionsResource.ListRequest.OrderEnum.Relevance;
- SubscriptionListResponse subResponse = await subRequest.ExecuteAsync();
- Subscriptions.Clear();
+ nextToken = playlistResponse.NextPageToken;
+ }
- foreach (Subscription s in subResponse.Items)
- Subscriptions.Add(s);
+ SubscriptionsResource.ListRequest subRequest = Service.Subscriptions.List("snippet");
+ subRequest.Mine = true;
+ subRequest.MaxResults = 50;
+ subRequest.Order = SubscriptionsResource.ListRequest.OrderEnum.Relevance;
+ SubscriptionListResponse subResponse = await subRequest.ExecuteAsync();
+ Subscriptions.Clear();
- nextToken = subResponse.NextPageToken;
- while(nextToken != null)
- {
- subRequest.PageToken = nextToken;
- subResponse = await subRequest.ExecuteAsync();
foreach (Subscription s in subResponse.Items)
Subscriptions.Add(s);
+
+ nextToken = subResponse.NextPageToken;
+ while (nextToken != null)
+ {
+ subRequest.PageToken = nextToken;
+ subResponse = await subRequest.ExecuteAsync();
+ foreach (Subscription s in subResponse.Items)
+ Subscriptions.Add(s);
+ }
+ }
+ catch
+ {
+ MessageDialog dialog = new MessageDialog("We were unabled to retrieve your account information due to weak internet connection or Google servers' problems. PLease, try again later", "Failed to connect");
+
+ dialog.Commands.Add(new UICommand("Try again", (command) =>
+ {
+ Authorize();
+ }));
+ dialog.Commands.Add(new UICommand("Quit", (command) =>
+ {
+ Methods.CloseApp();
+ }));
+ dialog.Commands.Add(new UICommand("Close"));
+
+ await dialog.ShowAsync();
+
+ IsAuthorized = false;
}
AuthorizationStateChanged.Invoke(null, null);
diff --git a/FoxTube/Pages/ChannelPage.xaml.cs b/FoxTube/Pages/ChannelPage.xaml.cs
index a9a4c24..a418392 100644
--- a/FoxTube/Pages/ChannelPage.xaml.cs
+++ b/FoxTube/Pages/ChannelPage.xaml.cs
@@ -141,6 +141,10 @@ namespace FoxTube.Pages
loading.Close();
}
+ catch (System.Net.Http.HttpRequestException)
+ {
+ loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
+ }
catch
{
loading.Error();
@@ -175,6 +179,10 @@ namespace FoxTube.Pages
playlistLoading.Close();
}
+ catch (System.Net.Http.HttpRequestException)
+ {
+ playlistLoading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
+ }
catch
{
playlistLoading.Error();
diff --git a/FoxTube/Pages/Home.xaml.cs b/FoxTube/Pages/Home.xaml.cs
index c50fcc8..5d1fe95 100644
--- a/FoxTube/Pages/Home.xaml.cs
+++ b/FoxTube/Pages/Home.xaml.cs
@@ -57,6 +57,15 @@ namespace FoxTube
trendMore.Clicked += TrendMore_Clicked;
subsMore.Clicked += SubsMore_Clicked;
+ recLoading.RefreshPage += refreshPage;
+ subsLoading.RefreshPage += refreshPage;
+ trendLoading.RefreshPage += refreshPage;
+
+ Initialize();
+ }
+
+ private void refreshPage(object sender, RoutedEventArgs e)
+ {
Initialize();
}
@@ -196,40 +205,73 @@ namespace FoxTube
async void LoadTrending()
{
- VideosResource.ListRequest request = SecretsVault.Service.Videos.List("id");
- request.MaxResults = 48;
-
- request.Chart = VideosResource.ListRequest.ChartEnum.MostPopular;
- request.RegionCode = reg;
- VideoListResponse response = await request.ExecuteAsync();
-
- if (!string.IsNullOrWhiteSpace(response.NextPageToken))
- trendToken = response.NextPageToken;
- else
- trendMore.Complete(true);
-
- foreach (Video vid in response.Items)
+ try
{
- VideoCard vCard = new VideoCard(vid.Id);
- trendGrid.Add(vCard);
- }
+ VideosResource.ListRequest request = SecretsVault.Service.Videos.List("id");
+ request.MaxResults = 48;
- trendLoading.Close();
- trendLoaded = true;
+ request.Chart = VideosResource.ListRequest.ChartEnum.MostPopular;
+ request.RegionCode = reg;
+ VideoListResponse response = await request.ExecuteAsync();
+
+ if (!string.IsNullOrWhiteSpace(response.NextPageToken))
+ trendToken = response.NextPageToken;
+ else
+ trendMore.Complete(true);
+
+ foreach (Video vid in response.Items)
+ {
+ VideoCard vCard = new VideoCard(vid.Id);
+ trendGrid.Add(vCard);
+ }
+
+ trendLoading.Close();
+ trendLoaded = true;
+ }
+ catch (System.Net.Http.HttpRequestException)
+ {
+ trendLoading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
+ }
+ catch
+ {
+ trendLoading.Error();
+ }
}
void LoadRecommendations()
{
- recLoading.Close();
- recLoaded = true;
- recLoading.Block();
+ try
+ {
+ recLoading.Close();
+ recLoaded = true;
+ recLoading.Block();
+ }
+ catch (System.Net.Http.HttpRequestException)
+ {
+ recLoading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
+ }
+ catch
+ {
+ recLoading.Error();
+ }
}
void LoadSubscriptions()
{
- subsLoading.Close();
- subsLoaded = true;
- subsLoading.Block();
+ try
+ {
+ subsLoading.Close();
+ subsLoaded = true;
+ subsLoading.Block();
+ }
+ catch (System.Net.Http.HttpRequestException)
+ {
+ subsLoading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
+ }
+ catch
+ {
+ subsLoading.Error();
+ }
}
}
}
diff --git a/FoxTube/Pages/LoadingPage.xaml b/FoxTube/Pages/LoadingPage.xaml
index 9fecba7..239bd4d 100644
--- a/FoxTube/Pages/LoadingPage.xaml
+++ b/FoxTube/Pages/LoadingPage.xaml
@@ -20,8 +20,8 @@
-
-
+
+
@@ -32,8 +32,8 @@
-
-
+
+
diff --git a/FoxTube/Pages/LoadingPage.xaml.cs b/FoxTube/Pages/LoadingPage.xaml.cs
index af33bd4..e783b84 100644
--- a/FoxTube/Pages/LoadingPage.xaml.cs
+++ b/FoxTube/Pages/LoadingPage.xaml.cs
@@ -38,15 +38,15 @@ namespace FoxTube
if (isWifiTrouble)
{
- wifiException.Text = exceptionId;
- wifiMessage.Text = details;
+ wifiException.Text = $"ID: {exceptionId}";
+ wifiMessage.Text = $"Details: {details}";
wifiTrouble.Visibility = Visibility.Visible;
}
else
{
- exception.Text = exceptionId;
- message.Text = details;
+ exception.Text = $"ID: {exceptionId}";
+ message.Text = $"Details: {details}";
trouble.Visibility = Visibility.Visible;
}
diff --git a/FoxTube/Pages/MainPage.xaml.cs b/FoxTube/Pages/MainPage.xaml.cs
index e376243..34c0e99 100644
--- a/FoxTube/Pages/MainPage.xaml.cs
+++ b/FoxTube/Pages/MainPage.xaml.cs
@@ -91,9 +91,6 @@ namespace FoxTube
SecretsVault.AuthorizationStateChanged += Vault_AuthorizationStateChanged;
SecretsVault.SubscriptionsChanged += SecretsVault_SubscriptionsChanged;
- SecretsVault.CheckAuthorization();
- if (!SecretsVault.IsAuthorized)
- nav.SelectedItem = toHome;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
@@ -492,5 +489,10 @@ namespace FoxTube
else
content.GoBack();
}
+
+ public void CloseApp()
+ {
+ CoreApplication.Exit();
+ }
}
}
diff --git a/FoxTube/Pages/PlaylistPage.xaml.cs b/FoxTube/Pages/PlaylistPage.xaml.cs
index 33d32fc..4e64061 100644
--- a/FoxTube/Pages/PlaylistPage.xaml.cs
+++ b/FoxTube/Pages/PlaylistPage.xaml.cs
@@ -104,6 +104,10 @@ namespace FoxTube.Pages
loading.Close();
}
+ catch (System.Net.Http.HttpRequestException)
+ {
+ loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
+ }
catch
{
loading.Error();
diff --git a/FoxTube/Pages/Search.xaml.cs b/FoxTube/Pages/Search.xaml.cs
index 18afb3f..efae899 100644
--- a/FoxTube/Pages/Search.xaml.cs
+++ b/FoxTube/Pages/Search.xaml.cs
@@ -168,6 +168,10 @@ namespace FoxTube
loading.Close();
}
+ catch (System.Net.Http.HttpRequestException)
+ {
+ loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
+ }
catch
{
loading.Error();
diff --git a/FoxTube/Pages/SettingsPages/Feedback.xaml.cs b/FoxTube/Pages/SettingsPages/Feedback.xaml.cs
index 1b49923..6415fc5 100644
--- a/FoxTube/Pages/SettingsPages/Feedback.xaml.cs
+++ b/FoxTube/Pages/SettingsPages/Feedback.xaml.cs
@@ -148,40 +148,5 @@ namespace FoxTube.Pages.SettingsPages
debugData = meta;
debugAttached.Visibility = Visibility.Visible;
}
-
-
- /*
- private void feedbackSubmit_Click(object sender, EventArgs e)
- {
- if (feedbackTitle.Text == "") MessageBox.Show("Please, fill the first field before submitting.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- else
- {
- string type()
- {
- if (feedbackSuggestion.Checked) return "Suggestion";
- else return "Problem";
- }
- try
- {
- MailMessage msg = new MailMessage();
- msg.To.Add("foxgameofficial@gmail.com");
- msg.From = new MailAddress("sender@gmail.com");
- msg.Subject = "Stream2String feedback";
- msg.Body = "Type: " + type() + "\n\nTitle: " + feedbackTitle.Text + "\nDetails: " + feedbackDetails.Text + "\n\n" + feedbackMail.Text;
-
- SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
- client.EnableSsl = true;
- client.Credentials = new NetworkCredential("sender@gmail.com", "Thisisthepassword07734");
-
- //Send the msg
- client.Send(msg);
- MessageBox.Show("Thank you for your feedback. You've just helped us to make our program better!", "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Information);
- proceedFeedback();
- Properties.Settings.Default.feedback = true;
- Properties.Settings.Default.Save();
- }
- catch { MessageBox.Show("Unfortunately, we can't send your feedback now. Please, try again later.", "Server connection error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
- }
- }*/
}
}
diff --git a/FoxTube/Pages/VideoPage.xaml.cs b/FoxTube/Pages/VideoPage.xaml.cs
index bef50b5..a71fc0b 100644
--- a/FoxTube/Pages/VideoPage.xaml.cs
+++ b/FoxTube/Pages/VideoPage.xaml.cs
@@ -193,6 +193,10 @@ namespace FoxTube.Pages
loading.Close();
}
+ catch (System.Net.Http.HttpRequestException)
+ {
+ loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
+ }
catch
{
loading.Error();