Archived
1
0
This commit is contained in:
Michael Gordeev
2018-10-09 18:16:23 +03:00
parent 7185561c82
commit 67dbd2f114
4 changed files with 62 additions and 39 deletions
+41
View File
@@ -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;
+1 -7
View File
@@ -91,18 +91,13 @@ namespace FoxTube.Controls
private async void subscribe_Click(object sender, RoutedEventArgs e)
{
if (subscribe.Background == new SolidColorBrush(Colors.Red))
{
if (await SecretsVault.Subscribe(channelId))
if (await SecretsVault.ChangeSubscriptionState(channelId))
{
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);
@@ -110,5 +105,4 @@ namespace FoxTube.Controls
}
}
}
}
}
+1 -7
View File
@@ -250,25 +250,19 @@ namespace FoxTube.Pages
private async void subscribe_Click(object sender, RoutedEventArgs e)
{
if (subscribe.Background == new SolidColorBrush(Colors.Red))
{
if (await SecretsVault.Subscribe(channelId))
if(await SecretsVault.ChangeSubscriptionState(channelId))
{
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";
}
}
}
private void Hyperlink_Click(Windows.UI.Xaml.Documents.Hyperlink sender, Windows.UI.Xaml.Documents.HyperlinkClickEventArgs args)
{
+1 -7
View File
@@ -523,18 +523,13 @@ namespace FoxTube.Pages
private async void subscribe_Click(object sender, RoutedEventArgs e)
{
if (subscribe.Background == new SolidColorBrush(Colors.Red))
{
if (await SecretsVault.Subscribe(item.Snippet.ChannelId))
if (await SecretsVault.ChangeSubscriptionState(channelId))
{
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);
@@ -542,5 +537,4 @@ namespace FoxTube.Pages
}
}
}
}
}