From 3d29a12fc486bfd87c4340ea844de1fe9a17725e Mon Sep 17 00:00:00 2001 From: Schnitzel5 Date: Sat, 9 Nov 2024 00:27:11 +0100 Subject: [PATCH] fix init settings --- lib/models/settings.dart | 47 ++++++++++- .../providers/reader_controller_provider.dart | 82 ++++++++++--------- 2 files changed, 88 insertions(+), 41 deletions(-) diff --git a/lib/models/settings.dart b/lib/models/settings.dart index ba0bc15..01d3c21 100644 --- a/lib/models/settings.dart +++ b/lib/models/settings.dart @@ -266,7 +266,7 @@ class Settings { this.animeLibraryShowNumbersOfItems = false, this.animeLibraryShowContinueReadingButton = false, this.animeLibraryLocalSource, - this.sortLibraryAnime, // TODO add novel settings + this.sortLibraryAnime, this.pagePreloadAmount = 6, this.scaleType = ScaleType.fitScreen, this.checkForExtensionUpdates = true, @@ -300,7 +300,19 @@ class Settings { this.mangaGridSize, this.animeGridSize, this.disableSectionType = SectionType.all, - this.useLibass = true}); + this.useLibass = true, + this.libraryFilterNovelDownloadType = 0, + this.libraryFilterNovelUnreadType = 0, + this.libraryFilterNovelStartedType = 0, + this.libraryFilterNovelBookMarkedType = 0, + this.novelLibraryShowCategoryTabs = false, + this.novelLibraryDownloadedChapters = false, + this.novelLibraryShowLanguage = false, + this.novelLibraryShowNumbersOfItems = false, + this.novelLibraryShowContinueReadingButton = false, + this.novelLibraryLocalSource, + this.sortLibraryNovel, + this.novelDisplayType = DisplayType.comfortableGrid}); Settings.fromJson(Map json) { animatePageTransitions = json['animatePageTransitions']; @@ -455,6 +467,22 @@ class Settings { disableSectionType = SectionType.values[json['disableSectionType'] ?? SectionType.all]; useLibass = json['useLibass']; + libraryFilterNovelBookMarkedType = json['libraryFilterNovelBookMarkedType']; + libraryFilterNovelDownloadType = json['libraryFilterNovelDownloadType']; + libraryFilterNovelStartedType = json['libraryFilterNovelStartedType']; + libraryFilterNovelUnreadType = json['libraryFilterNovelUnreadType']; + novelLibraryShowCategoryTabs = json['novelLibraryShowCategoryTabs']; + novelLibraryDownloadedChapters = json['novelLibraryDownloadedChapters']; + novelLibraryShowLanguage = json['novelLibraryShowLanguage']; + novelLibraryShowNumbersOfItems = json['novelLibraryShowNumbersOfItems']; + novelLibraryShowContinueReadingButton = + json['novelLibraryShowContinueReadingButton']; + novelLibraryLocalSource = json['novelLibraryLocalSource']; + sortLibraryNovel = json['sortLibraryNovel'] != null + ? SortLibraryManga.fromJson(json['sortLibraryNovel']) + : null; + novelDisplayType = DisplayType + .values[json['novelDisplayType'] ?? DisplayType.compactGrid.index]; } Map toJson() => { @@ -554,7 +582,20 @@ class Settings { 'mangaGridSize': mangaGridSize, 'animeGridSize': animeGridSize, 'disableSectionType': disableSectionType.index, - 'useLibass': useLibass + 'useLibass': useLibass, + 'libraryFilterNovelBookMarkedType': libraryFilterNovelBookMarkedType, + 'libraryFilterNovelDownloadType': libraryFilterNovelDownloadType, + 'libraryFilterNovelStartedType': libraryFilterNovelStartedType, + 'libraryFilterNovelUnreadType': libraryFilterNovelUnreadType, + 'novelLibraryShowCategoryTabs': novelLibraryShowCategoryTabs, + 'novelLibraryDownloadedChapters': novelLibraryDownloadedChapters, + 'novelLibraryShowLanguage': novelLibraryShowLanguage, + 'novelLibraryShowNumbersOfItems': novelLibraryShowNumbersOfItems, + 'novelLibraryShowContinueReadingButton': + novelLibraryShowContinueReadingButton, + 'novelLibraryLocalSource': novelLibraryLocalSource, + 'sortLibraryNovel': sortLibraryNovel?.toJson(), + 'novelDisplayType': novelDisplayType.index, }; } diff --git a/lib/modules/manga/reader/providers/reader_controller_provider.dart b/lib/modules/manga/reader/providers/reader_controller_provider.dart index 1754680..35b12f5 100644 --- a/lib/modules/manga/reader/providers/reader_controller_provider.dart +++ b/lib/modules/manga/reader/providers/reader_controller_provider.dart @@ -171,7 +171,7 @@ class ReaderController extends _$ReaderController { history = History( mangaId: getManga().id, date: DateTime.now().millisecondsSinceEpoch.toString(), - isManga: getManga().isManga, + itemType: getManga().itemType, chapterId: chapter.id) ..chapter.value = chapter; } else { @@ -379,7 +379,7 @@ extension ChapterExtensions on Chapter { final tracks = isar.tracks .filter() .idIsNotNull() - .isMangaEqualTo(manga.isManga) + .isMangaEqualTo(manga.itemType == ItemType.manga) .mangaIdEqualTo(manga.id!) .findAllSync(); @@ -398,15 +398,17 @@ extension ChapterExtensions on Chapter { track.status = TrackStatus.completed; track.finishedReadingDate = DateTime.now().millisecondsSinceEpoch; } else { - track.status = - manga.isManga! ? TrackStatus.reading : TrackStatus.watching; + track.status = manga.itemType == ItemType.manga + ? TrackStatus.reading + : TrackStatus.watching; if (track.lastChapterRead == 1) { track.startedReadingDate = DateTime.now().millisecondsSinceEpoch; } } } ref - .read(trackStateProvider(track: track, isManga: manga.isManga) + .read(trackStateProvider( + track: track, isManga: manga.itemType == ItemType.manga) .notifier) .updateManga(); } @@ -418,47 +420,51 @@ extension MangaExtensions on Manga { List getFilteredChapterList() { final data = this.chapters.toList().reversed.toList(); final filterUnread = (isar.settings - .getSync(227)! - .chapterFilterUnreadList! - .where((element) => element.mangaId == id) - .toList() - .firstOrNull ?? ChapterFilterUnread( - mangaId: id, - type: 0, - )) + .getSync(227)! + .chapterFilterUnreadList! + .where((element) => element.mangaId == id) + .toList() + .firstOrNull ?? + ChapterFilterUnread( + mangaId: id, + type: 0, + )) .type!; final filterBookmarked = (isar.settings - .getSync(227)! - .chapterFilterBookmarkedList! - .where((element) => element.mangaId == id) - .toList() - .firstOrNull ?? ChapterFilterBookmarked( - mangaId: id, - type: 0, - )) + .getSync(227)! + .chapterFilterBookmarkedList! + .where((element) => element.mangaId == id) + .toList() + .firstOrNull ?? + ChapterFilterBookmarked( + mangaId: id, + type: 0, + )) .type!; final filterDownloaded = (isar.settings - .getSync(227)! - .chapterFilterDownloadedList! - .where((element) => element.mangaId == id) - .toList() - .firstOrNull ?? ChapterFilterDownloaded( - mangaId: id, - type: 0, - )) + .getSync(227)! + .chapterFilterDownloadedList! + .where((element) => element.mangaId == id) + .toList() + .firstOrNull ?? + ChapterFilterDownloaded( + mangaId: id, + type: 0, + )) .type!; final sortChapter = (isar.settings - .getSync(227)! - .sortChapterList! - .where((element) => element.mangaId == id) - .toList() - .firstOrNull ?? SortChapter( - mangaId: id, - index: 1, - reverse: false, - )) + .getSync(227)! + .sortChapterList! + .where((element) => element.mangaId == id) + .toList() + .firstOrNull ?? + SortChapter( + mangaId: id, + index: 1, + reverse: false, + )) .index; final filterScanlator = _getFilterScanlator(this) ?? []; List? chapterList;