New UI (not wired up)

This commit is contained in:
2026-09-22 15:23:39 +03:00 Unverified
parent 8ab8dde837
commit 5cb8eee38c
14 changed files with 426 additions and 54 deletions
+5
View File
@@ -44,4 +44,9 @@ public abstract class Server
{
get; set;
} = false;
public List<string> Tags
{
get; set;
} = [];
}
@@ -14,7 +14,7 @@ namespace WinWARP.Core.Services.Implementations;
public partial class SubscriptionFetcher(IDialogService dialogService) : ISubscriptionFetcher
{
private static readonly HttpClient _httpClient = new HttpClient();
private readonly HttpClient _httpClient = new() { Timeout = TimeSpan.FromSeconds(10) };
private readonly IDialogService _dialogService = dialogService;
public bool IsUrlValid(string subscriptionUrl)
@@ -31,7 +31,6 @@ public partial class SubscriptionFetcher(IDialogService dialogService) : ISubscr
public async Task<Subscription> FetchAsync(string subscriptionUrl)
{
_httpClient.Timeout = TimeSpan.FromSeconds(10);
var subscription = new Subscription
{
Link = subscriptionUrl
@@ -239,7 +238,8 @@ public partial class SubscriptionFetcher(IDialogService dialogService) : ISubscr
{
DefaultTitle = GetServerTitle(title, out var region),
Region = FlagEmojiParser.ExtractCountryCodes(title).FirstOrDefault() ?? string.Empty,
ConnectionString = serverData
ConnectionString = serverData,
Tags = GetTags(serverData)
};
}
else
@@ -250,7 +250,7 @@ public partial class SubscriptionFetcher(IDialogService dialogService) : ISubscr
#endregion
#region Tags
public List<string> GetTags(string connection)
private static List<string> GetTags(string connection)
{
if (string.IsNullOrWhiteSpace(connection)) return null;
@@ -351,7 +351,7 @@ public partial class SubscriptionFetcher(IDialogService dialogService) : ISubscr
yield return transport.ToUpperInvariant();
}
private IEnumerable<string> GetJsonTags(string json)
private static IEnumerable<string> GetJsonTags(string json)
{
throw new NotImplementedException();
}
@@ -9,5 +9,4 @@ public interface ISubscriptionFetcher
{
public bool IsUrlValid(string url);
public Task<Subscription> FetchAsync(string url);
public List<string> GetTags(string connectionString);
}
+1 -1
View File
@@ -14,6 +14,6 @@ public partial class HomeViewModel(INavigationService navigationService) : Obser
[RelayCommand]
private void TestTransition()
{
_navigationService.NavigateTo<SettingsViewModel>();
_navigationService.NavigateTo<SubsSettingsViewModel>();
}
}
+17 -1
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -15,8 +16,11 @@ public abstract partial class ServerItemViewModel : ObservableObject
Id = server.Id;
DefaultTitle = server.DefaultTitle;
Title = server.Title;
ConnectionString = server.ConnectionString;
Region = server.Region;
ConnectionString = server.ConnectionString;
IsDeleted = server.IsDeleted;
IsDisabled = server.IsDisabled;
Tags = new ObservableCollection<string>(server.Tags);
}
public int Id
@@ -68,4 +72,16 @@ public abstract partial class ServerItemViewModel : ObservableObject
}
public ObservableCollection<string> Tags { get; } = [];
[ObservableProperty]
public partial bool IsDeleted
{
get; set;
}
[ObservableProperty]
public partial bool IsDisabled
{
get; set;
}
}
@@ -26,7 +26,7 @@ public partial class SubsSettingsViewModel(ISubscriptionDbService dbService, ISu
}
public ObservableCollection<SubscriptionViewModel> Subscriptions { get; } = [];
public ObservableCollection<ServerItemViewModel> Servers { get; } = [];
public ObservableCollection<StandaloneServerViewModel> Servers { get; } = [];
public async Task LoadSubscriptionsAsync()
{
@@ -37,8 +37,6 @@ public partial class SubsSettingsViewModel(ISubscriptionDbService dbService, ISu
Subscriptions.Add(new SubscriptionViewModel(subscription));
}
Servers.Add(new StandaloneServerViewModel(new StandaloneServer() { Region = "NO", Title = "Not default title", DefaultTitle = "Default title" }) { Tags = { "VLESS", "GRPC", "REALITY" } });
ShowLoadingIndicator = false;
}
@@ -66,13 +64,10 @@ public partial class SubsSettingsViewModel(ISubscriptionDbService dbService, ISu
subscription.Title = customName;
subscription.UpdateInterval = updateInterval;
Subscriptions.Add(new SubscriptionViewModel(subscription));
foreach (var server in subscription.Servers)
{
var serverVM = new SubscriptionServerViewModel(server);
foreach (var tag in _fetcher.GetTags(server.ConnectionString)) serverVM.Tags.Add(tag);
Servers.Add(serverVM);
}
var sub = new SubscriptionViewModel(subscription);
Subscriptions.Add(sub);
ShowLoadingIndicator = false;
}
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -21,6 +22,8 @@ public partial class SubscriptionViewModel : ObservableValidator
Title = subscription.Title;
UpdateInterval = subscription.UpdateInterval;
SupportURL = subscription.SupportURL;
Servers = new ObservableCollection<SubscriptionServerViewModel>(subscription.Servers.Select(s => new SubscriptionServerViewModel(s)));
}
[ObservableProperty]
@@ -30,12 +33,16 @@ public partial class SubscriptionViewModel : ObservableValidator
public partial string WebPage { get; set; }
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(GetTitle))]
[NotifyPropertyChangedFor(nameof(IsNotDefaultTitle))]
public partial string DefaultTitle { get; set; }
[ObservableProperty]
public partial int DefaultUpdateInterval { get; set; }
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(GetTitle))]
[NotifyPropertyChangedFor(nameof(IsNotDefaultTitle))]
public partial string Title { get; set; }
[ObservableProperty]
@@ -63,4 +70,70 @@ public partial class SubscriptionViewModel : ObservableValidator
{
return IsDirty && !HasErrors;
}
public ObservableCollection<SubscriptionServerViewModel> Servers
{
get; set;
}
[RelayCommand]
public async Task DeleteAsync()
{
}
public async Task EditNameAsync()
{
}
[ObservableProperty]
public partial bool IsNameEditing
{
get; set;
} = false;
[RelayCommand]
public void EditName()
{
if (IsNameEditing)
EditNameAsync();
IsNameEditing = !IsNameEditing;
}
[ObservableProperty]
public partial bool IsDeleted
{
get; set;
}
[ObservableProperty]
public partial bool IsDisabled
{
get; set;
}
public string GetUidForNameEditing(bool isNameEditing)
{
if (isNameEditing) return "ServerListElementMenuFlyoutSave";
else return "ServerListElementMenuFlyoutEdit";
}
public string GetGlyphForNameEditing(bool isNameEditing)
{
if (isNameEditing) return "\uE792";
else return "\uE70F";
}
public string GetTitle
{
get => string.IsNullOrEmpty(Title) ? (string.IsNullOrEmpty(DefaultTitle) ? string.Empty : DefaultTitle) : Title;
set => throw new InvalidOperationException();
}
public bool IsNotDefaultTitle
{
get => (!string.IsNullOrEmpty(Title) && Title != DefaultTitle);
set => throw new InvalidOperationException();
}
}