From 5fbae1256b2b67e32328f1386cbac144f10030d6 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sun, 17 Apr 2022 09:58:52 +0300 Subject: [PATCH] Fix branch detection #143 --- .../java/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt b/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt index 7c5fe8574..afc0129ac 100644 --- a/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt +++ b/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt @@ -191,7 +191,8 @@ class DetailsViewModel( // find default branch val hist = historyRepository.getOne(manga) selectedBranch.value = if (hist != null) { - manga.chapters?.find { it.id == hist.chapterId }?.branch + val currentChapter = manga.chapters?.find { it.id == hist.chapterId } + if (currentChapter != null) currentChapter.branch else predictBranch(manga.chapters) } else { predictBranch(manga.chapters) } @@ -203,6 +204,8 @@ class DetailsViewModel( } else { localMangaRepository.findSavedManga(manga) } + }.onFailure { error -> + if (BuildConfig.DEBUG) error.printStackTrace() }.getOrNull() }