Open Source Library for Holdable ViewHolder in RecyclerView
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.yeon-kyu.HoldableSwipeHandler:HoldableSwipeHandler:1.2.2'
}
val yourRecyclerView: RecyclerView
val yourAdapter: RecyclerView.Adapter or ListAdapter ..
HoldableSwipeHandler.Builder(requireContext())
.setOnRecyclerView(yourRecyclerView) // mandatory.
.setSwipeButtonAction(object : SwipeButtonAction { // mandatory.
override fun onClickFirstButton(absoluteAdapterPosition: Int) {
val item = yourAdapter.currentList[absoluteAdapterPosition]
viewModel.deletePushDB(item.articleId) // this is an example.
}
})
.setBackgroundColor("#ff0000") // optional. default value is pink color
.setFirstItemDrawable(ContextCompat.getDrawable(context, R.drawable.ic_check)!!) // optional. default value is a 'trash can' icon
.setFirstItemSideMarginDp(20) // optional. default value is 18. (in dip unit)
.setDismissOnClickFirstItem(true) // optional. default value is 'true'
.excludeFromHoldableViewHolder(10010) // optional. add ViewType that you want to exclude from holdable ViewHolder
.build()
- ์ผ์ชฝ -> ์ค๋ฅธ์ชฝ ์ค์์ดํ๋ ๊ฐ๋ฅํ๋๋ก ๋ณ๊ฒฝ
- setDirectionAsRightToLeft() ํ๋ผ๋ฏธํฐ์ false๋ฅผ ๋ฃ์ด์ ์ ์ฉ ๊ฐ๋ฅ (default๊ฐ : true)
- ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ Builder Pattern์ผ๋ก ๋ฆฌํฉํ ๋ง
- ๊ธฐ์กด์ ๊ธฐ๋ฅ๋ค์ ์ด์ ๋ฐฉ์(์๋ฐ๋น์ฆ ํจํด)์ผ๋ก๋ ์ฌ์ฉ ๊ฐ๋ฅํ๋ ๊ถ์ฅํ์ง ์์
- ์ง์ ํ ItemViewType์๋ Swipe ๋ถ๊ฐ๋ฅํ๊ฒ ๊ฐ๋ฅํ๋๋ก ์์
- excludeFromHoldableViewHolder() ์ด์ฉ ๊ฐ๋ฅ
- RecyclerView ๋ด์์ ์์ดํ ์ข ๋ฅ์ ๋ฐ๋ผ ์ฌ๋ฌ ViewType์ ๋๋์์ ๋ ์ ์ฉํ๊ฒ ์ฌ์ฉ ๊ฐ๋ฅ
- ๋ฒ๊ทธ ์์
- ์์ดํ ์ญ์ ๋๋ ๋์ค์ HoldingBackground๊ฐ ์ข ์ข ๋จ์์๋ ๋ฒ๊ทธ ์์
- ๋ทฐํ๋ ๋ฐฐ๊ฒฝ์ด ํฌ๋ช ํ ๊ฒฝ์ฐ์์์ UI ๋ฒ๊ทธ ์์ (๋จ์์๋ ํฌ๋ช ํด๋ฆญ ๋ฆฌ์ค๋ ์ด์)
- ๋ทฐํ๋ ์์ฒด์ ํด๋ฆญ ๋ฆฌ์ค๋๊ฐ ์๋ ๊ฒฝ์ฐ์์์ ๋ฒ๊ทธ ์ฒ๋ฆฌ
- ์์ ์ ์ธ ๋ฒ์ ์์
- Holding ๋ ๋ทฐํ๋๊ฐ ์ญ์ ๋๊ณ ๋์ ํด๋น ๋ทฐํ๋๊ฐ ์ฌํ์ฉ๋ ๋ translationX๊ฐ ์๋ณต๋์ง ์์๋ ์ด์ ์์
- HoldingBackground ์ ๋ฒํผ ํด๋ฆญ์ ์์ดํ
์ ์ฌ๋ผ์ง๊ฒ ํ๋์ง์ ๋ํ ์ต์
- setDismissBackgroundOnClickFirstItem() ์ด์ฉ
- default value : true
- setDismissBackgroundOnClickFirstItem() ์ด์ฉ
- ๋ทฐํ๋์ background๊ฐ ํฌ๋ช ํ ๊ฒฝ์ฐ UI ๋ฒ๊ทธ ์์ (๋ทฐํ๋ ์นจ๋ฒ ์ด์)
Designed and developed by 2021 yeon-kyu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.