Skip to content

Commit

Permalink
Avoid some crashes if router backstack is empty for whatever reason
Browse files Browse the repository at this point in the history
  • Loading branch information
arkon committed Feb 13, 2022
1 parent fad1449 commit c284a23
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
}
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)
Expand Down

0 comments on commit c284a23

Please sign in to comment.