Skip to content

Instantly share code, notes, and snippets.

View DanielKnauf's full-sized avatar
🍊

Daniel Knauf DanielKnauf

🍊
  • Hamburg, Germany
View GitHub Profile
@DanielKnauf
DanielKnauf / medium_horizontal_recyclerview_in_viewpager.kt
Last active August 18, 2023 04:48
OnItemTouchListener blocking MotionEvent from RecyclerViews' parent if RecyclerView can scroll left or right
addOnItemTouchListener(
object : RecyclerView.OnItemTouchListener {
private var startX = 0f
override fun onInterceptTouchEvent(
recyclerView: RecyclerView,
event: MotionEvent
): Boolean =
when (event.action) {
MotionEvent.ACTION_DOWN -> { startX = event.x }
interface IComponent {
val dataSource: Any
val layoutRes: Int
val bindingKey: Int
}
@DanielKnauf
DanielKnauf / medium_MergerLiveDataUseCase.kt
Last active April 18, 2021 14:14
MergerLiveData use case for medium article
/*
* before
*/
class ViewModel {
val nameInput = MutableLiveData("")
val ageInput = MutableLiveData(0)
}
<layout>
<data>
@DanielKnauf
DanielKnauf / medium_MergerLiveData.kt
Last active April 17, 2021 14:32
Excerpt of MergerLiveData from LiveData-Kit for Medium article
sealed class MergerLiveData<TargetType> : MediatorLiveData<TargetType>() {
// One
class Two<FirstSourceType, SecondSourceType, TargetType>(
private val firstSource: LiveData<FirstSourceType>,
private val secondSource: LiveData<SecondSourceType>,
private val distinctUntilChanged: Boolean = true,
private val merging: (FirstSourceType, SecondSourceType) -> TargetType
) : MediatorLiveData<TargetType>() {
override fun onActive() {
### Keybase proof
I hereby claim:
* I am danielknauf on github.
* I am knaufdan (https://keybase.io/knaufdan) on keybase.
* I have a public key ASBKEDkmhoAWM1v67IGHFio1viMY65i9dwUppIdYTw82GQo
To claim this, I am signing this object: