Skip to content

Instantly share code, notes, and snippets.

@orioonyx
orioonyx / 1 ViewBindingDelegates.kt
Created January 5, 2023 11:10 — forked from gmk57/1 ViewBindingDelegates.kt
Kotlin delegates for Android View Binding with usage examples
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.viewbinding.ViewBinding
@orioonyx
orioonyx / CenterZoomLayoutManager
Created January 8, 2023 14:23
RecyclerView Custom LayoutManager to centrally zoom items.
class CenterZoomLayoutManager : LinearLayoutManager {
private var mShrinkAmount = 0.1f
private val mShrinkDistance = 0.9f
constructor(context: Context?, orientation: Int, reverseLayout: Boolean, shrinkAmount: Float) : super(
context,
orientation,
reverseLayout
) {
class GravitySnapHelper @JvmOverloads constructor(
gravity: Int, enableSnapLastItem: Boolean = false,
snapListener: SnapListener? = null
) :
LinearSnapHelper() {
private val FLING_DISTANCE_DISABLE = -1
private val FLING_SIZE_FRACTION_DISABLE = -1f
private var gravity = 0
private var isRtl = false
private var snapLastItem = false
@orioonyx
orioonyx / OrientationAwareRecyclerView
Last active January 9, 2023 17:56
A RecyclerView that only handles scroll events with the same orientation of its LayoutManager.
/**
* A RecyclerView that only handles scroll events with the same orientation of its LayoutManager.
* Avoids situations where nested recyclerviews don't receive touch events properly:
*/
class OrientationAwareRecyclerView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) :
RecyclerView(context, attrs, defStyleAttr) {
private var lastX = 0.0f