Archived
1
0

Core refactoring (app doesn't work)

This commit is contained in:
Michael Gordeev
2020-05-09 23:16:19 +03:00
parent 2b1f06dd93
commit 2a987e33a2
35 changed files with 1135 additions and 817 deletions
+7
View File
@@ -0,0 +1,7 @@
using System;
namespace FoxTube.Attributes
{
[AttributeUsage(AttributeTargets.Class)]
public class RefreshableAttribute : Attribute { }
}
+42
View File
@@ -0,0 +1,42 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
using YoutubeExplode;
using YoutubeExplode.Videos.Streams;
namespace FoxTube.Models
{
public enum DownloadState { Initializing, Downloading, Cancelling }
public class DownloadItem : SavedVideo
{
public DownloadState State { get; private set; } = DownloadState.Initializing;
public IProgress<double> DownloadPercentage { get; set; }
private CancellationTokenSource CTS { get; set; } = new CancellationTokenSource();
public async Task CommenceDownload(IStreamInfo stream, IStorageFile destination)
{
Path = destination.Path;
YoutubeClient client = new YoutubeClient(UserManagement.Service.HttpClient);
State = DownloadState.Downloading;
Task task = client.Videos.Streams.DownloadAsync(stream, Path, DownloadPercentage, CTS.Token);
await task.ConfigureAwait(false);
if (!task.IsCanceled)
return;
await destination.DeleteAsync(StorageDeleteOption.PermanentDelete);
throw new OperationCanceledException();
}
public void Cancel()
{
State = DownloadState.Cancelling;
CTS.Cancel();
}
}
}
-7
View File
@@ -1,7 +0,0 @@
namespace FoxTube.Core.Models
{
public interface IRefreshable
{
void RefreshPage();
}
}
-19
View File
@@ -1,19 +0,0 @@
using System;
namespace FoxTube.Core.Models.Inbox
{
public class Changelog : InboxItem
{
public override string DefaultIcon => "\xE728";
public override string Title => "What's new in version " + Id;
public override string Type => "Changelog";
public Changelog(string version, string content, string description, DateTime timeStamp)
{
Id = version;
Content = content;
Description = description;
TimeStamp = timeStamp;
}
}
}
@@ -1,22 +0,0 @@
using System;
namespace FoxTube.Core.Models.Inbox
{
public class DeveloperMessage : InboxItem
{
public override string DefaultIcon => "\xE119";
public override string Title => _title;
string _title;
public override string Type => "Message from developers";
public DeveloperMessage(string id, string title, string content, DateTime timeStamp, string avatar)
{
Id = id;
_title = title;
Content = content;
Description = content;
TimeStamp = timeStamp;
Avatar = avatar;
}
}
}
-18
View File
@@ -1,18 +0,0 @@
using System;
namespace FoxTube.Core.Models
{
public abstract class InboxItem
{
public string Id { get; set; }
public abstract string DefaultIcon { get; }
public string Avatar { get; set; }
public abstract string Title { get; }
public string Description { get; set; }
public string Content { get; set; }
public DateTime TimeStamp { get; set; }
public abstract string Type { get; }
public string ShortTimeStamp => $"{TimeStamp.ToShortDateString()} {TimeStamp.ToShortTimeString()}";
}
}
+21
View File
@@ -0,0 +1,21 @@
using System;
namespace FoxTube.Models
{
public class InboxItem
{
public string Id { get; set; }
public string DefaultIcon { get; set; }
public string Avatar { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Content { get; set; }
public DateTime TimeStamp { get; set; }
public string Type { get; set; }
public string ShortTimeStamp => $"{TimeStamp.ToShortDateString()} {TimeStamp.ToShortTimeString()}";
}
}
-27
View File
@@ -1,27 +0,0 @@
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
namespace FoxTube.Core.Models
{
public static class Notifications
{
public static ToastNotification GetChangelogToast(string version)
{
XmlDocument template = new XmlDocument();
// TODO: Add backend
template.LoadXml($@"<toast activationType='foreground' launch='changelog|{version}'>
<visual>
<binding template='ToastGeneric'>
<image placement='hero' src='https://xfox111.net/FoxTube/Thumbnails/Changelog?ver={version}'/>
<image placement='appLogoOverride' hint-crop='circle' src='https://xfox111.net/FoxTube/Avatars/Changelog'/>
<text>Changelog</text>
<text>See what's new in {version}</text>
</binding>
</visual>
</toast>");
return new ToastNotification(template);
}
}
}
-28
View File
@@ -1,28 +0,0 @@
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace FoxTube.Core.Models
{
public class PageView : Page
{
public string Header
{
get => _header;
set
{
_header = value;
UpdateTitle();
}
}
string _header;
public object Parameter { get; private set; }
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
Parameter = e.Parameter;
}
public virtual void UpdateTitle() { }
}
}
+18
View File
@@ -0,0 +1,18 @@
using System;
namespace FoxTube.Models
{
public class SavedVideo
{
public string Title { get; set; }
public string Author { get; set; }
public string Thumbnail { get; set; }
public TimeSpan Duration { get; set; }
public string Id { get; set; }
public string AccessToken { get; set; }
public string Path { get; set; }
public bool IsPathValid { get; set; } = true;
}
}
+13 -13
View File
@@ -1,15 +1,15 @@
namespace FoxTube.Core.Models
namespace FoxTube.Models
{
public class SearchSuggestion
{
public string Icon { get; set; }
public string Text { get; set; }
public class SearchSuggestion
{
public string Icon { get; set; }
public string Text { get; set; }
public SearchSuggestion(string text) : this(text, false) { }
public SearchSuggestion(string text, bool isHistoryEntry)
{
Text = text;
Icon = isHistoryEntry ? "\xE81C" : "";
}
}
}
public SearchSuggestion(string text) : this(text, false) { }
public SearchSuggestion(string text, bool isHistoryEntry)
{
Text = text;
Icon = isHistoryEntry ? "\xE81C" : "";
}
}
}
+10
View File
@@ -0,0 +1,10 @@
namespace FoxTube.Models
{
public class SuspendedUser
{
public string Name { get; set; }
public string Email { get; set; }
public string Avatar { get; set; }
public string RefreshToken { get; set; }
}
}
+39 -39
View File
@@ -7,52 +7,52 @@ using Google.Apis.YouTube.v3.Data;
using System.Collections.Generic;
using YouTube;
namespace FoxTube.Core.Models
namespace FoxTube.Models
{
public class User
{
public Userinfoplus UserInfo { get; }
public UserCredential Credential { get; }
public Channel Channel { get; private set; }
public List<Subscription> Subscriptions { get; } = new List<Subscription>();
public ExtendedYouTubeService Service { get; }
public class User
{
public Userinfoplus UserInfo { get; }
public UserCredential Credential { get; }
public Channel Channel { get; private set; }
public List<Subscription> Subscriptions { get; } = new List<Subscription>();
public ExtendedYouTubeService Service { get; }
public User(UserCredential credential)
{
Credential = credential;
BaseClientService.Initializer initializer = new BaseClientService.Initializer
{
ApplicationName = "FoxTube",
HttpClientInitializer = Credential
};
public User(UserCredential credential)
{
Credential = credential;
BaseClientService.Initializer initializer = new BaseClientService.Initializer
{
ApplicationName = "FoxTube",
HttpClientInitializer = Credential
};
Service = new ExtendedYouTubeService(initializer);
Service = new ExtendedYouTubeService(initializer);
UserInfo = new Oauth2Service(initializer).Userinfo.Get().Execute();
UserInfo = new Oauth2Service(initializer).Userinfo.Get().Execute();
// TODO: Retrieve history and WL
// TODO: Retrieve history and WL
SubscriptionsResource.ListRequest subRequest = Service.Subscriptions.List("snippet");
subRequest.Mine = true;
subRequest.MaxResults = 50;
subRequest.Order = SubscriptionsResource.ListRequest.OrderEnum.Relevance;
SubscriptionListResponse subResponse;
string nextToken = null;
Subscriptions.Clear();
SubscriptionsResource.ListRequest subRequest = Service.Subscriptions.List("snippet");
subRequest.Mine = true;
subRequest.MaxResults = 50;
subRequest.Order = SubscriptionsResource.ListRequest.OrderEnum.Relevance;
SubscriptionListResponse subResponse;
string nextToken = null;
Subscriptions.Clear();
do
{
subRequest.PageToken = nextToken;
subResponse = subRequest.Execute();
foreach (Subscription s in subResponse.Items)
Subscriptions.Add(s);
nextToken = subResponse.NextPageToken;
do
{
subRequest.PageToken = nextToken;
subResponse = subRequest.Execute();
foreach (Subscription s in subResponse.Items)
Subscriptions.Add(s);
nextToken = subResponse.NextPageToken;
} while (!string.IsNullOrWhiteSpace(nextToken));
} while (!string.IsNullOrWhiteSpace(nextToken));
var request = Service.Channels.List("snippet,contentDetails");
request.Mine = true;
Channel = request.Execute().Items[0];
}
}
var request = Service.Channels.List("snippet,contentDetails,brandingSettings");
request.Mine = true;
Channel = request.Execute().Items[0];
}
}
}
+48
View File
@@ -0,0 +1,48 @@
using Google.Apis.YouTube.v3.Data;
using System;
using YoutubeExplode;
namespace FoxTube.Models
{
public class VideoItem
{
public Video Meta { get; set; }
public YoutubeExplode.Videos.Video AdditionalMeta { get; set; }
public YoutubeExplode.Channels.Channel ChannelMeta { get; set; }
public string TimeLabel { get; set; }
public string ViewsLabel { get; set; }
public int LiveLabelOpacity => Meta?.LiveStreamingDetails == null ? 0 : 1;
public string LiveLabel
{
get
{
if (Meta?.LiveStreamingDetails == null)
return "";
else if (Meta.LiveStreamingDetails.ActualStartTime.HasValue)
return "LIVE";
else if (Meta.LiveStreamingDetails.ScheduledStartTime.HasValue)
return $"Live in {Meta.LiveStreamingDetails.ScheduledStartTime - DateTime.Now}";
else
return "Upcoming";
}
}
public VideoItem(Video meta)
{
Meta = meta;
LoadInfo();
}
private async void LoadInfo()
{
YoutubeClient client = new YoutubeClient(UserManagement.Service.HttpClient);
AdditionalMeta = await client.Videos.GetAsync(Meta.Id);
ChannelMeta = await client.Channels.GetByVideoAsync(Meta.Id);
TimeLabel = $"{AdditionalMeta?.Duration} • {AdditionalMeta.UploadDate.DateTime.GetFriendlyDate()}";
ViewsLabel = $"{AdditionalMeta?.Engagement.ViewCount} views";
}
}
}