From 8556aba3ca211069e36c8e79dacf39a79a4bd98d Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Fri, 26 Mar 2021 15:07:14 -0400 Subject: [PATCH] Fixing crashes in post calls One day I'll use binding....one day --- .../java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt | 2 +- .../eu/kanade/tachiyomi/ui/library/LibraryController.kt | 6 +++--- .../kanade/tachiyomi/ui/library/LibraryGestureDetector.kt | 8 ++++---- .../eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt | 2 +- .../tachiyomi/ui/library/filter/FilterBottomSheet.kt | 4 ++++ .../kanade/tachiyomi/ui/manga/MangaDetailsController.kt | 1 + .../eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt | 1 + .../java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt | 2 +- .../ui/migration/manga/design/MigrationSourceHolder.kt | 2 +- .../tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt | 6 +++--- .../tachiyomi/ui/source/browse/SourceSearchSheet.kt | 4 ++-- 11 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt index 9e189cb72b..0b1bcd3114 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt @@ -107,7 +107,7 @@ class MaterialMenuSheet( currentIndex?.let { view.post { - menu_scroll_view.scrollTo(0, it * 48.dpToPx - menu_scroll_view.height / 2) + menu_scroll_view?.scrollTo(0, it * 48.dpToPx - menu_scroll_view.height / 2) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 22eee9c729..2c6abb865f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -748,7 +748,7 @@ class LibraryController( private fun setRecyclerLayout() { recycler.post { - recycler.updatePaddingRelative(bottom = 50.dpToPx + (activity?.bottom_nav?.height ?: 0)) + recycler?.updatePaddingRelative(bottom = 50.dpToPx + (activity?.bottom_nav?.height ?: 0)) } if (libraryLayout == 0) { recycler.spanCount = 1 @@ -839,7 +839,7 @@ class LibraryController( adapter.setItems(mangaMap) if (recycler.itemAnimator == null) { recycler.post { - recycler.itemAnimator = DefaultItemAnimator() + recycler?.itemAnimator = DefaultItemAnimator() } } singleCategory = presenter.categories.size <= 1 @@ -914,7 +914,7 @@ class LibraryController( animatorSet.startDelay = 1250 animatorSet.addListener( EndAnimatorListener { - category_hopper_frame.translationX = 0f + category_hopper_frame?.translationX = 0f isAnimatingHopper = false this.animatorSet = null } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGestureDetector.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGestureDetector.kt index 7ae62cf62c..9a949f9767 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGestureDetector.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGestureDetector.kt @@ -67,7 +67,7 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur if (hopperGravity == Gravity.TOP or Gravity.LEFT) 0f else (-(controller.view!!.width - controller.category_hopper_frame.width) / 2).toFloat() ).withEndAction { - controller.category_hopper_frame.updateLayoutParams { + controller.category_hopper_frame?.updateLayoutParams { gravity = Gravity.TOP or ( if (gravity == Gravity.TOP or Gravity.RIGHT) { @@ -86,7 +86,7 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur if (hopperGravity == Gravity.TOP or Gravity.RIGHT) 0f else ((controller.view!!.width - controller.category_hopper_frame.width) / 2).toFloat() ).withEndAction { - controller.category_hopper_frame.updateLayoutParams { + controller.category_hopper_frame?.updateLayoutParams { gravity = Gravity.TOP or ( if (gravity == Gravity.TOP or Gravity.LEFT) { @@ -107,12 +107,12 @@ class LibraryGestureDetector(private val controller: LibraryController) : Gestur return result } - fun savePrefs() { + private fun savePrefs() { if (!controller.hasMovedHopper) { controller.preferences.shownHopperSwipeTutorial().set(true) } controller.hopperGravity = controller.preferences.hopperGravity().get() - controller.category_hopper_frame.translationX = 0f + controller.category_hopper_frame?.translationX = 0f } private companion object { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index b27fe4af73..8fb5a1aead 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -69,7 +69,7 @@ class LibraryListHolder( subtitle.text = item.manga.author?.trim() title.post { - if (title.text == item.manga.title) { + if (title?.text == item.manga.title) { subtitle.visibleIf(title.lineCount == 1 && !item.manga.author.isNullOrBlank()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt index 64beedb7c8..8f13f675fd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt @@ -130,6 +130,9 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri ) post { + second_layout ?: return@post + first_layout ?: return@post + view_options ?: return@post if (second_layout.width + first_layout.width + 20.dpToPx < width) { second_layout.removeView(view_options) second_layout.removeView(reorder_filters) @@ -159,6 +162,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } post { + libraryRecyler ?: return@post updateRootPadding( when (sheetBehavior?.state) { BottomSheetBehavior.STATE_HIDDEN -> -1f diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index 7a6df689d0..041da48e12 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -1390,6 +1390,7 @@ class MangaDetailsController : expandedImageView.post { val defMargin = 16.dpToPx + manga_cover_full ?: return@post expandedImageView.updateLayoutParams { height = ViewGroup.LayoutParams.MATCH_PARENT width = ViewGroup.LayoutParams.MATCH_PARENT diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt index 7956df2279..e4a04517c4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt @@ -163,6 +163,7 @@ class MangaHeaderHolder( else manga.description?.trim() manga_summary.post { + manga_summary ?: return@post if (sub_item_group.visibility != View.GONE) { if ((manga_summary.lineCount < 3 && manga.genre.isNullOrBlank()) || less_button.isVisible()) { manga_summary.setTextIsSelectable(true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt index 35ecaa1903..8e12a7cef8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SourceHolder.kt @@ -24,7 +24,7 @@ class SourceHolder(view: View, val adapter: SourceAdapter) : // Set circle letter image. itemView.post { - edit_button.setImageDrawable(source.icon()) + edit_button?.setImageDrawable(source.icon()) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt index 5e2b8f79be..42350135f5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceHolder.kt @@ -24,7 +24,7 @@ class MigrationSourceHolder(view: View, val adapter: MigrationSourceAdapter) : // Update circle letter image. itemView.post { val icon = source.icon() - if (icon != null) edit_button.setImageDrawable(icon) + if (icon != null) edit_button?.setImageDrawable(icon) } if (sourceEnabled) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt index 34026c1717..9b4d78ae2a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt @@ -58,9 +58,9 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr } post { - chapter_recycler.alpha = if (sheetBehavior.isExpanded()) 1f else 0f - chapter_recycler.isClickable = sheetBehavior.isExpanded() - chapter_recycler.isFocusable = sheetBehavior.isExpanded() + chapter_recycler?.alpha = if (sheetBehavior.isExpanded()) 1f else 0f + chapter_recycler?.isClickable = sheetBehavior.isExpanded() + chapter_recycler?.isFocusable = sheetBehavior.isExpanded() } sheetBehavior?.addBottomSheetCallback( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt index 3a27580a6d..05d525c1a1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt @@ -68,9 +68,9 @@ class SourceSearchSheet(activity: Activity) : // the spinner in the recycler can break the sheet's layout on change // this is to reset it back source_filter_sheet.post { - (source_filter_sheet.parent as View).fitsSystemWindows = false + (source_filter_sheet?.parent as? View)?.fitsSystemWindows = false source_filter_sheet.viewTreeObserver.addOnDrawListener { - (source_filter_sheet.parent as View).fitsSystemWindows = false + (source_filter_sheet?.parent as? View)?.fitsSystemWindows = false } }