@@ -0,0 +1,59 @@
|
|||||||
|
<UserControl
|
||||||
|
x:Class="FoxTube.Controls.Chat"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="600"
|
||||||
|
d:DesignWidth="400">
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="auto"/>
|
||||||
|
<RowDefinition/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<Grid Name="inputField">
|
||||||
|
<TextBox Margin="5,5,42,5" PlaceholderText="Send a message" Name="newMessage" VerticalAlignment="Center" MinHeight="32" TextWrapping="Wrap" AcceptsReturn="True"/>
|
||||||
|
<Button HorizontalAlignment="Right" Name="send" Click="send_Click" VerticalAlignment="Top"
|
||||||
|
Height="32" Width="32"
|
||||||
|
Margin="0,5,5,0" Padding="0"
|
||||||
|
Background="Transparent"
|
||||||
|
FontFamily="Segoe MDL2 Assets"
|
||||||
|
Content="" FontSize="30"/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<ScrollViewer Grid.Row="1">
|
||||||
|
<ListView Name="list" SelectionMode="None">
|
||||||
|
<ListView.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Border BorderBrush="Red" BorderThickness="{Binding Path=BorderThickness}" CornerRadius="5" HorizontalAlignment="Stretch" Background="{Binding Path=Background}" Margin="0,2">
|
||||||
|
<Grid Margin="0,5,5,0">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="5,0">
|
||||||
|
<FontIcon Glyph="" ToolTipService.ToolTip="Verified" Margin="2,0" Visibility="{Binding Path=IsVerified}"/>
|
||||||
|
<FontIcon Glyph="" ToolTipService.ToolTip="Moderator" Margin="2,0" Visibility="{Binding Path=IsModerator}"/>
|
||||||
|
<FontIcon Glyph="" ToolTipService.ToolTip="Chat owner" Margin="2,0" Visibility="{Binding Path=IsOwner}"/>
|
||||||
|
<FontIcon Glyph="" ToolTipService.ToolTip="Sponsor" Margin="2,0" Visibility="{Binding Path=IsSponsor}"/>
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Orientation="Horizontal" Grid.Column="1" VerticalAlignment="Top" Margin="0,0,5,0">
|
||||||
|
<HyperlinkButton Content="{Binding Path=Author}" Tag="{Binding Path=ChannelId}" Grid.Column="1" Margin="0,-6,0,0" FontWeight="Bold" Click="HyperlinkButton_Click"/>
|
||||||
|
<TextBlock Text=":"/>
|
||||||
|
</StackPanel>
|
||||||
|
<TextBlock Grid.Column="2" IsTextSelectionEnabled="True" VerticalAlignment="Top" TextWrapping="WrapWholeWords" Text="{Binding Path=Message}"/>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListView.ItemTemplate>
|
||||||
|
<ListViewItem>
|
||||||
|
<TextBlock Text="Welcome to the chat room" Foreground="Gray"/>
|
||||||
|
</ListViewItem>
|
||||||
|
</ListView>
|
||||||
|
</ScrollViewer>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
using System;
|
||||||
|
using Windows.UI.Xaml;
|
||||||
|
using Windows.UI.Xaml.Controls;
|
||||||
|
using Windows.UI.Xaml.Media;
|
||||||
|
using Google.Apis.YouTube.v3.Data;
|
||||||
|
using Google.Apis.YouTube.v3;
|
||||||
|
using Windows.UI;
|
||||||
|
|
||||||
|
namespace FoxTube.Controls
|
||||||
|
{
|
||||||
|
public class ChatMessage
|
||||||
|
{
|
||||||
|
public string Author
|
||||||
|
{
|
||||||
|
get { return message.AuthorDetails.DisplayName; }
|
||||||
|
}
|
||||||
|
public string Message
|
||||||
|
{
|
||||||
|
get { return message.Snippet.DisplayMessage; }
|
||||||
|
}
|
||||||
|
public string ChannelId
|
||||||
|
{
|
||||||
|
get { return message.AuthorDetails.ChannelId; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Visibility IsVerified
|
||||||
|
{
|
||||||
|
get { return message.AuthorDetails.IsVerified.Value? Visibility.Visible : Visibility.Collapsed; }
|
||||||
|
}
|
||||||
|
public Visibility IsOwner
|
||||||
|
{
|
||||||
|
get { return message.AuthorDetails.IsChatOwner.Value ? Visibility.Visible : Visibility.Collapsed; }
|
||||||
|
}
|
||||||
|
public Visibility IsSponsor
|
||||||
|
{
|
||||||
|
get { return message.AuthorDetails.IsChatSponsor.Value ? Visibility.Visible : Visibility.Collapsed; }
|
||||||
|
}
|
||||||
|
public Visibility IsModerator
|
||||||
|
{
|
||||||
|
get { return message.AuthorDetails.IsChatModerator.Value ? Visibility.Visible : Visibility.Collapsed; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Brush Background
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (IsVerified == Visibility.Visible || IsOwner == Visibility.Visible || IsSponsor == Visibility.Visible || IsModerator == Visibility.Visible)
|
||||||
|
return new SolidColorBrush() { Color = Colors.Red, Opacity = .2 };
|
||||||
|
else
|
||||||
|
return new SolidColorBrush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Thickness BorderThickness
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (IsVerified == Visibility.Visible || IsOwner == Visibility.Visible || IsSponsor == Visibility.Visible || IsModerator == Visibility.Visible)
|
||||||
|
return new Thickness(2);
|
||||||
|
else
|
||||||
|
return new Thickness(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private LiveChatMessage message;
|
||||||
|
|
||||||
|
public ChatMessage(LiveChatMessage item)
|
||||||
|
{
|
||||||
|
message = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed partial class Chat : UserControl
|
||||||
|
{
|
||||||
|
string chatId;
|
||||||
|
DateTime lastInsert;
|
||||||
|
DispatcherTimer timer = new DispatcherTimer()
|
||||||
|
{
|
||||||
|
Interval = TimeSpan.FromSeconds(1)
|
||||||
|
};
|
||||||
|
|
||||||
|
public Chat(string id)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
if (!SecretsVault.IsAuthorized)
|
||||||
|
inputField.Visibility = Visibility.Collapsed;
|
||||||
|
|
||||||
|
chatId = id;
|
||||||
|
timer.Tick += Update;
|
||||||
|
timer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void Update(object sender, object e)
|
||||||
|
{
|
||||||
|
LiveChatMessagesResource.ListRequest request = SecretsVault.Service.LiveChatMessages.List(chatId, "snippet,authorDetails");
|
||||||
|
LiveChatMessageListResponse response = await request.ExecuteAsync();
|
||||||
|
foreach (LiveChatMessage i in response.Items)
|
||||||
|
if(i.Snippet.PublishedAt >= lastInsert)
|
||||||
|
list.Items.Insert(0, new ChatMessage(i));
|
||||||
|
lastInsert = DateTime.Now;
|
||||||
|
timer.Interval = TimeSpan.FromMilliseconds(response.PollingIntervalMillis.Value);
|
||||||
|
timer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Methods.MainPage.GoToChannel(((HyperlinkButton)sender).Tag as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void send_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
newMessage.IsEnabled = false;
|
||||||
|
send.IsEnabled = false;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(newMessage.Text))
|
||||||
|
return;
|
||||||
|
|
||||||
|
LiveChatMessage message = new LiveChatMessage()
|
||||||
|
{
|
||||||
|
Snippet = new LiveChatMessageSnippet()
|
||||||
|
{
|
||||||
|
Type = "textMessageEvent",
|
||||||
|
LiveChatId = chatId,
|
||||||
|
TextMessageDetails = new LiveChatTextMessageDetails()
|
||||||
|
{
|
||||||
|
MessageText = newMessage.Text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
LiveChatMessagesResource.InsertRequest request = SecretsVault.Service.LiveChatMessages.Insert(message, "snippet");
|
||||||
|
await request.ExecuteAsync();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
newMessage.Text = string.Empty;
|
||||||
|
newMessage.IsEnabled = true;
|
||||||
|
send.IsEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -73,6 +73,12 @@ namespace FoxTube
|
|||||||
catch { return null; }
|
catch { return null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetPlaylist()
|
||||||
|
{
|
||||||
|
try { return (videoPlaceholder.Content as VideoPage).playlistId; }
|
||||||
|
catch { return null; }
|
||||||
|
}
|
||||||
|
|
||||||
public void SetTitleBar()
|
public void SetTitleBar()
|
||||||
{
|
{
|
||||||
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
|
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace FoxTube.Pages
|
|||||||
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
|
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
|
||||||
|
|
||||||
public string videoId;
|
public string videoId;
|
||||||
string playlistId = null;
|
public string playlistId = null;
|
||||||
public Video item;
|
public Video item;
|
||||||
|
|
||||||
bool wide;
|
bool wide;
|
||||||
@@ -267,9 +267,13 @@ namespace FoxTube.Pages
|
|||||||
liveTimer.Start();
|
liveTimer.Start();
|
||||||
LiveStatsUpdate();
|
LiveStatsUpdate();
|
||||||
|
|
||||||
|
if(string.IsNullOrWhiteSpace(item.LiveStreamingDetails.ActiveLiveChatId))
|
||||||
|
pivot.Items.Remove(commentsPlaceholder);
|
||||||
|
else
|
||||||
|
{
|
||||||
commentsPlaceholder.Header = "Chat";
|
commentsPlaceholder.Header = "Chat";
|
||||||
//TODO: Initialize chat
|
commentsPlaceholder.Content = new Chat(item.LiveStreamingDetails.ActiveLiveChatId);
|
||||||
//TODO: Initialize player
|
}
|
||||||
download.Visibility = Visibility.Collapsed;
|
download.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user