此次提交主要对代码进行了简化和优化,具体更改如下: 1. 在 `App.xaml` 中,将 `ConCernItem` 的 `DataTemplate` 从 `StackPanel` 改为 `Grid`,并添加了 `Grid.ColumnDefinitions` 和 `Grid.RowDefinitions`。 2. 在 `App.xaml.cs` 中,删除了创建和解压缩 `RustCode` 目录的代码,改为直接从 `Assets` 目录获取 `DataBaseManifest` 文件,并更新了异常处理逻辑。 3. 在 `RustTools.csproj` 中,添加了新的 `PackageReference`,更新了 `RestSharp` 的版本,并注释掉了 `squirrel.windows` 的引用。 4. 在 `PostRwmod.xaml.cs` 中,删除了 `SharpCompress.Common` 和 `TinyPinyin` 的引用。 5. 在 `CodeDataPage.xaml.cs` 中,更新了 `filePath` 的路径,从 `ApplicationData.Current.LocalFolder.Path` 改为 `AppContext.BaseDirectory`。 6. 在 `ConcernPage.xaml` 中,调整了 `StackPanelA` 的 `MinWidth` 属性,并删除了 `StackPanel` 的 `Background` 属性。 7. 在 `ConcernPage.xaml.cs` 中,更新了 `Getlist` 方法的逻辑,增加了对 `response` 的空值和错误码检查。 8. 在 `ModulePage.xaml.cs` 中,删除了 `SharpCompress.Common` 和 `WinRT.Interop` 的引用。 9. 在 `SettingsPage.xaml` 中,更新了 `PersonPicture` 的 `ToolTipService.ToolTip` 属性。 10. 在 `IniHelper.cs` 中,更新了 `Load` 方法的 `filePath` 路径,并添加了目录不存在时创建目录的逻辑。 11. 在 `wj.cs` 中,更新了 `CD` 的路径为 `AppContext.BaseDirectory`,并注释掉了废弃的路径。 12. 在 `config.ini` 中,添加了 `[Settings]` 节点和 `SystemBackdrop=Mica` 设置。 此外,添加了以下新 JSON 文件: 1. `DataBaseManifest.json`:包含数据集的基本信息和数据表的映射。 2. `game_version.json`:包含游戏版本数据。 3. `section.json`:包含铁锈助手节名数据。 4. `value_type.json`:定义了一个名为 "值类型表" 的数据结构,包含多个值类型及其详细信息。
173 lines
4.9 KiB
C#
173 lines
4.9 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);
|
|
if (response != null && response.Code == 0 && response.Data != null)
|
|
{
|
|
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("全部"));
|
|
}
|
|
}
|