-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: 컨퍼런스 화면에서 맨 위로 스크롤하는 기능 구현 * feat: 스크랩 화면에서 맨 위로 스크롤하는 기능 구현 * feat: 대회 화면에서 맨 위로 스크롤하는 기능 구현 * refactor: ScrollTopListener의 클릭리스너를 내부에서 설정하도록 변경 * refactor(ScrollTopListener): getScrollUpStandardPosition() 메서드를 expression 형식으로 변경 * refactor(ScrollTopListener): 메서드 배치 순서 변경
- Loading branch information
Showing
8 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
android/2023-emmsale/app/src/main/java/com/emmsale/presentation/common/ScrollTopListener.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,53 @@ | ||
package com.emmsale.presentation.common | ||
|
||
import android.view.View | ||
import androidx.core.view.isVisible | ||
import androidx.recyclerview.widget.GridLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.emmsale.R | ||
|
||
class ScrollTopListener( | ||
private val targetView: View, | ||
) : RecyclerView.OnScrollListener() { | ||
private val isLandScape = getIsLandscape() | ||
private val scrollUpStandardPosition = getScrollUpStandardPosition(isLandScape) | ||
|
||
private fun getIsLandscape(): Boolean { | ||
return targetView.context.resources.getBoolean(R.bool.is_landscape) | ||
} | ||
|
||
private fun getScrollUpStandardPosition(isLandScape: Boolean): Int = if (isLandScape) { | ||
LANDSCAPE_SCROLL_UP_STANDARD_POSITION | ||
} else { | ||
PORTRAIT_SCROLL_UP_STANDARD_POSITION | ||
} | ||
|
||
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { | ||
super.onScrollStateChanged(recyclerView, newState) | ||
val layoutManager = recyclerView.layoutManager as GridLayoutManager | ||
val lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition() | ||
|
||
setupTargetView(recyclerView, lastVisibleItemPosition) | ||
} | ||
|
||
private fun setupTargetView(recyclerView: RecyclerView, lastVisibleItemPosition: Int) { | ||
setupTargetViewClickListener(recyclerView) | ||
targetView.isVisible = isVisibleTargetView(lastVisibleItemPosition) | ||
} | ||
|
||
private fun setupTargetViewClickListener(recyclerView: RecyclerView) { | ||
if (targetView.hasOnClickListeners()) return | ||
|
||
targetView.setOnClickListener { | ||
recyclerView.smoothScrollToPosition(0) | ||
} | ||
} | ||
|
||
private fun isVisibleTargetView(lastVisibleItemPosition: Int) = | ||
lastVisibleItemPosition >= scrollUpStandardPosition | ||
|
||
companion object { | ||
private const val PORTRAIT_SCROLL_UP_STANDARD_POSITION = 3 | ||
private const val LANDSCAPE_SCROLL_UP_STANDARD_POSITION = 6 | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
android/2023-emmsale/app/src/main/res/drawable/ic_all_arrow_up.xml
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,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="14dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="14"> | ||
<path | ||
android:fillColor="#000000" | ||
android:pathData="M22,14C21.471,13.998 20.963,13.786 20.59,13.41L12,4.83L3.41,13.41C3.027,13.738 2.535,13.909 2.032,13.889C1.529,13.87 1.051,13.661 0.695,13.305C0.339,12.949 0.13,12.472 0.111,11.968C0.091,11.465 0.262,10.973 0.59,10.59L10.59,0.59C10.965,0.218 11.472,0.008 12,0.008C12.528,0.008 13.035,0.218 13.41,0.59L23.41,10.59C23.688,10.87 23.877,11.225 23.954,11.612C24.03,11.999 23.991,12.4 23.84,12.764C23.689,13.129 23.434,13.44 23.107,13.66C22.779,13.88 22.394,13.998 22,14Z" /> | ||
</vector> |
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