Archived
1
0

Offline errors fix

This commit is contained in:
Michael Gordeev
2018-08-15 16:57:31 +03:00
parent 8e454c3375
commit 26907c9aac
12 changed files with 172 additions and 113 deletions
+2
View File
@@ -55,6 +55,8 @@ namespace FoxTube
/// <param name="e">Details about the launch request and process.</param>
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,
+7 -1
View File
@@ -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;
+64 -42
View File
@@ -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);
+8
View File
@@ -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();
+66 -24
View File
@@ -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();
}
}
}
}
+4 -4
View File
@@ -20,8 +20,8 @@
</StackPanel>
<TextBlock Text="OR" FontSize="20" HorizontalAlignment="Center"/>
<Button Name="wifiRefresh" Click="wifiRefresh_Click" Content="Refresh page" HorizontalAlignment="Center" Background="Red" Foreground="White" Margin="5"/>
<TextBlock Name="wifiException" Foreground="Gray" Text="Exception:" HorizontalAlignment="Center"/>
<TextBlock Name="wifiMessage" Foreground="Gray" Text="Message:" HorizontalAlignment="Center"/>
<TextBlock Name="wifiException" Foreground="Gray" Text="Exception:" HorizontalAlignment="Center" IsTextSelectionEnabled="True"/>
<TextBlock Name="wifiMessage" Foreground="Gray" Text="Message:" HorizontalAlignment="Center" IsTextSelectionEnabled="True"/>
</StackPanel>
<StackPanel Name="trouble" Visibility="Collapsed" VerticalAlignment="Center">
@@ -32,8 +32,8 @@
<Button Name="refresh" Click="wifiRefresh_Click" Content="Refresh page" Margin="5"/>
<Button Content="Leave feedback" Background="Red" Foreground="White" Margin="5" Name="feedback" Click="feedback_Click"/>
</StackPanel>
<TextBlock Name="exception" Foreground="Gray" Text="Exception:" HorizontalAlignment="Center"/>
<TextBlock Name="message" Foreground="Gray" Text="Message:" HorizontalAlignment="Center"/>
<TextBlock Name="exception" Foreground="Gray" Text="Exception:" HorizontalAlignment="Center" IsTextSelectionEnabled="True"/>
<TextBlock Name="message" Foreground="Gray" Text="Message:" HorizontalAlignment="Center" IsTextSelectionEnabled="True"/>
</StackPanel>
<FontIcon Name="blockIcon" Visibility="Collapsed" Glyph="&#xE25B;" FontSize="100" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Gray"/>
+4 -4
View File
@@ -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;
}
+5 -3
View File
@@ -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();
}
}
}
+4
View File
@@ -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();
+4
View File
@@ -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();
@@ -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); }
}
}*/
}
}
+4
View File
@@ -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();