mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-06 21:42:08 +03:00
Fix ViewModel and UI (#10093)
* Fix avalonia ScrollToEnd * Refactor ViewModel
This commit is contained in:
@@ -61,24 +61,22 @@ public partial class ProfilesSelectViewModel : MyReactiveObject, ICloseable
|
||||
SelectFinish();
|
||||
});
|
||||
|
||||
this.WhenAnyValue(
|
||||
x => x.SelectedSub,
|
||||
y => y != null && !y.Remarks.IsNullOrEmpty() && _subIndexId != y.Id)
|
||||
.Subscribe(async c => await SubSelectedChangedAsync(c));
|
||||
this.WhenAnyValue(x => x.SelectedSub)
|
||||
.Where(y => y != null && !y.Remarks.IsNullOrEmpty() && _subIndexId != y.Id)
|
||||
.SubscribeAsync(async _ => await SubSelectedChangedAsync());
|
||||
|
||||
this.WhenAnyValue(
|
||||
x => x.ServerFilter,
|
||||
y => y != null && _serverFilter != y)
|
||||
.Subscribe(async c => await ServerFilterChanged(c));
|
||||
this.WhenAnyValue(x => x.ServerFilter)
|
||||
.Where(y => y != null && _serverFilter != y)
|
||||
.SubscribeAsync(async _ => await ServerFilterChanged());
|
||||
|
||||
// React to ConfigType filter changes
|
||||
this.WhenAnyValue(x => x.FilterExclude)
|
||||
.Skip(1)
|
||||
.Subscribe(async _ => await RefreshServersBiz());
|
||||
.SubscribeAsync(async _ => await RefreshServersBiz());
|
||||
|
||||
this.WhenAnyValue(x => x.FilterConfigTypes)
|
||||
.Skip(1)
|
||||
.Subscribe(async _ => await RefreshServersBiz());
|
||||
.SubscribeAsync(async _ => await RefreshServersBiz());
|
||||
|
||||
#endregion WhenAnyValue && ReactiveCommand
|
||||
|
||||
@@ -128,12 +126,8 @@ public partial class ProfilesSelectViewModel : MyReactiveObject, ICloseable
|
||||
|
||||
#region Servers && Groups
|
||||
|
||||
private async Task SubSelectedChangedAsync(bool c)
|
||||
private async Task SubSelectedChangedAsync()
|
||||
{
|
||||
if (!c)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_subIndexId = SelectedSub?.Id;
|
||||
|
||||
await RefreshServers();
|
||||
@@ -141,12 +135,8 @@ public partial class ProfilesSelectViewModel : MyReactiveObject, ICloseable
|
||||
await ProfilesFocusInteraction.HandleSafe(RxVoid.Default);
|
||||
}
|
||||
|
||||
private async Task ServerFilterChanged(bool c)
|
||||
private async Task ServerFilterChanged()
|
||||
{
|
||||
if (!c)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_serverFilter = ServerFilter;
|
||||
if (_serverFilter.IsNullOrEmpty())
|
||||
{
|
||||
@@ -163,8 +153,7 @@ public partial class ProfilesSelectViewModel : MyReactiveObject, ICloseable
|
||||
{
|
||||
var lstModel = await GetProfileItemsEx(_subIndexId, _serverFilter);
|
||||
|
||||
ProfileItems.Clear();
|
||||
ProfileItems.AddRange(lstModel);
|
||||
ProfileItems.ReplaceRange(lstModel);
|
||||
if (lstModel.Count > 0)
|
||||
{
|
||||
var selected = lstModel.FirstOrDefault(t => t.IndexId == _config.IndexId);
|
||||
@@ -177,8 +166,7 @@ public partial class ProfilesSelectViewModel : MyReactiveObject, ICloseable
|
||||
var subItems = await AppManager.Instance.SubItems();
|
||||
subItems.Insert(0, new SubItem { Remarks = ResUI.AllGroupServers });
|
||||
|
||||
SubItems.Clear();
|
||||
SubItems.AddRange(subItems);
|
||||
SubItems.ReplaceRange(subItems);
|
||||
|
||||
SelectedSub = (_config.SubIndexId.IsNotEmpty()
|
||||
? subItems.FirstOrDefault(t => t.Id == _config.SubIndexId)
|
||||
@@ -298,8 +286,7 @@ public partial class ProfilesSelectViewModel : MyReactiveObject, ICloseable
|
||||
: ProfileItems.OrderByDescending(KeySelector, comparer);
|
||||
|
||||
var list = sorted.ToList();
|
||||
ProfileItems.Clear();
|
||||
ProfileItems.AddRange(list);
|
||||
ProfileItems.ReplaceRange(list);
|
||||
|
||||
_dicHeaderSort[colName] = !asc;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user