-Fixed Unspecified error on App.e.g.cs
-Refactoring
This commit is contained in:
@@ -11,18 +11,6 @@ namespace FoxTube
|
||||
|
||||
public delegate void ObjectEventHandler(object sender, params object[] args);
|
||||
|
||||
/*public class SearchParameters
|
||||
{
|
||||
public string ChannelId { get; set; }
|
||||
public string Term { get; set; }
|
||||
|
||||
public SearchParameters(string channelId, string term)
|
||||
{
|
||||
ChannelId = channelId;
|
||||
Term = term;
|
||||
}
|
||||
}*/
|
||||
|
||||
public class SearchParameters
|
||||
{
|
||||
public class Filters
|
||||
+40
-125
@@ -16,76 +16,49 @@ using Windows.UI.Popups;
|
||||
|
||||
namespace FoxTube
|
||||
{
|
||||
/*public class HistoryItem
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public double LeftOn { get; set; }
|
||||
|
||||
public HistoryItem(string id, TimeSpan elapsed, TimeSpan total)
|
||||
{
|
||||
Id = id;
|
||||
LeftOn = elapsed.TotalSeconds / total.TotalSeconds * 100;
|
||||
}
|
||||
|
||||
public HistoryItem(string id)
|
||||
{
|
||||
Id = id;
|
||||
LeftOn = 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
public static class SecretsVault
|
||||
{
|
||||
public static event EventHandler AuthorizationStateChanged;
|
||||
#region Properties
|
||||
//Events
|
||||
public static event Event AuthorizationStateChanged;
|
||||
public static event ObjectEventHandler SubscriptionsChanged;
|
||||
public static event Event NotPurchased; //Rising when app finds out that it's not a PRO version
|
||||
|
||||
private static ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
|
||||
public static NetworkCredential EmailCredential => new NetworkCredential("youwillneverknowthisadress@gmail.com", "thisisthepassword12345");
|
||||
public static ClientSecrets Secrets => new ClientSecrets()
|
||||
//Private properties
|
||||
private static ClientSecrets Secrets => new ClientSecrets()
|
||||
{
|
||||
ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com",
|
||||
ClientSecret = "BkVZOAaCU2Zclf0Zlicg6y2_"
|
||||
};
|
||||
private static UserCredential Credential;
|
||||
private static YouTubeService NoAuthService => new YouTubeService(new BaseClientService.Initializer()
|
||||
{
|
||||
ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0",
|
||||
ApplicationName = "FoxTube"
|
||||
});
|
||||
public static BaseClientService.Initializer Initializer => new BaseClientService.Initializer()
|
||||
{
|
||||
HttpClientInitializer = Credential,
|
||||
ApplicationName = "FoxTube"
|
||||
};
|
||||
public static YouTubeService Service => IsAuthorized ? new YouTubeService(Initializer) : NoAuthService;
|
||||
public static bool AdsDisabled { get; private set; } = true;
|
||||
|
||||
public static string AccountId { get; private set; }
|
||||
public static bool IsAuthorized { get; private set; } = false;
|
||||
//User info
|
||||
public static bool IsAuthorized => Credential != null;
|
||||
private static UserCredential Credential { get; set; }
|
||||
|
||||
public static string AccountId => UserChannel?.Id;
|
||||
public static Channel UserChannel { get; private set; }
|
||||
/*public static List<string> WatchLater { get; private set; } = new List<string>();
|
||||
public static List<HistoryItem> UserHistory { get; private set; } = new List<HistoryItem>();*/
|
||||
public static List<Subscription> Subscriptions { get; private set; } = new List<Subscription>();
|
||||
|
||||
public static YouTubeService NoAuthService => new YouTubeService(new BaseClientService.Initializer()
|
||||
{
|
||||
ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0",
|
||||
ApplicationName = "FoxTube"
|
||||
});
|
||||
public static YouTubeService Service
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsAuthorized)
|
||||
return new YouTubeService(Initializer);
|
||||
else
|
||||
return NoAuthService;
|
||||
}
|
||||
}
|
||||
|
||||
/*public static void HistoryAdd(string id, TimeSpan elapsed, TimeSpan total)
|
||||
{
|
||||
UserHistory.Remove(UserHistory.Find(x => x.Id == id));
|
||||
UserHistory.Add(new HistoryItem(id, elapsed, total));
|
||||
|
||||
if (UserHistory.Count > 100)
|
||||
UserHistory.RemoveAt(UserHistory.Count - 1);
|
||||
}*/
|
||||
public static List<Subscription> Subscriptions { get; } = new List<Subscription>();
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
/// <summary>
|
||||
/// Subscribes or unsibscribes authorized user from the channel
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of channel which has to be added/removed</param>
|
||||
/// <returns>Returns 'true' if channel is in subscriptions now; 'false' if it's not</returns>
|
||||
public static async Task<bool> ChangeSubscriptionState(string id)
|
||||
{
|
||||
if (!IsAuthorized)
|
||||
@@ -125,62 +98,10 @@ namespace FoxTube
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<bool> Subscribe(string id)
|
||||
{
|
||||
if (!IsAuthorized)
|
||||
return false;
|
||||
|
||||
var request = Service.Subscriptions.Insert(new Subscription()
|
||||
{
|
||||
Snippet = new SubscriptionSnippet()
|
||||
{
|
||||
ResourceId = new ResourceId()
|
||||
{
|
||||
ChannelId = id,
|
||||
Kind = "youtube#channel"
|
||||
}
|
||||
}
|
||||
}, "snippet");
|
||||
|
||||
Subscription s = await request.ExecuteAsync();
|
||||
if (s == null)
|
||||
return false;
|
||||
Subscriptions.Add(s);
|
||||
SubscriptionsChanged.Invoke(null, "add", s);
|
||||
|
||||
SaveSubscriptions();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<bool> Unsubscibe(string id)
|
||||
{
|
||||
if (!IsAuthorized)
|
||||
return false;
|
||||
|
||||
Subscription s = null;
|
||||
foreach(Subscription i in Subscriptions)
|
||||
if (i.Snippet.ResourceId.ChannelId == id)
|
||||
{
|
||||
s = i;
|
||||
break;
|
||||
}
|
||||
if (s == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
await Service.Subscriptions.Delete(s.Id).ExecuteAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
SubscriptionsChanged.Invoke(null, "remove", Subscriptions.IndexOf(s));
|
||||
Subscriptions.Remove(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prompts to add an Youtube account and retrieves its info when successful
|
||||
/// </summary>
|
||||
/// <param name="retrieveSubs"></param>
|
||||
public static async void Authorize(bool retrieveSubs = true)
|
||||
{
|
||||
try
|
||||
@@ -194,19 +115,17 @@ namespace FoxTube
|
||||
},
|
||||
"user",
|
||||
CancellationToken.None);
|
||||
|
||||
|
||||
if (Credential == null || !retrieveSubs)
|
||||
return;
|
||||
|
||||
if (settings.Values["authorized"] == null)
|
||||
settings.Values.Add("authorized", true);
|
||||
else settings.Values["authorized"] = true;
|
||||
IsAuthorized = true;
|
||||
|
||||
var request = Service.Channels.List("snippet,contentDetails");
|
||||
request.Mine = true;
|
||||
UserChannel = (await request.ExecuteAsync()).Items[0];
|
||||
AccountId = UserChannel.Id;
|
||||
|
||||
/*try
|
||||
{
|
||||
@@ -265,20 +184,20 @@ namespace FoxTube
|
||||
subRequest.Mine = true;
|
||||
subRequest.MaxResults = 50;
|
||||
subRequest.Order = SubscriptionsResource.ListRequest.OrderEnum.Relevance;
|
||||
SubscriptionListResponse subResponse = await subRequest.ExecuteAsync();
|
||||
SubscriptionListResponse subResponse;
|
||||
string nextToken = null;
|
||||
Subscriptions.Clear();
|
||||
|
||||
foreach (Subscription s in subResponse.Items)
|
||||
Subscriptions.Add(s);
|
||||
|
||||
string nextToken = subResponse.NextPageToken;
|
||||
while (nextToken != null)
|
||||
do
|
||||
{
|
||||
subRequest.PageToken = nextToken;
|
||||
subResponse = await subRequest.ExecuteAsync();
|
||||
foreach (Subscription s in subResponse.Items)
|
||||
Subscriptions.Add(s);
|
||||
}
|
||||
nextToken = subResponse.NextPageToken;
|
||||
|
||||
} while (!string.IsNullOrWhiteSpace(nextToken));
|
||||
|
||||
SaveSubscriptions();
|
||||
}
|
||||
catch
|
||||
@@ -317,21 +236,17 @@ namespace FoxTube
|
||||
if(await Credential.RevokeTokenAsync(CancellationToken.None))
|
||||
{
|
||||
Credential = null;
|
||||
IsAuthorized = false;
|
||||
AuthorizationStateChanged.Invoke(null, null);
|
||||
AuthorizationStateChanged.Invoke();
|
||||
settings.Values["authorized"] = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckAuthorization(bool retrieveSubs = true)
|
||||
{
|
||||
if (settings.Values["authorized"] == null || !(bool)settings.Values["authorized"])
|
||||
IsAuthorized = false;
|
||||
else
|
||||
if (settings.Values["authorized"] != null && (bool)settings.Values["authorized"])
|
||||
Authorize(retrieveSubs);
|
||||
}
|
||||
|
||||
public static bool AdsDisabled { get; private set; } = true;
|
||||
|
||||
public static void CheckAddons()
|
||||
{
|
||||
@@ -346,6 +261,6 @@ namespace FoxTube
|
||||
}
|
||||
}
|
||||
|
||||
public static event Event NotPurchased;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace FoxTube.Classes
|
||||
{
|
||||
public static class SettingsStorage
|
||||
{
|
||||
public static string VideoQuality
|
||||
{
|
||||
get { return (string)settings[0]; }
|
||||
set
|
||||
{
|
||||
settings[0] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static string RememberedQuality
|
||||
{
|
||||
get { return (string)settings[1]; }
|
||||
set
|
||||
{
|
||||
settings[1] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool VideoNotifications
|
||||
{
|
||||
get { return (bool)settings[2]; }
|
||||
set
|
||||
{
|
||||
settings[2] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static bool DevNotifications
|
||||
{
|
||||
get { return (bool)settings[3]; }
|
||||
set
|
||||
{
|
||||
settings[3] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckConnection
|
||||
{
|
||||
get { return (bool)settings[4]; }
|
||||
set
|
||||
{
|
||||
settings[4] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static bool Autoplay
|
||||
{
|
||||
get { return (bool)settings[5]; }
|
||||
set
|
||||
{
|
||||
settings[5] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static int Volume
|
||||
{
|
||||
get { return (int)settings[6]; }
|
||||
set
|
||||
{
|
||||
settings[6] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
public static string Language
|
||||
{
|
||||
get { return (string)settings[7]; }
|
||||
set
|
||||
{
|
||||
settings[7] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static string Region
|
||||
{
|
||||
get { return (string)settings[8]; }
|
||||
set
|
||||
{
|
||||
settings[8] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static int SafeSearch
|
||||
{
|
||||
get { return (int)settings[9]; }
|
||||
set
|
||||
{
|
||||
settings[9] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
public static int Theme
|
||||
{
|
||||
get { return (int)settings[10]; }
|
||||
set
|
||||
{
|
||||
settings[10] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
public static bool HasAccount
|
||||
{
|
||||
get { return (bool)settings[11]; }
|
||||
set
|
||||
{
|
||||
settings[11] = value;
|
||||
SaveData();
|
||||
}
|
||||
}
|
||||
|
||||
public static string Version
|
||||
{
|
||||
get
|
||||
{
|
||||
if (storage.Values["ver"] == null)
|
||||
{
|
||||
PackageVersion ver = Package.Current.Id.Version;
|
||||
return $"{ver.Major}.{ver.Minor}";
|
||||
}
|
||||
else return (string)storage.Values["version"];
|
||||
}
|
||||
set
|
||||
{
|
||||
storage.Values["version"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
//Settings storage
|
||||
private static ApplicationDataContainer storage = ApplicationData.Current.LocalSettings;
|
||||
|
||||
//Predefined preferences
|
||||
private static object[] settings = new object[]
|
||||
{
|
||||
"remember",
|
||||
"1080p",
|
||||
|
||||
true,
|
||||
true,
|
||||
|
||||
true,
|
||||
true,
|
||||
100,
|
||||
|
||||
(new[] { "ua", "ru", "by", "kz", "kg", "md", "lv", "ee" }).Contains(CultureInfo.InstalledUICulture.TwoLetterISOLanguageName) ? "ru-RU" : "en-US",
|
||||
CultureInfo.CurrentCulture.Name,
|
||||
0,
|
||||
|
||||
2,
|
||||
false
|
||||
};
|
||||
|
||||
public static void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
settings = JsonConvert.DeserializeObject<object[]>(storage.Values["settings"] as string);
|
||||
}
|
||||
catch (NullReferenceException) { }
|
||||
}
|
||||
|
||||
public static void SaveData()
|
||||
{
|
||||
storage.Values["settings"] = JsonConvert.SerializeObject(settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ namespace FoxTube.Controls
|
||||
|
||||
public async void Initialize(string id, string live)
|
||||
{
|
||||
ChannelsResource.ListRequest request = SecretsVault.NoAuthService.Channels.List("snippet,statistics,brandingSettings");
|
||||
ChannelsResource.ListRequest request = SecretsVault.Service.Channels.List("snippet,statistics,brandingSettings");
|
||||
request.Id = id;
|
||||
ChannelListResponse response = await request.ExecuteAsync();
|
||||
|
||||
|
||||
@@ -100,7 +100,8 @@
|
||||
<Compile Include="Classes\DownloadItemContainer.cs" />
|
||||
<Compile Include="Classes\InboxItem.cs" />
|
||||
<Compile Include="Classes\Methods.cs" />
|
||||
<Compile Include="Classes\ObjectEventArgs.cs" />
|
||||
<Compile Include="Classes\SearchPaameters.cs" />
|
||||
<Compile Include="Classes\SettingsStorage.cs" />
|
||||
<Compile Include="Controls\Advert.xaml.cs">
|
||||
<DependentUpon>Advert.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</NavigationViewItem>
|
||||
<NavigationViewItem x:Uid="/Main/liked" Icon="Like" Content="Liked videos" Name="toLiked" Visibility="Collapsed"/>
|
||||
<NavigationViewItem x:Uid="/Main/later" Icon="Clock" Content="Watch later" Name="toLater" Visibility="Collapsed"/>
|
||||
<NavigationViewItem x:Uid="/Main/downloads" Icon="Download" Content="Downloads" Name="toDownloads" Visibility="Collapsed"/>
|
||||
<NavigationViewItem x:Uid="/Main/downloads" Icon="Download" Content="Downloads" Name="toDownloads"/>
|
||||
<NavigationViewItemHeader x:Uid="/Main/subscriptions" Content="Subscriptions" Name="subsHeader" Visibility="Collapsed"/>
|
||||
</NavigationView.MenuItems>
|
||||
|
||||
|
||||
@@ -39,37 +39,11 @@ namespace FoxTube
|
||||
public enum Sender { Menu, Frame, None }
|
||||
|
||||
public sealed partial class MainPage : Page
|
||||
{
|
||||
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
|
||||
|
||||
{
|
||||
Sender s = Sender.None;
|
||||
public MainPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
if (settings.Values["quality"] == null)
|
||||
settings.Values.Add("quality", "remember");
|
||||
if (settings.Values["rememberedQuality"] == null)
|
||||
settings.Values.Add("rememberedQuality", "1080p");
|
||||
|
||||
if (settings.Values["newVideoNotification"] == null)
|
||||
settings.Values.Add("newVideoNotification", true);
|
||||
if (settings.Values["devNews"] == null)
|
||||
settings.Values.Add("devNews", true);
|
||||
|
||||
if (settings.Values["moblieWarning"] == null)
|
||||
settings.Values.Add("moblieWarning", false);
|
||||
if (settings.Values["videoAutoplay"] == null)
|
||||
settings.Values.Add("videoAutoplay", true);
|
||||
if (settings.Values["themeMode"] == null)
|
||||
settings.Values.Add("themeMode", 2);
|
||||
if (settings.Values["volume"] == null)
|
||||
settings.Values.Add("volume", 100);
|
||||
|
||||
if (settings.Values["region"] == null)
|
||||
settings.Values.Add("region", CultureInfo.CurrentCulture.Name);
|
||||
if (settings.Values["safeSearch"] == null)
|
||||
settings.Values.Add("safeSearch", 0);
|
||||
|
||||
PackageVersion ver = Package.Current.Id.Version;
|
||||
if (settings.Values["ver"] == null)
|
||||
@@ -90,9 +64,7 @@ namespace FoxTube
|
||||
catch { }
|
||||
}
|
||||
|
||||
content.Navigate(typeof(Home));
|
||||
|
||||
SecretsVault.AuthorizationStateChanged += Vault_AuthorizationStateChanged;
|
||||
SecretsVault.AuthorizationStateChanged += AuthorizationStateChanged;
|
||||
SecretsVault.SubscriptionsChanged += SecretsVault_SubscriptionsChanged;
|
||||
SecretsVault.NotPurchased += () => removeAds.Visibility = Visibility.Visible;
|
||||
SecretsVault.CheckAuthorization();
|
||||
@@ -165,7 +137,7 @@ namespace FoxTube
|
||||
nav.MenuItems.RemoveAt((int)args[1] + 9);
|
||||
}
|
||||
|
||||
private async void Vault_AuthorizationStateChanged(object sender, EventArgs e)
|
||||
private async void AuthorizationStateChanged()
|
||||
{
|
||||
if(SecretsVault.IsAuthorized)
|
||||
{
|
||||
@@ -186,7 +158,6 @@ namespace FoxTube
|
||||
toHistory.Visibility = Visibility.Visible;
|
||||
toLiked.Visibility = Visibility.Visible;
|
||||
toLater.Visibility = Visibility.Visible;
|
||||
toDownloads.Visibility = Visibility.Visible;
|
||||
subsHeader.Visibility = Visibility.Visible;
|
||||
|
||||
if (SecretsVault.Subscriptions.Count > 0)
|
||||
@@ -229,15 +200,13 @@ namespace FoxTube
|
||||
toHistory.Visibility = Visibility.Collapsed;
|
||||
toLiked.Visibility = Visibility.Collapsed;
|
||||
toLater.Visibility = Visibility.Collapsed;
|
||||
toDownloads.Visibility = Visibility.Collapsed;
|
||||
subsHeader.Visibility = Visibility.Collapsed;
|
||||
|
||||
subsHeader.Visibility = Visibility.Collapsed;
|
||||
for(int k = 9; k < nav.MenuItems.Count; k++)
|
||||
nav.MenuItems.RemoveAt(k);
|
||||
}
|
||||
|
||||
nav.SelectedItem = toHome;
|
||||
|
||||
content.Navigate(typeof(Home));
|
||||
|
||||
if (videoPlaceholder.Content != null)
|
||||
@@ -261,7 +230,7 @@ namespace FoxTube
|
||||
|
||||
private void myChannel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
content.Navigate(typeof(Channel), SecretsVault.UserChannel.Id);
|
||||
GoToChannel(SecretsVault.AccountId);
|
||||
}
|
||||
|
||||
private void logout_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user