Archived
1
0

222: Fixed

227: Additional fixes (final)
Introduced new settings storing system

Related Work Items: #222, #227
This commit is contained in:
Michael Gordeev
2018-12-23 22:22:22 +03:00
parent 91fd3f6ab9
commit efb07fda10
8 changed files with 96 additions and 229 deletions
+15 -120
View File
@@ -1,68 +1,39 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Globalization;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Windows.Storage;
using Windows.UI.Text;
using FoxTube.Controls;
using FoxTube.Pages;
using System.Collections.ObjectModel;
using System.Diagnostics;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
using System.Globalization;
namespace FoxTube
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// Home page
/// </summary>
public sealed partial class Home : Page
{
private bool recLoaded = false;
private bool trendLoaded = false;
private bool subsLoaded = false;
VideoGrid recGrid, trendGrid, subsGrid;
ShowMore recMore, trendMore, subsMore;
VideoGrid trendGrid;
ShowMore trendMore;
LoadingPage loading;
string trendToken, recToken;
string trendToken;
Dictionary<string, string> subsTokens = new Dictionary<string, string>();
string reg;
public Home()
{
this.InitializeComponent();
try
{
reg = (ApplicationData.Current.LocalSettings.Values["region"] as string).ToLower().Remove(0, 3);
}
catch (ArgumentOutOfRangeException)
{
reg = (ApplicationData.Current.LocalSettings.Values["region"] as string).ToUpper();
}
recGrid = ((recommended.Content as ScrollViewer).Content as StackPanel).Children[0] as VideoGrid;
InitializeComponent();
reg = CultureInfo.GetCultures(CultureTypes.AllCultures).Find(i => i.IetfLanguageTag == SettingsStorage.Region).IetfLanguageTag.Remove(0, 3);
trendGrid = ((trending.Content as ScrollViewer).Content as StackPanel).Children[0] as VideoGrid;
subsGrid = ((subscriptions.Content as ScrollViewer).Content as StackPanel).Children[0] as VideoGrid;
recMore = ((recommended.Content as ScrollViewer).Content as StackPanel).Children[1] as ShowMore;
trendMore = ((trending.Content as ScrollViewer).Content as StackPanel).Children[1] as ShowMore; ;
subsMore = ((subscriptions.Content as ScrollViewer).Content as StackPanel).Children[1] as ShowMore;
trendMore = ((trending.Content as ScrollViewer).Content as StackPanel).Children[1] as ShowMore;
loading = grid.Children[2] as LoadingPage;
@@ -74,11 +45,6 @@ namespace FoxTube
Methods.MainPage.GoToHome();
}
private void RecMore_Clicked()
{
throw new NotImplementedException();
}
private async void TrendMore_Clicked()
{
try
@@ -99,7 +65,7 @@ namespace FoxTube
foreach (Video vid in response.Items)
{
VideoCard vCard = new VideoCard(vid.Id);
recGrid.Add(vCard);
trendGrid.Add(vCard);
}
trendMore.Complete();
}
@@ -109,45 +75,6 @@ namespace FoxTube
}
}
private async void SubsMore_Clicked()
{
try
{
List<SearchResult> items = new List<SearchResult>();
Dictionary<string, string> pairs = new Dictionary<string, string>();
SearchResource.ListRequest request = SecretsVault.Service.Search.List("snippet");
request.Type = "video";
request.MaxResults = 10;
request.Order = SearchResource.ListRequest.OrderEnum.Date;
foreach (KeyValuePair<string, string> i in subsTokens)
{
request.ChannelId = i.Key;
request.PageToken = i.Value;
SearchListResponse response = await request.ExecuteAsync();
foreach (SearchResult result in response.Items)
items.Add(result);
if (response.NextPageToken != null)
pairs.Add(i.Value, response.NextPageToken);
}
if (pairs.Count == 0)
subsMore.Complete(true);
else
subsTokens = pairs;
items = items.OrderByDescending(x => x.Snippet.PublishedAt).ToList();
foreach (SearchResult i in items)
subsGrid.Add(new VideoCard(i.Id.VideoId));
subsMore.Complete();
}
catch
{
subsMore.Complete(true);
}
}
public void Initialize()
{
if(SecretsVault.IsAuthorized)
@@ -164,11 +91,11 @@ namespace FoxTube
private void pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
loading.Close();
if (pivot.SelectedItem == recommended && !recLoaded)
if (pivot.SelectedItem == recommended)
LoadRecommendations();
else if (pivot.SelectedItem == trending && !trendLoaded)
LoadTrending();
else if (pivot.SelectedItem == subscriptions && !subsLoaded)
else if (pivot.SelectedItem == subscriptions)
LoadSubscriptions();
}
@@ -215,63 +142,31 @@ namespace FoxTube
try
{
loading.Refresh();
throw new NotImplementedException();
loading.Close();
recLoaded = true;
throw new NotImplementedException("This page has not implemented yet.");
}
catch (System.Net.Http.HttpRequestException)
{
recLoaded = false;
loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
}
catch (Exception e)
{
recLoaded = false;
loading.Error(e.GetType().ToString(), e.Message);
}
}
async void LoadSubscriptions()
void LoadSubscriptions()
{
try
{
loading.Refresh();
List<SearchResult> items = new List<SearchResult>();
SearchResource.ListRequest request = SecretsVault.Service.Search.List("snippet");
request.Type = "video";
request.MaxResults = 10;
request.Order = SearchResource.ListRequest.OrderEnum.Date;
foreach (Subscription i in SecretsVault.Subscriptions)
{
request.ChannelId = i.Snippet.ResourceId.ChannelId;
SearchListResponse response = await request.ExecuteAsync();
foreach (SearchResult result in response.Items)
items.Add(result);
if (response.NextPageToken != null)
subsTokens.Add(i.Snippet.ResourceId.ChannelId, response.NextPageToken);
}
if (subsTokens.Count == 0)
subsMore.Complete(true);
items = items.OrderByDescending(x => x.Snippet.PublishedAt).ToList();
foreach (SearchResult i in items)
subsGrid.Add(new VideoCard(i.Id.VideoId));
loading.Close();
subsLoaded = true;
throw new NotImplementedException("This page has not implemented yet.");
}
catch (System.Net.Http.HttpRequestException)
{
subsLoaded = false;
loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true);
}
catch (Exception e)
{
subsLoaded = false;
loading.Error(e.GetType().ToString(), e.Message);
}
}