Archived
1
0

Notification system done

This commit is contained in:
Michael Gordeev
2018-11-04 15:15:57 +03:00
parent 3661f9be38
commit 75cf389286
8 changed files with 77 additions and 138 deletions
+2 -25
View File
@@ -1,16 +1,9 @@
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Services;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using Windows.ApplicationModel.Background;
using Windows.Storage;
@@ -21,14 +14,7 @@ namespace FoxTube.Background
public sealed class BackgroundProcessor : IBackgroundTask
{
private DateTime lastCheck = DateTime.Now;
private ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
private ClientSecrets Secrets => new ClientSecrets()
{
ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com",
ClientSecret = "BkVZOAaCU2Zclf0Zlicg6y2_"
};
private YouTubeService Service => new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0",
@@ -66,12 +52,7 @@ namespace FoxTube.Background
{
try
{
ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "Checking videos...", DateTime.Now.ToString(), null, null));
Dictionary<string, string> subscriptions = JsonConvert.DeserializeObject<Dictionary<string, string>>(await FileIO.ReadTextAsync(await ApplicationData.Current.RoamingFolder.GetFileAsync("background.json")));
Debug.WriteLine("Subscriptions list");
foreach (var i in subscriptions)
Debug.WriteLine($"{i.Key}: {i.Value}");
Debug.WriteLine("Subscriptions list end");
foreach (var s in subscriptions)
{
SearchResource.ListRequest request = Service.Search.List("snippet");
@@ -81,16 +62,12 @@ namespace FoxTube.Background
request.MaxResults = 5;
SearchListResponse response = await request.ExecuteAsync();
foreach (var i in response.Items)
foreach (SearchResult i in response.Items)
ToastNotificationManager.CreateToastNotifier().Show(
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 { }
ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "New videos checked", DateTime.Now.ToString(), null, null));
}
void CheckAnnouncements()
+2 -2
View File
@@ -30,8 +30,8 @@ namespace FoxTube.Background
template.LoadXml($@"<toast activationType='foreground' launch='video|{id}'>
<visual>
<binding template='ToastGeneric'>
<image placement='hero' src='{thumbnail}'/>
<image placement='appLogoOverride' hint-crop='circle' src='{avatar}'/>
<image placement='hero' src='{thumbnail.Replace("&", "%26")}'/>
<image placement='appLogoOverride' hint-crop='circle' src='{avatar.Replace("&", "%26") ?? "http://foxgame.hol.es/FoxTubeAssets/LogoAvatar.png"}'/>
<text>{title}</text>
<text>{channel} uploaded a new video</text>
</binding>
-20
View File
@@ -1,20 +0,0 @@
using FoxTube.Controls;
using Windows.UI.Xaml;
namespace FoxTube.Classes
{
public class AdSizeTrigger : StateTriggerBase
{
private Advert _class;
public Advert Class
{
get { return _class; }
set
{
_class = value;
SetActive(!_class.OverrideSize);
}
}
}
}
+4 -46
View File
@@ -5,55 +5,13 @@
xmlns:ad="using:Microsoft.Advertising.WinRT.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:classes="using:FoxTube.Classes">
mc:Ignorable="d">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="320"/>
<classes:AdSizeTrigger Class="{x:Bind Instance}"/>
</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"/>
<classes:AdSizeTrigger Class="{x:Bind Instance}"/>
</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"/>
<classes:AdSizeTrigger Class="{x:Bind Instance}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="ad.Width" Value="728"/>
<Setter Target="ad.Height" Value="90"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Name="grid" SizeChanged="Grid_SizeChanged">
<ad:AdControl VerticalAlignment="Top"
Name="ad" ApplicationId="{x:Bind AppId}"
AdUnitId="{x:Bind AdUnitId}"
Height="{x:Bind Height}"
Width="{x:Bind Width}"/>
Height="50"
Width="300"/>
</Grid>
</UserControl>
+47 -18
View File
@@ -1,20 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using System.Diagnostics;
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;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace FoxTube.Controls
{
@@ -23,10 +9,26 @@ namespace FoxTube.Controls
public string AdUnitId { get; set; } = "test";
public string AppId => "3f83fe91-d6be-434d-a0ae-7351c5a997f1";
public bool OverrideSize { get; set; } = false;
public Advert Instance => this;
public int Height { get; set; } = 50;
public int Width { get; set; } = 300;
public new double Height
{
get { return ad.Height; }
set
{
ad.Height = value;
OverrideSize = true;
}
}
public new double Width
{
get { return ad.Width; }
set
{
ad.Width = value;
OverrideSize = true;
}
}
public Advert()
{
@@ -37,5 +39,32 @@ namespace FoxTube.Controls
Visibility = Visibility.Collapsed;
SecretsVault.NotPurchased += () => Visibility = Visibility.Visible;
}
private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (OverrideSize)
return;
if(grid.ActualWidth >= 728)
{
ad.Width = 728;
ad.Height = 90;
}
else if (grid.ActualWidth >= 640)
{
ad.Width = 640;
ad.Height = 100;
}
else if (grid.ActualWidth >= 320)
{
ad.Width = 320;
ad.Height = 50;
}
else
{
ad.Width = 300;
ad.Height = 50;
}
}
}
}
-1
View File
@@ -96,7 +96,6 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Classes\AdSizeTrigger.cs" />
<Compile Include="Classes\Caption.cs" />
<Compile Include="Classes\DownloadItemContainer.cs" />
<Compile Include="Classes\InboxItem.cs" />
+18 -22
View File
@@ -125,29 +125,14 @@ namespace FoxTube
{
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
titleBar.ButtonBackgroundColor = Colors.Transparent;
titleBar.BackgroundColor = Colors.Red;
titleBar.ButtonBackgroundColor = Colors.Red;
titleBar.ButtonHoverBackgroundColor = Colors.IndianRed;
titleBar.ButtonPressedBackgroundColor = Colors.DarkRed;
titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
titleBar.ButtonInactiveBackgroundColor = Colors.DeepPink;
titleBar.ForegroundColor = Colors.White;
if((int)settings.Values["themeMode"] == 2)
{
Color uiTheme = new UISettings().GetColorValue(UIColorType.Background);
if (uiTheme == Colors.Black)
titleBar.ButtonForegroundColor = Colors.White;
else
titleBar.ButtonForegroundColor = Colors.Black;
}
else
{
if (RequestedTheme == ElementTheme.Dark)
titleBar.ButtonForegroundColor = Colors.White;
else if (RequestedTheme == ElementTheme.Light)
titleBar.ButtonForegroundColor = Colors.Black;
}
CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;
}
private void SecretsVault_SubscriptionsChanged(object sender, params object[] args)
@@ -393,6 +378,7 @@ namespace FoxTube
nav.IsBackEnabled = true;
else
nav.IsBackEnabled = false;
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
}
public void MaximizeVideo()
@@ -404,25 +390,33 @@ namespace FoxTube
videoPlaceholder.Margin = new Thickness(0);
nav.IsBackEnabled = true;
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;
}
public void Fullscreen(bool on)
{
if (on)
{
nav.CompactModeThresholdWidth = short.MaxValue;
nav.ExpandedModeThresholdWidth = short.MaxValue;
nav.OpenPaneLength = 0;
nav.CompactPaneLength = 0;
if ((videoPlaceholder.Content as VideoPage).player.MiniView)
nav.Margin = new Thickness(0, -80, 0, 0);
nav.Margin = new Thickness(0, -48, 0, 0);
else
nav.Margin = new Thickness(0, -91, 0, 0);
nav.Margin = new Thickness(0, -60, 0, 0);
}
else
{
nav.CompactModeThresholdWidth = 641;
nav.ExpandedModeThresholdWidth = 1008;
nav.Margin = new Thickness(0);
nav.OpenPaneLength = 300;
nav.CompactPaneLength = 48;
}
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = on;
}
public void CloseVideo()
@@ -441,6 +435,8 @@ namespace FoxTube
nav.IsBackEnabled = true;
else
nav.IsBackEnabled = false;
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;
}
private void search_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
+3 -3
View File
@@ -153,12 +153,12 @@
<AppBarButton Name="openBrowser" Click="openBrowser_Click" Icon="Globe" Label="Open in browser"/>
</CommandBar>
<Grid Grid.Column="1" Name="tabsPlaceholder">
<StackPanel Grid.Column="1" Name="tabsPlaceholder">
<controls1:Advert/>
<Pivot Grid.Row="1" Name="pivot" SelectedIndex="0" IsHeaderItemsCarouselEnabled="False">
<PivotItem Header="Suggestions">
<ScrollViewer>
<StackPanel>
<controls1:Advert/>
<StackPanel Name="relatedVideos"/>
</StackPanel>
</ScrollViewer>
@@ -194,7 +194,7 @@
</ScrollViewer>
</PivotItem>
</Pivot>
</Grid>
</StackPanel>
<local:LoadingPage Grid.ColumnSpan="2" Visibility="Collapsed"/>
</Grid>