Skip to content

Commit

Permalink
Fix subtitle selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Oct 25, 2020
1 parent 3da013e commit 3942c96
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class DownloadSingleSetupViewModel : DialogScreen<DownloadViewModel>

public SubtitleDownloadOption? SelectedSubtitleOption { get; set; }

public bool ShouldDownloadSubtitles { get; set; }

public DownloadSingleSetupViewModel(
IViewModelFactory viewModelFactory,
SettingsService settingsService,
Expand All @@ -51,7 +53,8 @@ public void OnViewLoaded()
// Select first subtitle download option matching last used language
SelectedSubtitleOption =
AvailableSubtitleOptions.FirstOrDefault(o =>
o.TrackInfo.Language.Code == _settingsService.LastSubtitleLanguageCode);
o.TrackInfo.Language.Code == _settingsService.LastSubtitleLanguageCode) ??
AvailableSubtitleOptions.FirstOrDefault();
}

public bool CanConfirm => SelectedVideoOption != null;
Expand Down Expand Up @@ -81,7 +84,7 @@ public void Confirm()
filePath,
format,
SelectedVideoOption,
SelectedSubtitleOption
ShouldDownloadSubtitles ? SelectedSubtitleOption : null
);

// Create empty file to "lock in" the file path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
VerticalAlignment="Center"
Text="Format:" />
<ComboBox
MinWidth="150"
Width="150"
Margin="8"
VerticalAlignment="Center"
IsReadOnly="True"
Expand All @@ -148,7 +148,7 @@
VerticalAlignment="Center"
Text="Video quality:" />
<ComboBox
MinWidth="150"
Width="150"
Margin="8"
VerticalAlignment="Center"
IsReadOnly="True"
Expand Down
9 changes: 4 additions & 5 deletions YoutubeDownloader/Views/Dialogs/DownloadSingleSetupView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
VerticalAlignment="Center"
Text="Format:" />
<ComboBox
MinWidth="150"
Width="150"
Margin="8"
VerticalAlignment="Center"
materialDesign:ComboBoxAssist.ShowSelectedItem="True"
Expand All @@ -105,16 +105,15 @@
IsEnabled="{Binding AvailableSubtitleOptions}"
Orientation="Horizontal">
<CheckBox
x:Name="SubtitlesCheckBox"
Margin="8"
VerticalAlignment="Center"
Content="Subtitles:"
Unchecked="SubtitlesCheckBox_OnUnchecked" />
IsChecked="{Binding ShouldDownloadSubtitles}" />
<ComboBox
MinWidth="150"
Width="150"
Margin="8"
materialDesign:ComboBoxAssist.ShowSelectedItem="True"
IsEnabled="{Binding IsChecked, ElementName=SubtitlesCheckBox}"
IsEnabled="{Binding ShouldDownloadSubtitles}"
IsReadOnly="True"
ItemsSource="{Binding AvailableSubtitleOptions}"
SelectedItem="{Binding SelectedSubtitleOption}" />
Expand Down
11 changes: 1 addition & 10 deletions YoutubeDownloader/Views/Dialogs/DownloadSingleSetupView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
using System.Windows;
using YoutubeDownloader.ViewModels.Dialogs;

namespace YoutubeDownloader.Views.Dialogs
namespace YoutubeDownloader.Views.Dialogs
{
public partial class DownloadSingleSetupView
{
public DownloadSingleSetupView()
{
InitializeComponent();
}

private void SubtitlesCheckBox_OnUnchecked(object sender, RoutedEventArgs args)
{
if (DataContext is DownloadSingleSetupViewModel vm)
vm.SelectedSubtitleOption = null;
}
}
}

0 comments on commit 3942c96

Please sign in to comment.