diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs
index 5f9a99f1..ae775507 100644
--- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs
+++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs
@@ -471,12 +471,12 @@ public static class ConfigHandler
/// Supports moving to top, up, down, bottom or specific position
///
/// Current configuration
- /// List of server profiles
+ /// List of server profile index ids
/// Index of the server to move
/// Direction to move the server
/// Target position when using EMove.Position
/// 0 if successful, -1 if failed
- public static async Task MoveServer(Config config, List lstProfile, int index, EMove eMove, int pos = -1)
+ public static async Task MoveServer(Config config, List lstProfile, int index, EMove eMove, int pos = -1)
{
var count = lstProfile.Count;
if (index < 0 || index > lstProfile.Count - 1)
@@ -486,7 +486,7 @@ public static class ConfigHandler
for (var i = 0; i < lstProfile.Count; i++)
{
- ProfileExManager.Instance.SetSort(lstProfile[i].IndexId, (i + 1) * 10);
+ ProfileExManager.Instance.SetSort(lstProfile[i], (i + 1) * 10);
}
var sort = 0;
@@ -498,7 +498,7 @@ public static class ConfigHandler
{
return 0;
}
- sort = ProfileExManager.Instance.GetSort(lstProfile.First().IndexId) - 1;
+ sort = ProfileExManager.Instance.GetSort(lstProfile.First()) - 1;
break;
}
@@ -508,7 +508,7 @@ public static class ConfigHandler
{
return 0;
}
- sort = ProfileExManager.Instance.GetSort(lstProfile[index - 1].IndexId) - 1;
+ sort = ProfileExManager.Instance.GetSort(lstProfile[index - 1]) - 1;
break;
}
@@ -519,7 +519,7 @@ public static class ConfigHandler
{
return 0;
}
- sort = ProfileExManager.Instance.GetSort(lstProfile[index + 1].IndexId) + 1;
+ sort = ProfileExManager.Instance.GetSort(lstProfile[index + 1]) + 1;
break;
}
@@ -529,7 +529,7 @@ public static class ConfigHandler
{
return 0;
}
- sort = ProfileExManager.Instance.GetSort(lstProfile[^1].IndexId) + 1;
+ sort = ProfileExManager.Instance.GetSort(lstProfile[^1]) + 1;
break;
}
@@ -538,7 +538,7 @@ public static class ConfigHandler
break;
}
- ProfileExManager.Instance.SetSort(lstProfile[index].IndexId, sort);
+ ProfileExManager.Instance.SetSort(lstProfile[index], sort);
return await Task.FromResult(0);
}
diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
index f173f58f..8cc01f02 100644
--- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
@@ -15,7 +15,6 @@ public partial class ProfilesViewModel : MyReactiveObject
#region private prop
- private List _lstProfile;
private string _serverFilter = string.Empty;
private readonly Dictionary _dicHeaderSort = new();
private SpeedtestService? _speedtestService;
@@ -362,7 +361,6 @@ public partial class ProfilesViewModel : MyReactiveObject
public async Task RefreshServersBiz()
{
var lstModel = await GetProfileItemsEx(_config.SubIndexId, _serverFilter);
- _lstProfile = JsonUtils.Deserialize>(JsonUtils.Serialize(lstModel)) ?? [];
ProfileItems.ReplaceRange(lstModel ?? []);
if (lstModel?.Count > 0)
@@ -677,19 +675,15 @@ public partial class ProfilesViewModel : MyReactiveObject
public async Task MoveServer(EMove eMove)
{
- var item = _lstProfile.FirstOrDefault(t => t.IndexId == SelectedProfile.IndexId);
- if (item is null)
+ var lstProfile = ProfileItems?.Select(t => t.IndexId).ToList() ?? [];
+ var index = lstProfile.IndexOf(SelectedProfile.IndexId);
+ if (index < 0)
{
NoticeManager.Instance.Enqueue(ResUI.PleaseSelectServer);
return;
}
- var index = _lstProfile.IndexOf(item);
- if (index < 0)
- {
- return;
- }
- if (await ConfigHandler.MoveServer(_config, _lstProfile, index, eMove) == 0)
+ if (await ConfigHandler.MoveServer(_config, lstProfile, index, eMove) == 0)
{
await RefreshServers();
}
@@ -700,7 +694,8 @@ public partial class ProfilesViewModel : MyReactiveObject
var targetIndex = ProfileItems.IndexOf(targetItem);
if (startIndex >= 0 && targetIndex >= 0 && startIndex != targetIndex)
{
- if (await ConfigHandler.MoveServer(_config, _lstProfile, startIndex, EMove.Position, targetIndex) == 0)
+ var lstProfile = ProfileItems?.Select(t => t.IndexId).ToList() ?? [];
+ if (await ConfigHandler.MoveServer(_config, lstProfile, startIndex, EMove.Position, targetIndex) == 0)
{
await RefreshServers();
}