Development 5
This commit is contained in:
+22
-13
@@ -40,17 +40,17 @@
|
||||
<TextBlock Name="views" Text="[views]" FontSize="24" Foreground="Gray"/>
|
||||
<ProgressBar Name="rating" Width="250" Background="Green" Foreground="Red"/>
|
||||
<Grid>
|
||||
<Button Background="Transparent" Foreground="Gray"
|
||||
Padding="0"
|
||||
FontFamily="Segoe MDL2 Assets" FontSize="40"
|
||||
Name="dislike" Click="dislike_Click"
|
||||
Content=""/>
|
||||
<FontIcon Foreground="Gray"
|
||||
HorizontalAlignment="Left"
|
||||
FontSize="40"
|
||||
Name="dislike" Tapped="dislike_Click"
|
||||
Glyph=""/>
|
||||
|
||||
<Button Background="Transparent" Foreground="Gray"
|
||||
Padding="0" HorizontalAlignment="Right"
|
||||
FontFamily="Segoe MDL2 Assets" FontSize="40"
|
||||
Name="like" Click="like_Click"
|
||||
Content=""/>
|
||||
<FontIcon Foreground="Gray"
|
||||
HorizontalAlignment="Right"
|
||||
FontSize="40"
|
||||
Name="like" Tapped="like_Click"
|
||||
Glyph=""/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<TextBlock Foreground="Gray" Text="[dislikes]" Name="dislikes"/>
|
||||
@@ -85,14 +85,23 @@
|
||||
|
||||
|
||||
<CommandBar VerticalAlignment="Bottom" Name="commandbar">
|
||||
<AppBarToggleButton Icon="Clock" Label="Watch later" Visibility="Collapsed"/>
|
||||
<AppBarButton Name="download" Icon="Download" Label="Download video">
|
||||
<AppBarButton.Flyout>
|
||||
<MenuFlyout>
|
||||
<MenuFlyoutItem Text="Select quality:" IsEnabled="False"/>
|
||||
<MenuFlyoutSeparator/>
|
||||
<MenuFlyoutItem Text="No items are available" IsEnabled="False"/>
|
||||
</MenuFlyout>
|
||||
</AppBarButton.Flyout>
|
||||
</AppBarButton>
|
||||
<AppBarToggleButton Name="addLater" Icon="Clock" Label="Watch later" Visibility="Collapsed"/>
|
||||
<AppBarButton Name="refresh" Click="refresh_Click" Icon="Refresh" Label="Refresh page"/>
|
||||
<AppBarButton Name="share" Click="share_Click" Icon="Share" Label="Share"/>
|
||||
<AppBarButton Name="openBrowser" Click="openBrowser_Click" Icon="Globe" Label="Open in browser"/>
|
||||
|
||||
<CommandBar.SecondaryCommands>
|
||||
<AppBarButton Icon="Add" Label="Add to playlist" Visibility="Collapsed"/>
|
||||
<AppBarButton Icon="Flag" Label="Report this video"/>
|
||||
<AppBarButton Name="addToPlaylist" Icon="Add" Label="Add to playlist" Visibility="Collapsed"/>
|
||||
<AppBarButton Icon="Flag" Label="Report this video" Visibility="Collapsed"/>
|
||||
</CommandBar.SecondaryCommands>
|
||||
</CommandBar>
|
||||
|
||||
|
||||
+83
-51
@@ -34,6 +34,8 @@ using FoxTube.Pages;
|
||||
|
||||
namespace FoxTube
|
||||
{
|
||||
public enum Rating { None, Like, Dislike }
|
||||
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
@@ -45,7 +47,10 @@ namespace FoxTube
|
||||
bool wide;
|
||||
bool isExtended = false;
|
||||
|
||||
Rating userRating = Rating.None;
|
||||
|
||||
public VideoPlayer player;
|
||||
public CommentsPage comments;
|
||||
LoadingPage LoadingScreen = new LoadingPage();
|
||||
LoadingPage loadingRelated = new LoadingPage();
|
||||
|
||||
@@ -106,7 +111,10 @@ namespace FoxTube
|
||||
else
|
||||
{
|
||||
views.Text = string.Format("{0:0,0} views", item.Statistics.ViewCount);
|
||||
(commentsPlaceholder.Content as CommentsPage).Initialize(item);
|
||||
comments = new CommentsPage();
|
||||
commentsPlaceholder.Content = null;
|
||||
commentsPlaceholder.Content = comments;
|
||||
comments.Initialize(item);
|
||||
}
|
||||
|
||||
VideoCategoriesResource.ListRequest categoryRequest = SecretsVault.NoAuthService.VideoCategories.List("snippet");
|
||||
@@ -136,11 +144,20 @@ namespace FoxTube
|
||||
channelName.Text = item.Snippet.ChannelTitle;
|
||||
subscribers.Text = item1.Statistics.SubscriberCount + " subscribers";
|
||||
|
||||
/*var ratingResponse = await SecretsVault.YoutubeService.Videos.GetRating(id).ExecuteAsync();
|
||||
if (ratingResponse.Items[0].Rating == "like")
|
||||
like.Foreground = new SolidColorBrush(Colors.Green);
|
||||
else if (ratingResponse.Items[0].Rating == "dislike")
|
||||
dislike.Foreground = new SolidColorBrush(Colors.Red);*/
|
||||
if(SecretsVault.IsAuthorized)
|
||||
{
|
||||
VideoGetRatingResponse ratingResponse = await SecretsVault.Service.Videos.GetRating(id).ExecuteAsync();
|
||||
if (ratingResponse.Items[0].Rating == "like")
|
||||
{
|
||||
userRating = Rating.Like;
|
||||
like.Foreground = new SolidColorBrush(Colors.Green);
|
||||
}
|
||||
else if (ratingResponse.Items[0].Rating == "dislike")
|
||||
{
|
||||
userRating = Rating.Dislike;
|
||||
dislike.Foreground = new SolidColorBrush(Colors.Red);
|
||||
}
|
||||
}
|
||||
|
||||
player = new VideoPlayer(item, item1.Snippet.Thumbnails.Medium.Url);
|
||||
player.SetFullSize += Player_SetFullSize;
|
||||
@@ -164,7 +181,7 @@ namespace FoxTube
|
||||
loadingRelated.Refresh();
|
||||
loadingRelated.Visibility = Visibility.Visible;
|
||||
|
||||
SearchResource.ListRequest request = SecretsVault.NoAuthService.Search.List("snippet");
|
||||
SearchResource.ListRequest request = SecretsVault.IsAuthorized? SecretsVault.Service.Search.List("snippet") : SecretsVault.NoAuthService.Search.List("snippet");
|
||||
request.RelatedToVideoId = videoId;
|
||||
request.MaxResults = 20;
|
||||
request.Type = "video";
|
||||
@@ -416,57 +433,72 @@ namespace FoxTube
|
||||
|
||||
private async void dislike_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if(like.Foreground == new SolidColorBrush(Colors.Green))
|
||||
{
|
||||
like.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
likes.Text = (Convert.ToInt32(likes.Text) - 1).ToString();
|
||||
rating.Value = (int)((item.Statistics.DislikeCount) / (item.Statistics.DislikeCount + item.Statistics.LikeCount - 1) * 100);
|
||||
await SecretsVault.NoAuthService.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.None).ExecuteAsync();
|
||||
}
|
||||
if (SecretsVault.IsAuthorized)
|
||||
switch (userRating)
|
||||
{
|
||||
case Rating.Like:
|
||||
like.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
likes.Text = (Convert.ToInt32(likes.Text) - 1).ToString();
|
||||
|
||||
if(dislike.Foreground == new SolidColorBrush(Colors.Red))
|
||||
{
|
||||
dislike.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
rating.Value = (int)((item.Statistics.DislikeCount - 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount - 1) * 100);
|
||||
await SecretsVault.NoAuthService.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.None).ExecuteAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
dislike.Foreground = new SolidColorBrush(Colors.Red);
|
||||
dislikes.Text = (Convert.ToInt32(dislikes.Text) + 1).ToString();
|
||||
rating.Value = (int)((item.Statistics.DislikeCount + 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount + 1) * 100);
|
||||
await SecretsVault.NoAuthService.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.Dislike).ExecuteAsync();
|
||||
}
|
||||
dislike.Foreground = new SolidColorBrush(Colors.Red);
|
||||
dislikes.Text = (Convert.ToInt32(dislikes.Text) + 1).ToString();
|
||||
rating.Value = (int)((item.Statistics.LikeCount - 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount) * 100);
|
||||
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.Dislike).ExecuteAsync();
|
||||
|
||||
userRating = Rating.Dislike;
|
||||
break;
|
||||
|
||||
case Rating.None:
|
||||
dislike.Foreground = new SolidColorBrush(Colors.Red);
|
||||
dislikes.Text = (Convert.ToInt32(dislikes.Text) + 1).ToString();
|
||||
rating.Value = (int)((item.Statistics.LikeCount) / (item.Statistics.DislikeCount + item.Statistics.LikeCount + 1) * 100);
|
||||
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.Dislike).ExecuteAsync();
|
||||
|
||||
userRating = Rating.Dislike;
|
||||
break;
|
||||
|
||||
case Rating.Dislike:
|
||||
dislike.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
dislikes.Text = (Convert.ToInt32(dislikes.Text) - 1).ToString();
|
||||
rating.Value = (int)((item.Statistics.LikeCount) / (item.Statistics.DislikeCount + item.Statistics.LikeCount - 1) * 100);
|
||||
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.None).ExecuteAsync();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async void like_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (dislike.Foreground == new SolidColorBrush(Colors.Red))
|
||||
{
|
||||
dislike.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
dislikes.Text = (Convert.ToInt32(likes.Text) - 1).ToString();
|
||||
rating.Value = (int)((item.Statistics.LikeCount) / (item.Statistics.DislikeCount + item.Statistics.LikeCount - 1) * 100);
|
||||
await SecretsVault.NoAuthService.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.None).ExecuteAsync();
|
||||
}
|
||||
if(SecretsVault.IsAuthorized)
|
||||
switch (userRating)
|
||||
{
|
||||
case Rating.Dislike:
|
||||
dislike.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
dislikes.Text = (Convert.ToInt32(dislikes.Text) - 1).ToString();
|
||||
|
||||
if (like.Foreground == new SolidColorBrush(Colors.Green))
|
||||
{
|
||||
like.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
rating.Value = (int)((item.Statistics.LikeCount - 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount - 1) * 100);
|
||||
await SecretsVault.NoAuthService.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.None).ExecuteAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
like.Foreground = new SolidColorBrush(Colors.Green);
|
||||
likes.Text = (Convert.ToInt32(dislikes.Text) + 1).ToString();
|
||||
rating.Value = (int)((item.Statistics.LikeCount + 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount + 1) * 100);
|
||||
await SecretsVault.NoAuthService.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.Dislike).ExecuteAsync();
|
||||
}
|
||||
}
|
||||
like.Foreground = new SolidColorBrush(Colors.Green);
|
||||
likes.Text = (Convert.ToInt32(likes.Text) + 1).ToString();
|
||||
rating.Value = (int)((item.Statistics.LikeCount + 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount) * 100);
|
||||
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.Like).ExecuteAsync();
|
||||
|
||||
private async void description_LinkClicked(object sender, Microsoft.Toolkit.Uwp.UI.Controls.LinkClickedEventArgs e)
|
||||
{
|
||||
await Launcher.LaunchUriAsync(new Uri(e.Link));
|
||||
userRating = Rating.Like;
|
||||
break;
|
||||
|
||||
case Rating.None:
|
||||
like.Foreground = new SolidColorBrush(Colors.Green);
|
||||
likes.Text = (Convert.ToInt32(likes.Text) + 1).ToString();
|
||||
rating.Value = (int)((item.Statistics.LikeCount + 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount + 1) * 100);
|
||||
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.Like).ExecuteAsync();
|
||||
|
||||
userRating = Rating.Like;
|
||||
break;
|
||||
|
||||
case Rating.Like:
|
||||
like.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
likes.Text = (Convert.ToInt32(likes.Text) - 1).ToString();
|
||||
rating.Value = (int)((item.Statistics.LikeCount - 1) / (item.Statistics.DislikeCount + item.Statistics.LikeCount - 1) * 100);
|
||||
await SecretsVault.Service.Videos.Rate(videoId, VideosResource.RateRequest.RatingEnum.None).ExecuteAsync();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user