From fc2e80f31efde7230252af699b947c8ded3f91e6 Mon Sep 17 00:00:00 2001 From: kodjomoustapha <107993382+kodjodevf@users.noreply.github.com> Date: Thu, 8 Feb 2024 17:18:59 +0100 Subject: [PATCH] feat: Added button for download next n chapters --- lib/l10n/app_ar.arb | 6 +- lib/l10n/app_de.arb | 6 +- lib/l10n/app_en.arb | 6 +- lib/l10n/app_es.arb | 6 +- lib/l10n/app_es_419.arb | 6 +- lib/l10n/app_fr.arb | 6 +- lib/l10n/app_id.arb | 6 +- lib/l10n/app_it.arb | 6 +- lib/l10n/app_pt.arb | 6 +- lib/l10n/app_pt_BR.arb | 6 +- lib/l10n/app_ru.arb | 6 +- lib/l10n/app_tr.arb | 6 +- lib/l10n/app_zh.arb | 6 +- .../manga/detail/manga_detail_view.dart | 120 ++++++++++++++++-- 14 files changed, 173 insertions(+), 25 deletions(-) diff --git a/lib/l10n/app_ar.arb b/lib/l10n/app_ar.arb index 35391b7f..4795a235 100644 --- a/lib/l10n/app_ar.arb +++ b/lib/l10n/app_ar.arb @@ -283,5 +283,9 @@ "aniskip_button_timeout": "مهلة زر", "fullscreen": "شاشة كاملة", "update_library": "تحديث المكتبة", - "updating_library": "جاري تحديث المكتبة" + "updating_library": "جاري تحديث المكتبة", + "next_chapter": "الفصل التالي", + "next_5_chapters": "الفصول الخمسة التالية", + "next_10_chapters": "الفصول العشرة التالية", + "next_25_chapters": "الفصول الخمسة والعشرون التالية" } \ No newline at end of file diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 92778c94..5a26676e 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -283,5 +283,9 @@ "aniskip_button_timeout": "Timeout für Taste", "fullscreen": "Vollbild", "update_library": "Bibliothek aktualisieren", - "updating_library": "Bibliothek wird aktualisiert" + "updating_library": "Bibliothek wird aktualisiert", + "next_chapter": "Nächstes Kapitel", + "next_5_chapters": "Nächsten 5 Kapitel", + "next_10_chapters": "Nächsten 10 Kapitel", + "next_25_chapters": "Nächsten 25 Kapitel" } \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index be47ad7a..2ab2fd11 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -285,5 +285,9 @@ "skip_ending": "Skip ending", "fullscreen": "Fullscreen", "update_library": "Update library", - "updating_library": "Updating library" + "updating_library": "Updating library", + "next_chapter": "Next chapter", + "next_5_chapters": "Next 5 chapters", + "next_10_chapters": "Next 10 chapters", + "next_25_chapters": "Next 25 chapters" } \ No newline at end of file diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index 9d4fbc6f..5f7c8425 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -283,5 +283,9 @@ "aniskip_button_timeout": "Tiempo de espera del botón", "fullscreen": "Pantalla completa", "update_library": "Actualizar biblioteca", - "updating_library": "Actualizando biblioteca" + "updating_library": "Actualizando biblioteca", + "next_chapter": "Próximo capítulo", + "next_5_chapters": "Próximos 5 capítulos", + "next_10_chapters": "Próximos 10 capítulos", + "next_25_chapters": "Próximos 25 capítulos" } \ No newline at end of file diff --git a/lib/l10n/app_es_419.arb b/lib/l10n/app_es_419.arb index 3392949c..84ea57eb 100644 --- a/lib/l10n/app_es_419.arb +++ b/lib/l10n/app_es_419.arb @@ -283,5 +283,9 @@ "aniskip_button_timeout": "Tiempo de espera del botón", "fullscreen": "Pantalla completa", "update_library": "Actualizar biblioteca", - "updating_library": "Actualizando biblioteca" + "updating_library": "Actualizando biblioteca", + "next_chapter": "Siguiente capítulo", + "next_5_chapters": "Siguientes 5 capítulos", + "next_10_chapters": "Siguientes 10 capítulos", + "next_25_chapters": "Siguientes 25 capítulos" } \ No newline at end of file diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index a31e50b1..137738c9 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -284,5 +284,9 @@ "skip_opening": "Passer l'opening", "skip_ending": "Passer l'ending", "update_library": "Mettre à jour la bibliothèque", - "updating_library": "Mise à jour de la bibliothèque" + "updating_library": "Mise à jour de la bibliothèque", + "next_chapter": "Chapitre suivant", + "next_5_chapters": "5 chapitres suivants", + "next_10_chapters": "10 chapitres suivants", + "next_25_chapters": "25 chapitres suivants" } \ No newline at end of file diff --git a/lib/l10n/app_id.arb b/lib/l10n/app_id.arb index 2a1e8881..35c7041c 100644 --- a/lib/l10n/app_id.arb +++ b/lib/l10n/app_id.arb @@ -283,5 +283,9 @@ "aniskip_button_timeout": "Timeout tombol", "fullscreen": "Layar Penuh", "update_library": "Perbarui perpustakaan", - "updating_library": "Memperbarui perpustakaan" + "updating_library": "Memperbarui perpustakaan", + "next_chapter": "Berikutnya bab", + "next_5_chapters": "5 bab berikutnya", + "next_10_chapters": "10 bab berikutnya", + "next_25_chapters": "25 bab berikutnya" } \ No newline at end of file diff --git a/lib/l10n/app_it.arb b/lib/l10n/app_it.arb index c10443e0..d96ace03 100644 --- a/lib/l10n/app_it.arb +++ b/lib/l10n/app_it.arb @@ -283,5 +283,9 @@ "aniskip_button_timeout": "Timeout del pulsante", "fullscreen": "Schermo intero", "update_library": "Aggiorna libreria", - "updating_library": "Aggiornamento della libreria" + "updating_library": "Aggiornamento della libreria", + "next_chapter": "Capitolo successivo", + "next_5_chapters": "Prossimi 5 capitoli", + "next_10_chapters": "Prossimi 10 capitoli", + "next_25_chapters": "Prossimi 25 capitoli" } \ No newline at end of file diff --git a/lib/l10n/app_pt.arb b/lib/l10n/app_pt.arb index 814205a9..8ff14810 100644 --- a/lib/l10n/app_pt.arb +++ b/lib/l10n/app_pt.arb @@ -283,5 +283,9 @@ "aniskip_button_timeout": "Tempo limite do botão", "fullscreen": "Tela cheia", "update_library": "Atualizar biblioteca", - "updating_library": "Atualizando biblioteca" + "updating_library": "Atualizando biblioteca", + "next_chapter": "Próximo capítulo", + "next_5_chapters": "Próximos 5 capítulos", + "next_10_chapters": "Próximos 10 capítulos", + "next_25_chapters": "Próximos 25 capítulos" } \ No newline at end of file diff --git a/lib/l10n/app_pt_BR.arb b/lib/l10n/app_pt_BR.arb index f2979949..faae244a 100644 --- a/lib/l10n/app_pt_BR.arb +++ b/lib/l10n/app_pt_BR.arb @@ -283,5 +283,9 @@ "aniskip_button_timeout": "Timeout do botão", "fullscreen": "Tela cheia", "update_library": "Atualizar biblioteca", - "updating_library": "Atualizando biblioteca" + "updating_library": "Atualizando biblioteca", + "next_chapter": "Próximo capítulo", + "next_5_chapters": "Próximos 5 capítulos", + "next_10_chapters": "Próximos 10 capítulos", + "next_25_chapters": "Próximos 25 capítulos" } \ No newline at end of file diff --git a/lib/l10n/app_ru.arb b/lib/l10n/app_ru.arb index ce74ed92..3a7fc222 100644 --- a/lib/l10n/app_ru.arb +++ b/lib/l10n/app_ru.arb @@ -283,5 +283,9 @@ "aniskip_button_timeout": "Тайм-аут кнопки", "fullscreen": "Полноэкранный режим", "update_library": "Обновить библиотеку", - "updating_library": "Обновление библиотеки" + "updating_library": "Обновление библиотеки", + "next_chapter": "Следующая глава", + "next_5_chapters": "Следующие 5 глав", + "next_10_chapters": "Следующие 10 глав", + "next_25_chapters": "Следующие 25 глав" } \ No newline at end of file diff --git a/lib/l10n/app_tr.arb b/lib/l10n/app_tr.arb index 50a904c3..fd06b9e6 100644 --- a/lib/l10n/app_tr.arb +++ b/lib/l10n/app_tr.arb @@ -283,5 +283,9 @@ "aniskip_button_timeout": "Düğme Zaman Aşımı", "fullscreen": "Tam ekran", "update_library": "Kütüphaneyi güncelle", - "updating_library": "Kütüphaneyi güncelleme" + "updating_library": "Kütüphaneyi güncelleme", + "next_chapter": "Sonraki bölüm", + "next_5_chapters": "Sonraki 5 bölüm", + "next_10_chapters": "Sonraki 10 bölüm", + "next_25_chapters": "Sonraki 25 bölüm" } \ No newline at end of file diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 1c3791fa..3d6112fb 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -285,5 +285,9 @@ "skip_ending": "跳过结尾", "fullscreen": "全屏", "update_library": "更新库", - "updating_library": "正在更新库" + "updating_library": "正在更新库", + "next_chapter": "下一章", + "next_5_chapters": "下5章", + "next_10_chapters": "下10章", + "next_25_chapters": "下25章" } \ No newline at end of file diff --git a/lib/modules/manga/detail/manga_detail_view.dart b/lib/modules/manga/detail/manga_detail_view.dart index 74608516..1a4a5b0f 100644 --- a/lib/modules/manga/detail/manga_detail_view.dart +++ b/lib/modules/manga/detail/manga_detail_view.dart @@ -361,15 +361,109 @@ class _MangaDetailViewState extends ConsumerState ? Colors.transparent : Theme.of(context).scaffoldBackgroundColor, actions: [ - if (!isLocalArchive) - IconButton( - splashRadius: 20, - onPressed: () { - widget.checkForUpdate(true); + if (!isLocalArchive) ...[ + PopupMenuButton( + icon: const Icon(Icons.download_outlined), + itemBuilder: (context) { + return [ + PopupMenuItem( + value: 0, + child: Text( + context.l10n.next_chapter)), + PopupMenuItem( + value: 1, + child: Text( + context.l10n.next_5_chapters)), + PopupMenuItem( + value: 2, + child: Text( + context.l10n.next_10_chapters)), + PopupMenuItem( + value: 3, + child: Text( + context.l10n.next_25_chapters)), + PopupMenuItem( + value: 4, + child: Text(context.l10n.unread)), + ]; }, - icon: const Icon( - Icons.refresh, - )), + onSelected: (value) { + final chapters = isar.chapters + .filter() + .idIsNotNull() + .mangaIdEqualTo(widget.manga!.id!) + .findAllSync(); + if (value == 0 || + value == 1 || + value == 2 || + value == 3) { + final lastChapterReadIndex = + chapters.lastIndexWhere((element) => + element.isRead == true); + if (lastChapterReadIndex == -1 || + chapters.length == 1) { + final chapter = chapters.first; + final entry = isar.downloads + .filter() + .idIsNotNull() + .chapterIdEqualTo(chapter.id) + .findFirstSync(); + if (entry == null || + !entry.isDownload!) { + ref.watch(downloadChapterProvider( + chapter: chapter)); + } + } else { + final length = switch (value) { + 0 => 1, + 1 => 5, + 2 => 10, + _ => 25, + }; + for (var i = 1; i < length + 1; i++) { + if (chapters.length > 1 && + chapters.elementAtOrNull( + lastChapterReadIndex + + i) != + null) { + final chapter = chapters[ + lastChapterReadIndex + i]; + final entry = isar.downloads + .filter() + .idIsNotNull() + .chapterIdEqualTo(chapter.id) + .findFirstSync(); + if (entry == null || + !entry.isDownload!) { + ref.watch( + downloadChapterProvider( + chapter: chapter)); + } + } + } + } + } else if (value == 4) { + final unreadChapters = isar.chapters + .filter() + .idIsNotNull() + .mangaIdEqualTo(widget.manga!.id!) + .isReadEqualTo(false) + .findAllSync(); + for (var chapter in unreadChapters) { + final entry = isar.downloads + .filter() + .idIsNotNull() + .chapterIdEqualTo(chapter.id) + .findFirstSync(); + if (entry == null || + !entry.isDownload!) { + ref.watch(downloadChapterProvider( + chapter: chapter)); + } + } + } + }), + ], IconButton( splashRadius: 20, onPressed: () { @@ -382,19 +476,21 @@ class _MangaDetailViewState extends ConsumerState )), PopupMenuButton(itemBuilder: (context) { return [ + if (!isLocalArchive) + PopupMenuItem( + value: 3, child: Text(l10n.refresh)), if (widget.manga!.favorite!) PopupMenuItem( value: 0, child: Text(l10n.edit_categories)), - // if (!isLocalArchive) - // if (widget.manga!.favorite!) - // PopupMenuItem( - // value: 1, child: Text(l10n.migrate)), if (!isLocalArchive) PopupMenuItem( value: 2, child: Text(l10n.share)), ]; }, onSelected: (value) { + if (value == 3) { + widget.checkForUpdate(true); + } if (value == 0) { context.push("/categories", extra: ( true,