From 1f3cf5181b90de283632b8b79dc48cd20f04f9c8 Mon Sep 17 00:00:00 2001 From: SeongHoonC <108349655+SeongHoonC@users.noreply.github.com> Date: Wed, 6 Mar 2024 19:13:49 +0900 Subject: [PATCH] =?UTF-8?q?[AN/USER]=20feat:=20=EC=B6=95=EC=A0=9C=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=ED=99=94=EB=A9=B4=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A1=A4=20=EB=AF=BC=EA=B0=90=EB=8F=84=EB=A5=BC=20=EC=A4=84?= =?UTF-8?q?=EC=9D=B8=EB=8B=A4(#=08764)=20(#765)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(customView): 가로 스크롤 시 세로 스크롤과 중첩되지 않는 커스텀 리사이클러뷰 작성 * feat(FestivalList): 축제 목록 리사이클러뷰의 민감도를 줄인다 * feat(FestivalList): 스와이프 새로고침의 민감도를 줄인다 * feat(FestivalList): 축제 목록 tab 디자인 수정 * feat(FestivalList): 축제 이름에서 대학교 이름을 뺀다 --- .../OrientationAwareRecyclerView.kt | 59 +++++++++++++++++++ .../home/festivallist/FestivalListFragment.kt | 1 + .../res/layout/fragment_festival_list.xml | 2 +- .../res/layout/item_festival_list_popular.xml | 6 +- .../res/layout/item_festival_list_tab.xml | 7 ++- 5 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/customview/OrientationAwareRecyclerView.kt diff --git a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/customview/OrientationAwareRecyclerView.kt b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/customview/OrientationAwareRecyclerView.kt new file mode 100644 index 000000000..6cadf13f8 --- /dev/null +++ b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/customview/OrientationAwareRecyclerView.kt @@ -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) + } +} diff --git a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/festivallist/FestivalListFragment.kt b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/festivallist/FestivalListFragment.kt index 38213de80..47ebe1b2d 100644 --- a/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/festivallist/FestivalListFragment.kt +++ b/android/festago/presentation/src/main/java/com/festago/festago/presentation/ui/home/festivallist/FestivalListFragment.kt @@ -78,6 +78,7 @@ class FestivalListFragment : Fragment() { vm.initFestivalList() binding.srlFestivalList.isRefreshing = false } + binding.srlFestivalList.setDistanceToTriggerSync(400) binding.ivSearch.setOnClickListener { // 임시 연결 showSchoolDetail() } diff --git a/android/festago/presentation/src/main/res/layout/fragment_festival_list.xml b/android/festago/presentation/src/main/res/layout/fragment_festival_list.xml index 2020f8f84..70e55fb23 100644 --- a/android/festago/presentation/src/main/res/layout/fragment_festival_list.xml +++ b/android/festago/presentation/src/main/res/layout/fragment_festival_list.xml @@ -69,7 +69,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/containerAppBarFestivalList"> - + tools:text="연세대 아카라카 연세대 아카라카 연세대 아카라카" /> + +