Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
完成支持子回复的集合(未测试)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiichiamane committed Sep 28, 2019
1 parent 5688d1a commit 58e2a26
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
27 changes: 27 additions & 0 deletions PixivFSUWP/Converters/ChildrenCommentVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace PixivFSUWP.Converters
{
public class ChildrenCommentVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var childrenComments = value as ObservableCollection<ViewModels.CommentViewModel>;
if (childrenComments == null) return Visibility.Collapsed;
if (childrenComments.Count == 0) return Visibility.Collapsed;
return Visibility.Visible;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
44 changes: 41 additions & 3 deletions PixivFSUWP/Data/CommentsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CommentsCollection : ObservableCollection<ViewModels.CommentViewMod
bool _emergencyStop = false;
EventWaitHandle pause = new ManualResetEvent(true);
readonly string illustid;
List<ViewModels.CommentViewModel> ChildrenComments = new List<ViewModels.CommentViewModel>();

public CommentsCollection(string IllustID) => illustid = IllustID;

Expand Down Expand Up @@ -98,9 +99,46 @@ protected async Task<LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c
}
Data.IllustCommentItem recommendi = Data.IllustCommentItem.FromJsonValue(recillust.GetObject());
var recommendmodel = ViewModels.CommentViewModel.FromItem(recommendi);
//await recommendmodel.LoadAvatarAsync();
Add(recommendmodel);
toret.Count++;
//查找是否存在子回复
var children = from item
in ChildrenComments
where item.ParentID == recommendmodel.ID
select item;
if (children.Count() > 0)
{
//存在子回复
recommendmodel.ChildrenComments = new ObservableCollection<ViewModels.CommentViewModel>();
foreach (var child in children)
{
if (child.ChildrenComments != null)
{
foreach (var childschild in child.ChildrenComments)
{
childschild.Comment = string.Format("RE {0}: {1}",
child.UserName, childschild.Comment);
recommendmodel.ChildrenComments.Add(childschild);
}
child.ChildrenComments.Clear();
child.ChildrenComments = null;
GC.Collect();
}
recommendmodel.ChildrenComments.Add(child);
ChildrenComments.Remove(child);
}
}
//检查自己是不是子回复
if (recommendmodel.ParentID != -1)
{
//自己也是子回复
ChildrenComments.Add(recommendmodel);
}
else
{
//自己并非子回复
//await recommendmodel.LoadAvatarAsync();
Add(recommendmodel);
toret.Count++;
}
}
return toret;
}
Expand Down
1 change: 0 additions & 1 deletion PixivFSUWP/Data/IllustCommentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class IllustCommentItem
public string UserAccount { get; set; }
public string AvatarUrl { get; set; }
public int ParentCommentID { get; set; }
public List<int> ChildrenComments { get; set; } = null;

public static IllustCommentItem FromJsonValue(JsonObject Source)
{
Expand Down
1 change: 1 addition & 0 deletions PixivFSUWP/PixivFSUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<Compile Include="Controls\WaterfallContentPanel.cs" />
<Compile Include="Controls\WaterfallListView.cs" />
<Compile Include="Converters\BookmarkHeartVisibilityConverter.cs" />
<Compile Include="Converters\ChildrenCommentVisibilityConverter.cs" />
<Compile Include="Converters\MultiPageVisibilityConverter.cs" />
<Compile Include="Data\Backstack.cs" />
<Compile Include="Data\BigImageDetail.cs" />
Expand Down
9 changes: 8 additions & 1 deletion PixivFSUWP/ViewModels/CommentViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -9,12 +10,16 @@ namespace PixivFSUWP.ViewModels
{
public class CommentViewModel
{
public int ID { get; set; }
public string Comment { get; set; }
public string UserName { get; set; }
public string UserAccount { get; set; }
private string _dateTime { get; set; }
public string AvatarUrl { get; set; }
//public BitmapImage Avatar { get; set; }
public int ParentID { get; set; }
public ObservableCollection<CommentViewModel> ChildrenComments { get; set; } = null;

public string DateTime
{
get => DateTimeOffset.Parse(_dateTime).LocalDateTime.ToString();
Expand All @@ -27,11 +32,13 @@ public static CommentViewModel FromItem(Data.IllustCommentItem Item)
{
return new CommentViewModel()
{
ID = Item.ID,
Comment = Item.Comment,
UserName = Item.UserName,
UserAccount = "@" + Item.UserAccount,
_dateTime = Item.DateTime,
AvatarUrl = Item.AvatarUrl
AvatarUrl = Item.AvatarUrl,
ParentID = Item.ParentCommentID
};
}
}
Expand Down

0 comments on commit 58e2a26

Please sign in to comment.