Archived
1
0

Development 110218

This commit is contained in:
Michael Gordeev
2018-11-02 10:33:34 +03:00
parent 3126b9cf19
commit bba4fe4f00
16 changed files with 400 additions and 125 deletions
+26 -33
View File
@@ -2,8 +2,10 @@
using Google.Apis.Services; using Google.Apis.Services;
using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data; using Google.Apis.YouTube.v3.Data;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -34,56 +36,43 @@ namespace FoxTube.Background
}); });
BackgroundTaskDeferral def; BackgroundTaskDeferral def;
public void Run(IBackgroundTaskInstance taskInstance) public async void Run(IBackgroundTaskInstance taskInstance)
{ {
def = taskInstance.GetDeferral(); def = taskInstance.GetDeferral();
try
{
if (settings.Values["lastCheck"] == null) if (settings.Values["lastCheck"] == null)
settings.Values.Add("lastCheck", XmlConvert.ToString(DateTime.Now, "YYYY-MM-DDThh:mm:ss")); settings.Values.Add("lastCheck", XmlConvert.ToString(DateTime.Now));
else lastCheck = XmlConvert.ToDateTime(settings.Values["lastCheck"] as string, XmlDateTimeSerializationMode.Unspecified); else lastCheck = XmlConvert.ToDateTime(settings.Values["lastCheck"] as string, XmlDateTimeSerializationMode.Unspecified);
}
catch
{
lastCheck = DateTime.Now;
}
if((bool)settings.Values["newVideoNotification"]) bool[] notificationsSettings = JsonConvert.DeserializeObject<bool[]>(await FileIO.ReadTextAsync(await ApplicationData.Current.RoamingFolder.GetFileAsync("notifications.json")));
if(notificationsSettings[0])
CheckAnnouncements(); CheckAnnouncements();
if((bool)settings.Values["devNews"]) if(notificationsSettings[1])
CheckAccount(); CheckAccount();
settings.Values["lastCheck"] = XmlConvert.ToString(DateTime.Now, "YYYY-MM-DDThh:mm:ss"); settings.Values["lastCheck"] = XmlConvert.ToString(DateTime.Now, "YYYY-MM-DDThh:mm:ss");
def.Complete(); def.Complete();
ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "Background task complete", DateTime.Now.ToString(), null, null));
} }
async void CheckAccount() async void CheckAccount()
{ {
try try
{ {
UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, new[] { Google.Apis.Oauth2.v2.Oauth2Service.Scope.UserinfoProfile, YouTubeService.Scope.YoutubeForceSsl }, "user", CancellationToken.None); ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "Checking videos...", DateTime.Now.ToString(), null, null));
if (credential == null) Dictionary<string, string> subscriptions = JsonConvert.DeserializeObject<Dictionary<string, string>>(await FileIO.ReadTextAsync(await ApplicationData.Current.RoamingFolder.GetFileAsync("background.json")));
return; Debug.WriteLine("Subscriptions list");
foreach (var i in subscriptions)
SubscriptionsResource.ListRequest subRequest = new YouTubeService(new BaseClientService.Initializer() Debug.WriteLine($"{i.Key}: {i.Value}");
{ Debug.WriteLine("Subscriptions list end");
HttpClientInitializer = credential, foreach (var s in subscriptions)
ApplicationName = "FoxTube"
}).Subscriptions.List("snippet");
subRequest.Mine = true;
subRequest.MaxResults = 50;
SubscriptionListResponse subResponse = await subRequest.ExecuteAsync();
Dictionary<string, string> subs = new Dictionary<string, string>();
foreach (Subscription s in subResponse.Items)
subs.Add(s.Snippet.ResourceId.ChannelId, s.Snippet.Thumbnails.Standard.Url);
string nextToken = subResponse.NextPageToken;
while (nextToken != null)
{
subRequest.PageToken = nextToken;
subResponse = await subRequest.ExecuteAsync();
nextToken = subResponse.NextPageToken;
foreach (Subscription s in subResponse.Items)
subs.Add(s.Snippet.ResourceId.ChannelId, s.Snippet.Thumbnails.Standard.Url);
}
foreach (var s in subs)
{ {
SearchResource.ListRequest request = Service.Search.List("snippet"); SearchResource.ListRequest request = Service.Search.List("snippet");
request.PublishedAfter = lastCheck; request.PublishedAfter = lastCheck;
@@ -95,9 +84,13 @@ namespace FoxTube.Background
foreach (var i in response.Items) foreach (var i in response.Items)
ToastNotificationManager.CreateToastNotifier().Show( ToastNotificationManager.CreateToastNotifier().Show(
Notification.GetVideoToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title, i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, s.Value)); Notification.GetVideoToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title, i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, s.Value));
ToastNotificationManager.CreateToastNotifier().Show(Notification.GetVideoToast(null, s.Key, DateTime.Now.ToString(), s.Key, null, s.Value));
} }
} }
catch { } catch { }
ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "New videos checked", DateTime.Now.ToString(), null, null));
} }
void CheckAnnouncements() void CheckAnnouncements()
+120 -9
View File
@@ -1,11 +1,18 @@
using System; using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Linq;
using Windows.ApplicationModel; using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation; using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Background;
using Windows.ApplicationModel.Core; using Windows.ApplicationModel.Core;
using Windows.Globalization; using Windows.Globalization;
using Windows.Storage; using Windows.Storage;
using Windows.System.Power;
using Windows.UI.Notifications;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; using Windows.UI.Xaml.Navigation;
@@ -94,12 +101,124 @@ namespace FoxTube
} }
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
ActivateToastBackgoundTask();
ActivateBackgoundTask();
}
public async void ActivateToastBackgoundTask()
{
const string taskName = "FoxtubeToastBackground";
if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(taskName)))
return;
var backgroundRequest = await BackgroundExecutionManager.RequestAccessAsync();
var saverRequest = PowerManager.EnergySaverStatus;
if (backgroundRequest == BackgroundAccessStatus.DeniedBySystemPolicy || backgroundRequest == BackgroundAccessStatus.DeniedByUser)
return;
BackgroundTaskBuilder builder = new BackgroundTaskBuilder() { Name = taskName };
builder.SetTrigger(new ToastNotificationActionTrigger());
BackgroundTaskRegistration registration = builder.Register();
}
public async void ActivateBackgoundTask()
{
const string taskName = "FoxtubeBackgound";
Debug.WriteLine($"Background task active: {BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(taskName))}");
if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(taskName)))
return;
var backgroundRequest = await BackgroundExecutionManager.RequestAccessAsync();
var saverRequest = PowerManager.EnergySaverStatus;
if (backgroundRequest == BackgroundAccessStatus.DeniedBySystemPolicy || backgroundRequest == BackgroundAccessStatus.DeniedByUser || saverRequest == EnergySaverStatus.On)
return;
BackgroundTaskBuilder builder = new BackgroundTaskBuilder()
{
Name = taskName,
IsNetworkRequested = true,
TaskEntryPoint = "FoxTube.Background.BackgroundProcessor"
};
builder.SetTrigger(new TimeTrigger(15, false));
BackgroundTaskRegistration registration = builder.Register();
Debug.WriteLine($"2. Background task active: {BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(taskName))}");
}
protected async override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
{
var deferral = args.TaskInstance.GetDeferral();
base.OnBackgroundActivated(args);
if (args.TaskInstance.Task.Name == "FoxtubeToastBackground")
{
var details = args.TaskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;
if (details != null)
{
string[] arguments = details.Argument.Split('|');
switch(arguments[0])
{
case "dcancel":
Debug.WriteLine("Cancel has been required");
try { Methods.MainPage.Agent.Remove(arguments[1]); }
catch { }
break;
case "later":
try
{
if(!SecretsVault.IsAuthorized)
SecretsVault.CheckAuthorization(false);
if (!SecretsVault.IsAuthorized)
throw new Exception("Not authenticated");
PlaylistItem item = new PlaylistItem()
{
Snippet = new PlaylistItemSnippet()
{
ResourceId = new ResourceId()
{
Kind = "youtube#video",
VideoId = arguments[1]
},
PlaylistId = "WL"
}
};
await SecretsVault.Service.PlaylistItems.Insert(item, "snippet").ExecuteAsync();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
break;
}
}
}
deferral.Complete();
} }
protected override void OnActivated(IActivatedEventArgs e) protected override void OnActivated(IActivatedEventArgs e)
{ {
base.OnActivated(e); base.OnActivated(e);
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(MainPage));
}
if (e is ToastNotificationActivatedEventArgs) if (e is ToastNotificationActivatedEventArgs)
{ {
string[] args = (e as ToastNotificationActivatedEventArgs).Argument.Split('|'); string[] args = (e as ToastNotificationActivatedEventArgs).Argument.Split('|');
@@ -114,17 +233,9 @@ namespace FoxTube
Methods.MainPage.GoToVideo(args[1]); Methods.MainPage.GoToVideo(args[1]);
break; break;
case "dcancel":
Methods.MainPage.Agent.Remove(args[1]);
break;
case "channel": case "channel":
Methods.MainPage.GoToChannel(args[1]); Methods.MainPage.GoToChannel(args[1]);
break; break;
case "later":
//Add to WL playlist
break;
} }
} }
+2 -2
View File
@@ -25,7 +25,7 @@ namespace FoxTube.Controls
{ {
try try
{ {
List<DownloadItemContainer> containers = JsonConvert.DeserializeObject<List<DownloadItemContainer>>(await FileIO.ReadTextAsync(await roaming.GetFileAsync("data.json"))); List<DownloadItemContainer> containers = JsonConvert.DeserializeObject<List<DownloadItemContainer>>(await FileIO.ReadTextAsync(await roaming.GetFileAsync("downloads.json")));
foreach (DownloadItemContainer i in containers) foreach (DownloadItemContainer i in containers)
try { items.Add(new DownloadItem(i)); } try { items.Add(new DownloadItem(i)); }
@@ -67,7 +67,7 @@ namespace FoxTube.Controls
containers.Add(i.Container); containers.Add(i.Container);
await FileIO.WriteTextAsync( await FileIO.WriteTextAsync(
await roaming.CreateFileAsync("data.json", CreationCollisionOption.ReplaceExisting), await roaming.CreateFileAsync("downloads.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(containers)); JsonConvert.SerializeObject(containers));
})); }));
dialog.Commands.Add(new UICommand("No")); dialog.Commands.Add(new UICommand("No"));
+14 -7
View File
@@ -9,6 +9,7 @@ using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Services; using Google.Apis.Services;
using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data; using Google.Apis.YouTube.v3.Data;
using Newtonsoft.Json;
using Windows.Storage; using Windows.Storage;
using Windows.UI.Popups; using Windows.UI.Popups;
@@ -150,7 +151,7 @@ namespace FoxTube
return true; return true;
} }
public static async void Authorize() public static async void Authorize(bool retrieveSubs = true)
{ {
try try
{ {
@@ -164,8 +165,9 @@ namespace FoxTube
"user", "user",
CancellationToken.None); CancellationToken.None);
if (Credential != null) if (Credential == null || !retrieveSubs)
{ return;
if (settings.Values["authorized"] == null) if (settings.Values["authorized"] == null)
settings.Values.Add("authorized", true); settings.Values.Add("authorized", true);
else settings.Values["authorized"] = true; else settings.Values["authorized"] = true;
@@ -222,7 +224,12 @@ namespace FoxTube
foreach (Subscription s in subResponse.Items) foreach (Subscription s in subResponse.Items)
Subscriptions.Add(s); Subscriptions.Add(s);
} }
}
Dictionary<string, string> subs = new Dictionary<string, string>();
Subscriptions.ForEach(x => subs.Add(x.Snippet.ResourceId.ChannelId, x.Snippet.Thumbnails.Medium.Url));
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("background.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(subs));
} }
catch catch
{ {
@@ -257,12 +264,12 @@ namespace FoxTube
} }
} }
public static void CheckAuthorization() public static void CheckAuthorization(bool retrieveSubs = true)
{ {
if (settings.Values["authorized"] == null || !(bool)settings.Values["authorized"]) if (settings.Values["authorized"] == null || !(bool)settings.Values["authorized"])
IsAuthorized = false; IsAuthorized = false;
else else
Authorize(); Authorize(retrieveSubs);
} }
public static bool AdsDisabled { get; private set; } = true; public static bool AdsDisabled { get; private set; } = true;
@@ -270,7 +277,7 @@ namespace FoxTube
public static void CheckAddons() public static void CheckAddons()
{ {
//TO-DO: Check addons list //TO-DO: Check addons list
bool purchased = true; bool purchased = false;
if(!purchased) if(!purchased)
{ {
+41 -4
View File
@@ -2,14 +2,51 @@
x:Class="FoxTube.Controls.Advert" x:Class="FoxTube.Controls.Advert"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FoxTube.Controls" xmlns:ad="using:Microsoft.Advertising.WinRT.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" mc:Ignorable="d">
d:DesignHeight="300"
d:DesignWidth="400">
<Grid> <Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="320"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="ad.Width" Value="320"/>
<Setter Target="ad.Height" Value="50"/>
</VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="640"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="ad.Width" Value="640"/>
<Setter Target="ad.Height" Value="100"/>
</VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="728"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="ad.Width" Value="728"/>
<Setter Target="ad.Height" Value="90"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ad:AdControl Name="ad" ApplicationId="{x:Bind AppId}"
AdUnitId="{x:Bind AdUnitId}"
Height="50"
Width="300"/>
</Grid> </Grid>
</UserControl> </UserControl>
+7
View File
@@ -19,9 +19,16 @@ namespace FoxTube.Controls
{ {
public sealed partial class Advert : UserControl public sealed partial class Advert : UserControl
{ {
public string AdUnitId { get; set; } = "test";
public string AppId => "3f83fe91-d6be-434d-a0ae-7351c5a997f1";
public Advert() public Advert()
{ {
this.InitializeComponent(); this.InitializeComponent();
if (!SecretsVault.AdsDisabled)
Visibility = Visibility.Visible;
else
Visibility = Visibility.Collapsed;
SecretsVault.NotPurchased += () => Visibility = Visibility.Visible;
} }
} }
} }
+4
View File
@@ -190,7 +190,11 @@ namespace FoxTube.Controls
progressBar.IsIndeterminate = true; progressBar.IsIndeterminate = true;
cancel.IsEnabled = false; cancel.IsEnabled = false;
cts.Cancel(); cts.Cancel();
try
{
await Container.File.DeleteAsync(); await Container.File.DeleteAsync();
}
catch { }
Methods.MainPage.Agent.Remove(Container.Id); Methods.MainPage.Agent.Remove(Container.Id);
} }
+12
View File
@@ -25,6 +25,18 @@
</uap:DefaultTile> </uap:DefaultTile>
<uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="red" /> <uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="red" />
</uap:VisualElements> </uap:VisualElements>
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="FoxTube.Background.BackgroundProcessor">
<BackgroundTasks>
<Task Type="general" />
<Task Type="systemEvent" />
<Task Type="timer" />
<Task Type="pushNotification" />
<uap:Task Type="chatMessageNotification" />
<uap:Task Type="mediaProcessing" />
</BackgroundTasks>
</Extension>
</Extensions>
</Application> </Application>
</Applications> </Applications>
<Capabilities> <Capabilities>
+2 -2
View File
@@ -8,12 +8,12 @@
mc:Ignorable="d" mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Name="grid"> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition/> <RowDefinition/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid> <Grid Name="grid">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
+2
View File
@@ -43,6 +43,8 @@ namespace FoxTube.Pages
if (!SecretsVault.IsAuthorized) if (!SecretsVault.IsAuthorized)
grid.RowDefinitions[0].Height = new GridLength(0); grid.RowDefinitions[0].Height = new GridLength(0);
else
grid.RowDefinitions[0].Height = GridLength.Auto;
counter.Text = string.Format("{0:0,0} Comments", video.Statistics.CommentCount); counter.Text = string.Format("{0:0,0} Comments", video.Statistics.CommentCount);
+43 -7
View File
@@ -24,6 +24,8 @@ using System.Net;
using Windows.UI.Popups; using Windows.UI.Popups;
using Windows.Networking.Connectivity; using Windows.Networking.Connectivity;
using Windows.UI.Core; using Windows.UI.Core;
using System.IO;
using Newtonsoft.Json;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
@@ -74,7 +76,7 @@ namespace FoxTube
if (settings.Values["ver"] == null) if (settings.Values["ver"] == null)
settings.Values.Add("ver", $"{ver.Major}.{ver.Minor}"); settings.Values.Add("ver", $"{ver.Major}.{ver.Minor}");
//if((string)settings.Values["ver"] != $"{ver.Major}.{ver.Minor}") if((string)settings.Values["ver"] != $"{ver.Major}.{ver.Minor}")
{ {
try try
{ {
@@ -93,6 +95,16 @@ namespace FoxTube
SecretsVault.SubscriptionsChanged += SecretsVault_SubscriptionsChanged; SecretsVault.SubscriptionsChanged += SecretsVault_SubscriptionsChanged;
SecretsVault.CheckAuthorization(); SecretsVault.CheckAuthorization();
SetTitleBar(); SetTitleBar();
Initialize();
}
public async void Initialize()
{
bool[] notificationsSettings = new bool[] { (bool)settings.Values["newVideoNotification"], (bool)settings.Values["devNews"] };
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("notifications.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(notificationsSettings));
Debug.WriteLine(ApplicationData.Current.RoamingFolder.Path);
} }
protected override void OnNavigatedTo(NavigationEventArgs e) protected override void OnNavigatedTo(NavigationEventArgs e)
@@ -227,6 +239,7 @@ namespace FoxTube
} }
nav.SelectedItem = toHome; nav.SelectedItem = toHome;
if(content.Content is Home)
content.Navigate(typeof(Home)); content.Navigate(typeof(Home));
if (videoPlaceholder.Content != null) if (videoPlaceholder.Content != null)
@@ -274,13 +287,12 @@ namespace FoxTube
public async void GoToVideo(string id, string playlistId = null) public async void GoToVideo(string id, string playlistId = null)
{ {
Debug.WriteLine($"Video id: {id}; Playlist id: {playlistId}"); bool cancel = false;
try try
{ {
var connection = NetworkInformation.GetInternetConnectionProfile().GetConnectionCost(); var connection = NetworkInformation.GetInternetConnectionProfile().GetConnectionCost();
if ((bool)settings.Values["moblieWarning"] && (connection.NetworkCostType == NetworkCostType.Fixed || connection.NetworkCostType == NetworkCostType.Variable)) if ((bool)settings.Values["moblieWarning"] && (connection.NetworkCostType == NetworkCostType.Fixed || connection.NetworkCostType == NetworkCostType.Variable))
{ {
bool cancel = false;
MessageDialog dialog = new MessageDialog("You are on metered connection now. Additional charges may apply. Do you want to continue?") MessageDialog dialog = new MessageDialog("You are on metered connection now. Additional charges may apply. Do you want to continue?")
{ {
DefaultCommandIndex = 2, DefaultCommandIndex = 2,
@@ -290,16 +302,40 @@ namespace FoxTube
dialog.Commands.Add(new UICommand("No", (command) => cancel = true)); dialog.Commands.Add(new UICommand("No", (command) => cancel = true));
dialog.Commands.Add(new UICommand("Add to 'Watch later' playlist", (command) => dialog.Commands.Add(new UICommand("Add to 'Watch later' playlist", (command) =>
{ {
//TO-DO: Adding video to "Watch later" try
{
if (!SecretsVault.IsAuthorized)
SecretsVault.CheckAuthorization(false);
if (!SecretsVault.IsAuthorized)
throw new Exception("Not authenticated");
PlaylistItem item = new PlaylistItem()
{
Snippet = new PlaylistItemSnippet()
{
ResourceId = new ResourceId()
{
Kind = "youtube#video",
VideoId = id
},
PlaylistId = "WL"
}
};
SecretsVault.Service.PlaylistItems.Insert(item, "snippet").Execute();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
cancel = true; cancel = true;
})); }));
await dialog.ShowAsync(); await dialog.ShowAsync();
if (cancel)
return;
} }
} }
catch { } catch { }
if (cancel)
return;
nav.IsPaneOpen = false; nav.IsPaneOpen = false;
+8 -2
View File
@@ -28,6 +28,7 @@ namespace FoxTube
public sealed partial class Settings : Page public sealed partial class Settings : Page
{ {
bool inboxLoaded = false; bool inboxLoaded = false;
string inboxId = null;
public Settings() public Settings()
{ {
this.InitializeComponent(); this.InitializeComponent();
@@ -40,9 +41,9 @@ namespace FoxTube
{ {
if ((e.Parameter as string).Contains("inbox") || (e.Parameter as string).Contains("changelog")) if ((e.Parameter as string).Contains("inbox") || (e.Parameter as string).Contains("changelog"))
{ {
pivot.SelectedIndex = 2;
if ((string)e.Parameter != "inbox" && (string)e.Parameter != "changelog") if ((string)e.Parameter != "inbox" && (string)e.Parameter != "changelog")
((pivot.SelectedItem as PivotItem).Content as Inbox).Open(e.Parameter as string); inboxId = e.Parameter as string;
pivot.SelectedIndex = 2;
} }
else else
switch(e.Parameter as string) switch(e.Parameter as string)
@@ -63,6 +64,11 @@ namespace FoxTube
{ {
(((pivot.Items[2] as PivotItem).Content as ScrollViewer).Content as Inbox).LoadItems(); (((pivot.Items[2] as PivotItem).Content as ScrollViewer).Content as Inbox).LoadItems();
inboxLoaded = true; inboxLoaded = true;
if(inboxId != null)
{
(((pivot.Items[2] as PivotItem).Content as ScrollViewer).Content as Inbox).Open(inboxId as string);
inboxId = null;
}
} }
} }
} }
+12 -3
View File
@@ -1,4 +1,5 @@
using System; using Newtonsoft.Json;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
@@ -90,9 +91,13 @@ namespace FoxTube.Pages.SettingsPages
settings.Values["videoAutoplay"] = autoplay.IsOn; settings.Values["videoAutoplay"] = autoplay.IsOn;
} }
private void notification_IsEnabledChanged(object sender, RoutedEventArgs e) private async void notification_IsEnabledChanged(object sender, RoutedEventArgs e)
{ {
settings.Values["newVideoNotification"] = newVideo.IsOn; settings.Values["newVideoNotification"] = newVideo.IsOn;
bool[] notificationsSettings = new bool[] { (bool)settings.Values["newVideoNotification"], (bool)settings.Values["devNews"] };
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("notifications.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(notificationsSettings));
} }
private void region_SelectionChanged(object sender, SelectionChangedEventArgs e) private void region_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -135,9 +140,13 @@ namespace FoxTube.Pages.SettingsPages
CoreApplication.Exit(); CoreApplication.Exit();
} }
private void devNews_Toggled(object sender, RoutedEventArgs e) private async void devNews_Toggled(object sender, RoutedEventArgs e)
{ {
settings.Values["devnews"] = devNews.IsOn; settings.Values["devnews"] = devNews.IsOn;
bool[] notificationsSettings = new bool[] { (bool)settings.Values["newVideoNotification"], (bool)settings.Values["devNews"] };
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("notifications.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(notificationsSettings));
} }
} }
} }
+4 -3
View File
@@ -5,8 +5,8 @@
xmlns:local="using:FoxTube" xmlns:local="using:FoxTube"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls" xmlns:ui="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:ui="using:Microsoft.Advertising.WinRT.UI" xmlns:controls="using:FoxTube.Controls"
x:Name="root" x:Name="root"
mc:Ignorable="d"> mc:Ignorable="d">
@@ -15,7 +15,8 @@
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition/> <RowDefinition/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<controls:AdaptiveGridView Name="list" OneRowModeEnabled="False" DesiredWidth="384" SelectionMode="None" Grid.Row="1"/> <controls:Advert/>
<ui:AdaptiveGridView Name="list" OneRowModeEnabled="False" DesiredWidth="384" SelectionMode="None" Grid.Row="1"/>
<TextBlock Name="empty" Text="&#xD8;" FontSize="200" Foreground="Gray" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.RowSpan="2"/> <TextBlock Name="empty" Text="&#xD8;" FontSize="200" Foreground="Gray" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.RowSpan="2"/>
</Grid> </Grid>
</Page> </Page>
+45 -1
View File
@@ -8,6 +8,7 @@
xmlns:pages="using:FoxTube.Pages" xmlns:pages="using:FoxTube.Pages"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls" xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:ui="using:Microsoft.Advertising.WinRT.UI" xmlns:ui="using:Microsoft.Advertising.WinRT.UI"
xmlns:controls1="using:FoxTube.Controls"
mc:Ignorable="d"> mc:Ignorable="d">
@@ -106,7 +107,47 @@
<MenuFlyout x:Name="downloadSelector"/> <MenuFlyout x:Name="downloadSelector"/>
</AppBarButton.Flyout> </AppBarButton.Flyout>
</AppBarButton> </AppBarButton>
<AppBarButton Label="Add to" Icon="Add" IsEnabled="False"/> <AppBarButton Name="addTo" Label="Add to" Icon="Add">
<AppBarButton.Flyout>
<Flyout>
<ScrollViewer Margin="-12" MaxHeight="300">
<NavigationViewList Width="200" IsMultiSelectCheckBoxEnabled="True" SelectionMode="Multiple">
<NavigationViewItem Content="Watch later">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE728;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="New playlist">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE109;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItemHeader Content="Other playlists"/>
<NavigationViewItem Content="My playlist">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE292;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="Cats">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE292;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="Dogs">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE292;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="Another playlist">
<NavigationViewItem.Icon>
<FontIcon Glyph="&#xE292;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
</NavigationViewList>
</ScrollViewer>
</Flyout>
</AppBarButton.Flyout>
</AppBarButton>
<AppBarButton Name="refresh" Click="refresh_Click" Icon="Refresh" Label="Refresh page"/> <AppBarButton Name="refresh" Click="refresh_Click" Icon="Refresh" Label="Refresh page"/>
<AppBarButton Name="share" Click="share_Click" Icon="Share" Label="Share"/> <AppBarButton Name="share" Click="share_Click" Icon="Share" Label="Share"/>
<AppBarButton Name="openBrowser" Click="openBrowser_Click" Icon="Globe" Label="Open in browser"/> <AppBarButton Name="openBrowser" Click="openBrowser_Click" Icon="Globe" Label="Open in browser"/>
@@ -116,7 +157,10 @@
<Pivot Grid.Row="1" Name="pivot" SelectedIndex="0" IsHeaderItemsCarouselEnabled="False"> <Pivot Grid.Row="1" Name="pivot" SelectedIndex="0" IsHeaderItemsCarouselEnabled="False">
<PivotItem Header="Suggestions"> <PivotItem Header="Suggestions">
<ScrollViewer> <ScrollViewer>
<StackPanel>
<controls1:Advert/>
<StackPanel Name="relatedVideos"/> <StackPanel Name="relatedVideos"/>
</StackPanel>
</ScrollViewer> </ScrollViewer>
</PivotItem> </PivotItem>
<PivotItem Header="Comments" Name="commentsPlaceholder"> <PivotItem Header="Comments" Name="commentsPlaceholder">
+6
View File
@@ -209,6 +209,12 @@ namespace FoxTube.Pages
} }
subscribe.Visibility = Visibility.Visible; subscribe.Visibility = Visibility.Visible;
} }
else
{
download.Visibility = Visibility.Collapsed;
addTo.Visibility = Visibility.Collapsed;
subscribe.Visibility = Visibility.Collapsed;
}
ChannelsResource.ListRequest channelRequest = SecretsVault.Service.Channels.List("snippet, statistics"); ChannelsResource.ListRequest channelRequest = SecretsVault.Service.Channels.List("snippet, statistics");
channelRequest.Id = item.Snippet.ChannelId; channelRequest.Id = item.Snippet.ChannelId;