feature: Ask for playback type when media is downloaded (#361)

Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
PartyDonut 2025-06-01 17:05:16 +02:00 committed by GitHub
parent 563d267566
commit 5ef7936c33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 194 additions and 148 deletions

View file

@ -202,14 +202,28 @@ extension EpisodeListExtensions on List<EpisodeModel> {
final episodes = where((e) => e.season > 0 && e.status == EpisodeStatus.available).toList();
if (episodes.isEmpty) return null;
final lastWatchedIndex = [
episodes.lastIndexWhere((e) => e.userData.progress != 0),
episodes.lastIndexWhere((e) => e.userData.played),
].reduce((a, b) => a > b ? a : b);
final lastProgressIndex = episodes.lastIndexWhere((e) => e.userData.progress != 0);
final lastPlayedIndex = episodes.lastIndexWhere((e) => e.userData.played);
final lastWatchedIndex = [lastProgressIndex, lastPlayedIndex].reduce((a, b) => a > b ? a : b);
if (lastWatchedIndex >= 0 && lastWatchedIndex + 1 < episodes.length) {
final next = episodes.sublist(lastWatchedIndex + 1).firstWhereOrNull((e) => e.status == EpisodeStatus.available);
if (next != null) return next;
if (lastWatchedIndex >= 0) {
final current = episodes[lastWatchedIndex];
if (!current.userData.played && current.userData.progress != 0) {
return current;
}
final nextIndex = lastWatchedIndex + 1;
if (nextIndex < episodes.length) {
final next = episodes[nextIndex];
if (!next.userData.played && next.userData.progress != 0) {
return next;
}
final nextUnplayed = episodes.sublist(nextIndex).firstWhereOrNull(
(e) => e.status == EpisodeStatus.available && !e.userData.played,
);
if (nextUnplayed != null) return nextUnplayed;
}
}
return episodes.firstOrNull;