在 `MovingInfo.cs` 中: * 添加了类注释 `/// <summary>动态信息</summary>`。 * 将 `Data` 类重命名为 `MovingInfo`,并添加了属性 `Code`、`Message` 和 `Data`。 * 将 `Data` 类中的 `name` 字段重命名为 `Id`,并添加了多个属性:`Account`、`Content`、`Visible`、`Time`、`Location`、`UserName`、`HeadIcon`、`Email`、`Permission`、`LoginTime`、`Gender` 和 `Enable`。 在 `ItemView.xaml` 中: * 添加了 `xmlns:DataType="datalist:MovingInfo"` 命名空间。 * 修改了 `Ellipse.Fill` 的 `ImageBrush`,将 `ImageSource` 从固定路径改为绑定 `HeadIcon`。 * 修改了 `TextBlock` 的 `Text` 属性,绑定 `UserName` 和 `Time`。 * 修改了 `TextBlock` 的 `Text` 属性,绑定 `Content`。 在 `ConcernPage.xaml.cs` 中: * 将 `ObservableCollection<CommunityList.Data>` 和 `ObservableCollection<MovingInfo.Data>` 分别修改为 `ObservableCollection<CommunityList.Data>` 和 `ObservableCollection<MovingInfo.DynamicRecord>`。 * 修改了 `dongtaixiaoxi` 方法,添加了 `account` 和 `ALL` 参数,并根据 `ALL` 参数调用不同的 API 获取数据。 * 在 `ListViewA_SelectionChanged` 方法中,修改了调用 `dongtaixiaoxi` 方法时传递的参数。 在 `Dynamic.cs` 中: * 新增了 `Dynamic` 类,并添加了两个静态方法 `GetAllDynamic` 和 `Getlist`,用于异步获取动态信息。
170 lines
4.8 KiB
C#
170 lines
4.8 KiB
C#
using System.Collections.ObjectModel;
|
|
using System.Diagnostics;
|
|
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using Newtonsoft.Json;
|
|
using RustTools.DataList;
|
|
using RustTools.muqing;
|
|
using RustTools.ViewModels;
|
|
|
|
// To learn more about WinUI, the WinUI project structure,
|
|
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
|
|
|
namespace RustTools.Views;
|
|
|
|
/// <summary>
|
|
/// 动态界面
|
|
/// </summary>
|
|
public sealed partial class ConcernPage : Page
|
|
{
|
|
public ConcernViewModel ViewModels
|
|
{
|
|
get; set;
|
|
}
|
|
public ObservableCollection<CommunityList.Data> communitylist = [];
|
|
public ObservableCollection<MovingInfo.DynamicRecord> MovingInfoList = [];
|
|
private bool IsLogin = false;
|
|
public ConcernPage()
|
|
{
|
|
ViewModels = App.GetService<ConcernViewModel>();
|
|
InitializeComponent();
|
|
//如果未登陆
|
|
|
|
Init();
|
|
if (IsLogin)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private async void Init()
|
|
{
|
|
try
|
|
{
|
|
|
|
var ini = new IniHelper();
|
|
ini.Load(IniHelper.FILE.User);
|
|
var account = ini.GetValue(IniHelper.CODE.User, IniHelper.KEY.account);
|
|
var value = await ApiFox.community.getList(account, true, 0);
|
|
//Debug.WriteLine(value);
|
|
if (value == string.Empty) return;
|
|
var response = JsonConvert.DeserializeObject<CommunityList>(value);
|
|
var a = new CommunityList.Data
|
|
{
|
|
UserName = "全部",
|
|
HeadIcon = "/Assets/tool.png",
|
|
Account = account
|
|
};
|
|
communitylist.Add(a);
|
|
foreach (var item in response.data)
|
|
{
|
|
//item.UserName
|
|
item.HeadIcon = item.HeadIcon.Replace("..", wl.api);
|
|
communitylist.Add(item);
|
|
}
|
|
|
|
if (ListViewA.Items.Count > 0)
|
|
{
|
|
ListViewA.SelectedIndex = 0;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.WriteLine(e);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 每个关注的动态消息内容
|
|
/// </summary>
|
|
private void dongtaixiaoxi(string account, bool ALL)
|
|
{
|
|
MovingInfoList.Clear();
|
|
if (account == null)
|
|
{
|
|
return;
|
|
};
|
|
if (ALL)
|
|
{
|
|
ApiFox.Dynamic.GetAllDynamic(account).ContinueWith((task) =>
|
|
{
|
|
var value = task.Result;
|
|
if (string.IsNullOrEmpty(value)) return;
|
|
|
|
// 使用 Newtonsoft.Json 进行反序列化
|
|
var response = JsonConvert.DeserializeObject<MovingInfo>(value);
|
|
|
|
if (response != null && response.Code == 0)
|
|
{
|
|
foreach (var item in response.Data)
|
|
{
|
|
// 替换头像链接中的相对路径为绝对路径
|
|
item.HeadIcon = item.HeadIcon.Replace("..", wl.api);
|
|
|
|
// 将处理后的记录添加到 ObservableCollection 中
|
|
MovingInfoList.Add(item);
|
|
}
|
|
}
|
|
else if (response != null)
|
|
{
|
|
Console.WriteLine($"Error: {response.Message}");
|
|
}
|
|
}, TaskScheduler.FromCurrentSynchronizationContext()); // 确保UI线程更新
|
|
}
|
|
else
|
|
{
|
|
ApiFox.Dynamic.Getlist(account).ContinueWith((task) =>
|
|
{
|
|
var value = task.Result;
|
|
if (value == string.Empty) return;
|
|
var response = JsonConvert.DeserializeObject<MovingInfo>(value);
|
|
foreach (var item in response.Data)
|
|
{
|
|
item.HeadIcon = item.HeadIcon.Replace("..", wl.api);
|
|
MovingInfoList.Add(item);
|
|
}
|
|
},TaskScheduler.FromCurrentSynchronizationContext());
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
{
|
|
|
|
var height = ActualHeight; // 确保使用页面的实际高度
|
|
|
|
// 检查是否为有效的数值
|
|
if (!double.IsNaN(height) && !double.IsInfinity(height) && height > 16)
|
|
{
|
|
ListViewA.Height = height - 36;
|
|
ListViewB.Height = height - 16;
|
|
}
|
|
else
|
|
{
|
|
ListViewA.Height = 500; // 或者其他适当的默认值
|
|
ListViewB.Height = 500; // 或者其他适当的默认值
|
|
}
|
|
}
|
|
|
|
private void ItemsView_ItemInvoked(ItemsView sender, ItemsViewItemInvokedEventArgs args)
|
|
{
|
|
gj.sc("You invoked ");
|
|
}
|
|
private void ListViewA_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
// 获取当前选中的项目
|
|
var selectedItem = ListViewA.SelectedItem;
|
|
var data = selectedItem as CommunityList.Data;
|
|
gj.sc(data?.Account);
|
|
dongtaixiaoxi(data?.Account, data.UserName.Equals("全部"));
|
|
}
|
|
}
|