2024-05-04 15:35:32 +00:00
|
|
|
|
using System;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
using System.Diagnostics;
|
2024-06-26 22:04:50 +00:00
|
|
|
|
using System.Linq;
|
2024-05-04 15:35:32 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2024-06-21 01:49:44 +00:00
|
|
|
|
using Avalonia.Platform.Storage;
|
2024-05-04 15:35:32 +00:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
|
using CRD.Downloader;
|
2024-05-11 11:08:24 +00:00
|
|
|
|
using CRD.Utils;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
using CRD.Utils.Sonarr;
|
2024-06-26 22:04:50 +00:00
|
|
|
|
using CRD.Utils.Structs;
|
|
|
|
|
using CRD.Utils.Structs.History;
|
2024-05-04 15:35:32 +00:00
|
|
|
|
using CRD.Views;
|
|
|
|
|
using ReactiveUI;
|
|
|
|
|
|
|
|
|
|
namespace CRD.ViewModels;
|
|
|
|
|
|
|
|
|
|
public partial class SeriesPageViewModel : ViewModelBase{
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public HistorySeries _selectedSeries;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
|
2024-05-11 11:08:24 +00:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public static bool _editMode;
|
|
|
|
|
|
2024-05-25 22:02:45 +00:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public static bool _sonarrAvailable;
|
|
|
|
|
|
2024-06-21 01:49:44 +00:00
|
|
|
|
private IStorageProvider _storageProvider;
|
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
public SeriesPageViewModel(){
|
|
|
|
|
_selectedSeries = Crunchyroll.Instance.SelectedSeries;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
if (_selectedSeries.ThumbnailImage == null){
|
|
|
|
|
_selectedSeries.LoadImage();
|
|
|
|
|
}
|
2024-06-26 22:04:50 +00:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(SelectedSeries.SonarrSeriesId) && Crunchyroll.Instance.CrunOptions.SonarrProperties != null){
|
|
|
|
|
SonarrAvailable = SelectedSeries.SonarrSeriesId.Length > 0 && Crunchyroll.Instance.CrunOptions.SonarrProperties.SonarrEnabled;
|
|
|
|
|
}else{
|
2024-05-25 22:02:45 +00:00
|
|
|
|
SonarrAvailable = false;
|
|
|
|
|
}
|
2024-06-26 22:04:50 +00:00
|
|
|
|
|
2024-05-25 22:02:45 +00:00
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
}
|
2024-06-21 01:49:44 +00:00
|
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
|
public async Task OpenFolderDialogAsync(HistorySeason? season){
|
|
|
|
|
if (_storageProvider == null){
|
|
|
|
|
Console.Error.WriteLine("StorageProvider must be set before using the dialog.");
|
|
|
|
|
throw new InvalidOperationException("StorageProvider must be set before using the dialog.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = await _storageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions{
|
|
|
|
|
Title = "Select Folder"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (result.Count > 0){
|
|
|
|
|
var selectedFolder = result[0];
|
|
|
|
|
// Do something with the selected folder path
|
|
|
|
|
Console.WriteLine($"Selected folder: {selectedFolder.Path.LocalPath}");
|
|
|
|
|
|
|
|
|
|
if (season != null){
|
|
|
|
|
season.SeasonDownloadPath = selectedFolder.Path.LocalPath;
|
|
|
|
|
} else{
|
|
|
|
|
SelectedSeries.SeriesDownloadPath = selectedFolder.Path.LocalPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CfgManager.WriteJsonToFile(CfgManager.PathCrHistory, Crunchyroll.Instance.HistoryList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetStorageProvider(IStorageProvider storageProvider){
|
|
|
|
|
_storageProvider = storageProvider ?? throw new ArgumentNullException(nameof(storageProvider));
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-26 22:04:50 +00:00
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public async Task UpdateData(string? season){
|
|
|
|
|
await SelectedSeries.FetchData(season);
|
2024-06-27 20:52:12 +00:00
|
|
|
|
|
|
|
|
|
// MessageBus.Current.SendMessage(new NavigationMessage(typeof(SeriesPageViewModel), false, true));
|
2024-05-04 15:35:32 +00:00
|
|
|
|
}
|
2024-05-25 22:02:45 +00:00
|
|
|
|
|
2024-05-11 11:08:24 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public void RemoveSeason(string? season){
|
2024-06-26 22:04:50 +00:00
|
|
|
|
HistorySeason? objectToRemove = SelectedSeries.Seasons.FirstOrDefault(se => se.SeasonId == season) ?? null;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
if (objectToRemove != null){
|
2024-05-11 11:08:24 +00:00
|
|
|
|
SelectedSeries.Seasons.Remove(objectToRemove);
|
|
|
|
|
}
|
2024-05-25 22:02:45 +00:00
|
|
|
|
|
|
|
|
|
CfgManager.WriteJsonToFile(CfgManager.PathCrHistory, Crunchyroll.Instance.HistoryList);
|
|
|
|
|
MessageBus.Current.SendMessage(new NavigationMessage(typeof(SeriesPageViewModel), false, true));
|
2024-05-11 11:08:24 +00:00
|
|
|
|
}
|
2024-05-25 22:02:45 +00:00
|
|
|
|
|
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public void NavBack(){
|
|
|
|
|
SelectedSeries.UpdateNewEpisodes();
|
2024-05-25 22:02:45 +00:00
|
|
|
|
MessageBus.Current.SendMessage(new NavigationMessage(null, true, false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-06-26 22:04:50 +00:00
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
}
|