Skip to content

Commit

Permalink
⚛ Use ReactiveUI
Browse files Browse the repository at this point in the history
- Packages: ReactiveUI.WPF and ReactiveUI.Events.WPF
- ViewModelBase -> ReactiveObject
  • Loading branch information
database64128 committed Sep 25, 2020
1 parent 68a05a2 commit 56dbf6b
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 90 deletions.
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ $ git clone --recursive https://github.com/database64128/youtube-dl-wpf.git

## License

`youtube-dl-wpf` is licensed under [GPLv3](LICENSE).

[`youtube-dl`](https://github.com/ytdl-org/youtube-dl) is licensed under [The Unlicense](https://github.com/ytdl-org/youtube-dl/blob/master/LICENSE).

[Material Design Themes](https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit) is licensed under [MIT](https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/master/LICENSE).

[`PeanutButter.TinyEventAggregator`](https://github.com/fluffynuts/PeanutButter) is licensed under [BSD-3-Clause License](https://github.com/fluffynuts/PeanutButter/blob/master/LICENSE).

[Roboto Mono](https://fonts.google.com/specimen/Roboto+Mono) is licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
- `youtube-dl-wpf` is licensed under [GPLv3](LICENSE).
- [`youtube-dl`](https://github.com/ytdl-org/youtube-dl) is licensed under [The Unlicense](https://github.com/ytdl-org/youtube-dl/blob/master/LICENSE).
- [Material Design Themes](https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit) is licensed under [MIT](https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/master/LICENSE).
- [`PeanutButter.TinyEventAggregator`](https://github.com/fluffynuts/PeanutButter) is licensed under [BSD-3-Clause License](https://github.com/fluffynuts/PeanutButter/blob/master/LICENSE).
- [Roboto Mono](https://fonts.google.com/specimen/Roboto+Mono) is licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
- [ReactiveUI](https://github.com/reactiveui/ReactiveUI) is licensed under [MIT](https://github.com/reactiveui/ReactiveUI/blob/main/LICENSE).
10 changes: 6 additions & 4 deletions YoutubeDl.Wpf/ViewModels/DrawerItem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace YoutubeDl.Wpf.ViewModels
using ReactiveUI;

namespace YoutubeDl.Wpf.ViewModels
{
public class DrawerItem : ViewModelBase
public class DrawerItem : ReactiveObject
{
private string _name;
private object _content;
Expand All @@ -14,13 +16,13 @@ public DrawerItem(string name, object content)
public string Name
{
get => _name;
set => SetProperty(ref _name, value);
set => this.RaiseAndSetIfChanged(ref _name, value);
}

public object Content
{
get => _content;
set => SetProperty(ref _content, value);
set => this.RaiseAndSetIfChanged(ref _content, value);
}
}
}
59 changes: 30 additions & 29 deletions YoutubeDl.Wpf/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MaterialDesignThemes.Wpf;
using PeanutButter.TinyEventAggregator;
using ReactiveUI;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
Expand All @@ -13,7 +14,7 @@

namespace YoutubeDl.Wpf.ViewModels
{
public class HomeViewModel : ViewModelBase
public class HomeViewModel : ReactiveObject
{
public HomeViewModel(ISnackbarMessageQueue snackbarMessageQueue)
{
Expand Down Expand Up @@ -165,14 +166,14 @@ public HomeViewModel(ISnackbarMessageQueue snackbarMessageQueue)
/// </summary>
private void ApplySettings()
{
SetProperty(ref _container, _settings.Container);
SetProperty(ref _format, _settings.Format);
SetProperty(ref _addMetadata, _settings.AddMetadata);
SetProperty(ref _downloadThumbnail, _settings.DownloadThumbnail);
SetProperty(ref _downloadSubtitles, _settings.DownloadSubtitles);
SetProperty(ref _downloadPlaylist, _settings.DownloadPlaylist);
SetProperty(ref _useCustomPath, _settings.UseCustomPath);
SetProperty(ref _downloadPath, _settings.DownloadPath);
this.RaiseAndSetIfChanged(ref _container, _settings.Container);
this.RaiseAndSetIfChanged(ref _format, _settings.Format);
this.RaiseAndSetIfChanged(ref _addMetadata, _settings.AddMetadata);
this.RaiseAndSetIfChanged(ref _downloadThumbnail, _settings.DownloadThumbnail);
this.RaiseAndSetIfChanged(ref _downloadSubtitles, _settings.DownloadSubtitles);
this.RaiseAndSetIfChanged(ref _downloadPlaylist, _settings.DownloadPlaylist);
this.RaiseAndSetIfChanged(ref _useCustomPath, _settings.UseCustomPath);
this.RaiseAndSetIfChanged(ref _downloadPath, _settings.DownloadPath);

if (_container == "Auto")
EnableFormatSelection = true;
Expand Down Expand Up @@ -490,7 +491,7 @@ public string Link
get => _link;
set
{
SetProperty(ref _link, value);
this.RaiseAndSetIfChanged(ref _link, value);
_startDownload.InvokeCanExecuteChanged();
_listFormats.InvokeCanExecuteChanged();
if (String.IsNullOrEmpty(_settings.DlPath))
Expand All @@ -505,12 +506,12 @@ public string Container
get => _container;
set
{
SetProperty(ref _container, value);
this.RaiseAndSetIfChanged(ref _container, value);
if (_container == "Auto")
EnableFormatSelection = true;
else
{
SetProperty(ref _format, "Auto", "Format");
this.RaiseAndSetIfChanged(ref _format, "Auto", "Format");
_settings.Format = _format;
EnableFormatSelection = false;
}
Expand All @@ -528,7 +529,7 @@ public string Format
get => _format;
set
{
SetProperty(ref _format, value);
this.RaiseAndSetIfChanged(ref _format, value);
_startDownload.InvokeCanExecuteChanged();
_listFormats.InvokeCanExecuteChanged();
_settings.Format = _format;
Expand All @@ -539,15 +540,15 @@ public string Format
public bool EnableFormatSelection
{
get => _enableFormatSelection;
set => SetProperty(ref _enableFormatSelection, value);
set => this.RaiseAndSetIfChanged(ref _enableFormatSelection, value);
}

public bool AddMetadata
{
get => _addMetadata;
set
{
SetProperty(ref _addMetadata, value);
this.RaiseAndSetIfChanged(ref _addMetadata, value);
_settings.AddMetadata = _addMetadata;
PublishSettings();
}
Expand All @@ -558,7 +559,7 @@ public bool DownloadThumbnail
get => _downloadThumbnail;
set
{
SetProperty(ref _downloadThumbnail, value);
this.RaiseAndSetIfChanged(ref _downloadThumbnail, value);
_settings.DownloadThumbnail = _downloadThumbnail;
PublishSettings();
}
Expand All @@ -569,7 +570,7 @@ public bool DownloadSubtitles
get => _downloadSubtitles;
set
{
SetProperty(ref _downloadSubtitles, value);
this.RaiseAndSetIfChanged(ref _downloadSubtitles, value);
_settings.DownloadSubtitles = _downloadSubtitles;
PublishSettings();
}
Expand All @@ -580,7 +581,7 @@ public bool DownloadPlaylist
get => _downloadPlaylist;
set
{
SetProperty(ref _downloadPlaylist, value);
this.RaiseAndSetIfChanged(ref _downloadPlaylist, value);
_settings.DownloadPlaylist = _downloadPlaylist;
PublishSettings();
}
Expand All @@ -591,7 +592,7 @@ public bool UseCustomPath
get => _useCustomPath;
set
{
SetProperty(ref _useCustomPath, value);
this.RaiseAndSetIfChanged(ref _useCustomPath, value);
_settings.UseCustomPath = _useCustomPath;
PublishSettings();
}
Expand All @@ -602,7 +603,7 @@ public string DownloadPath
get => _downloadPath;
set
{
SetProperty(ref _downloadPath, value);
this.RaiseAndSetIfChanged(ref _downloadPath, value);
_openFolder.InvokeCanExecuteChanged();
_settings.DownloadPath = _downloadPath;
PublishSettings();
Expand All @@ -612,55 +613,55 @@ public string DownloadPath
public string Output
{
get => _output;
set => SetProperty(ref _output, value);
set => this.RaiseAndSetIfChanged(ref _output, value);
}

public bool FreezeButton
{
get => _freezeButton;
set => SetProperty(ref _freezeButton, value);
set => this.RaiseAndSetIfChanged(ref _freezeButton, value);
}

public bool DownloadButtonProgressIndeterminate
{
get => _downloadButtonProgressIndeterminate;
set => SetProperty(ref _downloadButtonProgressIndeterminate, value);
set => this.RaiseAndSetIfChanged(ref _downloadButtonProgressIndeterminate, value);
}

public bool FormatsButtonProgressIndeterminate
{
get => _formatsButtonProgressIndeterminate;
set => SetProperty(ref _formatsButtonProgressIndeterminate, value);
set => this.RaiseAndSetIfChanged(ref _formatsButtonProgressIndeterminate, value);
}

public double DownloadButtonProgressPercentageValue
{
get => _downloadButtonProgressPercentageValue;
set => SetProperty(ref _downloadButtonProgressPercentageValue, value);
set => this.RaiseAndSetIfChanged(ref _downloadButtonProgressPercentageValue, value);
}

public string DownloadButtonProgressPercentageString
{
get => _downloadButtonProgressPercentageString;
set => SetProperty(ref _downloadButtonProgressPercentageString, value);
set => this.RaiseAndSetIfChanged(ref _downloadButtonProgressPercentageString, value);
}

public string FileSizeString
{
get => _fileSizeString;
set => SetProperty(ref _fileSizeString, value);
set => this.RaiseAndSetIfChanged(ref _fileSizeString, value);
}

public string DownloadSpeedString
{
get => _downloadSpeedString;
set => SetProperty(ref _downloadSpeedString, value);
set => this.RaiseAndSetIfChanged(ref _downloadSpeedString, value);
}

public string DownloadETAString
{
get => _downloadETAString;
set => SetProperty(ref _downloadETAString, value);
set => this.RaiseAndSetIfChanged(ref _downloadETAString, value);
}
}

Expand Down
7 changes: 4 additions & 3 deletions YoutubeDl.Wpf/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MaterialDesignThemes.Wpf;
using ReactiveUI;
using System;
using System.Collections.ObjectModel;
using System.Linq;
Expand All @@ -7,7 +8,7 @@

namespace YoutubeDl.Wpf.ViewModels
{
public class MainWindowViewModel : ViewModelBase
public class MainWindowViewModel : ReactiveObject
{
public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue)
{
Expand Down Expand Up @@ -35,13 +36,13 @@ private async void OnOpenAboutDialog(object commandParameter)
public ObservableCollection<DrawerItem> DrawerItems
{
get => _drawerItems;
set => SetProperty(ref _drawerItems, value);
set => this.RaiseAndSetIfChanged(ref _drawerItems, value);
}

public DrawerItem SelectedItem
{
get => _selectedItem;
set => SetProperty(ref _selectedItem, value);
set => this.RaiseAndSetIfChanged(ref _selectedItem, value);
}

private ObservableCollection<DrawerItem> GenerateItems(ISnackbarMessageQueue snackbarMessageQueue)
Expand Down
43 changes: 22 additions & 21 deletions YoutubeDl.Wpf/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MaterialDesignThemes.Wpf;
using PeanutButter.TinyEventAggregator;
using ReactiveUI;
using System;
using System.IO;
using System.Text.Json;
Expand All @@ -9,7 +10,7 @@

namespace YoutubeDl.Wpf.ViewModels
{
public class SettingsViewModel : ViewModelBase
public class SettingsViewModel : ReactiveObject
{
public SettingsViewModel(ISnackbarMessageQueue snackbarMessageQueue)
{
Expand Down Expand Up @@ -157,28 +158,28 @@ private async Task ApplySettings()
switch (_settings.AppColorMode)
{
case ColorMode.System:
SetProperty(ref _followOSColorMode, true);
SetProperty(ref _lightMode, false);
SetProperty(ref _darkMode, false);
this.RaiseAndSetIfChanged(ref _followOSColorMode, true);
this.RaiseAndSetIfChanged(ref _lightMode, false);
this.RaiseAndSetIfChanged(ref _darkMode, false);
break;
case ColorMode.Light:
SetProperty(ref _followOSColorMode, false);
SetProperty(ref _lightMode, true);
SetProperty(ref _darkMode, false);
this.RaiseAndSetIfChanged(ref _followOSColorMode, false);
this.RaiseAndSetIfChanged(ref _lightMode, true);
this.RaiseAndSetIfChanged(ref _darkMode, false);
break;
case ColorMode.Dark:
SetProperty(ref _followOSColorMode, false);
SetProperty(ref _lightMode, false);
SetProperty(ref _darkMode, true);
this.RaiseAndSetIfChanged(ref _followOSColorMode, false);
this.RaiseAndSetIfChanged(ref _lightMode, false);
this.RaiseAndSetIfChanged(ref _darkMode, true);
break;
default:
throw new ArgumentException("Invalid AppColorMode");
}
OnChangeColorMode(_settings.AppColorMode);
SetProperty(ref _autoUpdateDl, _settings.AutoUpdateDl);
SetProperty(ref _dlPath, _settings.DlPath);
SetProperty(ref _ffmpegPath, _settings.FfmpegPath);
SetProperty(ref _proxy, _settings.Proxy);
this.RaiseAndSetIfChanged(ref _autoUpdateDl, _settings.AutoUpdateDl);
this.RaiseAndSetIfChanged(ref _dlPath, _settings.DlPath);
this.RaiseAndSetIfChanged(ref _ffmpegPath, _settings.FfmpegPath);
this.RaiseAndSetIfChanged(ref _proxy, _settings.Proxy);

await settingsChangedEvent.PublishAsync(_settings);
}
Expand Down Expand Up @@ -220,27 +221,27 @@ private async Task SaveSettingsAsync()
public bool FollowOSColorMode
{
get => _followOSColorMode;
set => SetProperty(ref _followOSColorMode, value);
set => this.RaiseAndSetIfChanged(ref _followOSColorMode, value);
}

public bool LightMode
{
get => _lightMode;
set => SetProperty(ref _lightMode, value);
set => this.RaiseAndSetIfChanged(ref _lightMode, value);
}

public bool DarkMode
{
get => _darkMode;
set => SetProperty(ref _darkMode, value);
set => this.RaiseAndSetIfChanged(ref _darkMode, value);
}

public bool AutoUpdateDl
{
get => _autoUpdateDl;
set
{
SetProperty(ref _autoUpdateDl, value);
this.RaiseAndSetIfChanged(ref _autoUpdateDl, value);
_settings.AutoUpdateDl = _autoUpdateDl;
SaveSettings();
}
Expand All @@ -251,7 +252,7 @@ public string DlPath
get => _dlPath;
set
{
SetProperty(ref _dlPath, value);
this.RaiseAndSetIfChanged(ref _dlPath, value);
_settings.DlPath = _dlPath;
SaveSettings();
PublishSettings();
Expand All @@ -263,7 +264,7 @@ public string FfmpegPath
get => _ffmpegPath;
set
{
SetProperty(ref _ffmpegPath, value);
this.RaiseAndSetIfChanged(ref _ffmpegPath, value);
_settings.FfmpegPath = _ffmpegPath;
SaveSettings();
PublishSettings();
Expand All @@ -275,7 +276,7 @@ public string Proxy
get => _proxy;
set
{
SetProperty(ref _proxy, value);
this.RaiseAndSetIfChanged(ref _proxy, value);
_settings.Proxy = _proxy;
SaveSettings();
PublishSettings();
Expand Down
Loading

0 comments on commit 56dbf6b

Please sign in to comment.