Skip to content

Commit d8c632d

Browse files
committed
Rename view model manager methods
1 parent b203de8 commit d8c632d

7 files changed

Lines changed: 28 additions & 36 deletions

File tree

‎YoutubeDownloader/App.axaml.cs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ public override void OnFrameworkInitializationCompleted()
112112
{
113113
desktop.MainWindow = _services
114114
.GetRequiredService<ViewManager>()
115-
.TryBindWindow(
116-
_services.GetRequiredService<ViewModelManager>().CreateMainViewModel()
117-
);
115+
.TryBindWindow(_services.GetRequiredService<ViewModelManager>().GetMainViewModel());
118116

119117
// Although `App.Dispose()` is invoked from `Program.Main(...)`, on some platforms
120118
// it may be called too late in the shutdown lifecycle. Attach an exit

‎YoutubeDownloader/Framework/ViewModelManager.cs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ namespace YoutubeDownloader.Framework;
1212

1313
public class ViewModelManager(IServiceProvider services)
1414
{
15-
public MainViewModel CreateMainViewModel() => services.GetRequiredService<MainViewModel>();
15+
public MainViewModel GetMainViewModel() => services.GetRequiredService<MainViewModel>();
1616

17-
public DashboardViewModel CreateDashboardViewModel() =>
17+
public DashboardViewModel GetDashboardViewModel() =>
1818
services.GetRequiredService<DashboardViewModel>();
1919

20-
public AuthSetupViewModel CreateAuthSetupViewModel() =>
20+
public AuthSetupViewModel GetAuthSetupViewModel() =>
2121
services.GetRequiredService<AuthSetupViewModel>();
2222

23-
public DownloadViewModel CreateDownloadViewModel(
23+
public DownloadViewModel GetDownloadViewModel(
2424
IVideo video,
2525
VideoDownloadOption downloadOption,
2626
string filePath
@@ -35,7 +35,7 @@ string filePath
3535
return viewModel;
3636
}
3737

38-
public DownloadViewModel CreateDownloadViewModel(
38+
public DownloadViewModel GetDownloadViewModel(
3939
IVideo video,
4040
VideoDownloadPreference downloadPreference,
4141
string filePath
@@ -50,7 +50,7 @@ string filePath
5050
return viewModel;
5151
}
5252

53-
public DownloadMultipleSetupViewModel CreateDownloadMultipleSetupViewModel(
53+
public DownloadMultipleSetupViewModel GetDownloadMultipleSetupViewModel(
5454
string title,
5555
IReadOnlyList<IVideo> availableVideos,
5656
bool preselectVideos = true
@@ -67,7 +67,7 @@ public DownloadMultipleSetupViewModel CreateDownloadMultipleSetupViewModel(
6767
return viewModel;
6868
}
6969

70-
public DownloadSingleSetupViewModel CreateDownloadSingleSetupViewModel(
70+
public DownloadSingleSetupViewModel GetDownloadSingleSetupViewModel(
7171
IVideo video,
7272
IReadOnlyList<VideoDownloadOption> availableDownloadOptions
7373
)
@@ -80,7 +80,7 @@ IReadOnlyList<VideoDownloadOption> availableDownloadOptions
8080
return viewModel;
8181
}
8282

83-
public MessageBoxViewModel CreateMessageBoxViewModel(
83+
public MessageBoxViewModel GetMessageBoxViewModel(
8484
string title,
8585
string message,
8686
string? okButtonText,
@@ -97,7 +97,7 @@ public MessageBoxViewModel CreateMessageBoxViewModel(
9797
return viewModel;
9898
}
9999

100-
public MessageBoxViewModel CreateMessageBoxViewModel(string title, string message)
100+
public MessageBoxViewModel GetMessageBoxViewModel(string title, string message)
101101
{
102102
var viewModel = services.GetRequiredService<MessageBoxViewModel>();
103103

@@ -107,6 +107,6 @@ public MessageBoxViewModel CreateMessageBoxViewModel(string title, string messag
107107
return viewModel;
108108
}
109109

110-
public SettingsViewModel CreateSettingsViewModel() =>
110+
public SettingsViewModel GetSettingsViewModel() =>
111111
services.GetRequiredService<SettingsViewModel>();
112112
}

‎YoutubeDownloader/ViewModels/Components/DashboardViewModel.cs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private async Task EnsureFFmpegAsync()
9696
return;
9797

9898
// Otherwise, prompt the user to download FFmpeg
99-
var dialog = _viewModelManager.CreateMessageBoxViewModel(
99+
var dialog = _viewModelManager.GetMessageBoxViewModel(
100100
_localizationManager.FFmpegMissingTitle,
101101
string.Format(_localizationManager.FFmpegMissingMessage, Program.Name),
102102
_localizationManager.DownloadButton,
@@ -126,7 +126,7 @@ await FFmpeg.DownloadAsync(
126126
catch (Exception ex)
127127
{
128128
await _dialogManager.ShowDialogAsync(
129-
_viewModelManager.CreateMessageBoxViewModel(
129+
_viewModelManager.GetMessageBoxViewModel(
130130
_localizationManager.ErrorTitle,
131131
ex.Message
132132
)
@@ -145,13 +145,13 @@ await _dialogManager.ShowDialogAsync(
145145

146146
[RelayCommand(CanExecute = nameof(CanShowAuthSetup))]
147147
private async Task ShowAuthSetupAsync() =>
148-
await _dialogManager.ShowDialogAsync(_viewModelManager.CreateAuthSetupViewModel());
148+
await _dialogManager.ShowDialogAsync(_viewModelManager.GetAuthSetupViewModel());
149149

150150
private bool CanShowSettings() => !IsBusy;
151151

152152
[RelayCommand(CanExecute = nameof(CanShowSettings))]
153153
private async Task ShowSettingsAsync() =>
154-
await _dialogManager.ShowDialogAsync(_viewModelManager.CreateSettingsViewModel());
154+
await _dialogManager.ShowDialogAsync(_viewModelManager.GetSettingsViewModel());
155155

156156
private async void EnqueueDownload(DownloadViewModel download, int position = 0)
157157
{
@@ -291,7 +291,7 @@ private async Task ProcessQueryAsync()
291291
);
292292

293293
var download = await _dialogManager.ShowDialogAsync(
294-
_viewModelManager.CreateDownloadSingleSetupViewModel(video, downloadOptions)
294+
_viewModelManager.GetDownloadSingleSetupViewModel(video, downloadOptions)
295295
);
296296

297297
if (download is null)
@@ -305,7 +305,7 @@ private async Task ProcessQueryAsync()
305305
else if (queryResult.Videos.Count > 1)
306306
{
307307
var downloads = await _dialogManager.ShowDialogAsync(
308-
_viewModelManager.CreateDownloadMultipleSetupViewModel(
308+
_viewModelManager.GetDownloadMultipleSetupViewModel(
309309
queryResult.Title,
310310
queryResult.Videos,
311311
// Pre-select videos if they come from a single query and not from search
@@ -327,7 +327,7 @@ and not QueryResultKind.Aggregate
327327
else
328328
{
329329
await _dialogManager.ShowDialogAsync(
330-
_viewModelManager.CreateMessageBoxViewModel(
330+
_viewModelManager.GetMessageBoxViewModel(
331331
LocalizationManager.NothingFoundTitle,
332332
LocalizationManager.NothingFoundMessage
333333
)
@@ -337,7 +337,7 @@ await _dialogManager.ShowDialogAsync(
337337
catch (Exception ex)
338338
{
339339
await _dialogManager.ShowDialogAsync(
340-
_viewModelManager.CreateMessageBoxViewModel(
340+
_viewModelManager.GetMessageBoxViewModel(
341341
LocalizationManager.ErrorTitle,
342342
// Short error message for YouTube-related errors, full for others
343343
ex is YoutubeExplodeException
@@ -392,12 +392,12 @@ private void RestartDownload(DownloadViewModel download)
392392
RemoveDownload(download);
393393

394394
var newDownload = download.DownloadOption is not null
395-
? _viewModelManager.CreateDownloadViewModel(
395+
? _viewModelManager.GetDownloadViewModel(
396396
download.Video!,
397397
download.DownloadOption,
398398
download.FilePath!
399399
)
400-
: _viewModelManager.CreateDownloadViewModel(
400+
: _viewModelManager.GetDownloadViewModel(
401401
download.Video!,
402402
download.DownloadPreference!,
403403
download.FilePath!

‎YoutubeDownloader/ViewModels/Components/DownloadViewModel.cs‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ private async Task ShowFileAsync()
110110
catch (Exception ex)
111111
{
112112
await _dialogManager.ShowDialogAsync(
113-
_viewModelManager.CreateMessageBoxViewModel(
114-
LocalizationManager.ErrorTitle,
115-
ex.Message
116-
)
113+
_viewModelManager.GetMessageBoxViewModel(LocalizationManager.ErrorTitle, ex.Message)
117114
);
118115
}
119116
}
@@ -133,10 +130,7 @@ private async Task OpenFileAsync()
133130
catch (Exception ex)
134131
{
135132
await _dialogManager.ShowDialogAsync(
136-
_viewModelManager.CreateMessageBoxViewModel(
137-
LocalizationManager.ErrorTitle,
138-
ex.Message
139-
)
133+
_viewModelManager.GetMessageBoxViewModel(LocalizationManager.ErrorTitle, ex.Message)
140134
);
141135
}
142136
}

‎YoutubeDownloader/ViewModels/Dialogs/DownloadMultipleSetupViewModel.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private async Task ConfirmAsync()
9797
await File.WriteAllBytesAsync(filePath, []);
9898

9999
downloads.Add(
100-
viewModelManager.CreateDownloadViewModel(
100+
viewModelManager.GetDownloadViewModel(
101101
video,
102102
new VideoDownloadPreference(SelectedContainer, SelectedVideoQualityPreference),
103103
filePath

‎YoutubeDownloader/ViewModels/Dialogs/DownloadSingleSetupViewModel.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ private async Task ConfirmAsync()
7777

7878
settingsService.LastContainer = container;
7979

80-
Close(viewModelManager.CreateDownloadViewModel(Video, SelectedDownloadOption, filePath));
80+
Close(viewModelManager.GetDownloadViewModel(Video, SelectedDownloadOption, filePath));
8181
}
8282
}

‎YoutubeDownloader/ViewModels/MainViewModel.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ UpdateService updateService
2121
{
2222
public string Title { get; } = $"{Program.Name} v{Program.VersionString}";
2323

24-
public DashboardViewModel Dashboard { get; } = viewModelManager.CreateDashboardViewModel();
24+
public DashboardViewModel Dashboard { get; } = viewModelManager.GetDashboardViewModel();
2525

2626
private async Task ShowUkraineSupportMessageAsync()
2727
{
2828
if (!settingsService.IsUkraineSupportMessageEnabled)
2929
return;
3030

31-
var dialog = viewModelManager.CreateMessageBoxViewModel(
31+
var dialog = viewModelManager.GetMessageBoxViewModel(
3232
localizationManager.UkraineSupportTitle,
3333
localizationManager.UkraineSupportMessage,
3434
localizationManager.LearnMoreButton,
@@ -52,7 +52,7 @@ private async Task ShowDevelopmentBuildMessageAsync()
5252
if (Debugger.IsAttached)
5353
return;
5454

55-
var dialog = viewModelManager.CreateMessageBoxViewModel(
55+
var dialog = viewModelManager.GetMessageBoxViewModel(
5656
localizationManager.UnstableBuildTitle,
5757
string.Format(localizationManager.UnstableBuildMessage, Program.Name),
5858
localizationManager.SeeReleasesButton,

0 commit comments

Comments
 (0)