#205: Fixed
This commit is contained in:
@@ -57,6 +57,45 @@ namespace FoxTube
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<bool> ChangeSubscriptionState(string id)
|
||||||
|
{
|
||||||
|
if (!IsAuthorized)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(Subscriptions.Find(x => x.Snippet.ResourceId.ChannelId == id) != null)
|
||||||
|
{
|
||||||
|
Subscription s = Subscriptions.Find(x => x.Snippet.ResourceId.ChannelId == id);
|
||||||
|
|
||||||
|
try { await Service.Subscriptions.Delete(s.Id).ExecuteAsync(); }
|
||||||
|
catch { return true; }
|
||||||
|
|
||||||
|
SubscriptionsChanged.Invoke(null, "remove", Subscriptions.IndexOf(s));
|
||||||
|
Subscriptions.Remove(s);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<bool> Subscribe(string id)
|
public static async Task<bool> Subscribe(string id)
|
||||||
{
|
{
|
||||||
if (!IsAuthorized)
|
if (!IsAuthorized)
|
||||||
@@ -75,6 +114,8 @@ namespace FoxTube
|
|||||||
}, "snippet");
|
}, "snippet");
|
||||||
|
|
||||||
Subscription s = await request.ExecuteAsync();
|
Subscription s = await request.ExecuteAsync();
|
||||||
|
if (s == null)
|
||||||
|
return false;
|
||||||
Subscriptions.Add(s);
|
Subscriptions.Add(s);
|
||||||
SubscriptionsChanged.Invoke(null, "add", s);
|
SubscriptionsChanged.Invoke(null, "add", s);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -91,23 +91,17 @@ namespace FoxTube.Controls
|
|||||||
|
|
||||||
private async void subscribe_Click(object sender, RoutedEventArgs e)
|
private async void subscribe_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (subscribe.Background == new SolidColorBrush(Colors.Red))
|
if (await SecretsVault.ChangeSubscriptionState(channelId))
|
||||||
{
|
{
|
||||||
if (await SecretsVault.Subscribe(channelId))
|
subscribe.Background = new SolidColorBrush(Colors.Transparent);
|
||||||
{
|
subscribe.Foreground = new SolidColorBrush(Colors.Gray);
|
||||||
subscribe.Background = new SolidColorBrush(Colors.Transparent);
|
subscribe.Content = "Subscribed";
|
||||||
subscribe.Foreground = new SolidColorBrush(Colors.Gray);
|
|
||||||
subscribe.Content = "Subscribed";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (await SecretsVault.Unsubscibe(channelId))
|
subscribe.Background = new SolidColorBrush(Colors.Red);
|
||||||
{
|
subscribe.Foreground = new SolidColorBrush(Colors.White);
|
||||||
subscribe.Background = new SolidColorBrush(Colors.Red);
|
subscribe.Content = "Subscribe";
|
||||||
subscribe.Foreground = new SolidColorBrush(Colors.White);
|
|
||||||
subscribe.Content = "Subscribe";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -250,23 +250,17 @@ namespace FoxTube.Pages
|
|||||||
|
|
||||||
private async void subscribe_Click(object sender, RoutedEventArgs e)
|
private async void subscribe_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (subscribe.Background == new SolidColorBrush(Colors.Red))
|
if(await SecretsVault.ChangeSubscriptionState(channelId))
|
||||||
{
|
{
|
||||||
if (await SecretsVault.Subscribe(channelId))
|
subscribe.Background = new SolidColorBrush(Colors.Transparent);
|
||||||
{
|
subscribe.Foreground = new SolidColorBrush(Colors.Gray);
|
||||||
subscribe.Background = new SolidColorBrush(Colors.Transparent);
|
subscribe.Content = "Subscribed";
|
||||||
subscribe.Foreground = new SolidColorBrush(Colors.Gray);
|
|
||||||
subscribe.Content = "Subscribed";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (await SecretsVault.Unsubscibe(channelId))
|
subscribe.Background = new SolidColorBrush(Colors.Red);
|
||||||
{
|
subscribe.Foreground = new SolidColorBrush(Colors.White);
|
||||||
subscribe.Background = new SolidColorBrush(Colors.Red);
|
subscribe.Content = "Subscribe";
|
||||||
subscribe.Foreground = new SolidColorBrush(Colors.White);
|
|
||||||
subscribe.Content = "Subscribe";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -523,23 +523,17 @@ namespace FoxTube.Pages
|
|||||||
|
|
||||||
private async void subscribe_Click(object sender, RoutedEventArgs e)
|
private async void subscribe_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (subscribe.Background == new SolidColorBrush(Colors.Red))
|
if (await SecretsVault.ChangeSubscriptionState(channelId))
|
||||||
{
|
{
|
||||||
if (await SecretsVault.Subscribe(item.Snippet.ChannelId))
|
subscribe.Background = new SolidColorBrush(Colors.Transparent);
|
||||||
{
|
subscribe.Foreground = new SolidColorBrush(Colors.Gray);
|
||||||
subscribe.Background = new SolidColorBrush(Colors.Transparent);
|
subscribe.Content = "Subscribed";
|
||||||
subscribe.Foreground = new SolidColorBrush(Colors.Gray);
|
|
||||||
subscribe.Content = "Subscribed";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (await SecretsVault.Unsubscibe(item.Snippet.ChannelId))
|
subscribe.Background = new SolidColorBrush(Colors.Red);
|
||||||
{
|
subscribe.Foreground = new SolidColorBrush(Colors.White);
|
||||||
subscribe.Background = new SolidColorBrush(Colors.Red);
|
subscribe.Content = "Subscribe";
|
||||||
subscribe.Foreground = new SolidColorBrush(Colors.White);
|
|
||||||
subscribe.Content = "Subscribe";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user