Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AN/USER] feat: 축제 목록 화면 스크롤 민감도를 줄인다(#764) #765

Merged
merged 5 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class FestivalListFragment : Fragment() {
vm.loadFestivals()
binding.srlFestivalList.isRefreshing = false
}
binding.srlFestivalList.setDistanceToTriggerSync(400)
binding.ivSearch.setOnClickListener { // 임시 연결
showSchoolDetail()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/containerAppBarFestivalList">

<androidx.recyclerview.widget.RecyclerView
<com.festago.festago.presentation.ui.customview.OrientationAwareRecyclerView
android:id="@+id/rvFestivalList"
visibility="@{uiState.shouldShowSuccess}"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
android:ellipsize="end"
android:gravity="center"
android:lineSpacingExtra="0dp"
android:maxLines="2"
android:text="@{item.schoolUiState.name+'\n'+ item.name }"
android:lines="2"
android:text="@{item.name}"
android:textColor="@color/background_gray_01"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/vpPopularFestivalForeground"
tools:text="대학교 \n 축제 이름" />
tools:text="연세대 아카라카 연세대 아카라카 연세대 아카라카" />

<TextView
android:id="@+id/tvFestivalSchedule"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
android:background="@android:color/transparent"
app:tabGravity="fill"
app:tabIndicatorColor="@color/contents_gray_07"
app:tabIndicatorFullWidth="true"
app:tabIndicatorFullWidth="false"
app:tabIndicatorHeight="2dp"
app:tabSelectedTextColor="@color/contents_gray_07"
app:tabTextAppearance="@style/H1Bold20Lh20"
app:tabTextColor="@color/contents_gray_04">

</com.google.android.material.tabs.TabLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/background_gray_03" />

</LinearLayout>
</layout>
Loading