#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)
|
||||
{
|
||||
if (!IsAuthorized)
|
||||
@@ -75,6 +114,8 @@ namespace FoxTube
|
||||
}, "snippet");
|
||||
|
||||
Subscription s = await request.ExecuteAsync();
|
||||
if (s == null)
|
||||
return false;
|
||||
Subscriptions.Add(s);
|
||||
SubscriptionsChanged.Invoke(null, "add", s);
|
||||
return true;
|
||||
|
||||
@@ -91,23 +91,17 @@ namespace FoxTube.Controls
|
||||
|
||||
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.Content = "Subscribed";
|
||||
}
|
||||
subscribe.Background = new SolidColorBrush(Colors.Transparent);
|
||||
subscribe.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
subscribe.Content = "Subscribed";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (await SecretsVault.Unsubscibe(channelId))
|
||||
{
|
||||
subscribe.Background = new SolidColorBrush(Colors.Red);
|
||||
subscribe.Foreground = new SolidColorBrush(Colors.White);
|
||||
subscribe.Content = "Subscribe";
|
||||
}
|
||||
subscribe.Background = new SolidColorBrush(Colors.Red);
|
||||
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)
|
||||
{
|
||||
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.Content = "Subscribed";
|
||||
}
|
||||
subscribe.Background = new SolidColorBrush(Colors.Transparent);
|
||||
subscribe.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
subscribe.Content = "Subscribed";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (await SecretsVault.Unsubscibe(channelId))
|
||||
{
|
||||
subscribe.Background = new SolidColorBrush(Colors.Red);
|
||||
subscribe.Foreground = new SolidColorBrush(Colors.White);
|
||||
subscribe.Content = "Subscribe";
|
||||
}
|
||||
subscribe.Background = new SolidColorBrush(Colors.Red);
|
||||
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)
|
||||
{
|
||||
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.Content = "Subscribed";
|
||||
}
|
||||
subscribe.Background = new SolidColorBrush(Colors.Transparent);
|
||||
subscribe.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
subscribe.Content = "Subscribed";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (await SecretsVault.Unsubscibe(item.Snippet.ChannelId))
|
||||
{
|
||||
subscribe.Background = new SolidColorBrush(Colors.Red);
|
||||
subscribe.Foreground = new SolidColorBrush(Colors.White);
|
||||
subscribe.Content = "Subscribe";
|
||||
}
|
||||
subscribe.Background = new SolidColorBrush(Colors.Red);
|
||||
subscribe.Foreground = new SolidColorBrush(Colors.White);
|
||||
subscribe.Content = "Subscribe";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user