Fixing crashes in post calls

One day I'll use binding....one day
This commit is contained in:
Jays2Kings 2021-03-26 15:07:14 -04:00
parent 8f2b120454
commit 8556aba3ca
11 changed files with 22 additions and 16 deletions

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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<CoordinatorLayout.LayoutParams> {
controller.category_hopper_frame?.updateLayoutParams<CoordinatorLayout.LayoutParams> {
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<CoordinatorLayout.LayoutParams> {
controller.category_hopper_frame?.updateLayoutParams<CoordinatorLayout.LayoutParams> {
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 {

View File

@ -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())
}
}

View File

@ -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

View File

@ -1390,6 +1390,7 @@ class MangaDetailsController :
expandedImageView.post {
val defMargin = 16.dpToPx
manga_cover_full ?: return@post
expandedImageView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
height = ViewGroup.LayoutParams.MATCH_PARENT
width = ViewGroup.LayoutParams.MATCH_PARENT

View File

@ -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)

View File

@ -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())
}
}
}

View File

@ -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) {

View File

@ -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(

View File

@ -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
}
}