140 lines
3.4 KiB
C#
140 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Text;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using WinWARP.Core.Models.Entities;
|
|
|
|
namespace WinWARP.Core.ViewModels.Wrappers;
|
|
|
|
public partial class SubscriptionViewModel : ObservableValidator
|
|
{
|
|
private readonly Subscription _subscription;
|
|
|
|
public SubscriptionViewModel(Subscription subscription)
|
|
{
|
|
_subscription = subscription;
|
|
Link = subscription.Link;
|
|
WebPage = subscription.WebPage;
|
|
DefaultTitle = subscription.DefaultTitle;
|
|
DefaultUpdateInterval = subscription.DefaultUpdateInterval;
|
|
Title = subscription.Title;
|
|
UpdateInterval = subscription.UpdateInterval;
|
|
SupportURL = subscription.SupportURL;
|
|
|
|
Servers = new ObservableCollection<SubscriptionServerViewModel>(subscription.Servers.Select(s => new SubscriptionServerViewModel(s)));
|
|
}
|
|
|
|
[ObservableProperty]
|
|
public partial string Link { get; set; }
|
|
|
|
[ObservableProperty]
|
|
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]
|
|
public partial int UpdateInterval { get; set; }
|
|
|
|
[ObservableProperty]
|
|
public partial string SupportURL { get; set; }
|
|
|
|
[ObservableProperty]
|
|
[NotifyCanExecuteChangedFor(nameof(SaveCommand))]
|
|
public partial bool IsDirty { get; private set; }
|
|
|
|
[RelayCommand(CanExecute = nameof(CanSave))]
|
|
private void Save()
|
|
{
|
|
ValidateAllProperties();
|
|
|
|
if (!HasErrors)
|
|
{
|
|
// Save logic here
|
|
}
|
|
}
|
|
|
|
private bool CanSave()
|
|
{
|
|
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();
|
|
}
|
|
}
|