Use some more core-ktx extensions

This commit is contained in:
arkon 2020-07-25 12:07:20 -04:00
parent 9e51d82154
commit dd66c83c50
4 changed files with 12 additions and 11 deletions

View File

@ -5,6 +5,7 @@ import android.graphics.Canvas
import android.graphics.Rect import android.graphics.Rect
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.View import android.view.View
import androidx.core.view.marginBottom
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
class ExtensionDividerItemDecoration(context: Context) : RecyclerView.ItemDecoration() { class ExtensionDividerItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
@ -25,8 +26,7 @@ class ExtensionDividerItemDecoration(context: Context) : RecyclerView.ItemDecora
if (holder is ExtensionHolder && if (holder is ExtensionHolder &&
parent.getChildViewHolder(parent.getChildAt(i + 1)) is ExtensionHolder parent.getChildViewHolder(parent.getChildAt(i + 1)) is ExtensionHolder
) { ) {
val params = child.layoutParams as RecyclerView.LayoutParams val top = child.bottom + child.marginBottom
val top = child.bottom + params.bottomMargin
val bottom = top + divider.intrinsicHeight val bottom = top + divider.intrinsicHeight
val left = parent.paddingStart + holder.margin val left = parent.paddingStart + holder.margin
val right = parent.width - parent.paddingEnd - holder.margin val right = parent.width - parent.paddingEnd - holder.margin

View File

@ -5,6 +5,7 @@ import android.graphics.Canvas
import android.graphics.Rect import android.graphics.Rect
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.View import android.view.View
import androidx.core.view.marginBottom
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
class SourceDividerItemDecoration(context: Context) : RecyclerView.ItemDecoration() { class SourceDividerItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
@ -25,8 +26,7 @@ class SourceDividerItemDecoration(context: Context) : RecyclerView.ItemDecoratio
if (holder is SourceHolder && if (holder is SourceHolder &&
parent.getChildViewHolder(parent.getChildAt(i + 1)) is SourceHolder parent.getChildViewHolder(parent.getChildAt(i + 1)) is SourceHolder
) { ) {
val params = child.layoutParams as RecyclerView.LayoutParams val top = child.bottom + child.marginBottom
val top = child.bottom + params.bottomMargin
val bottom = top + divider.intrinsicHeight val bottom = top + divider.intrinsicHeight
val left = parent.paddingStart + holder.margin val left = parent.paddingStart + holder.margin
val right = parent.width - parent.paddingEnd - holder.margin val right = parent.width - parent.paddingEnd - holder.margin

View File

@ -11,6 +11,7 @@ import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import com.bluelinelabs.conductor.Conductor import com.bluelinelabs.conductor.Conductor
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeHandler
@ -393,11 +394,11 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
} }
// Ensure the snackbar sits above the bottom nav // Ensure the snackbar sits above the bottom nav
val layoutParams = view.layoutParams as CoordinatorLayout.LayoutParams view.updateLayoutParams<CoordinatorLayout.LayoutParams> {
layoutParams.anchorId = binding.bottomNav.id anchorId = binding.bottomNav.id
layoutParams.anchorGravity = Gravity.TOP anchorGravity = Gravity.TOP
layoutParams.gravity = Gravity.TOP gravity = Gravity.TOP
view.layoutParams = layoutParams }
} }
// Manually handle dismiss delay since Snackbar.LENGTH_LONG is a too short // Manually handle dismiss delay since Snackbar.LENGTH_LONG is a too short

View File

@ -5,6 +5,7 @@ import android.graphics.Canvas
import android.graphics.Rect import android.graphics.Rect
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.View import android.view.View
import androidx.core.view.marginBottom
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
/** /**
@ -32,8 +33,7 @@ class ChapterDividerItemDecoration(context: Context) : RecyclerView.ItemDecorati
val childCount = parent.childCount val childCount = parent.childCount
for (i in 1 until childCount) { for (i in 1 until childCount) {
val child = parent.getChildAt(i) val child = parent.getChildAt(i)
val params = child.layoutParams as RecyclerView.LayoutParams val top = child.bottom + child.marginBottom
val top = child.bottom + params.bottomMargin
val bottom = top + divider.intrinsicHeight val bottom = top + divider.intrinsicHeight
val left = parent.paddingStart val left = parent.paddingStart
val right = parent.width - parent.paddingEnd val right = parent.width - parent.paddingEnd