├── .gitignore
├── Adapter
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── rv
│ └── adapter
│ └── core
│ ├── Adapter.kt
│ ├── AdapterAchieve.kt
│ ├── AdapterApi.kt
│ ├── ItemTypes.kt
│ ├── XAdapter.kt
│ └── listener
│ ├── XScrollListener.kt
│ └── XTouchListener.kt
├── DataBinding
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── rv
│ └── adapter
│ └── data
│ └── binding
│ ├── XDataBindingAdapter.kt
│ └── XDataBindingHolder.kt
├── LICENSE
├── Layout
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── rv
│ │ └── adapter
│ │ └── layout
│ │ ├── LayoutStatus.kt
│ │ ├── XLoadMoreStatus.kt
│ │ ├── XLoadMoreView.kt
│ │ ├── XRefreshStatus.kt
│ │ ├── XRefreshView.kt
│ │ └── simple
│ │ ├── SimpleLoadMoreView.kt
│ │ └── SimpleRefreshView.kt
│ └── res
│ ├── drawable-hdpi
│ └── ic_refresh_action.png
│ ├── layout
│ ├── simple_load_more.xml
│ └── simple_refresh.xml
│ └── values
│ ├── dimens.xml
│ └── strings.xml
├── Material
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── rv
│ └── adapter
│ └── material
│ └── AppBarStateChangeListener.kt
├── README.md
├── RecyclerView
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── rv
│ └── adapter
│ └── recyclerview
│ ├── Adapter.kt
│ ├── Core.kt
│ ├── DataBinding.kt
│ ├── LayoutManagerExt.kt
│ └── ViewBinding.kt
├── ViewBinding
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── rv
│ └── adapter
│ └── view
│ └── binding
│ ├── XViewBindingAdapter.kt
│ └── XViewBindingHolder.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── sample
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── rv
│ │ └── adapter
│ │ └── sample
│ │ ├── Ext.kt
│ │ ├── MainActivity.kt
│ │ ├── json
│ │ ├── JsonUtils.kt
│ │ └── SampleEntity.kt
│ │ └── page
│ │ ├── BaseActivity.kt
│ │ ├── DataBindingActivity.kt
│ │ └── ViewBindingActivity.kt
│ └── res
│ ├── layout
│ ├── activity_base.xml
│ ├── activity_data_binding.xml
│ ├── activity_main.xml
│ ├── activity_view_binding.xml
│ ├── adapter_footer.xml
│ ├── adapter_header.xml
│ ├── item_databinding.xml
│ ├── layout_json_item.xml
│ └── layout_recyclerview.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── settings.gradle.kts
└── viewholder
├── build.gradle
└── src
└── main
├── AndroidManifest.xml
└── java
└── rv
└── adapter
└── view
└── holder
└── XViewHolder.kt
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .DS_Store
5 | *build
6 | /captures
7 | .externalNativeBuild
8 | /.idea/
9 |
--------------------------------------------------------------------------------
/Adapter/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-kapt'
4 | apply plugin: 'com.github.dcendents.android-maven'
5 | android {
6 | compileSdkVersion rootProject.ext.compileSdkVersion
7 | defaultConfig {
8 | minSdkVersion rootProject.ext.minSdkVersion
9 | targetSdkVersion rootProject.ext.targetSdkVersion
10 | }
11 | compileOptions {
12 | kotlinOptions.freeCompilerArgs += ['-module-name', "com.github.7449.XAdapter.AdapterCore"]
13 | }
14 | }
15 | dependencies {
16 | compileOnly project(path: ':Layout')
17 | compileOnly project(path: ':ViewHolder')
18 | implementation "androidx.recyclerview:recyclerview:$recyclerviewVersion"
19 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
20 | }
21 |
--------------------------------------------------------------------------------
/Adapter/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Adapter/src/main/java/rv/adapter/core/Adapter.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.core
2 |
3 | import android.annotation.SuppressLint
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.recyclerview.widget.GridLayoutManager
8 | import androidx.recyclerview.widget.RecyclerView
9 | import androidx.recyclerview.widget.StaggeredGridLayoutManager
10 | import rv.adapter.layout.LayoutStatus
11 | import rv.adapter.layout.XLoadMoreStatus
12 | import rv.adapter.layout.XRefreshStatus
13 | import rv.adapter.layout.simple.SimpleLoadMoreView
14 | import rv.adapter.layout.simple.SimpleRefreshView
15 | import rv.adapter.view.holder.XViewHolder
16 |
17 | @SuppressLint("ClickableViewAccessibility")
18 | interface Adapter {
19 |
20 | /**
21 | * [XAdapter]
22 | */
23 | val adapter: XAdapter
24 |
25 | /**
26 | * 获取目前数据
27 | */
28 | val items: MutableList
29 |
30 | /**
31 | * 获取HeaderView
32 | */
33 | val headerViews: ArrayList
34 |
35 | /**
36 | * HeaderView ViewType
37 | */
38 | val headerTypes: ArrayList
39 |
40 | /**
41 | * 获取FooterView
42 | */
43 | val footerViews: ArrayList
44 |
45 | /**
46 | * FooterView ViewType
47 | */
48 | val footerTypes: ArrayList
49 |
50 | /**
51 | * 是否开启了下拉刷新
52 | */
53 | val isPullRefresh: Boolean
54 |
55 | /**
56 | * 是否正在刷新
57 | */
58 | val isRefresh: Boolean
59 |
60 | /**
61 | * 当前刷新状态
62 | */
63 | val refreshStatus: LayoutStatus
64 |
65 | /**
66 | * 是否开启了上拉加载
67 | */
68 | val isLoadingMore: Boolean
69 |
70 | /**
71 | * 是否正在加载
72 | */
73 | val isLoading: Boolean
74 |
75 | /**
76 | * 当前加载状态
77 | */
78 | val loadingMoreStatus: LayoutStatus
79 |
80 | /**
81 | * 默认的ViewType
82 | */
83 | val adapterViewType: Int
84 | get() = 100000
85 |
86 | /**
87 | * 总的Items.size
88 | */
89 | fun finalItemCount(): Int {
90 | return items.size + if ((isLoadingMore && items.isNotEmpty()) && isPullRefresh) {
91 | // load and refresh
92 | 2
93 | } else if ((isLoadingMore && items.isNotEmpty()) || isPullRefresh) {
94 | // refresh
95 | 1
96 | } else {
97 | // nothing
98 | 0
99 | } + footerViews.size + headerViews.size
100 | }
101 |
102 | /**
103 | * 是否为ItemPosition
104 | * false 不是
105 | * true 是
106 | */
107 | fun isItemViewType(position: Int): Boolean {
108 | return finalItemViewType(position) == ItemTypes.ITEM.type
109 | }
110 |
111 | /**
112 | * 获取ViewType
113 | */
114 | fun finalItemViewType(position: Int): Int {
115 | var mPos = position
116 | if (isRefreshViewType(mPos)) {
117 | return ItemTypes.REFRESH.type
118 | }
119 | if (isLoadingMoreViewType(mPos)) {
120 | return ItemTypes.LOAD_MORE.type
121 | }
122 | if (isPullRefresh) {
123 | mPos -= 1
124 | }
125 | if (isHeaderViewType(mPos)) {
126 | val headerType = mPos * adapterViewType
127 | if (!headerTypes.contains(headerType)) {
128 | headerTypes.add(headerType)
129 | }
130 | return headerType
131 | }
132 | if (isFooterViewType(mPos)) {
133 | val footerType = mPos * adapterViewType
134 | if (!footerTypes.contains(footerType)) {
135 | footerTypes.add(footerType)
136 | }
137 | return footerType
138 | }
139 | return ItemTypes.ITEM.type
140 | }
141 |
142 | /**
143 | * 获取当前Item的position
144 | */
145 | fun currentPosition(position: Int): Int {
146 | var mPos = position
147 | if (isPullRefresh) {
148 | mPos -= 1
149 | }
150 | return mPos - headerViews.size
151 | }
152 |
153 | /**
154 | * 是否为头部刷新ViewType
155 | */
156 | fun isRefreshViewType(position: Int): Boolean {
157 | return isPullRefresh && position == 0
158 | }
159 |
160 | /**
161 | * 是否为尾部刷新ViewType
162 | */
163 | fun isLoadingMoreViewType(position: Int): Boolean {
164 | return isLoadingMore && items.isNotEmpty() && position == adapter.itemCount - 1
165 | }
166 |
167 | /**
168 | * 是否为HeaderView ViewType
169 | */
170 | fun isHeaderViewType(position: Int): Boolean {
171 | return headerViews.isNotEmpty() && position < headerViews.size
172 | }
173 |
174 | /**
175 | * 是否为FooterView ViewType
176 | */
177 | fun isFooterViewType(position: Int): Boolean {
178 | return footerViews.isNotEmpty() && position >= items.size + headerViews.size
179 | }
180 |
181 | /**
182 | * 获取HeaderView ViewHolder
183 | */
184 | fun createHeaderViewHolder(viewType: Int): XViewHolder {
185 | return XViewHolder(headerViews[viewType / adapterViewType])
186 | }
187 |
188 | /**
189 | * 获取FooterView ViewHolder
190 | */
191 | fun createFooterViewHolder(viewType: Int): XViewHolder {
192 | return XViewHolder(footerViews[viewType / adapterViewType - items.size - headerViews.size])
193 | }
194 |
195 | /**
196 | * 获取Refresh ViewHolder
197 | */
198 | fun createRefreshViewHolder(parent: ViewGroup, status: XRefreshStatus): XViewHolder {
199 | return XViewHolder(status.xRootView)
200 | }
201 |
202 | /**
203 | * 获取RefreshView
204 | */
205 | fun createRefreshView(parent: ViewGroup): XRefreshStatus {
206 | return SimpleRefreshView(parent.context)
207 | }
208 |
209 | /**
210 | * 获取LoadMoreView
211 | */
212 | fun createLoadingMoreView(parent: ViewGroup): XLoadMoreStatus {
213 | return SimpleLoadMoreView(parent.context)
214 | }
215 |
216 | /**
217 | * 获取LoadMore ViewHolder
218 | */
219 | fun createLoadingViewHolder(parent: ViewGroup, status: XLoadMoreStatus): XViewHolder {
220 | return XViewHolder(status.xRootView)
221 | }
222 |
223 | /**
224 | * 获取ViewHolder
225 | */
226 | fun createItemViewHolder(
227 | parent: ViewGroup,
228 | layoutId: Int,
229 | click: ((view: View, position: Int, entity: T) -> Unit)?,
230 | longClick: ((view: View, position: Int, entity: T) -> Boolean)?
231 | ): XViewHolder {
232 | return XViewHolder(
233 | LayoutInflater.from(parent.context).inflate(layoutId, parent, false)
234 | ).apply {
235 | setOnClickListener(this, click)
236 | setOnLongClickListener(this, longClick)
237 | }
238 | }
239 |
240 | /**
241 | * 点击事件
242 | */
243 | fun setOnClickListener(
244 | holder: XViewHolder,
245 | action: ((view: View, position: Int, entity: T) -> Unit)?
246 | ): XViewHolder {
247 | action?.let { listener ->
248 | holder.itemView.setOnClickListener { view ->
249 | listener.invoke(
250 | view,
251 | currentPosition(holder.bindingAdapterPosition),
252 | items[currentPosition(holder.bindingAdapterPosition)]
253 | )
254 | }
255 | }
256 | return holder
257 | }
258 |
259 | /**
260 | * 长按事件
261 | */
262 | fun setOnLongClickListener(
263 | holder: XViewHolder,
264 | action: ((view: View, position: Int, entity: T) -> Boolean)?
265 | ): XViewHolder {
266 | action?.let { listener ->
267 | holder.itemView.setOnLongClickListener { view ->
268 | listener.invoke(
269 | view,
270 | currentPosition(holder.bindingAdapterPosition),
271 | items[currentPosition(holder.bindingAdapterPosition)]
272 | )
273 | }
274 | }
275 | return holder
276 | }
277 |
278 | /**
279 | * 注册滑动和触摸
280 | */
281 | fun registerListener(
282 | view: RecyclerView,
283 | onScrollListener: RecyclerView.OnScrollListener,
284 | onTouchListener: View.OnTouchListener
285 | ) {
286 | view.addOnScrollListener(onScrollListener)
287 | view.setOnTouchListener(onTouchListener)
288 | attachedToParent(view)
289 | }
290 |
291 | /**
292 | * 取消注册滑动和触摸
293 | */
294 | fun unregisterListener(
295 | view: RecyclerView,
296 | onScrollListener: RecyclerView.OnScrollListener
297 | ) {
298 | view.removeOnScrollListener(onScrollListener)
299 | view.setOnTouchListener(null)
300 | }
301 |
302 | /**
303 | * 适配[GridLayoutManager]
304 | */
305 | fun attachedToParent(view: RecyclerView) {
306 | val manager = view.layoutManager
307 | if (manager is GridLayoutManager) {
308 | manager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
309 | override fun getSpanSize(position: Int): Int =
310 | if (!isItemViewType(position))
311 | manager.spanCount
312 | else
313 | 1
314 | }
315 | }
316 | }
317 |
318 | /**
319 | * 适配[StaggeredGridLayoutManager]
320 | */
321 | fun attachedToWindow(viewHolder: RecyclerView.ViewHolder) {
322 | viewHolder.itemView.layoutParams?.let {
323 | if (it is StaggeredGridLayoutManager.LayoutParams) {
324 | it.isFullSpan = !isItemViewType(viewHolder.bindingAdapterPosition)
325 | }
326 | }
327 | }
328 |
329 | }
--------------------------------------------------------------------------------
/Adapter/src/main/java/rv/adapter/core/AdapterAchieve.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.core
2 |
3 | import android.view.View
4 | import rv.adapter.layout.LayoutStatus
5 | import rv.adapter.layout.XLoadMoreStatus
6 | import rv.adapter.layout.XRefreshStatus
7 | import rv.adapter.view.holder.XViewHolder
8 |
9 | interface AdapterAchieve : AdapterApi {
10 |
11 | override fun setItemLayoutId(layoutId: Int): XAdapter {
12 | return adapter.apply {
13 | itemLayoutId = layoutId
14 | }
15 | }
16 |
17 | override fun bindItem(action: (holder: XViewHolder, position: Int, entity: T) -> Unit): XAdapter {
18 | return adapter.apply {
19 | bindListener = action
20 | }
21 | }
22 |
23 | override fun pullRefresh(switch: Boolean): XAdapter {
24 | return adapter.apply {
25 | pullRefreshEnabled = switch
26 | }
27 | }
28 |
29 | override fun loadMore(switch: Boolean): XAdapter {
30 | return adapter.apply {
31 | loadingMoreEnabled = switch
32 | }
33 | }
34 |
35 | override fun setAppbarListener(action: () -> Boolean): XAdapter {
36 | return adapter.apply {
37 | appBarListener = action
38 | }
39 | }
40 |
41 | override fun setRefreshListener(action: (adapter: XAdapter) -> Unit): XAdapter {
42 | return adapter.apply {
43 | refreshListener = action
44 | }
45 | }
46 |
47 | override fun setLoadingMoreListener(action: (adapter: XAdapter) -> Unit): XAdapter {
48 | return adapter.apply {
49 | loadingMoreListener = action
50 | }
51 | }
52 |
53 | override fun setOnItemClickListener(action: (view: View, position: Int, entity: T) -> Unit): XAdapter {
54 | return adapter.apply {
55 | clickListener = action
56 | }
57 | }
58 |
59 | override fun setOnItemLongClickListener(action: (view: View, position: Int, entity: T) -> Boolean): XAdapter {
60 | return adapter.apply {
61 | longClickListener = action
62 | }
63 | }
64 |
65 | override fun setRefreshView(view: XRefreshStatus): XAdapter {
66 | return adapter.apply {
67 | xRefreshStatus = view
68 | }
69 | }
70 |
71 | override fun setLoadingMoreView(view: XLoadMoreStatus): XAdapter {
72 | return adapter.apply {
73 | xLoadMoreStatus = view
74 | }
75 | }
76 |
77 | override fun setScrollLoadMoreItemCount(count: Int): XAdapter {
78 | return adapter.apply {
79 | scrollLoadMoreItemCount = count
80 | }
81 | }
82 |
83 | override fun onRefresh() {
84 | adapter.xLoadMoreStatus?.xRootView?.visibility = View.GONE
85 | adapter.refreshListener?.invoke(adapter)
86 | }
87 |
88 | override fun onLoadingMore() {
89 | if (items.isEmpty() || isRefresh || isLoading || !isLoadingMore) {
90 | return
91 | }
92 | setLoadingMoreStatus(LayoutStatus.LOAD)
93 | adapter.loadingMoreListener?.invoke(adapter)
94 | }
95 |
96 | override fun setRefreshStatus(status: LayoutStatus): XAdapter {
97 | return adapter.apply {
98 | xRefreshStatus?.onChanged(status)
99 | if (xRefreshStatus?.isDone == true && loadingMoreEnabled) {
100 | xLoadMoreStatus?.xRootView?.visibility = View.VISIBLE
101 | setLoadingMoreStatus(LayoutStatus.NORMAL)
102 | }
103 | }
104 | }
105 |
106 | override fun setLoadingMoreStatus(status: LayoutStatus): XAdapter {
107 | return adapter.apply {
108 | xLoadMoreStatus?.onChanged(status)
109 | }
110 | }
111 |
112 | }
--------------------------------------------------------------------------------
/Adapter/src/main/java/rv/adapter/core/AdapterApi.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.core
2 |
3 | import android.view.View
4 | import androidx.recyclerview.widget.RecyclerView
5 | import rv.adapter.layout.LayoutStatus
6 | import rv.adapter.layout.XLoadMoreStatus
7 | import rv.adapter.layout.XRefreshStatus
8 | import rv.adapter.layout.simple.SimpleRefreshView
9 | import rv.adapter.view.holder.XViewHolder
10 |
11 | interface AdapterApi : Adapter {
12 |
13 | fun setItemLayoutId(layoutId: Int): XAdapter
14 | fun bindItem(action: (holder: XViewHolder, position: Int, entity: T) -> Unit): XAdapter
15 | fun pullRefresh(switch: Boolean): XAdapter
16 | fun loadMore(switch: Boolean): XAdapter
17 | fun setAppbarListener(action: () -> Boolean): XAdapter
18 | fun setRefreshListener(action: (adapter: XAdapter) -> Unit): XAdapter
19 | fun setLoadingMoreListener(action: (adapter: XAdapter) -> Unit): XAdapter
20 | fun setOnItemClickListener(action: (view: View, position: Int, entity: T) -> Unit): XAdapter
21 | fun setOnItemLongClickListener(action: (view: View, position: Int, entity: T) -> Boolean): XAdapter
22 | fun setRefreshStatus(status: LayoutStatus): XAdapter
23 | fun setRefreshView(view: XRefreshStatus): XAdapter
24 | fun setLoadingMoreStatus(status: LayoutStatus): XAdapter
25 | fun setLoadingMoreView(view: XLoadMoreStatus): XAdapter
26 | fun setScrollLoadMoreItemCount(count: Int): XAdapter
27 |
28 | fun onRefresh()
29 | fun onLoadingMore()
30 |
31 | fun onRefreshSuccess() {
32 | setRefreshStatus(LayoutStatus.SUCCESS)
33 | }
34 |
35 | fun onRefreshError() {
36 | setRefreshStatus(LayoutStatus.ERROR)
37 | }
38 |
39 | fun onLoadingMoreSuccess() {
40 | setLoadingMoreStatus(LayoutStatus.SUCCESS)
41 | }
42 |
43 | fun onLoadingMoreError() {
44 | setLoadingMoreStatus(LayoutStatus.ERROR)
45 | }
46 |
47 | fun onLoadingMoreLoad() {
48 | setLoadingMoreStatus(LayoutStatus.LOAD)
49 | }
50 |
51 | fun onLoadingMoreNoMore() {
52 | setLoadingMoreStatus(LayoutStatus.NO_MORE)
53 | }
54 |
55 | fun openPullRefresh() = pullRefresh(true)
56 | fun openLoadingMore() = loadMore(true)
57 | fun addHeaderView(view: View) = apply { headerViews.add(view) }
58 | fun getHeaderView(position: Int): View = headerViews[position]
59 | fun addFooterView(view: View) = apply { footerViews.add(view) }
60 | fun getFooterView(position: Int): View = footerViews[position]
61 | fun getItem(position: Int): T = items[position]
62 | fun getLast(): T = items.last()
63 | fun getFirst(): T = items.first()
64 |
65 | fun addAll(data: List, isNotify: Boolean = true) = also {
66 | items.addAll(data)
67 | if (isNotify) {
68 | adapter.notifyDataSetChanged()
69 | }
70 | }
71 |
72 | fun add(data: T, isNotify: Boolean = true) = also {
73 | items.add(data)
74 | if (isNotify) {
75 | adapter.notifyDataSetChanged()
76 | }
77 | }
78 |
79 | fun removeAll(isNotify: Boolean = true) = also {
80 | items.clear()
81 | if (isNotify) {
82 | adapter.notifyDataSetChanged()
83 | }
84 | }
85 |
86 | fun remove(position: Int, isNotify: Boolean = true) = also {
87 | items.removeAt(position)
88 | if (isNotify) {
89 | adapter.notifyDataSetChanged()
90 | }
91 | }
92 |
93 | fun autoRefresh(
94 | view: RecyclerView,
95 | refreshView: XRefreshStatus = SimpleRefreshView(view.context)
96 | ) = also {
97 | openPullRefresh()
98 | setRefreshView(refreshView)
99 | refreshView.let {
100 | it.onStartRefresh()
101 | onRefresh()
102 | }
103 | }
104 |
105 | }
--------------------------------------------------------------------------------
/Adapter/src/main/java/rv/adapter/core/ItemTypes.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.core
2 |
3 | enum class ItemTypes(val type: Int) {
4 | ITEM(-1),
5 | REFRESH(-2),
6 | LOAD_MORE(-3)
7 | }
--------------------------------------------------------------------------------
/Adapter/src/main/java/rv/adapter/core/XAdapter.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("MemberVisibilityCanBePrivate", "unused", "ClickableViewAccessibility")
2 |
3 | package rv.adapter.core
4 |
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.recyclerview.widget.RecyclerView
8 | import rv.adapter.core.listener.XScrollListener
9 | import rv.adapter.core.listener.XTouchListener
10 | import rv.adapter.layout.LayoutStatus
11 | import rv.adapter.layout.XLoadMoreStatus
12 | import rv.adapter.layout.XRefreshStatus
13 | import rv.adapter.view.holder.XViewHolder
14 |
15 | /**
16 | * by y on 2016/11/15
17 | */
18 | open class XAdapter : RecyclerView.Adapter(), AdapterAchieve {
19 |
20 | protected open val dataContainer: MutableList = ArrayList()
21 | private val headerViewContainer = arrayListOf()
22 | private val footerViewContainer = arrayListOf()
23 | private val headerViewType = arrayListOf()
24 | private val footerViewType = arrayListOf()
25 |
26 | override val adapter: XAdapter
27 | get() = this
28 |
29 | override val items: MutableList
30 | get() = dataContainer
31 |
32 | override val headerViews: ArrayList
33 | get() = headerViewContainer
34 |
35 | override val headerTypes: ArrayList
36 | get() = headerViewType
37 |
38 | override val footerViews: ArrayList
39 | get() = footerViewContainer
40 |
41 | override val footerTypes: ArrayList
42 | get() = footerViewType
43 |
44 | override val isPullRefresh: Boolean
45 | get() = pullRefreshEnabled
46 |
47 | override val isRefresh
48 | get() = xRefreshStatus?.isRefresh ?: false
49 |
50 | override val refreshStatus: LayoutStatus
51 | get() = xRefreshStatus?.status ?: LayoutStatus.NORMAL
52 |
53 | override val isLoadingMore: Boolean
54 | get() = loadingMoreEnabled
55 |
56 | override val isLoading
57 | get() = xLoadMoreStatus?.isLoad ?: false
58 |
59 | override val loadingMoreStatus: LayoutStatus
60 | get() = xLoadMoreStatus?.status ?: LayoutStatus.NORMAL
61 |
62 | private val onScrollListener = XScrollListener { onLoadingMore() }
63 | private val onTouchListener =
64 | XTouchListener(
65 | { xRefreshStatus },
66 | { appBarListener.invoke() },
67 | { isLoading }) { onRefresh() }
68 |
69 | internal var itemLayoutId = View.NO_ID
70 | internal var appBarListener: (() -> Boolean) = { true }
71 | internal var bindListener: ((holder: XViewHolder, position: Int, entity: T) -> Unit)? = null
72 | internal var pullRefreshEnabled = false
73 | internal var loadingMoreEnabled = false
74 | internal var refreshListener: ((adapter: XAdapter) -> Unit)? = null
75 | internal var loadingMoreListener: ((adapter: XAdapter) -> Unit)? = null
76 | internal var clickListener: ((view: View, position: Int, entity: T) -> Unit)? = null
77 | internal var longClickListener: ((view: View, position: Int, entity: T) -> Boolean)? = null
78 | internal var xRefreshStatus: XRefreshStatus? = null
79 | internal var xLoadMoreStatus: XLoadMoreStatus? = null
80 | internal var scrollLoadMoreItemCount = 1
81 | set(value) {
82 | field = value
83 | onScrollListener.updateScrollItemCount(value)
84 | }
85 |
86 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): XViewHolder {
87 | if (headerTypes.contains(viewType)) {
88 | return createHeaderViewHolder(viewType)
89 | }
90 | if (footerTypes.contains(viewType)) {
91 | return createFooterViewHolder(viewType)
92 | }
93 | if (viewType == ItemTypes.REFRESH.type && xRefreshStatus == null) {
94 | xRefreshStatus = createRefreshView(parent)
95 | }
96 | if (viewType == ItemTypes.LOAD_MORE.type && xLoadMoreStatus == null) {
97 | xLoadMoreStatus = createLoadingMoreView(parent)
98 | }
99 | return when (viewType) {
100 | ItemTypes.REFRESH.type -> createRefreshViewHolder(parent, checkNotNull(xRefreshStatus))
101 | ItemTypes.LOAD_MORE.type -> createLoadingViewHolder(
102 | parent,
103 | checkNotNull(xLoadMoreStatus)
104 | )
105 | else -> createItemViewHolder(parent, itemLayoutId, clickListener, longClickListener)
106 | }
107 | }
108 |
109 | override fun onBindViewHolder(holder: XViewHolder, position: Int) {
110 | if (!isItemViewType(position)) {
111 | return
112 | }
113 | val pos = currentPosition(position)
114 | bindListener?.invoke(holder, pos, getItem(pos))
115 | }
116 |
117 | override fun getItemViewType(position: Int) = finalItemViewType(position)
118 |
119 | override fun getItemCount() = finalItemCount()
120 |
121 | override fun onAttachedToRecyclerView(view: RecyclerView) {
122 | registerListener(view, onScrollListener, onTouchListener)
123 | }
124 |
125 | override fun onDetachedFromRecyclerView(view: RecyclerView) {
126 | unregisterListener(view, onScrollListener)
127 | }
128 |
129 | override fun onViewAttachedToWindow(holder: XViewHolder) = attachedToWindow(holder)
130 |
131 | }
--------------------------------------------------------------------------------
/Adapter/src/main/java/rv/adapter/core/listener/XScrollListener.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.core.listener
2 |
3 | import androidx.recyclerview.widget.LinearLayoutManager
4 | import androidx.recyclerview.widget.RecyclerView
5 | import androidx.recyclerview.widget.StaggeredGridLayoutManager
6 |
7 | /**
8 | * by y on 2016/11/15
9 | */
10 | internal class XScrollListener(private val scrollBottom: () -> Unit) :
11 | RecyclerView.OnScrollListener() {
12 |
13 | companion object {
14 | const val NO_MANAGER = -1
15 | const val LINEAR = 0
16 | const val STAGGERED_GRID = 1
17 | }
18 |
19 | private var layoutManagerType: Int = NO_MANAGER
20 | private var lastVisibleItemPosition: Int = 0
21 | private var scrollItemCount: Int = 1
22 |
23 | fun updateScrollItemCount(value: Int) {
24 | this.scrollItemCount = value
25 | }
26 |
27 | override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
28 | super.onScrolled(recyclerView, dx, dy)
29 | val layoutManager = recyclerView.layoutManager
30 | if (layoutManagerType == NO_MANAGER) {
31 | layoutManagerType = when (layoutManager) {
32 | is LinearLayoutManager -> LINEAR
33 | is StaggeredGridLayoutManager -> STAGGERED_GRID
34 | else -> throw RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager")
35 | }
36 | }
37 | when (layoutManagerType) {
38 | LINEAR -> lastVisibleItemPosition =
39 | (layoutManager as LinearLayoutManager).findLastVisibleItemPosition()
40 | STAGGERED_GRID -> lastVisibleItemPosition = findMax(
41 | (layoutManager as StaggeredGridLayoutManager).findLastVisibleItemPositions(null)
42 | )
43 | }
44 | }
45 |
46 | override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
47 | super.onScrollStateChanged(recyclerView, newState)
48 | val layoutManager = recyclerView.layoutManager
49 | val visibleItemCount = layoutManager?.childCount ?: 0
50 | val totalItemCount = layoutManager?.itemCount ?: 0
51 | if (visibleItemCount > 0 && newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItemPosition >= totalItemCount - scrollItemCount) {
52 | scrollBottom.invoke()
53 | }
54 | }
55 |
56 | private fun findMax(lastPositions: IntArray): Int {
57 | var max = lastPositions[0]
58 | for (value in lastPositions) {
59 | if (value > max) {
60 | max = value
61 | }
62 | }
63 | return max
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/Adapter/src/main/java/rv/adapter/core/listener/XTouchListener.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.core.listener
2 |
3 | import android.annotation.SuppressLint
4 | import android.view.MotionEvent
5 | import android.view.View
6 | import rv.adapter.layout.XRefreshStatus
7 |
8 | /**
9 | * by y on 2016/11/15
10 | */
11 | internal class XTouchListener(
12 | private val refreshStatus: () -> XRefreshStatus?,
13 | private val appBar: () -> Boolean,
14 | private val loadMoreCallback: () -> Boolean,
15 | private val refreshInterface: () -> Unit
16 | ) : View.OnTouchListener {
17 |
18 | companion object {
19 | private const val DAMP = 3
20 | }
21 |
22 | private var rawY = -1f
23 |
24 | private val isTop: Boolean
25 | get() = refreshStatus.invoke()?.refreshParent != null
26 |
27 | @SuppressLint("ClickableViewAccessibility")
28 | override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
29 | val refreshView = refreshStatus.invoke()
30 | if (refreshView == null || refreshView.isRefresh || loadMoreCallback.invoke()) {
31 | return false
32 | }
33 | if (rawY == -1f) {
34 | rawY = motionEvent.rawY
35 | }
36 | when (motionEvent.action) {
37 | MotionEvent.ACTION_DOWN -> rawY = motionEvent.rawY
38 | MotionEvent.ACTION_MOVE -> {
39 | val deltaY = motionEvent.rawY - rawY
40 | rawY = motionEvent.rawY
41 | if (isTop && appBar.invoke()) {
42 | refreshView.onChangedHeight((deltaY / DAMP).toInt())
43 | if (refreshView.visibleHeight > 0 && refreshView.isBegin) {
44 | return true
45 | }
46 | }
47 | }
48 | else -> {
49 | rawY = -1f
50 | if (isTop && appBar.invoke() && refreshView.isReleaseAction) {
51 | refreshInterface()
52 | }
53 | }
54 | }
55 | return false
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/DataBinding/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-kapt'
4 | apply plugin: 'com.github.dcendents.android-maven'
5 | android {
6 | compileSdkVersion rootProject.ext.compileSdkVersion
7 | defaultConfig {
8 | minSdkVersion rootProject.ext.minSdkVersion
9 | targetSdkVersion rootProject.ext.targetSdkVersion
10 | }
11 | buildFeatures {
12 | dataBinding = true
13 | }
14 | compileOptions {
15 | kotlinOptions.freeCompilerArgs += ['-module-name', "com.github.7449.XAdapter.DataBinding"]
16 | }
17 | }
18 | dependencies {
19 | compileOnly project(path: ':Adapter')
20 | compileOnly project(path: ':ViewHolder')
21 | implementation "androidx.recyclerview:recyclerview:$recyclerviewVersion"
22 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
23 | }
24 |
--------------------------------------------------------------------------------
/DataBinding/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/DataBinding/src/main/java/rv/adapter/data/binding/XDataBindingAdapter.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.data.binding
2 |
3 | import android.view.LayoutInflater
4 | import android.view.View
5 | import android.view.ViewGroup
6 | import androidx.databinding.DataBindingUtil
7 | import androidx.databinding.ObservableArrayList
8 | import rv.adapter.core.XAdapter
9 | import rv.adapter.view.holder.XViewHolder
10 |
11 | /**
12 | * @author y
13 | * @create 2018/12/25
14 | */
15 | open class XDataBindingAdapter(
16 | private val variableId: Int,
17 | private val executePendingBindings: Boolean = true
18 | ) : XAdapter() {
19 |
20 | private val mData: ObservableArrayList = ObservableArrayList()
21 |
22 | override var dataContainer: MutableList
23 | get() = mData
24 | set(value) {
25 | mData.addAll(value)
26 | }
27 |
28 | override fun createItemViewHolder(
29 | parent: ViewGroup,
30 | layoutId: Int,
31 | click: ((view: View, position: Int, entity: T) -> Unit)?,
32 | longClick: ((view: View, position: Int, entity: T) -> Boolean)?
33 | ): XViewHolder {
34 | return XDataBindingHolder(
35 | DataBindingUtil.inflate(
36 | LayoutInflater.from(parent.context),
37 | layoutId,
38 | parent,
39 | false
40 | )
41 | ).apply {
42 | setOnClickListener(this, click)
43 | setOnLongClickListener(this, longClick)
44 | }
45 | }
46 |
47 | override fun onBindViewHolder(holder: XViewHolder, position: Int) {
48 | if (!isItemViewType(position)) {
49 | return
50 | }
51 | val pos = currentPosition(position)
52 | holder as XDataBindingHolder
53 | holder.viewDataBinding.setVariable(variableId, getItem(pos))
54 | if (executePendingBindings) {
55 | holder.viewDataBinding.executePendingBindings()
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/DataBinding/src/main/java/rv/adapter/data/binding/XDataBindingHolder.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.data.binding
2 |
3 | import androidx.databinding.ViewDataBinding
4 | import rv.adapter.view.holder.XViewHolder
5 |
6 | class XDataBindingHolder(val viewDataBinding: ViewDataBinding) : XViewHolder(viewDataBinding.root)
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Layout/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'com.github.dcendents.android-maven'
4 | android {
5 | compileSdkVersion rootProject.ext.compileSdkVersion
6 | defaultConfig {
7 | minSdkVersion rootProject.ext.minSdkVersion
8 | targetSdkVersion rootProject.ext.targetSdkVersion
9 | }
10 | compileOptions {
11 | kotlinOptions.freeCompilerArgs += ['-module-name', "com.github.7449.XAdapter.Layout"]
12 | }
13 | buildFeatures {
14 | viewBinding = true
15 | }
16 | }
17 | dependencies {
18 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
19 | }
20 |
--------------------------------------------------------------------------------
/Layout/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Layout/src/main/java/rv/adapter/layout/LayoutStatus.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.layout
2 |
3 | enum class LayoutStatus {
4 |
5 | NORMAL,
6 |
7 | READY,
8 |
9 | REFRESH,
10 |
11 | SUCCESS,
12 |
13 | ERROR,
14 |
15 | LOAD,
16 |
17 | NO_MORE,
18 |
19 | }
--------------------------------------------------------------------------------
/Layout/src/main/java/rv/adapter/layout/XLoadMoreStatus.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.layout
2 |
3 | import android.view.ViewGroup
4 |
5 | interface XLoadMoreStatus {
6 |
7 | val xRootView: ViewGroup
8 |
9 | var status: LayoutStatus
10 |
11 | val isNormal: Boolean
12 | get() = status == LayoutStatus.NORMAL
13 |
14 | val isLoad: Boolean
15 | get() = status == LayoutStatus.LOAD
16 |
17 | val isSuccess: Boolean
18 | get() = status == LayoutStatus.SUCCESS
19 |
20 | val isError: Boolean
21 | get() = status == LayoutStatus.ERROR
22 |
23 | val isNoMore: Boolean
24 | get() = status == LayoutStatus.NO_MORE
25 |
26 | fun onChanged(status: LayoutStatus) {
27 | if (this.status == status) return
28 | when (status) {
29 | LayoutStatus.NORMAL -> onNormal()
30 | LayoutStatus.LOAD -> onLoad()
31 | LayoutStatus.SUCCESS -> onSuccess()
32 | LayoutStatus.ERROR -> onError()
33 | LayoutStatus.NO_MORE -> onNoMore()
34 | else -> throw RuntimeException("check status:$status")
35 | }
36 | this.status = status
37 | }
38 |
39 | fun onNormal()
40 |
41 | fun onLoad()
42 |
43 | fun onSuccess()
44 |
45 | fun onError()
46 |
47 | fun onNoMore()
48 |
49 | }
--------------------------------------------------------------------------------
/Layout/src/main/java/rv/adapter/layout/XLoadMoreView.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.layout
2 |
3 | import android.content.Context
4 | import android.util.AttributeSet
5 | import android.view.ViewGroup
6 | import android.widget.FrameLayout
7 |
8 | abstract class XLoadMoreView @JvmOverloads constructor(
9 | context: Context,
10 | attrs: AttributeSet? = null,
11 | defStyleAttr: Int = 0
12 | ) : FrameLayout(context, attrs, defStyleAttr), XLoadMoreStatus {
13 | override var status: LayoutStatus = LayoutStatus.NORMAL
14 | override val xRootView: ViewGroup
15 | get() = this
16 | }
--------------------------------------------------------------------------------
/Layout/src/main/java/rv/adapter/layout/XRefreshStatus.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.layout
2 |
3 | import android.view.ViewGroup
4 | import android.view.ViewParent
5 |
6 | interface XRefreshStatus {
7 |
8 | val xRootView: ViewGroup
9 |
10 | var status: LayoutStatus
11 |
12 | val visibleHeight: Int
13 |
14 | val isReleaseAction: Boolean
15 |
16 | val refreshParent: ViewParent? get() = xRootView.parent
17 |
18 | val isNormal: Boolean
19 | get() = status == LayoutStatus.NORMAL
20 |
21 | val isReady: Boolean
22 | get() = status == LayoutStatus.READY
23 |
24 | val isRefresh: Boolean
25 | get() = status == LayoutStatus.REFRESH
26 |
27 | val isSuccess: Boolean
28 | get() = status == LayoutStatus.SUCCESS
29 |
30 | val isError: Boolean
31 | get() = status == LayoutStatus.ERROR
32 |
33 | val isDone: Boolean
34 | get() = isSuccess || isError
35 |
36 | val isBegin: Boolean
37 | get() = isNormal || isReady
38 |
39 | fun onChanged(status: LayoutStatus) {
40 | if (this.status == status) return
41 | when (status) {
42 | LayoutStatus.NORMAL -> onNormal()
43 | LayoutStatus.READY -> onReady()
44 | LayoutStatus.REFRESH -> onRefresh()
45 | LayoutStatus.SUCCESS -> onSuccess()
46 | LayoutStatus.ERROR -> onError()
47 | else -> throw RuntimeException("check status:$status")
48 | }
49 | this.status = status
50 | }
51 |
52 | fun onStartRefresh()
53 |
54 | fun onChangedHeight(height: Int)
55 |
56 | fun onNormal()
57 |
58 | fun onReady()
59 |
60 | fun onRefresh()
61 |
62 | fun onSuccess()
63 |
64 | fun onError()
65 |
66 | }
--------------------------------------------------------------------------------
/Layout/src/main/java/rv/adapter/layout/XRefreshView.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.layout
2 |
3 | import android.animation.ValueAnimator
4 | import android.content.Context
5 | import android.util.AttributeSet
6 | import android.view.ViewGroup
7 | import android.view.ViewParent
8 | import android.widget.FrameLayout
9 | import kotlin.math.max
10 |
11 | abstract class XRefreshView @JvmOverloads constructor(
12 | context: Context,
13 | attrs: AttributeSet? = null,
14 | defStyleAttr: Int = 0
15 | ) : FrameLayout(context, attrs, defStyleAttr), XRefreshStatus {
16 |
17 | private val animator: ValueAnimator = ValueAnimator.ofInt().setDuration(300)
18 | private val childView by lazy { getChildAt(0) }
19 | private val initHeight by lazy {
20 | measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
21 | measuredHeight
22 | }
23 |
24 | init {
25 | layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
26 | animator.addUpdateListener { animation -> onChangedHeights(animation.animatedValue as Int) }
27 | }
28 |
29 | override var status: LayoutStatus = LayoutStatus.NORMAL
30 |
31 | override val visibleHeight: Int
32 | get() = childView.layoutParams.height
33 |
34 | override val refreshParent: ViewParent?
35 | get() = parent
36 |
37 | override val xRootView: ViewGroup
38 | get() = this
39 |
40 | override val isReleaseAction: Boolean
41 | get() {
42 | if (isReady) {
43 | onChanged(LayoutStatus.REFRESH)
44 | }
45 | smoothScrollTo(if (isRefresh) initHeight else 0)
46 | return isRefresh
47 | }
48 |
49 | override fun onStartRefresh() {
50 | onChanged(LayoutStatus.REFRESH)
51 | animator.setIntValues(1, initHeight)
52 | animator.start()
53 | }
54 |
55 | override fun onChanged(status: LayoutStatus) {
56 | super.onChanged(status)
57 | if (isDone) {
58 | postDelayed({ smoothScrollTo(0) }, 200)
59 | }
60 | }
61 |
62 | override fun onChangedHeight(height: Int) {
63 | if (visibleHeight < 0 && height < 0) {
64 | return
65 | }
66 | onChangedHeights(visibleHeight + height)
67 | if (isBegin) {
68 | onChanged(if (visibleHeight > initHeight) LayoutStatus.READY else LayoutStatus.NORMAL)
69 | }
70 | }
71 |
72 | private fun onChangedHeights(height: Int) {
73 | val lastValue = max(0, height)
74 | if (lastValue == 0) {
75 | onChanged(LayoutStatus.NORMAL)
76 | }
77 | val lp = childView.layoutParams
78 | lp.height = lastValue
79 | childView.layoutParams = lp
80 | }
81 |
82 | private fun smoothScrollTo(destHeight: Int) {
83 | animator.setIntValues(visibleHeight, destHeight)
84 | animator.start()
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/Layout/src/main/java/rv/adapter/layout/simple/SimpleLoadMoreView.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.layout.simple
2 |
3 | import android.content.Context
4 | import android.graphics.Color
5 | import android.view.LayoutInflater
6 | import rv.adapter.layout.R
7 | import rv.adapter.layout.XLoadMoreView
8 | import rv.adapter.layout.databinding.SimpleLoadMoreBinding
9 |
10 | /**
11 | * by y on 2016/9/29
12 | */
13 | class SimpleLoadMoreView(context: Context) : XLoadMoreView(context) {
14 |
15 | private val binding by lazy {
16 | SimpleLoadMoreBinding.inflate(
17 | LayoutInflater.from(context),
18 | this,
19 | true
20 | )
21 | }
22 |
23 | init {
24 | binding.progressBar.visibility = GONE
25 | binding.show.setTextColor(Color.BLACK)
26 | binding.show.text = context.getString(R.string.load_more_init)
27 | layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
28 | }
29 |
30 | override fun onLoad() {
31 | binding.progressBar.visibility = VISIBLE
32 | binding.show.text = context.getString(R.string.load_more_load)
33 | }
34 |
35 | override fun onNoMore() {
36 | binding.progressBar.visibility = GONE
37 | binding.show.text = context.getString(R.string.load_more_no_more)
38 | }
39 |
40 | override fun onSuccess() {
41 | binding.progressBar.visibility = GONE
42 | binding.show.text = context.getString(R.string.load_more_success)
43 | }
44 |
45 | override fun onError() {
46 | binding.progressBar.visibility = GONE
47 | binding.show.text = context.getString(R.string.load_more_error)
48 | }
49 |
50 | override fun onNormal() {
51 | binding.progressBar.visibility = GONE
52 | binding.show.text = context.getString(R.string.load_more_normal)
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/Layout/src/main/java/rv/adapter/layout/simple/SimpleRefreshView.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.layout.simple
2 |
3 | import android.content.Context
4 | import android.graphics.Color
5 | import android.view.LayoutInflater
6 | import android.view.animation.Animation
7 | import android.view.animation.RotateAnimation
8 | import rv.adapter.layout.R
9 | import rv.adapter.layout.XRefreshView
10 | import rv.adapter.layout.databinding.SimpleRefreshBinding
11 |
12 | /**
13 | * by y on 2016/11/16
14 | */
15 | class SimpleRefreshView(context: Context) : XRefreshView(context) {
16 |
17 | private val mRotateUpAnim: Animation = RotateAnimation(
18 | 0.0f,
19 | -180.0f,
20 | Animation.RELATIVE_TO_SELF,
21 | 0.5f,
22 | Animation.RELATIVE_TO_SELF,
23 | 0.5f
24 | ).apply {
25 | duration = 180
26 | fillAfter = true
27 | }
28 | private val mRotateDownAnim: Animation = RotateAnimation(
29 | -180.0f,
30 | 0.0f,
31 | Animation.RELATIVE_TO_SELF,
32 | 0.5f,
33 | Animation.RELATIVE_TO_SELF,
34 | 0.5f
35 | ).apply {
36 | duration = 180
37 | fillAfter = true
38 | }
39 |
40 | private val viewBinding by lazy {
41 | SimpleRefreshBinding.inflate(
42 | LayoutInflater.from(context),
43 | this,
44 | true
45 | )
46 | }
47 |
48 | init {
49 | viewBinding.root.layoutParams.height = 0
50 | viewBinding.show.setTextColor(Color.BLACK)
51 | viewBinding.show.text = context.getString(R.string.refresh_more_init)
52 | viewBinding.progressBar.visibility = GONE
53 | }
54 |
55 | override fun onReady() {
56 | viewBinding.action.startAnimation(mRotateUpAnim)
57 | viewBinding.progressBar.visibility = INVISIBLE
58 | viewBinding.action.visibility = VISIBLE
59 | viewBinding.show.text = context.getString(R.string.refresh_more_ready)
60 | }
61 |
62 | override fun onRefresh() {
63 | viewBinding.progressBar.visibility = VISIBLE
64 | viewBinding.action.clearAnimation()
65 | viewBinding.action.visibility = INVISIBLE
66 | viewBinding.show.text = context.getString(R.string.refresh_more_refresh)
67 | }
68 |
69 | override fun onSuccess() {
70 | viewBinding.progressBar.visibility = INVISIBLE
71 | viewBinding.action.visibility = INVISIBLE
72 | viewBinding.action.clearAnimation()
73 | viewBinding.show.text = context.getString(R.string.refresh_more_success)
74 | }
75 |
76 | override fun onError() {
77 | viewBinding.progressBar.visibility = INVISIBLE
78 | viewBinding.action.visibility = INVISIBLE
79 | viewBinding.action.clearAnimation()
80 | viewBinding.show.text = context.getString(R.string.refresh_more_error)
81 | }
82 |
83 | override fun onNormal() {
84 | if (isReady) {
85 | viewBinding.action.startAnimation(mRotateDownAnim)
86 | } else {
87 | viewBinding.action.clearAnimation()
88 | }
89 | viewBinding.action.visibility = VISIBLE
90 | viewBinding.progressBar.visibility = INVISIBLE
91 | viewBinding.show.text = context.getString(R.string.refresh_more_normal)
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/Layout/src/main/res/drawable-hdpi/ic_refresh_action.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/7449/XAdapter/1c054e2c446aec48202542114efbcdb897d7a61f/Layout/src/main/res/drawable-hdpi/ic_refresh_action.png
--------------------------------------------------------------------------------
/Layout/src/main/res/layout/simple_load_more.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
25 |
26 |
--------------------------------------------------------------------------------
/Layout/src/main/res/layout/simple_refresh.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
24 |
25 |
35 |
36 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/Layout/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 10dp
4 | 25dp
5 | 10dp
6 | 56dp
7 | 40dp
8 | 10dp
9 | 25dp
10 | 10dp
11 |
--------------------------------------------------------------------------------
/Layout/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 上拉加载…
3 | 正在加载…
4 | 没有数据了…
5 | 加载成功…
6 | 加载失败…
7 | 上拉加载…
8 |
9 | 下拉刷新…
10 | 释放立即刷新…
11 | 正在刷新…
12 | 刷新成功…
13 | 刷新失败…
14 | 下拉刷新…
15 |
16 |
--------------------------------------------------------------------------------
/Material/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'com.github.dcendents.android-maven'
4 | android {
5 | compileSdkVersion rootProject.ext.compileSdkVersion
6 | defaultConfig {
7 | minSdkVersion rootProject.ext.minSdkVersion
8 | targetSdkVersion rootProject.ext.targetSdkVersion
9 | }
10 | compileOptions {
11 | kotlinOptions.freeCompilerArgs += ['-module-name', "com.github.7449.XAdapter.Material"]
12 | }
13 | }
14 | dependencies {
15 | implementation "com.google.android.material:material:$googleMaterialVersion"
16 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
17 | }
18 |
--------------------------------------------------------------------------------
/Material/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Material/src/main/java/rv/adapter/material/AppBarStateChangeListener.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.material
2 |
3 | import com.google.android.material.appbar.AppBarLayout
4 | import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener
5 | import kotlin.math.abs
6 |
7 | class AppBarStateChangeListener : OnOffsetChangedListener {
8 |
9 | companion object {
10 | const val EXPANDED = 0
11 | const val COLLAPSED = 1
12 | const val IDLE = 2
13 | }
14 |
15 | var currentState = IDLE
16 | private set
17 |
18 | override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) {
19 | currentState = when {
20 | verticalOffset == 0 -> EXPANDED
21 | abs(verticalOffset) >= appBarLayout.totalScrollRange -> COLLAPSED
22 | else -> IDLE
23 | }
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # XAdapter
2 |
3 | Support for the pull-down refresh loading and the addition of multiple header and footer RecyclerViewAdapter
4 |
5 | ### gradle
6 |
7 | ### sample
8 |
9 | xAdapter
10 | .setItemLayoutId(layoutId)
11 | .customRefreshView(View)
12 | .customLoadMoreView(View)
13 | .openLoadingMore()
14 | .openPullRefresh()
15 | .setScrollLoadMoreItemCount(2)
16 | .addHeaderView(View)
17 | .addFooterView(View)
18 | .setOnBind { holder, position, entity ->
19 | }
20 | .setOnItemClickListener { view, position, entity ->
21 | }
22 | .setOnItemLongClickListener { view, position, entity ->
23 | true
24 | }
25 | .setRefreshListener {
26 | }
27 | .setLoadMoreListener {
28 | }
29 | .addAll(mainBeen)
30 |
31 | ### recyclerview core sample
32 |
33 | recyclerView
34 | .linearLayoutManager()
35 | .attachAdapter()
36 | .setItemLayoutId(layoutId)
37 | .customRefreshView(View)
38 | .customLoadMoreView(View)
39 | .openLoadingMore()
40 | .openPullRefresh()
41 | .setScrollLoadMoreItemCount(2)
42 | .addHeaderView(View)
43 | .addFooterView(View)
44 | .setOnBind { holder, position, entity ->
45 | }
46 | .setOnItemClickListener { view, position, entity ->
47 | }
48 | .setOnItemLongClickListener { view, position, entity ->
49 | true
50 | }
51 | .setRefreshListener {
52 | }
53 | .setLoadMoreListener {
54 | }
55 | .addAll(mainBeen)
56 |
57 | ####### recyclerview core sample
58 |
59 | recyclerView
60 | .linearLayoutManager()
61 | .fixedSize()
62 | .setAdapter {
63 | loadingMore = true
64 | pullRefresh = true
65 | itemLayoutId = layoutId
66 | addHeaderViews(
67 | view...
68 | )
69 | addFooterViews(
70 | view...
71 | )
72 | onBind { holder, position, entity ->
73 | }
74 | onItemLongClickListener { view, position, entity ->
75 | true
76 | }
77 | onItemClickListener { view, position, entity ->
78 | }
79 | refreshListener {
80 | }
81 | loadMoreListener {
82 | }
83 | }
84 | .addAll(JsonUtils.jsonList)
85 |
86 | #### pull to refresh and load more
87 |
88 | xAdapter.openLoadingMore()
89 | .openPullRefresh()
90 | .setRefreshListener {
91 | }
92 | .setLoadMoreListener {
93 | }
94 | //
95 | .customRefreshView(View)
96 | .customLoadMoreView(View)
97 | //
98 |
99 | ### MultipleAdapter
100 |
101 | recyclerView
102 | .attachMultiAdapter(XMultiAdapter(initData()))
103 | .multiSetItemLayoutId { viewType ->
104 | when (viewType) {
105 | // return layoutId
106 | }
107 | }
108 | .multiSetBind { holder, entity, itemViewType, _ ->
109 | }
110 | .multiGridLayoutManagerSpanSize { itemViewType, manager, _ ->
111 | }
112 | .multiStaggeredGridLayoutManagerFullSpan {
113 | }
114 | .multiSetOnItemClickListener { view, _, entity ->
115 | }
116 | .multiSetOnItemLongClickListener { view, _, entity ->
117 | true
118 | }
119 |
120 | #### CustomRefreshView
121 |
122 | class RefreshView(context: Context) : XRefreshView(context, layoutId) {
123 |
124 | override fun initView() {
125 | }
126 |
127 | override fun onStart() {
128 | }
129 |
130 | override fun onNormal() {
131 | }
132 |
133 | override fun onReady() {
134 | }
135 |
136 | override fun onRefresh() {
137 | }
138 |
139 | override fun onSuccess() {
140 | }
141 |
142 | override fun onError() {
143 | }
144 | }
145 |
146 | #### CustomLoadMoreView
147 |
148 | class LoadMoreView(context: Context) : XLoadMoreView(context, layoutId) {
149 |
150 | override fun initView() {
151 | }
152 |
153 | override fun onStart() {
154 | }
155 |
156 | override fun onLoad() {
157 | }
158 |
159 | override fun onNoMore() {
160 | }
161 |
162 | override fun onSuccess() {
163 | }
164 |
165 | override fun onError() {
166 | }
167 |
168 | override fun onNormal() {
169 | }
170 | }
--------------------------------------------------------------------------------
/RecyclerView/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'com.github.dcendents.android-maven'
4 | android {
5 | compileSdkVersion rootProject.ext.compileSdkVersion
6 | defaultConfig {
7 | minSdkVersion rootProject.ext.minSdkVersion
8 | targetSdkVersion rootProject.ext.targetSdkVersion
9 | }
10 | compileOptions {
11 | kotlinOptions.freeCompilerArgs += ['-module-name', "com.github.7449.XAdapter.RecyclerView"]
12 | }
13 | }
14 | dependencies {
15 | compileOnly project(path: ':Layout')
16 | compileOnly project(path: ':Adapter')
17 | compileOnly project(path: ':ViewHolder')
18 | compileOnly project(path: ':Material')
19 | compileOnly project(path: ':DataBinding')
20 | compileOnly project(path: ':ViewBinding')
21 | implementation "com.google.android.material:material:$googleMaterialVersion"
22 | implementation "androidx.recyclerview:recyclerview:$recyclerviewVersion"
23 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
24 | }
25 |
--------------------------------------------------------------------------------
/RecyclerView/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/RecyclerView/src/main/java/rv/adapter/recyclerview/Adapter.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("UNCHECKED_CAST")
2 |
3 | package rv.adapter.recyclerview
4 |
5 | import androidx.recyclerview.widget.RecyclerView
6 | import rv.adapter.core.XAdapter
7 |
8 | /**
9 | * get [XAdapter]
10 | */
11 | fun RecyclerView.xAdapter() = adapter as XAdapter
12 |
13 | /**
14 | * Init [XAdapter]
15 | */
16 | fun RecyclerView.convertAdapter() = convertAdapter(XAdapter())
17 |
18 | /**
19 | * Init [XAdapter]
20 | */
21 | fun RecyclerView.convertAdapter(adapter: XAdapter) =
22 | also { setAdapter(adapter) }.xAdapter()
23 |
24 | /**
25 | * Init [XAdapter]
26 | */
27 | fun RecyclerView.attachXAdapter() = attachXAdapter(XAdapter())
28 |
29 | /**
30 | * Init [XAdapter]
31 | */
32 | fun RecyclerView.attachXAdapter(adapter: XAdapter) = also { setAdapter(adapter) }
33 |
--------------------------------------------------------------------------------
/RecyclerView/src/main/java/rv/adapter/recyclerview/Core.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("UNCHECKED_CAST")
2 |
3 | package rv.adapter.recyclerview
4 |
5 | import android.view.View
6 | import androidx.recyclerview.widget.RecyclerView
7 | import com.google.android.material.appbar.AppBarLayout
8 | import rv.adapter.core.XAdapter
9 | import rv.adapter.layout.LayoutStatus
10 | import rv.adapter.layout.XRefreshStatus
11 | import rv.adapter.layout.simple.SimpleRefreshView
12 | import rv.adapter.material.AppBarStateChangeListener
13 | import rv.adapter.view.holder.XViewHolder
14 |
15 | fun RecyclerView.checkAdapter(): Boolean = adapter != null && adapter is XAdapter<*>
16 |
17 | fun XAdapter.supportAppbar(appBarLayout: AppBarLayout) = also {
18 | val listener = AppBarStateChangeListener()
19 | appBarLayout.addOnOffsetChangedListener(listener)
20 | setAppbarListener { listener.currentState == AppBarStateChangeListener.EXPANDED }
21 | }
22 |
23 | fun RecyclerView.setItemLayoutId(layoutId: Int) = also {
24 | if (checkAdapter()) {
25 | xAdapter().setItemLayoutId(layoutId)
26 | }
27 | }
28 |
29 | fun RecyclerView.setOnBind(action: (holder: XViewHolder, position: Int, entity: T) -> Unit) =
30 | also {
31 | if (checkAdapter()) {
32 | xAdapter().bindItem(action)
33 | }
34 | }
35 |
36 | fun RecyclerView.openPullRefresh() = also {
37 | if (checkAdapter()) {
38 | xAdapter().openPullRefresh()
39 | }
40 | }
41 |
42 | fun RecyclerView.openLoadingMore() = also {
43 | if (checkAdapter()) {
44 | xAdapter().openLoadingMore()
45 | }
46 | }
47 |
48 | fun RecyclerView.setAppbarListener(action: () -> Boolean) = also {
49 | if (checkAdapter()) {
50 | xAdapter().setAppbarListener(action)
51 | }
52 | }
53 |
54 | fun RecyclerView.setRefreshListener(action: (adapter: XAdapter<*>) -> Unit) = also {
55 | if (checkAdapter()) {
56 | xAdapter().setRefreshListener(action)
57 | }
58 | }
59 |
60 | fun RecyclerView.setLoadMoreListener(action: (adapter: XAdapter<*>) -> Unit) = also {
61 | if (checkAdapter()) {
62 | xAdapter().setLoadingMoreListener(action)
63 | }
64 | }
65 |
66 | fun RecyclerView.setOnItemClickListener(action: (view: View, position: Int, entity: T) -> Unit) =
67 | also {
68 | if (checkAdapter()) {
69 | xAdapter().setOnItemClickListener(action)
70 | }
71 | }
72 |
73 | fun RecyclerView.setOnItemLongClickListener(action: (view: View, position: Int, entity: T) -> Boolean) =
74 | also {
75 | if (checkAdapter()) {
76 | xAdapter().setOnItemLongClickListener(action)
77 | }
78 | }
79 |
80 | fun RecyclerView.setRefreshStatus(status: LayoutStatus) = also {
81 | if (checkAdapter()) {
82 | xAdapter().setRefreshStatus(status)
83 | }
84 | }
85 |
86 | fun RecyclerView.setLoadMoreStatus(status: LayoutStatus) = also {
87 | if (checkAdapter()) {
88 | xAdapter().setLoadingMoreStatus(status)
89 | }
90 | }
91 |
92 | fun RecyclerView.setScrollLoadMoreItemCount(count: Int) = also {
93 | if (checkAdapter()) {
94 | xAdapter().setScrollLoadMoreItemCount(count)
95 | }
96 | }
97 |
98 | fun RecyclerView.onRefreshSuccess() = also {
99 | if (checkAdapter()) {
100 | xAdapter().setRefreshStatus(LayoutStatus.SUCCESS)
101 | }
102 | }
103 |
104 | fun RecyclerView.onRefreshError() = also {
105 | if (checkAdapter()) {
106 | xAdapter().setRefreshStatus(LayoutStatus.ERROR)
107 | }
108 | }
109 |
110 | fun RecyclerView.onLoadingMoreSuccess() = also {
111 | if (checkAdapter()) {
112 | xAdapter().setLoadingMoreStatus(LayoutStatus.SUCCESS)
113 | }
114 | }
115 |
116 | fun RecyclerView.onLoadingMoreError() = also {
117 | if (checkAdapter()) {
118 | xAdapter().setLoadingMoreStatus(LayoutStatus.ERROR)
119 | }
120 | }
121 |
122 | fun RecyclerView.onLoadingMoreLoad() = also {
123 | if (checkAdapter()) {
124 | xAdapter().setLoadingMoreStatus(LayoutStatus.LOAD)
125 | }
126 | }
127 |
128 | fun RecyclerView.onLoadingMoreNoMore() = also {
129 | if (checkAdapter()) {
130 | xAdapter().setLoadingMoreStatus(LayoutStatus.NO_MORE)
131 | }
132 | }
133 |
134 | fun RecyclerView.addHeaderView(view: View) = also {
135 | if (checkAdapter()) {
136 | xAdapter().addHeaderView(view)
137 | }
138 | }
139 |
140 | fun RecyclerView.getHeaderView(position: Int) = xAdapter().getHeaderView(position)
141 |
142 | fun RecyclerView.addFooterView(view: View) = also {
143 | if (checkAdapter()) {
144 | xAdapter().addFooterView(view)
145 | }
146 | }
147 |
148 | fun RecyclerView.getFooterView(position: Int) = xAdapter().getFooterView(position)
149 |
150 | fun RecyclerView.getItem(position: Int): T = xAdapter().getItem(position)
151 |
152 | fun RecyclerView.getLast(): T = xAdapter().getLast()
153 |
154 | fun RecyclerView.getFirst(): T = xAdapter().getFirst()
155 |
156 | fun RecyclerView.addAll(data: List, isNotify: Boolean = true) {
157 | if (checkAdapter()) {
158 | xAdapter().addAll(data, isNotify)
159 | }
160 | }
161 |
162 | fun RecyclerView.add(data: Any, isNotify: Boolean = true) {
163 | if (checkAdapter()) {
164 | xAdapter().add(data, isNotify)
165 | }
166 | }
167 |
168 | fun RecyclerView.removeAll(isNotify: Boolean = true) {
169 | if (checkAdapter()) {
170 | xAdapter().removeAll(isNotify)
171 | }
172 | }
173 |
174 | fun RecyclerView.remove(position: Int, isNotify: Boolean = true) {
175 | if (checkAdapter()) {
176 | xAdapter().remove(position, isNotify)
177 | }
178 | }
179 |
180 | fun RecyclerView.autoRefresh(
181 | refreshView: XRefreshStatus = SimpleRefreshView(context)
182 | ) {
183 | if (checkAdapter()) {
184 | xAdapter().autoRefresh(this, refreshView)
185 | }
186 | }
--------------------------------------------------------------------------------
/RecyclerView/src/main/java/rv/adapter/recyclerview/DataBinding.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("UNCHECKED_CAST")
2 |
3 | package rv.adapter.recyclerview
4 |
5 | import androidx.recyclerview.widget.RecyclerView
6 | import rv.adapter.data.binding.XDataBindingAdapter
7 |
8 | /**
9 | * get [XDataBindingAdapter]
10 | */
11 | fun RecyclerView.dataBindingAdapter() = adapter as XDataBindingAdapter
12 |
13 | /**
14 | * Init [XDataBindingAdapter]
15 | */
16 | fun RecyclerView.convertDataBindingAdapter(variableId: Int) =
17 | convertDataBindingAdapter(XDataBindingAdapter(variableId))
18 |
19 | /**
20 | * Init [XDataBindingAdapter]
21 | */
22 | fun RecyclerView.convertDataBindingAdapter(adapter: XDataBindingAdapter) =
23 | also { setAdapter(adapter) }.dataBindingAdapter()
24 |
25 | /**
26 | * Init [XDataBindingAdapter]
27 | */
28 | fun RecyclerView.attachDataBindingAdapter(variableId: Int) =
29 | attachDataBindingAdapter(XDataBindingAdapter(variableId))
30 |
31 | /**
32 | * Init [XDataBindingAdapter]
33 | */
34 | fun RecyclerView.attachDataBindingAdapter(adapter: XDataBindingAdapter) =
35 | also { setAdapter(adapter) }
36 |
--------------------------------------------------------------------------------
/RecyclerView/src/main/java/rv/adapter/recyclerview/LayoutManagerExt.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.recyclerview
2 |
3 | import androidx.recyclerview.widget.GridLayoutManager
4 | import androidx.recyclerview.widget.LinearLayoutManager
5 | import androidx.recyclerview.widget.RecyclerView
6 | import androidx.recyclerview.widget.StaggeredGridLayoutManager
7 |
8 | fun RecyclerView.linearLayoutManager() = also { layoutManager = LinearLayoutManager(this.context) }
9 |
10 | fun RecyclerView.gridLayoutManager(spanCount: Int = 2) =
11 | also { layoutManager = GridLayoutManager(this.context, spanCount) }
12 |
13 | fun RecyclerView.staggeredGridLayoutManager(spanCount: Int, orientation: Int) =
14 | also { layoutManager = StaggeredGridLayoutManager(spanCount, orientation) }
--------------------------------------------------------------------------------
/RecyclerView/src/main/java/rv/adapter/recyclerview/ViewBinding.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("UNCHECKED_CAST")
2 |
3 | package rv.adapter.recyclerview
4 |
5 | import androidx.recyclerview.widget.RecyclerView
6 | import androidx.viewbinding.ViewBinding
7 | import rv.adapter.view.binding.XViewBindingAdapter
8 |
9 | /**
10 | * get [XViewBindingAdapter]
11 | */
12 | fun RecyclerView.viewBindingAdapter() = adapter as XViewBindingAdapter
13 |
14 | /**
15 | * Init [XViewBindingAdapter]
16 | */
17 | fun RecyclerView.convertViewBindingAdapter() =
18 | convertViewBindingAdapter(XViewBindingAdapter())
19 |
20 | /**
21 | * Init [XViewBindingAdapter]
22 | */
23 | fun RecyclerView.convertViewBindingAdapter(adapter: XViewBindingAdapter) =
24 | also { setAdapter(adapter) }.viewBindingAdapter()
25 |
26 | /**
27 | * Init [XViewBindingAdapter]
28 | */
29 | fun RecyclerView.attachViewBindingAdapter() =
30 | attachViewBindingAdapter(XViewBindingAdapter())
31 |
32 | /**
33 | * Init [XViewBindingAdapter]
34 | */
35 | fun RecyclerView.attachViewBindingAdapter(adapter: XViewBindingAdapter) =
36 | also { setAdapter(adapter) }
--------------------------------------------------------------------------------
/ViewBinding/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'com.github.dcendents.android-maven'
4 | android {
5 | compileSdkVersion rootProject.ext.compileSdkVersion
6 | defaultConfig {
7 | minSdkVersion rootProject.ext.minSdkVersion
8 | targetSdkVersion rootProject.ext.targetSdkVersion
9 | }
10 | buildFeatures {
11 | viewBinding = true
12 | }
13 | compileOptions {
14 | kotlinOptions.freeCompilerArgs += ['-module-name', "com.github.7449.XAdapter.ViewBinding"]
15 | }
16 | }
17 | dependencies {
18 | compileOnly project(path: ':Adapter')
19 | compileOnly project(path: ':ViewHolder')
20 | implementation "androidx.recyclerview:recyclerview:$recyclerviewVersion"
21 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
22 | }
23 |
--------------------------------------------------------------------------------
/ViewBinding/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/ViewBinding/src/main/java/rv/adapter/view/binding/XViewBindingAdapter.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.view.binding
2 |
3 | import android.view.View
4 | import android.view.ViewGroup
5 | import androidx.viewbinding.ViewBinding
6 | import rv.adapter.core.XAdapter
7 | import rv.adapter.view.holder.XViewHolder
8 |
9 | class XViewBindingAdapter : XAdapter() {
10 |
11 | companion object {
12 | private const val viewBindingTag = -11
13 | }
14 |
15 | private var itemViewBinding: ((parent: ViewGroup) -> VB)? =
16 | null
17 | private var viewBindingListener: ((viewBinding: VB, position: Int, entity: T) -> Unit)? =
18 | null
19 | private var viewBindingAndHolderListener: ((viewBinding: VB, holder: XViewBindingHolder, position: Int, entity: T) -> Unit)? =
20 | null
21 |
22 | override fun createItemViewHolder(
23 | parent: ViewGroup,
24 | layoutId: Int,
25 | click: ((view: View, position: Int, entity: T) -> Unit)?,
26 | longClick: ((view: View, position: Int, entity: T) -> Boolean)?
27 | ): XViewHolder {
28 | val viewBinding = requireNotNull(itemViewBinding?.invoke(parent))
29 | return XViewBindingHolder(viewBinding).apply {
30 | itemView.setTag(viewBindingTag, viewBinding)
31 | setOnClickListener(this, click)
32 | setOnLongClickListener(this, longClick)
33 | }
34 | }
35 |
36 | @Suppress("UNCHECKED_CAST")
37 | override fun onBindViewHolder(holder: XViewHolder, position: Int) {
38 | if (!isItemViewType(position)) {
39 | return
40 | }
41 | val viewBinding = holder.itemView.getTag(viewBindingTag) as VB
42 | val pos = currentPosition(position)
43 | viewBindingListener?.invoke(viewBinding, pos, getItem(pos))
44 | viewBindingAndHolderListener?.invoke(
45 | viewBinding,
46 | holder as XViewBindingHolder,
47 | pos,
48 | getItem(pos)
49 | )
50 | }
51 |
52 | override fun bindItem(action: (holder: XViewHolder, position: Int, entity: T) -> Unit): XAdapter {
53 | throw RuntimeException("@see onBindItem")
54 | }
55 |
56 | override fun setItemLayoutId(layoutId: Int): XAdapter {
57 | throw RuntimeException("@see onCreateViewBinding")
58 | }
59 |
60 | fun onCreateViewBinding(action: (parent: ViewGroup) -> VB) = also {
61 | this.itemViewBinding = action
62 | }
63 |
64 | fun onBindItem(action: (viewBinding: VB, position: Int, entity: T) -> Unit) =
65 | also {
66 | this.viewBindingListener = action
67 | }
68 |
69 | fun onBindItem(action: (viewBinding: VB, holder: XViewBindingHolder, position: Int, entity: T) -> Unit) =
70 | also {
71 | this.viewBindingAndHolderListener = action
72 | }
73 |
74 | }
--------------------------------------------------------------------------------
/ViewBinding/src/main/java/rv/adapter/view/binding/XViewBindingHolder.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.view.binding
2 |
3 | import androidx.viewbinding.ViewBinding
4 | import rv.adapter.view.holder.XViewHolder
5 |
6 | class XViewBindingHolder(val viewBinding: VB) : XViewHolder(viewBinding.root)
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.5.10'
3 | repositories {
4 | google()
5 | mavenCentral()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:4.2.1'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"
12 | }
13 | }
14 | allprojects {
15 | repositories {
16 | google()
17 | mavenCentral()
18 | jcenter()
19 | }
20 | }
21 | ext {
22 | compileSdkVersion = 30
23 | minSdkVersion = 19
24 | targetSdkVersion = 30
25 | recyclerviewVersion = "1.2.1"
26 | googleMaterialVersion = "1.3.0"
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.useAndroidX=true
2 | android.enableJetifier=true
3 | publishType=3
4 | databindingType=1
5 | multiType=2
6 | recyclerviewType=3
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/7449/XAdapter/1c054e2c446aec48202542114efbcdb897d7a61f/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Apr 09 21:04:01 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-kapt'
4 | android {
5 | compileSdkVersion rootProject.ext.compileSdkVersion
6 | defaultConfig {
7 | applicationId "rv.adapter.sample"
8 | minSdkVersion rootProject.ext.minSdkVersion
9 | targetSdkVersion rootProject.ext.targetSdkVersion
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildFeatures {
14 | viewBinding = true
15 | dataBinding = true
16 | }
17 | compileOptions {
18 | sourceCompatibility 1.8
19 | targetCompatibility 1.8
20 | }
21 | }
22 | dependencies {
23 | implementation fileTree(include: ['*.jar'], dir: 'libs')
24 | implementation 'com.google.code.gson:gson:2.8.5'
25 | implementation "com.google.android.material:material:$googleMaterialVersion"
26 | implementation 'com.github.bumptech.glide:glide:4.12.0'
27 | implementation project(path: ':Adapter')
28 | implementation project(path: ':DataBinding')
29 | implementation project(path: ':ViewBinding')
30 | implementation project(path: ':Material')
31 | implementation project(path: ':RecyclerView')
32 | implementation project(path: ':Layout')
33 | implementation project(path: ':ViewHolder')
34 | }
35 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
28 |
29 |
30 |
33 |
34 |
--------------------------------------------------------------------------------
/sample/src/main/java/rv/adapter/sample/Ext.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.sample
2 |
3 | import android.view.LayoutInflater
4 | import android.widget.ImageView
5 | import androidx.appcompat.app.AppCompatActivity
6 | import androidx.databinding.BindingAdapter
7 | import androidx.viewbinding.ViewBinding
8 | import com.bumptech.glide.Glide
9 |
10 | @BindingAdapter("imageUrl")
11 | fun loadImage(imageView: ImageView, url: String) {
12 | Glide.with(imageView.context).load(url).into(imageView)
13 | }
14 |
15 | inline fun AppCompatActivity.viewBindingInflater(
16 | crossinline bindingInflater: (LayoutInflater) -> T
17 | ) = lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
18 | bindingInflater.invoke(layoutInflater).apply { setContentView(root) }
19 | }
20 |
--------------------------------------------------------------------------------
/sample/src/main/java/rv/adapter/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.sample
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.view.View
6 | import android.widget.Toast
7 | import androidx.recyclerview.widget.GridLayoutManager
8 | import androidx.recyclerview.widget.LinearLayoutManager
9 | import androidx.recyclerview.widget.RecyclerView
10 | import androidx.recyclerview.widget.StaggeredGridLayoutManager
11 | import com.bumptech.glide.Glide
12 | import rv.adapter.recyclerview.convertAdapter
13 | import rv.adapter.sample.databinding.ActivityMainBinding
14 | import rv.adapter.sample.json.JsonUtils
15 | import rv.adapter.sample.json.SampleEntity
16 | import rv.adapter.sample.page.BaseActivity
17 | import rv.adapter.sample.page.DataBindingActivity
18 | import rv.adapter.sample.page.ViewBindingActivity
19 |
20 | class MainActivity : BaseActivity(R.layout.activity_main, false) {
21 |
22 | override fun onCreateViewBinding(rootView: View): ActivityMainBinding {
23 | return ActivityMainBinding.bind(rootView)
24 | }
25 |
26 | override fun onCreate(savedInstanceState: Bundle?) {
27 | super.onCreate(savedInstanceState)
28 | viewBinding.dataBinding.setOnClickListener { startActivity(DataBindingActivity::class.java) }
29 | viewBinding.viewBinding.setOnClickListener { startActivity(ViewBindingActivity::class.java) }
30 | viewBinding.linear.setOnClickListener {
31 | bindRecyclerView(LinearLayoutManager(this))
32 | }
33 | viewBinding.grid.setOnClickListener {
34 | bindRecyclerView(GridLayoutManager(this, 2))
35 | }
36 | viewBinding.staggered.setOnClickListener {
37 | bindRecyclerView(StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL))
38 | }
39 | viewBinding.linear.performClick()
40 | }
41 |
42 | private fun bindRecyclerView(layoutManager: RecyclerView.LayoutManager) {
43 | viewBinding.recyclerView.layoutManager = layoutManager
44 | viewBinding.recyclerView
45 | .convertAdapter()
46 | .setItemLayoutId(R.layout.layout_json_item)
47 | .bindItem { holder, _, entity ->
48 | Glide.with(holder.context).load(entity.image).into(holder.imageView(R.id.image))
49 | holder.setText(R.id.title, entity.title)
50 | }
51 | .setOnItemClickListener { _, position, _ ->
52 | Toast.makeText(this, position.toString(), Toast.LENGTH_SHORT).show()
53 | }
54 | .addAll(JsonUtils.jsonList)
55 | }
56 |
57 | private fun startActivity(clz: Class<*>) {
58 | startActivity(Intent(this, clz))
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/sample/src/main/java/rv/adapter/sample/json/JsonUtils.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.sample.json
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.reflect.TypeToken
5 |
6 | /**
7 | * by y on 2016/11/17
8 | */
9 | object JsonUtils {
10 |
11 | private const val json =
12 | "[{\"image_hue\":\"0x7d95b3\",\"hint\":\"作者 \\/ 张文远\",\"url\":\"https:\\/\\/daily.zhihu.com\\/story\\/9717792\",\"image\":\"https:\\/\\/pic4.zhimg.com\\/v2-51e98034d2b0f95a6ac8311a5ffb5c9f.jpg\",\"title\":\"如何快速记下所有奥特曼?\",\"ga_prefix\":\"120620\",\"type\":0,\"id\":9717792},{\"image_hue\":\"0x879943\",\"hint\":\"作者 \\/ 苏澄宇\",\"url\":\"https:\\/\\/daily.zhihu.com\\/story\\/9717531\",\"image\":\"https:\\/\\/pic2.zhimg.com\\/v2-5c87a645d36d140fa87df6e8ca7cb989.jpg\",\"title\":\"斑马的条纹到底是干嘛用的?\",\"ga_prefix\":\"120407\",\"type\":0,\"id\":9717531},{\"image_hue\":\"0xb39a7d\",\"hint\":\"作者 \\/ 混乱博物馆\",\"url\":\"https:\\/\\/daily.zhihu.com\\/story\\/9717547\",\"image\":\"https:\\/\\/pic4.zhimg.com\\/v2-60f220ee6c5bf035d0eaf2dd4736342b.jpg\",\"title\":\"为什么狗会如此亲近人类?\",\"ga_prefix\":\"120107\",\"type\":0,\"id\":9717547},{\"image_hue\":\"0x384c62\",\"hint\":\"作者 \\/ 丘寒\",\"url\":\"https:\\/\\/daily.zhihu.com\\/story\\/9717774\",\"image\":\"https:\\/\\/pic4.zhimg.com\\/v2-2379bf3e788a57c55a036bfb0b9b4aff.jpg\",\"title\":\"我在成都,观雪山\",\"ga_prefix\":\"112716\",\"type\":0,\"id\":9717774},{\"image_hue\":\"0x57778f\",\"hint\":\"作者 \\/ 卢西\",\"url\":\"https:\\/\\/daily.zhihu.com\\/story\\/9717456\",\"image\":\"https:\\/\\/pic3.zhimg.com\\/v2-8e9852df41f6c0624096f01dd9f72e0e.jpg\",\"title\":\"假如乘坐超音速飞机时突然弹射出去,会不会在音障上被撞成碎片?\",\"ga_prefix\":\"112509\",\"type\":0,\"id\":9717456}]"
13 |
14 | val jsonList: ArrayList =
15 | Gson().fromJson(json, object : TypeToken>() {}.type)
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/sample/src/main/java/rv/adapter/sample/json/SampleEntity.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.sample.json
2 |
3 | /**
4 | * by y on 2016/11/15
5 | */
6 | data class SampleEntity(val title: String, val image: String)
7 |
--------------------------------------------------------------------------------
/sample/src/main/java/rv/adapter/sample/page/BaseActivity.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.sample.page
2 |
3 | import android.os.Bundle
4 | import android.view.MenuItem
5 | import android.view.View
6 | import androidx.appcompat.app.AppCompatActivity
7 | import androidx.viewbinding.ViewBinding
8 | import rv.adapter.sample.R
9 | import rv.adapter.sample.databinding.ActivityBaseBinding
10 | import rv.adapter.sample.viewBindingInflater
11 |
12 | abstract class BaseActivity(
13 | private val layoutId: Int,
14 | private val showBackIcon: Boolean = true
15 | ) : AppCompatActivity() {
16 |
17 | private val viewBind by viewBindingInflater(ActivityBaseBinding::inflate)
18 |
19 | protected val viewBinding by lazy { onCreateViewBinding(viewBind.rootView.getChildAt(0)) }
20 |
21 | abstract fun onCreateViewBinding(rootView: View): VB
22 |
23 | override fun onCreate(savedInstanceState: Bundle?) {
24 | super.onCreate(savedInstanceState)
25 | setContentView(R.layout.activity_base)
26 | setSupportActionBar(viewBind.toolbar)
27 | viewBind.rootView.addView(View.inflate(this, layoutId, null))
28 | viewBind.toolbar.title = javaClass.simpleName
29 | supportActionBar?.setDisplayHomeAsUpEnabled(showBackIcon)
30 | }
31 |
32 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
33 | if (item.itemId == android.R.id.home) {
34 | finish()
35 | }
36 | return super.onOptionsItemSelected(item)
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/sample/src/main/java/rv/adapter/sample/page/DataBindingActivity.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.sample.page
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.MenuItem
6 | import androidx.appcompat.app.AppCompatActivity
7 | import androidx.appcompat.widget.Toolbar
8 | import androidx.databinding.DataBindingUtil
9 | import androidx.databinding.library.baseAdapters.BR
10 | import androidx.recyclerview.widget.LinearLayoutManager
11 | import rv.adapter.data.binding.XDataBindingAdapter
12 | import rv.adapter.layout.LayoutStatus
13 | import rv.adapter.recyclerview.convertDataBindingAdapter
14 | import rv.adapter.recyclerview.setLoadMoreStatus
15 | import rv.adapter.recyclerview.setRefreshStatus
16 | import rv.adapter.sample.R
17 | import rv.adapter.sample.databinding.ActivityDataBindingBinding
18 | import rv.adapter.sample.json.JsonUtils
19 | import rv.adapter.sample.json.SampleEntity
20 |
21 | /**
22 | * @author y
23 | * @create 2018/12/25
24 | */
25 | class DataBindingActivity : AppCompatActivity() {
26 |
27 | private lateinit var binding: ActivityDataBindingBinding
28 |
29 | override fun onCreate(savedInstanceState: Bundle?) {
30 | super.onCreate(savedInstanceState)
31 | binding = DataBindingUtil.setContentView(this, R.layout.activity_data_binding)
32 | setSupportActionBar(findViewById(R.id.toolbar))
33 | findViewById(R.id.toolbar).title = title
34 | supportActionBar?.setDisplayHomeAsUpEnabled(true)
35 | binding.layoutManager = LinearLayoutManager(this)
36 | binding.recyclerView
37 | .convertDataBindingAdapter(XDataBindingAdapter(BR.entity))
38 | .setItemLayoutId(R.layout.item_databinding)
39 | .setScrollLoadMoreItemCount(10)
40 | .openPullRefresh()
41 | .openLoadingMore()
42 | .addHeaderView(
43 | LayoutInflater.from(applicationContext)
44 | .inflate(R.layout.adapter_header, findViewById(android.R.id.content), false)
45 | )
46 | .addFooterView(
47 | LayoutInflater.from(applicationContext)
48 | .inflate(R.layout.adapter_footer, findViewById(android.R.id.content), false)
49 | )
50 | .setRefreshListener {
51 | binding.recyclerView.postDelayed({
52 | binding.recyclerView.setRefreshStatus(LayoutStatus.SUCCESS)
53 | }, 4000)
54 | }
55 | .setLoadingMoreListener {
56 | binding.recyclerView.postDelayed({
57 | binding.recyclerView.setLoadMoreStatus(LayoutStatus.ERROR)
58 | }, 4000)
59 | }
60 | .addAll(JsonUtils.jsonList)
61 | }
62 |
63 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
64 | if (item.itemId == android.R.id.home) {
65 | finish()
66 | }
67 | return super.onOptionsItemSelected(item)
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/sample/src/main/java/rv/adapter/sample/page/ViewBindingActivity.kt:
--------------------------------------------------------------------------------
1 | package rv.adapter.sample.page
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.widget.Toast
7 | import com.bumptech.glide.Glide
8 | import rv.adapter.layout.LayoutStatus
9 | import rv.adapter.recyclerview.convertViewBindingAdapter
10 | import rv.adapter.recyclerview.linearLayoutManager
11 | import rv.adapter.recyclerview.setLoadMoreStatus
12 | import rv.adapter.recyclerview.setRefreshStatus
13 | import rv.adapter.sample.R
14 | import rv.adapter.sample.databinding.ActivityViewBindingBinding
15 | import rv.adapter.sample.databinding.LayoutJsonItemBinding
16 | import rv.adapter.sample.json.JsonUtils
17 | import rv.adapter.sample.json.SampleEntity
18 | import rv.adapter.view.binding.XViewBindingAdapter
19 |
20 | /**
21 | * by y on 2016/11/17
22 | */
23 | class ViewBindingActivity :
24 | BaseActivity(R.layout.activity_view_binding) {
25 |
26 | override fun onCreateViewBinding(rootView: View): ActivityViewBindingBinding {
27 | return ActivityViewBindingBinding.bind(rootView)
28 | }
29 |
30 | override fun onCreate(savedInstanceState: Bundle?) {
31 | super.onCreate(savedInstanceState)
32 | viewBinding.include.recyclerView
33 | .linearLayoutManager()
34 | .convertViewBindingAdapter(XViewBindingAdapter())
35 | .onCreateViewBinding {
36 | LayoutJsonItemBinding.inflate(LayoutInflater.from(it.context), it, false)
37 | }
38 | .onBindItem { viewBinding, _, entity ->
39 | Glide.with(viewBinding.root.context).load(entity.image).into(viewBinding.image)
40 | viewBinding.title.text = entity.title
41 | }
42 | .setScrollLoadMoreItemCount(10)
43 | .openPullRefresh()
44 | .openLoadingMore()
45 | .addHeaderView(
46 | LayoutInflater.from(applicationContext)
47 | .inflate(R.layout.adapter_header, findViewById(android.R.id.content), false)
48 | )
49 | .addFooterView(
50 | LayoutInflater.from(applicationContext)
51 | .inflate(R.layout.adapter_footer, findViewById(android.R.id.content), false)
52 | )
53 | .setOnItemClickListener { _, position, _ ->
54 | Toast.makeText(baseContext, "position:$position", Toast.LENGTH_SHORT).show()
55 | }
56 | .setOnItemLongClickListener { _, _, _ ->
57 | Toast.makeText(baseContext, "onLongClick", Toast.LENGTH_SHORT).show()
58 | true
59 | }
60 | .setRefreshListener {
61 | viewBinding.include.recyclerView.postDelayed({
62 | viewBinding.include.recyclerView.setRefreshStatus(LayoutStatus.SUCCESS)
63 | }, 4000)
64 | }
65 | .setLoadingMoreListener {
66 | viewBinding.include.recyclerView.postDelayed({
67 | viewBinding.include.recyclerView.setLoadMoreStatus(LayoutStatus.ERROR)
68 | }, 4000)
69 | }
70 | .addAll(JsonUtils.jsonList)
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
19 |
20 |
24 |
25 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_data_binding.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
16 |
17 |
21 |
22 |
27 |
28 |
29 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
22 |
23 |
31 |
32 |
33 |
37 |
38 |
47 |
48 |
57 |
58 |
67 |
68 |
69 |
73 |
74 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_view_binding.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/adapter_footer.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/adapter_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/item_databinding.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
17 |
18 |
24 |
25 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/layout_json_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/layout_recyclerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/7449/XAdapter/1c054e2c446aec48202542114efbcdb897d7a61f/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/7449/XAdapter/1c054e2c446aec48202542114efbcdb897d7a61f/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/7449/XAdapter/1c054e2c446aec48202542114efbcdb897d7a61f/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FF02A5D2
4 | #FF02A5D2
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | XAdapter
3 | DataBinding
4 | ViewBinding
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | include(
2 | ":sample",
3 | ":Adapter",
4 | ":RecyclerView",
5 | ":DataBinding",
6 | ":Layout",
7 | ":Material",
8 | ":ViewHolder",
9 | ":ViewBinding"
10 | )
--------------------------------------------------------------------------------
/viewholder/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'com.github.dcendents.android-maven'
4 | android {
5 | compileSdkVersion rootProject.ext.compileSdkVersion
6 | defaultConfig {
7 | minSdkVersion rootProject.ext.minSdkVersion
8 | targetSdkVersion rootProject.ext.targetSdkVersion
9 | }
10 | compileOptions {
11 | kotlinOptions.freeCompilerArgs += ['-module-name', "com.github.7449.XAdapter.ViewHolder"]
12 | }
13 | }
14 | dependencies {
15 | implementation "androidx.recyclerview:recyclerview:$recyclerviewVersion"
16 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
17 | }
18 |
--------------------------------------------------------------------------------
/viewholder/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/viewholder/src/main/java/rv/adapter/view/holder/XViewHolder.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("UNCHECKED_CAST", "MemberVisibilityCanBePrivate")
2 |
3 | package rv.adapter.view.holder
4 |
5 | import android.content.Context
6 | import android.graphics.Bitmap
7 | import android.graphics.drawable.Drawable
8 | import android.util.SparseArray
9 | import android.view.View
10 | import android.widget.*
11 | import androidx.recyclerview.widget.RecyclerView
12 |
13 | open class XViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
14 |
15 | private val idsTag = -1
16 |
17 | val context: Context
18 | get() = itemView.context
19 |
20 | fun viewById(id: Int) = findViewById(id)
21 | fun recyclerView(id: Int) = findViewById(id)
22 | fun relativeLayout(id: Int) = findViewById(id)
23 | fun linearLayout(id: Int) = findViewById(id)
24 | fun frameLayout(id: Int) = findViewById(id)
25 | fun button(id: Int) = findViewById