History (local)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -38,8 +39,8 @@ namespace FoxTube
|
||||
public static bool IsAuthorized { get; private set; } = false;
|
||||
|
||||
public static Channel UserChannel { get; private set; }
|
||||
public static List<PlaylistItem> WatchLater { get; private set; } = new List<PlaylistItem>();
|
||||
public static List<PlaylistItem> UserHistory { get; private set; } = new List<PlaylistItem>();
|
||||
public static List<string> WatchLater { get; private set; } = new List<string>();
|
||||
public static List<string> UserHistory { get; private set; } = new List<string>();
|
||||
public static List<Subscription> Subscriptions { get; private set; } = new List<Subscription>();
|
||||
|
||||
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)
|
||||
{
|
||||
if (!IsAuthorized)
|
||||
@@ -177,8 +209,32 @@ namespace FoxTube
|
||||
request.Mine = true;
|
||||
UserChannel = (await request.ExecuteAsync()).Items[0];
|
||||
AccountId = UserChannel.Id;
|
||||
|
||||
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>()));
|
||||
}
|
||||
|
||||
PlaylistItemsResource.ListRequest playlistRequest = Service.PlaylistItems.List("snippet");
|
||||
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.MaxResults = 50;
|
||||
PlaylistItemListResponse playlistResponse = await playlistRequest.ExecuteAsync();
|
||||
@@ -204,7 +260,7 @@ namespace FoxTube
|
||||
WatchLater.Add(i);
|
||||
|
||||
nextToken = playlistResponse.NextPageToken;
|
||||
}
|
||||
}*/
|
||||
|
||||
SubscriptionsResource.ListRequest subRequest = Service.Subscriptions.List("snippet");
|
||||
subRequest.Mine = true;
|
||||
@@ -216,7 +272,7 @@ namespace FoxTube
|
||||
foreach (Subscription s in subResponse.Items)
|
||||
Subscriptions.Add(s);
|
||||
|
||||
nextToken = subResponse.NextPageToken;
|
||||
string nextToken = subResponse.NextPageToken;
|
||||
while (nextToken != null)
|
||||
{
|
||||
subRequest.PageToken = nextToken;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<RowDefinition Height="75"/>
|
||||
</Grid.RowDefinitions>
|
||||
<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">
|
||||
<TextBlock Text="Watched" Foreground="Gray" FontSize="12"/>
|
||||
</StackPanel>
|
||||
|
||||
@@ -82,12 +82,8 @@ namespace FoxTube.Controls
|
||||
}
|
||||
catch { }
|
||||
|
||||
foreach(PlaylistItem i in SecretsVault.UserHistory)
|
||||
if (i.Snippet.ResourceId.VideoId == id)
|
||||
{
|
||||
watched.Visibility = Visibility.Visible;
|
||||
break;
|
||||
}
|
||||
if(SecretsVault.UserHistory.Contains(videoId))
|
||||
watched.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
public async void Button_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
|
||||
<Grid Name="grid">
|
||||
<ScrollViewer Margin="0,0,0,50">
|
||||
<StackPanel Name="stack">
|
||||
<local:VideoGrid/>
|
||||
<controls:ShowMore Clicked="ShowMore_Clicked"/>
|
||||
</StackPanel>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ScrollViewer Name="scroll">
|
||||
<local:VideoGrid/>
|
||||
</ScrollViewer>
|
||||
<CommandBar VerticalAlignment="Bottom">
|
||||
<CommandBar Grid.Row="1">
|
||||
<AppBarButton Label="Open in browser" Icon="Globe" Name="toBrowser" Click="toBrowser_Click"/>
|
||||
<AppBarButton Label="Refresh" Icon="Refresh" Name="refresh" Click="refresh_Click"/>
|
||||
</CommandBar>
|
||||
<foxtube:LoadingPage Visibility="Collapsed"/>
|
||||
<foxtube:LoadingPage Visibility="Collapsed" Grid.RowSpan="2"/>
|
||||
</Grid>
|
||||
</Page>
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
using FoxTube.Controls;
|
||||
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.System;
|
||||
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 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
|
||||
{
|
||||
LoadingPage loading;
|
||||
ShowMore more;
|
||||
VideoGrid list;
|
||||
|
||||
public History()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
|
||||
loading = grid.Children[2] as LoadingPage;
|
||||
more = stack.Children[1] as ShowMore;
|
||||
list = stack.Children[0] as VideoGrid;
|
||||
list = scroll.Content as VideoGrid;
|
||||
Initialize();
|
||||
}
|
||||
|
||||
@@ -40,24 +35,15 @@ namespace FoxTube.Pages
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void toBrowser_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void refresh_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
await Launcher.LaunchUriAsync(new Uri("youtube.com/feed/history"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,11 +102,13 @@ namespace FoxTube
|
||||
|
||||
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);
|
||||
if (await ApplicationData.Current.RoamingFolder.GetFileAsync("notifications.json") != null)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
@@ -128,7 +130,7 @@ namespace FoxTube
|
||||
titleBar.ButtonBackgroundColor = Colors.Red;
|
||||
titleBar.ButtonHoverBackgroundColor = Colors.IndianRed;
|
||||
titleBar.ButtonPressedBackgroundColor = Colors.DarkRed;
|
||||
titleBar.ButtonInactiveBackgroundColor = Colors.DeepPink;
|
||||
titleBar.ButtonInactiveBackgroundColor = Colors.DarkRed;
|
||||
titleBar.ForegroundColor = Colors.White;
|
||||
|
||||
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;
|
||||
|
||||
@@ -52,8 +52,8 @@ namespace FoxTube.Pages.SettingsPages
|
||||
items.Add(new InboxItem(
|
||||
e["header"].InnerText,
|
||||
e["content"].InnerText,
|
||||
DateTime.Parse(e.GetAttribute("time")),
|
||||
e.GetAttribute("id")
|
||||
DateTime.Parse(e["time"].InnerText),
|
||||
e["id"].InnerText
|
||||
));
|
||||
|
||||
items.OrderBy(item => item.TimeStamp);
|
||||
|
||||
@@ -208,6 +208,8 @@ namespace FoxTube.Pages
|
||||
}
|
||||
}
|
||||
subscribe.Visibility = Visibility.Visible;
|
||||
|
||||
SecretsVault.HistoryAdd(videoId);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user