Răsfoiți Sursa

Use some more core-ktx extensions

arkon 4 ani în urmă
părinte
comite
dd66c83c50

+ 2 - 2
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

+ 2 - 2
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

+ 6 - 5
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<MainActivityBinding>() {
             }
 
             // 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<CoordinatorLayout.LayoutParams> {
+                anchorId = binding.bottomNav.id
+                anchorGravity = Gravity.TOP
+                gravity = Gravity.TOP
+            }
         }
 
         // Manually handle dismiss delay since Snackbar.LENGTH_LONG is a too short

+ 2 - 2
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