54 lines
1.6 KiB
C#
54 lines
1.6 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;
|
|
using WinWARP.Core.Services.Interfaces;
|
|
|
|
namespace WinWARP.Core.ViewModels;
|
|
|
|
public partial class SubsSettingsViewModel(ISubscriptionDbService dbService) : ObservableObject
|
|
{
|
|
private readonly ISubscriptionDbService _dbService = dbService;
|
|
|
|
public ObservableCollection<Subscription> Subscriptions { get; } = [];
|
|
|
|
public async Task LoadSubscriptionsAsync()
|
|
{
|
|
Subscriptions.Clear();
|
|
var data = await _dbService.GetSubscriptionsAsync();
|
|
foreach (var subscription in data)
|
|
{
|
|
Subscriptions.Add(subscription);
|
|
}
|
|
}
|
|
|
|
[ObservableProperty]
|
|
[NotifyCanExecuteChangedFor(nameof(AddSubscriptionCommand))]
|
|
public partial string NewSubscriptionLink { get; set; } = string.Empty;
|
|
|
|
[RelayCommand(CanExecute = nameof(CanAddSubscription))]
|
|
public async Task AddSubscriptionAsync()
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(NewSubscriptionLink))
|
|
{
|
|
var subscription = new Subscription
|
|
{
|
|
Link = NewSubscriptionLink,
|
|
Title = "New Subscription",
|
|
UpdateInterval = 60 // Default update interval
|
|
};
|
|
await _dbService.AddSubscriptionAsync(subscription);
|
|
Subscriptions.Add(subscription);
|
|
NewSubscriptionLink = string.Empty;
|
|
}
|
|
}
|
|
|
|
private bool CanAddSubscription()
|
|
{
|
|
return !string.IsNullOrWhiteSpace(NewSubscriptionLink);
|
|
}
|
|
}
|