fix: story scrolling issue
This commit is contained in:
parent
fb65cb601e
commit
72fe910c59
2 changed files with 97 additions and 77 deletions
|
@ -74,8 +74,7 @@ class Stories @JvmOverloads constructor(
|
||||||
|
|
||||||
if (context is StoriesCallback) storiesListener = context as StoriesCallback
|
if (context is StoriesCallback) storiesListener = context as StoriesCallback
|
||||||
|
|
||||||
binding.leftTouchPanel.setOnTouchListener(this)
|
binding.touchPanel.setOnTouchListener(this)
|
||||||
binding.rightTouchPanel.setOnTouchListener(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -264,49 +263,7 @@ class Stories @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private var startClickTime = 0L
|
|
||||||
private var startX = 0f
|
|
||||||
private var startY = 0f
|
|
||||||
private var isLongPress = false
|
|
||||||
private val swipeThreshold = 100
|
|
||||||
override fun onTouch(view: View?, event: MotionEvent?): Boolean {
|
|
||||||
val maxClickDuration = 200
|
|
||||||
when (event?.action) {
|
|
||||||
MotionEvent.ACTION_DOWN -> {
|
|
||||||
startX = event.x
|
|
||||||
startY = event.y
|
|
||||||
startClickTime = Calendar.getInstance().timeInMillis
|
|
||||||
pause()
|
|
||||||
isLongPress = false
|
|
||||||
}
|
|
||||||
|
|
||||||
MotionEvent.ACTION_MOVE -> {
|
|
||||||
val deltaX = event.x - startX
|
|
||||||
val deltaY = event.y - startY
|
|
||||||
if (!isLongPress && (abs(deltaX) > swipeThreshold || abs(deltaY) > swipeThreshold)) {
|
|
||||||
isLongPress = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MotionEvent.ACTION_UP -> {
|
|
||||||
val clickDuration = Calendar.getInstance().timeInMillis - startClickTime
|
|
||||||
if (clickDuration < maxClickDuration && !isLongPress) {
|
|
||||||
when (view?.id) {
|
|
||||||
R.id.leftTouchPanel -> leftPanelTouch()
|
|
||||||
R.id.rightTouchPanel -> rightPanelTouch()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resume()
|
|
||||||
}
|
|
||||||
val deltaX = event.x - startX
|
|
||||||
if (abs(deltaX) > swipeThreshold) {
|
|
||||||
if (deltaX > 0) onStoriesPrevious()
|
|
||||||
else onStoriesCompleted()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun rightPanelTouch() {
|
private fun rightPanelTouch() {
|
||||||
Logger.log("rightPanelTouch: $storyIndex")
|
Logger.log("rightPanelTouch: $storyIndex")
|
||||||
|
@ -359,6 +316,7 @@ class Stories @JvmOverloads constructor(
|
||||||
timer.resume()
|
timer.resume()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private fun loadStory(story: Activity) {
|
private fun loadStory(story: Activity) {
|
||||||
val key = "activities"
|
val key = "activities"
|
||||||
val set = PrefManager.getCustomVal<Set<Int>>(key, setOf()).plus((story.id))
|
val set = PrefManager.getCustomVal<Set<Int>>(key, setOf()).plus((story.id))
|
||||||
|
@ -374,6 +332,15 @@ class Stories @JvmOverloads constructor(
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.textActivity.setOnTouchListener { v, event ->
|
||||||
|
onTouchView(v, event, true)
|
||||||
|
v.onTouchEvent(event)
|
||||||
|
}
|
||||||
|
binding.textActivityContainer.setOnTouchListener { v, event ->
|
||||||
|
onTouchView(v, event, true)
|
||||||
|
v.onTouchEvent(event)
|
||||||
|
}
|
||||||
fun visible(isList: Boolean) {
|
fun visible(isList: Boolean) {
|
||||||
binding.textActivity.isVisible = !isList
|
binding.textActivity.isVisible = !isList
|
||||||
binding.textActivityContainer.isVisible = !isList
|
binding.textActivityContainer.isVisible = !isList
|
||||||
|
@ -397,15 +364,15 @@ class Stories @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ${story.progress ?: story.media?.title?.userPreferred} " +
|
} ${story.progress ?: story.media?.title?.userPreferred} " +
|
||||||
if (
|
if (
|
||||||
story.status?.contains("completed") == false &&
|
story.status?.contains("completed") == false &&
|
||||||
!story.status.contains("plans") &&
|
!story.status.contains("plans") &&
|
||||||
!story.status.contains("repeating")
|
!story.status.contains("repeating")
|
||||||
) {
|
) {
|
||||||
"of ${story.media?.title?.userPreferred}"
|
"of ${story.media?.title?.userPreferred}"
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
binding.infoText.text = text
|
binding.infoText.text = text
|
||||||
val bannerAnimations: Boolean = PrefManager.getVal(PrefName.BannerAnimations)
|
val bannerAnimations: Boolean = PrefManager.getVal(PrefName.BannerAnimations)
|
||||||
blurImage(
|
blurImage(
|
||||||
|
@ -502,4 +469,66 @@ class Stories @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private var startClickTime = 0L
|
||||||
|
private var startX = 0f
|
||||||
|
private var startY = 0f
|
||||||
|
private var isLongPress = false
|
||||||
|
private val swipeThreshold = 100
|
||||||
|
override fun onTouch(view: View, event: MotionEvent): Boolean {
|
||||||
|
onTouchView(view, event)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
private fun onTouchView(view: View, event: MotionEvent, isText: Boolean = false){
|
||||||
|
val maxClickDuration = 200
|
||||||
|
val screenWidth = view.width
|
||||||
|
val leftHalf = screenWidth / 2
|
||||||
|
val leftQuarter = screenWidth * 0.15
|
||||||
|
val rightQuarter = screenWidth * 0.85
|
||||||
|
when (event.action) {
|
||||||
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
startX = event.x
|
||||||
|
startY = event.y
|
||||||
|
startClickTime = Calendar.getInstance().timeInMillis
|
||||||
|
pause()
|
||||||
|
isLongPress = false
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_MOVE -> {
|
||||||
|
val deltaX = event.x - startX
|
||||||
|
val deltaY = event.y - startY
|
||||||
|
if (!isLongPress && (abs(deltaX) > swipeThreshold || abs(deltaY) > swipeThreshold)) {
|
||||||
|
isLongPress = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_UP -> {
|
||||||
|
val clickDuration = Calendar.getInstance().timeInMillis - startClickTime
|
||||||
|
if (isText) {
|
||||||
|
if (clickDuration < maxClickDuration && !isLongPress) {
|
||||||
|
if (event.x < leftQuarter) {
|
||||||
|
leftPanelTouch()
|
||||||
|
} else if (event.x > rightQuarter) {
|
||||||
|
rightPanelTouch()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resume()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (clickDuration < maxClickDuration && !isLongPress) {
|
||||||
|
if (event.x < leftHalf) {
|
||||||
|
leftPanelTouch()
|
||||||
|
} else {
|
||||||
|
rightPanelTouch()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resume()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val deltaX = event.x - startX
|
||||||
|
if (abs(deltaX) > swipeThreshold) {
|
||||||
|
if (deltaX > 0) onStoriesPrevious()
|
||||||
|
else onStoriesCompleted()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -28,45 +28,36 @@
|
||||||
android:src="@drawable/linear_gradient_bg"
|
android:src="@drawable/linear_gradient_bg"
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/touchPanel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true" />
|
||||||
|
|
||||||
<androidx.core.widget.NestedScrollView
|
<androidx.core.widget.NestedScrollView
|
||||||
android:id="@+id/textActivityContainer"
|
android:id="@+id/textActivityContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center"
|
android:layout_marginHorizontal="16dp"
|
||||||
android:orientation="horizontal">
|
android:layout_marginVertical="94dp"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:scrollbars="none">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textActivity"
|
android:id="@+id/textActivity"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
android:fontFamily="@font/poppins_semi_bold"
|
android:fontFamily="@font/poppins_semi_bold"
|
||||||
android:gravity="center"
|
|
||||||
android:paddingHorizontal="12dp"
|
android:paddingHorizontal="12dp"
|
||||||
android:text="Play"
|
android:text="test"
|
||||||
|
android:textAlignment="center"
|
||||||
android:textColor="@color/bg_white"
|
android:textColor="@color/bg_white"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:visibility="gone"
|
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/leftTouchPanel"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintWidth_percent="0.5" />
|
|
||||||
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/rightTouchPanel"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintWidth_percent="0.5" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue