-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # android/festago/presentation/src/main/res/values/strings.xml
- Loading branch information
Showing
56 changed files
with
1,031 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
.../main/java/com/festago/festago/presentation/ui/customview/OrientationAwareRecyclerView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.festago.festago.presentation.ui.customview | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.MotionEvent | ||
import androidx.recyclerview.widget.RecyclerView | ||
|
||
/** | ||
* 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, | ||
defStyleAttr: Int = 0, | ||
) : RecyclerView(context, attrs, defStyleAttr) { | ||
|
||
private var lastX = 0.0f | ||
private var lastY = 0.0f | ||
private var scrolling = false | ||
|
||
init { | ||
addOnScrollListener(object : OnScrollListener() { | ||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { | ||
super.onScrollStateChanged(recyclerView, newState) | ||
scrolling = newState != SCROLL_STATE_IDLE | ||
} | ||
}) | ||
} | ||
|
||
override fun onInterceptTouchEvent(e: MotionEvent): Boolean { | ||
val lm = layoutManager ?: return super.onInterceptTouchEvent(e) | ||
var allowScroll = true | ||
when (e.actionMasked) { | ||
MotionEvent.ACTION_DOWN -> { | ||
lastX = e.x | ||
lastY = e.y | ||
// If we were scrolling, stop now by faking a touch release | ||
if (scrolling) { | ||
val newEvent = MotionEvent.obtain(e) | ||
newEvent.action = MotionEvent.ACTION_UP | ||
return super.onInterceptTouchEvent(newEvent) | ||
} | ||
} | ||
|
||
MotionEvent.ACTION_MOVE -> { | ||
// We're moving, so check if we're trying | ||
// to scroll vertically or horizontally so we don't intercept the wrong event. | ||
val currentX = e.x | ||
val currentY = e.y | ||
val dx = Math.abs(currentX - lastX) | ||
val dy = Math.abs(currentY - lastY) | ||
allowScroll = if (dy > dx) lm.canScrollVertically() else lm.canScrollHorizontally() | ||
} | ||
} | ||
if (!allowScroll) return false | ||
return super.onInterceptTouchEvent(e) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.