Skip to content

Commit

Permalink
[AN/USER] feat: 축제 목록 화면 스크롤 민감도를 줄인다(#�764) (#765)
Browse files Browse the repository at this point in the history
* feat(customView): 가로 스크롤 시 세로 스크롤과 중첩되지 않는 커스텀 리사이클러뷰 작성

* feat(FestivalList): 축제 목록 리사이클러뷰의 민감도를 줄인다

* feat(FestivalList): 스와이프 새로고침의 민감도를 줄인다

* feat(FestivalList): 축제 목록 tab 디자인 수정

* feat(FestivalList): 축제 이름에서 대학교 이름을 뺀다
  • Loading branch information
SeongHoonC authored Mar 6, 2024
1 parent 0bcd8d7 commit 1f3cf51
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
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 @@ -78,6 +78,7 @@ class FestivalListFragment : Fragment() {
vm.initFestivalList()
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>

0 comments on commit 1f3cf51

Please sign in to comment.