diff --git a/TwitchDownloaderWPF/WindowMassDownload.xaml.cs b/TwitchDownloaderWPF/WindowMassDownload.xaml.cs index 18cf974a..3e65bce0 100644 --- a/TwitchDownloaderWPF/WindowMassDownload.xaml.cs +++ b/TwitchDownloaderWPF/WindowMassDownload.xaml.cs @@ -25,7 +25,7 @@ public partial class WindowMassDownload : Window public ObservableCollection videoList { get; set; } = new ObservableCollection(); public readonly List selectedItems = new List(); public readonly List cursorList = new List(); - public int cursorIndex = -1; + public int cursorIndex = 0; public string currentChannel = ""; public string period = ""; public int videoCount = 50; @@ -49,12 +49,18 @@ private async void btnChannel_Click(object sender, RoutedEventArgs e) await ChangeCurrentChannel(); } - private Task ChangeCurrentChannel() + private void ResetLists() { - currentChannel = textChannel.Text; videoList.Clear(); cursorList.Clear(); - cursorIndex = -1; + cursorList.Add(""); + cursorIndex = 0; + } + + private Task ChangeCurrentChannel() + { + currentChannel = textChannel.Text; + ResetLists(); return UpdateList(); } @@ -69,9 +75,7 @@ private async Task UpdateList() { // Pretend we are doing something so the status icon has time to show await Task.Delay(50); - videoList.Clear(); - cursorList.Clear(); - cursorIndex = -1; + ResetLists(); StatusImage.Visibility = Visibility.Hidden; return; } @@ -125,13 +129,18 @@ private async Task UpdateList() }); } - btnNext.IsEnabled = res.data.user.videos.pageInfo.hasNextPage; - btnPrev.IsEnabled = res.data.user.videos.pageInfo.hasPreviousPage; + btnPrev.IsEnabled = cursorIndex > 0; if (res.data.user.videos.pageInfo.hasNextPage) { - string newCursor = res.data.user.videos.edges[0].cursor; - if (!cursorList.Contains(newCursor)) - cursorList.Add(newCursor); + string newCursor = res.data.user.videos.edges.FirstOrDefault()?.cursor; + if (newCursor is not null) + { + btnNext.IsEnabled = true; + if (!cursorList.Contains(newCursor)) + { + cursorList.Add(newCursor); + } + } } } } @@ -184,13 +193,18 @@ private async Task UpdateList() }); } - btnNext.IsEnabled = res.data.user.clips.pageInfo.hasNextPage; - btnPrev.IsEnabled = cursorIndex >= 0; + btnPrev.IsEnabled = cursorIndex > 0; if (res.data.user.clips.pageInfo.hasNextPage) { - string newCursor = res.data.user.clips.edges.First(x => x.cursor != null).cursor; - if (!cursorList.Contains(newCursor)) - cursorList.Add(newCursor); + string newCursor = res.data.user.clips.edges.FirstOrDefault(x => x.cursor != null)?.cursor; + if (newCursor is not null) + { + btnNext.IsEnabled = true; + if (!cursorList.Contains(newCursor)) + { + cursorList.Add(newCursor); + } + } } } } @@ -220,7 +234,11 @@ private async void btnNext_Click(object sender, RoutedEventArgs e) { btnNext.IsEnabled = false; btnPrev.IsEnabled = false; - cursorIndex++; + if (cursorIndex < cursorList.Count - 1) + { + cursorIndex++; + } + await UpdateList(); } @@ -228,7 +246,11 @@ private async void btnPrev_Click(object sender, RoutedEventArgs e) { btnNext.IsEnabled = false; btnPrev.IsEnabled = false; - cursorIndex--; + if (cursorIndex > 0) + { + cursorIndex--; + } + await UpdateList(); } @@ -260,9 +282,7 @@ private void btnQueue_Click(object sender, RoutedEventArgs e) private async void ComboSortByDate_SelectionChanged(object sender, SelectionChangedEventArgs e) { period = ((ComboBoxItem)ComboSortByDate.SelectedItem).Tag.ToString(); - videoList.Clear(); - cursorList.Clear(); - cursorIndex = -1; + ResetLists(); await UpdateList(); } @@ -312,9 +332,7 @@ private async void TextChannel_OnKeyDown(object sender, KeyEventArgs e) private async void ComboVideoCount_SelectionChanged(object sender, SelectionChangedEventArgs e) { videoCount = int.Parse((string)((ComboBoxItem)ComboVideoCount.SelectedValue).Content); - videoList.Clear(); - cursorList.Clear(); - cursorIndex = -1; + ResetLists(); await UpdateList(); }