fix cancel all in download queue

This commit is contained in:
kodjomoustapha 2024-09-12 16:53:57 +01:00
parent 1a03a4ec79
commit 4facf34f44

View file

@ -55,7 +55,8 @@ class DownloadQueueScreen extends ConsumerWidget {
), ),
body: GroupedListView<Download, String>( body: GroupedListView<Download, String>(
elements: entries, elements: entries,
groupBy: (element) => element.chapter.value!.manga.value!.source!, groupBy: (element) =>
element.chapter.value?.manga.value?.source ?? "",
groupSeparatorBuilder: (String groupByValue) { groupSeparatorBuilder: (String groupByValue) {
final sourceQueueLength = entries final sourceQueueLength = entries
.where((element) => .where((element) =>
@ -150,8 +151,12 @@ class DownloadQueueScreen extends ConsumerWidget {
} else if (value.toString() == 'CancelAll') { } else if (value.toString() == 'CancelAll') {
final chapterIds = entries final chapterIds = entries
.where((e) => .where((e) =>
e.chapter.value!.name == e.chapter.value!.manga.value!.name ==
element.chapter.value!.name) element.chapter.value!.manga.value!
.name &&
e.chapter.value!.manga.value!.source ==
element.chapter.value!.manga.value!
.source)
.map((e) => e.chapterId) .map((e) => e.chapterId)
.toList(); .toList();
for (var chapterId in chapterIds) { for (var chapterId in chapterIds) {
@ -165,21 +170,24 @@ class DownloadQueueScreen extends ConsumerWidget {
[]; [];
await FileDownloader() await FileDownloader()
.cancelTasksWithIds(taskIds); .cancelTasksWithIds(taskIds);
await Future.delayed( Future.delayed(const Duration(seconds: 2)).then(
const Duration(milliseconds: 300)); (value) {
final chapterD = isar.downloads final chapterD = isar.downloads
.filter() .filter()
.chapterIdEqualTo(chapterId) .chapterIdEqualTo(chapterId)
.findFirstSync(); .findFirstSync();
if (chapterD != null) { if (chapterD != null) {
final verifyId = final verifyId =
isar.downloads.getSync(chapterD.id!); isar.downloads.getSync(chapterD.id!);
isar.writeTxnSync(() { isar.writeTxnSync(() {
if (verifyId != null) { if (verifyId != null) {
isar.downloads.deleteSync(chapterD.id!); isar.downloads
.deleteSync(chapterD.id!);
}
});
} }
}); },
} );
} }
} }
}, },
@ -196,9 +204,9 @@ class DownloadQueueScreen extends ConsumerWidget {
), ),
); );
}, },
itemComparator: (item1, item2) => item1 itemComparator: (item1, item2) =>
.chapter.value!.manga.value!.source! (item1.chapter.value?.manga.value?.source ?? "").compareTo(
.compareTo(item2.chapter.value!.manga.value!.source!), item2.chapter.value?.manga.value?.source ?? ""),
order: GroupedListOrder.DESC, order: GroupedListOrder.DESC,
), ),
); );