mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-27 18:42:52 +00:00
Sort
This commit is contained in:
parent
4d23911bfb
commit
f2e27d2d6f
1 changed files with 49 additions and 13 deletions
|
|
@ -67,20 +67,56 @@ public class ProfilesSelectViewModel(Func<EViewAction, object?, Task<bool>>? upd
|
|||
|
||||
public Task SortServer(string colName)
|
||||
{
|
||||
_ = colName;
|
||||
//if (colName.IsNullOrEmpty())
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
if (colName.IsNullOrEmpty())
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
var prop = typeof(ProfileItemModel).GetProperty(colName);
|
||||
if (prop == null)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
_dicHeaderSort.TryAdd(colName, true);
|
||||
var asc = _dicHeaderSort[colName];
|
||||
|
||||
var comparer = Comparer<object?>.Create((a, b) =>
|
||||
{
|
||||
if (ReferenceEquals(a, b))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (a is null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (b is null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (a.GetType() == b.GetType() && a is IComparable ca)
|
||||
{
|
||||
return ca.CompareTo(b);
|
||||
}
|
||||
return string.Compare(a.ToString(), b.ToString(), StringComparison.OrdinalIgnoreCase);
|
||||
});
|
||||
|
||||
object? KeySelector(ProfileItemModel x)
|
||||
{
|
||||
return prop.GetValue(x);
|
||||
}
|
||||
|
||||
IEnumerable<ProfileItemModel> sorted = asc
|
||||
? ProfileItems.OrderBy(KeySelector, comparer)
|
||||
: ProfileItems.OrderByDescending(KeySelector, comparer);
|
||||
|
||||
var list = sorted.ToList();
|
||||
ProfileItems.Clear();
|
||||
ProfileItems.AddRange(list);
|
||||
|
||||
_dicHeaderSort[colName] = !asc;
|
||||
|
||||
//_dicHeaderSort.TryAdd(colName, true);
|
||||
//_dicHeaderSort.TryGetValue(colName, out bool asc);
|
||||
//if (await ConfigHandler.SortServers(_config, _config.SubIndexId, colName, asc) != 0)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//_dicHeaderSort[colName] = !asc;
|
||||
//await RefreshServers();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue