From c284a23afb4d0eea9b5547b09182d238eca48a6d Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 13 Feb 2022 11:10:13 -0500 Subject: [PATCH] Avoid some crashes if router backstack is empty for whatever reason --- .../main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt | 2 +- .../tachiyomi/ui/browse/migration/search/SearchController.kt | 2 +- app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt index 294a7079fd..e3f103aca2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt @@ -96,7 +96,7 @@ class BrowseController : /* It's possible to switch to the Library controller by the time setExtensionUpdateBadge is called, resulting in a badge being put on the category tabs (if enabled). This check prevents that from happening */ - if (router.backstack.last().controller !is BrowseController) return + if (router.backstack.lastOrNull()?.controller !is BrowseController) return (activity as? MainActivity)?.binding?.tabs?.apply { val updates = preferences.extensionUpdatesCount().get() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt index b6fa0ecac6..fef73116ba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt @@ -76,7 +76,7 @@ class SearchController( router.popController(this) if (newManga != null) { val newMangaController = RouterTransaction.with(MangaController(newManga)) - if (router.backstack.last().controller is MangaController) { + if (router.backstack.lastOrNull()?.controller is MangaController) { // Replace old MangaController router.replaceTopController(newMangaController) } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 78b74756d8..566ebe9f0e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -409,7 +409,7 @@ class MainActivity : BaseViewBindingActivity() { } SHORTCUT_MANGA -> { val extras = intent.extras ?: return false - val fgController = router.backstack.last()?.controller as? MangaController + val fgController = router.backstack.lastOrNull()?.controller as? MangaController if (fgController?.manga?.id != extras.getLong(MangaController.MANGA_EXTRA)) { router.popToRoot() setSelectedNavItem(R.id.nav_library)