Archived
1
0
This commit is contained in:
Michael Gordeev
2018-09-23 20:39:25 +03:00
parent 8bb0a0e11b
commit 559b776756
2 changed files with 40 additions and 49 deletions
+2 -4
View File
@@ -77,6 +77,7 @@
</StackPanel>
</Button>
</StackPanel>
<ProgressBar Grid.Row="2" VerticalAlignment="Bottom" IsIndeterminate="True" Visibility="Collapsed" Name="commentsLoading"/>
</Grid>
</Grid>
@@ -91,9 +92,6 @@
Content="&#xE122;" />
<ProgressBar Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" IsIndeterminate="True" Foreground="Red" Name="sending" Visibility="Collapsed"/>
<StackPanel Grid.Row="2" Name="repliesPlaceholder">
<StackPanel Margin="60,0,0,0" Name="replies"/>
<local:ShowMore Clicked="more_Click"/>
</StackPanel>
<StackPanel Grid.Row="2" Margin="60,0,0,0" Name="replies"/>
</Grid>
</UserControl>
+38 -45
View File
@@ -26,21 +26,18 @@ namespace FoxTube.Controls
public enum CommentType { TopLevel, Reply }
public sealed partial class CommentCard : UserControl
{
ShowMore more;
Comment item;
CommentThread thread;
bool repliesLoaded = false;
CommentType type = CommentType.TopLevel;
string NextPageToken;
public CommentCard(CommentThread comment)
{
this.InitializeComponent();
more = repliesPlaceholder.Children[1] as ShowMore;
Initialize(comment);
}
public async void Initialize(CommentThread comment)
public void Initialize(CommentThread comment)
{
item = comment.Snippet.TopLevelComment;
thread = comment;
@@ -67,24 +64,6 @@ namespace FoxTube.Controls
try { avatar.ProfilePicture = new BitmapImage(new Uri(comment.Snippet.TopLevelComment.Snippet.AuthorProfileImageUrl)); }
catch { }
if(comment.Snippet.TotalReplyCount > 0)
{
var request = SecretsVault.Service.Comments.List("snippet");
request.ParentId = item.Id;
request.TextFormat = CommentsResource.ListRequest.TextFormatEnum.PlainText;
request.MaxResults = 10;
var response = await request.ExecuteAsync();
if (response.NextPageToken != null)
NextPageToken = response.NextPageToken;
else
more.Visibility = Visibility.Collapsed;
foreach (Comment c in response.Items.Reverse())
replies.Children.Add(new CommentCard(c));
}
}
public CommentCard(Comment comment)
@@ -125,10 +104,45 @@ namespace FoxTube.Controls
grid.RowDefinitions[1].Height = new GridLength(0);
}
private void showReplies_Click(object sender, RoutedEventArgs e)
private async void showReplies_Click(object sender, RoutedEventArgs e)
{
if (grid.RowDefinitions[2].Height == new GridLength(0))
{
if(type == CommentType.TopLevel && !repliesLoaded)
{
commentsLoading.Visibility = Visibility.Visible;
var request = SecretsVault.Service.Comments.List("snippet");
request.ParentId = item.Id;
request.TextFormat = CommentsResource.ListRequest.TextFormatEnum.PlainText;
request.MaxResults = 50;
string token;
IList<Comment> list = new List<Comment>();
var response = await request.ExecuteAsync();
token = response.NextPageToken;
foreach (Comment i in response.Items)
list.Add(i);
while(token != null)
{
request.PageToken = token;
response = await request.ExecuteAsync();
token = response.NextPageToken;
foreach (Comment i in response.Items)
list.Add(i);
}
foreach (Comment c in list.Reverse())
replies.Children.Add(new CommentCard(c));
repliesLoaded = true;
commentsLoading.Visibility = Visibility.Collapsed;
}
grid.RowDefinitions[2].Height = GridLength.Auto;
}
else
grid.RowDefinitions[2].Height = new GridLength(0);
}
@@ -138,27 +152,6 @@ namespace FoxTube.Controls
Methods.MainPage.GoToChannel(item.Snippet.AuthorChannelId.ToString().Split('"')[3]);
}
private async void more_Click()
{
var request = SecretsVault.NoAuthService.Comments.List("snippet");
request.ParentId = item.Id;
request.MaxResults = 10;
request.PageToken = NextPageToken;
request.TextFormat = CommentsResource.ListRequest.TextFormatEnum.PlainText;
var response = await request.ExecuteAsync();
foreach (Comment c in response.Items.Reverse())
replies.Children.Add(new CommentCard(c));
if (response.NextPageToken != null)
{
NextPageToken = response.NextPageToken;
more.Complete();
}
else
more.Complete(true);
}
private void reply_TextChanged(object sender, TextChangedEventArgs e)
{
if (reply.Text.Length == 0)