Archived
1
0

History (local)

This commit is contained in:
Michael Gordeev
2018-11-09 22:27:51 +03:00
parent 4d13ea1226
commit 1a6447a4aa
9 changed files with 100 additions and 56 deletions
@@ -36,6 +36,8 @@ namespace FoxTube.Background
lastCheck = DateTime.Now; lastCheck = DateTime.Now;
} }
ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "Background task initialized. Retrieving videos since", lastCheck.ToString(), null, null));
bool[] notificationsSettings = JsonConvert.DeserializeObject<bool[]>(await FileIO.ReadTextAsync(await ApplicationData.Current.RoamingFolder.GetFileAsync("notifications.json"))); bool[] notificationsSettings = JsonConvert.DeserializeObject<bool[]>(await FileIO.ReadTextAsync(await ApplicationData.Current.RoamingFolder.GetFileAsync("notifications.json")));
if(notificationsSettings[0]) if(notificationsSettings[0])
CheckAnnouncements(); CheckAnnouncements();
+61 -5
View File
@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Net; using System.Net;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -38,8 +39,8 @@ namespace FoxTube
public static bool IsAuthorized { get; private set; } = false; public static bool IsAuthorized { get; private set; } = false;
public static Channel UserChannel { get; private set; } public static Channel UserChannel { get; private set; }
public static List<PlaylistItem> WatchLater { get; private set; } = new List<PlaylistItem>(); public static List<string> WatchLater { get; private set; } = new List<string>();
public static List<PlaylistItem> UserHistory { get; private set; } = new List<PlaylistItem>(); public static List<string> UserHistory { get; private set; } = new List<string>();
public static List<Subscription> Subscriptions { get; private set; } = new List<Subscription>(); public static List<Subscription> Subscriptions { get; private set; } = new List<Subscription>();
public static YouTubeService NoAuthService => new YouTubeService(new BaseClientService.Initializer() public static YouTubeService NoAuthService => new YouTubeService(new BaseClientService.Initializer()
@@ -58,6 +59,37 @@ namespace FoxTube
} }
} }
public static async void HistoryAdd(string id)
{
UserHistory.Remove(id);
UserHistory.Add(id);
if (UserHistory.Count > 100)
UserHistory.RemoveAt(UserHistory.Count - 1);
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("history.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(UserHistory));
}
public static async void LaterAdd(string id)
{
WatchLater.Add(id);
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("watchlater.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(UserHistory));
}
public static async void LaterRemove(string id)
{
WatchLater.Remove(id);
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("watchlater.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(UserHistory));
}
public static async Task<bool> ChangeSubscriptionState(string id) public static async Task<bool> ChangeSubscriptionState(string id)
{ {
if (!IsAuthorized) if (!IsAuthorized)
@@ -178,7 +210,31 @@ namespace FoxTube
UserChannel = (await request.ExecuteAsync()).Items[0]; UserChannel = (await request.ExecuteAsync()).Items[0];
AccountId = UserChannel.Id; AccountId = UserChannel.Id;
PlaylistItemsResource.ListRequest playlistRequest = Service.PlaylistItems.List("snippet"); try
{
await ApplicationData.Current.RoamingFolder.GetFileAsync("history.json");
}
catch (FileNotFoundException)
{
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("history.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(new List<string>()));
}
try
{
await ApplicationData.Current.RoamingFolder.GetFileAsync("watchlater.json");
}
catch (FileNotFoundException)
{
await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("watchlater.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(new List<string>()));
}
UserHistory = JsonConvert.DeserializeObject<List<string>>(await FileIO.ReadTextAsync(await ApplicationData.Current.RoamingFolder.GetFileAsync("history.json")));
WatchLater = JsonConvert.DeserializeObject<List<string>>(await FileIO.ReadTextAsync(await ApplicationData.Current.RoamingFolder.GetFileAsync("watchlater.json")));
/*PlaylistItemsResource.ListRequest playlistRequest = Service.PlaylistItems.List("snippet");
playlistRequest.PlaylistId = UserChannel.ContentDetails.RelatedPlaylists.WatchHistory; playlistRequest.PlaylistId = UserChannel.ContentDetails.RelatedPlaylists.WatchHistory;
playlistRequest.MaxResults = 50; playlistRequest.MaxResults = 50;
PlaylistItemListResponse playlistResponse = await playlistRequest.ExecuteAsync(); PlaylistItemListResponse playlistResponse = await playlistRequest.ExecuteAsync();
@@ -204,7 +260,7 @@ namespace FoxTube
WatchLater.Add(i); WatchLater.Add(i);
nextToken = playlistResponse.NextPageToken; nextToken = playlistResponse.NextPageToken;
} }*/
SubscriptionsResource.ListRequest subRequest = Service.Subscriptions.List("snippet"); SubscriptionsResource.ListRequest subRequest = Service.Subscriptions.List("snippet");
subRequest.Mine = true; subRequest.Mine = true;
@@ -216,7 +272,7 @@ namespace FoxTube
foreach (Subscription s in subResponse.Items) foreach (Subscription s in subResponse.Items)
Subscriptions.Add(s); Subscriptions.Add(s);
nextToken = subResponse.NextPageToken; string nextToken = subResponse.NextPageToken;
while (nextToken != null) while (nextToken != null)
{ {
subRequest.PageToken = nextToken; subRequest.PageToken = nextToken;
+1 -1
View File
@@ -18,7 +18,7 @@
<RowDefinition Height="75"/> <RowDefinition Height="75"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Image Name="thumbnail" Source="/Assets/videoThumbSample.png" Stretch="Fill"/> <Image Name="thumbnail" Source="/Assets/videoThumbSample.png" Stretch="Fill"/>
<Grid Background="{ThemeResource ButtonBackgroundThemeBrush}" Name="watched" Visibility="Collapsed"> <Grid Background="#7F000000" Name="watched" Visibility="Collapsed">
<StackPanel Margin="5" Background="{ThemeResource SystemControlBackgroundChromeMediumBrush}" VerticalAlignment="Top" HorizontalAlignment="Left" Padding="5,2,5,2" BorderBrush="Gray" BorderThickness="1"> <StackPanel Margin="5" Background="{ThemeResource SystemControlBackgroundChromeMediumBrush}" VerticalAlignment="Top" HorizontalAlignment="Left" Padding="5,2,5,2" BorderBrush="Gray" BorderThickness="1">
<TextBlock Text="Watched" Foreground="Gray" FontSize="12"/> <TextBlock Text="Watched" Foreground="Gray" FontSize="12"/>
</StackPanel> </StackPanel>
+1 -5
View File
@@ -82,12 +82,8 @@ namespace FoxTube.Controls
} }
catch { } catch { }
foreach(PlaylistItem i in SecretsVault.UserHistory) if(SecretsVault.UserHistory.Contains(videoId))
if (i.Snippet.ResourceId.VideoId == id)
{
watched.Visibility = Visibility.Visible; watched.Visibility = Visibility.Visible;
break;
}
} }
public async void Button_Click(object sender, RoutedEventArgs e) public async void Button_Click(object sender, RoutedEventArgs e)
+7 -7
View File
@@ -12,16 +12,16 @@
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Name="grid"> <Grid Name="grid">
<ScrollViewer Margin="0,0,0,50"> <Grid.RowDefinitions>
<StackPanel Name="stack"> <RowDefinition/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<ScrollViewer Name="scroll">
<local:VideoGrid/> <local:VideoGrid/>
<controls:ShowMore Clicked="ShowMore_Clicked"/>
</StackPanel>
</ScrollViewer> </ScrollViewer>
<CommandBar VerticalAlignment="Bottom"> <CommandBar Grid.Row="1">
<AppBarButton Label="Open in browser" Icon="Globe" Name="toBrowser" Click="toBrowser_Click"/> <AppBarButton Label="Open in browser" Icon="Globe" Name="toBrowser" Click="toBrowser_Click"/>
<AppBarButton Label="Refresh" Icon="Refresh" Name="refresh" Click="refresh_Click"/>
</CommandBar> </CommandBar>
<foxtube:LoadingPage Visibility="Collapsed"/> <foxtube:LoadingPage Visibility="Collapsed" Grid.RowSpan="2"/>
</Grid> </Grid>
</Page> </Page>
+14 -28
View File
@@ -1,17 +1,8 @@
using FoxTube.Controls; using FoxTube.Controls;
using System; using System;
using System.Collections.Generic; using Windows.System;
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;
using Windows.UI.Xaml.Controls; 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 Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
@@ -24,15 +15,19 @@ namespace FoxTube.Pages
public sealed partial class History : Page public sealed partial class History : Page
{ {
LoadingPage loading; LoadingPage loading;
ShowMore more;
VideoGrid list; VideoGrid list;
public History() public History()
{ {
this.InitializeComponent(); InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
loading = grid.Children[2] as LoadingPage; loading = grid.Children[2] as LoadingPage;
more = stack.Children[1] as ShowMore; list = scroll.Content as VideoGrid;
list = stack.Children[0] as VideoGrid;
Initialize(); Initialize();
} }
@@ -40,24 +35,15 @@ namespace FoxTube.Pages
{ {
loading.Refresh(); loading.Refresh();
more.Complete(true); list.Clear();
SecretsVault.UserHistory.ForEach(i => list.Add(new VideoCard(i)));
loading.Block(); loading.Close();
} }
private void ShowMore_Clicked() private async void toBrowser_Click(object sender, RoutedEventArgs e)
{ {
await Launcher.LaunchUriAsync(new Uri("youtube.com/feed/history"));
}
private void toBrowser_Click(object sender, RoutedEventArgs e)
{
}
private void refresh_Click(object sender, RoutedEventArgs e)
{
} }
} }
} }
+4 -2
View File
@@ -101,12 +101,14 @@ namespace FoxTube
} }
public async void Initialize() public async void Initialize()
{
if (await ApplicationData.Current.RoamingFolder.GetFileAsync("notifications.json") != null)
{ {
bool[] notificationsSettings = new bool[] { (bool)settings.Values["newVideoNotification"], (bool)settings.Values["devNews"] }; bool[] notificationsSettings = new bool[] { (bool)settings.Values["newVideoNotification"], (bool)settings.Values["devNews"] };
await FileIO.WriteTextAsync( await FileIO.WriteTextAsync(
await ApplicationData.Current.RoamingFolder.CreateFileAsync("notifications.json", CreationCollisionOption.ReplaceExisting), await ApplicationData.Current.RoamingFolder.CreateFileAsync("notifications.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(notificationsSettings)); JsonConvert.SerializeObject(notificationsSettings));
Debug.WriteLine(ApplicationData.Current.RoamingFolder.Path); }
} }
protected override void OnNavigatedTo(NavigationEventArgs e) protected override void OnNavigatedTo(NavigationEventArgs e)
@@ -128,7 +130,7 @@ namespace FoxTube
titleBar.ButtonBackgroundColor = Colors.Red; titleBar.ButtonBackgroundColor = Colors.Red;
titleBar.ButtonHoverBackgroundColor = Colors.IndianRed; titleBar.ButtonHoverBackgroundColor = Colors.IndianRed;
titleBar.ButtonPressedBackgroundColor = Colors.DarkRed; titleBar.ButtonPressedBackgroundColor = Colors.DarkRed;
titleBar.ButtonInactiveBackgroundColor = Colors.DeepPink; titleBar.ButtonInactiveBackgroundColor = Colors.DarkRed;
titleBar.ForegroundColor = Colors.White; titleBar.ForegroundColor = Colors.White;
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false; CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;
+2 -2
View File
@@ -52,8 +52,8 @@ namespace FoxTube.Pages.SettingsPages
items.Add(new InboxItem( items.Add(new InboxItem(
e["header"].InnerText, e["header"].InnerText,
e["content"].InnerText, e["content"].InnerText,
DateTime.Parse(e.GetAttribute("time")), DateTime.Parse(e["time"].InnerText),
e.GetAttribute("id") e["id"].InnerText
)); ));
items.OrderBy(item => item.TimeStamp); items.OrderBy(item => item.TimeStamp);
+2
View File
@@ -208,6 +208,8 @@ namespace FoxTube.Pages
} }
} }
subscribe.Visibility = Visibility.Visible; subscribe.Visibility = Visibility.Visible;
SecretsVault.HistoryAdd(videoId);
} }
else else
{ {