From dd66c83c50b7950b934a7d118e3a30ea52c460e2 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 25 Jul 2020 12:07:20 -0400 Subject: [PATCH] Use some more core-ktx extensions --- .../extension/ExtensionDividerItemDecoration.kt | 4 ++-- .../ui/browse/source/SourceDividerItemDecoration.kt | 4 ++-- .../java/eu/kanade/tachiyomi/ui/main/MainActivity.kt | 11 ++++++----- .../ui/manga/chapter/ChapterDividerItemDecoration.kt | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDividerItemDecoration.kt index 839d199562..ff936f9b7c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDividerItemDecoration.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionDividerItemDecoration.kt @@ -5,6 +5,7 @@ import android.graphics.Canvas import android.graphics.Rect import android.graphics.drawable.Drawable import android.view.View +import androidx.core.view.marginBottom import androidx.recyclerview.widget.RecyclerView class ExtensionDividerItemDecoration(context: Context) : RecyclerView.ItemDecoration() { @@ -25,8 +26,7 @@ class ExtensionDividerItemDecoration(context: Context) : RecyclerView.ItemDecora if (holder is ExtensionHolder && parent.getChildViewHolder(parent.getChildAt(i + 1)) is ExtensionHolder ) { - val params = child.layoutParams as RecyclerView.LayoutParams - val top = child.bottom + params.bottomMargin + val top = child.bottom + child.marginBottom val bottom = top + divider.intrinsicHeight val left = parent.paddingStart + holder.margin val right = parent.width - parent.paddingEnd - holder.margin diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceDividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceDividerItemDecoration.kt index a64de84011..8ef13d8404 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceDividerItemDecoration.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceDividerItemDecoration.kt @@ -5,6 +5,7 @@ import android.graphics.Canvas import android.graphics.Rect import android.graphics.drawable.Drawable import android.view.View +import androidx.core.view.marginBottom import androidx.recyclerview.widget.RecyclerView class SourceDividerItemDecoration(context: Context) : RecyclerView.ItemDecoration() { @@ -25,8 +26,7 @@ class SourceDividerItemDecoration(context: Context) : RecyclerView.ItemDecoratio if (holder is SourceHolder && parent.getChildViewHolder(parent.getChildAt(i + 1)) is SourceHolder ) { - val params = child.layoutParams as RecyclerView.LayoutParams - val top = child.bottom + params.bottomMargin + val top = child.bottom + child.marginBottom val bottom = top + divider.intrinsicHeight val left = parent.paddingStart + holder.margin val right = parent.width - parent.paddingEnd - holder.margin 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 1dba59ccc6..17f6dcf362 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 @@ -11,6 +11,7 @@ import android.view.ViewGroup import android.widget.Toast import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.view.isVisible +import androidx.core.view.updateLayoutParams import com.bluelinelabs.conductor.Conductor import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.ControllerChangeHandler @@ -393,11 +394,11 @@ class MainActivity : BaseActivity() { } // Ensure the snackbar sits above the bottom nav - val layoutParams = view.layoutParams as CoordinatorLayout.LayoutParams - layoutParams.anchorId = binding.bottomNav.id - layoutParams.anchorGravity = Gravity.TOP - layoutParams.gravity = Gravity.TOP - view.layoutParams = layoutParams + view.updateLayoutParams { + anchorId = binding.bottomNav.id + anchorGravity = Gravity.TOP + gravity = Gravity.TOP + } } // Manually handle dismiss delay since Snackbar.LENGTH_LONG is a too short diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterDividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterDividerItemDecoration.kt index e59a835c2d..88288c7280 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterDividerItemDecoration.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterDividerItemDecoration.kt @@ -5,6 +5,7 @@ import android.graphics.Canvas import android.graphics.Rect import android.graphics.drawable.Drawable import android.view.View +import androidx.core.view.marginBottom import androidx.recyclerview.widget.RecyclerView /** @@ -32,8 +33,7 @@ class ChapterDividerItemDecoration(context: Context) : RecyclerView.ItemDecorati val childCount = parent.childCount for (i in 1 until childCount) { val child = parent.getChildAt(i) - val params = child.layoutParams as RecyclerView.LayoutParams - val top = child.bottom + params.bottomMargin + val top = child.bottom + child.marginBottom val bottom = top + divider.intrinsicHeight val left = parent.paddingStart val right = parent.width - parent.paddingEnd