Skip to content

Commit 8c9c942

Browse files
committed
refactor: convert AdapterLayout modules from Java to Kotlin
1 parent bc839d5 commit 8c9c942

File tree

9 files changed

+312
-355
lines changed

9 files changed

+312
-355
lines changed

adapterflowlayout/src/main/java/com/commit451/adapterflowlayout/AdapterFlowLayout.java

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@file:Suppress("unused")
2+
3+
package com.commit451.adapterflowlayout
4+
5+
import android.content.Context
6+
import android.util.AttributeSet
7+
import androidx.annotation.Nullable
8+
import androidx.recyclerview.widget.RecyclerView
9+
import com.commit451.adapterlayout.AdapterLayoutDelegate
10+
import com.wefika.flowlayout.FlowLayout
11+
12+
/**
13+
* [FlowLayout] with [RecyclerView.Adapter] support.
14+
*/
15+
class AdapterFlowLayout : FlowLayout {
16+
17+
private var adapterLayoutDelegate: AdapterLayoutDelegate? = null
18+
19+
constructor(context: Context?) : super(context)
20+
21+
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
22+
23+
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
24+
25+
@get:Nullable
26+
var adapter: RecyclerView.Adapter<*>?
27+
get() = adapterLayoutDelegate?.getAdapter()
28+
set(value) {
29+
if (adapterLayoutDelegate == null) {
30+
adapterLayoutDelegate = AdapterLayoutDelegate(this)
31+
}
32+
adapterLayoutDelegate?.setAdapter(value)
33+
}
34+
35+
@Nullable
36+
fun getViewHolderAt(index: Int): RecyclerView.ViewHolder? {
37+
return adapterLayoutDelegate?.getViewHolderAt(index)
38+
}
39+
}

adapterlayout/src/main/java/com/commit451/adapterlayout/AdapterLayout.java

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.commit451.adapterlayout
2+
3+
import androidx.recyclerview.widget.RecyclerView
4+
5+
/**
6+
* Provides access to some of the public API of AdapterLayout in a way that will be available for any given
7+
* AdapterLayout
8+
*/
9+
class AdapterLayout {
10+
companion object {
11+
/**
12+
* Get the position in the AdapterLayout of the View holder.
13+
* Use this instead of [RecyclerView.ViewHolder.getAdapterPosition]
14+
*
15+
* @param viewHolder the holder to find the position of
16+
* @return the index of the holder, or -1 if not found
17+
*/
18+
@JvmStatic
19+
fun getAdapterPosition(viewHolder: RecyclerView.ViewHolder): Int {
20+
return getPosition(viewHolder)
21+
}
22+
23+
/**
24+
* Get the position in the AdapterLayout of the View holder.
25+
* Use this instead of [RecyclerView.ViewHolder.getLayoutPosition]
26+
*
27+
* @param viewHolder the holder to find the position of
28+
* @return the index of the holder, or -1 if not found
29+
*/
30+
@JvmStatic
31+
fun getLayoutPosition(viewHolder: RecyclerView.ViewHolder): Int {
32+
return getPosition(viewHolder)
33+
}
34+
35+
private fun getPosition(viewHolder: RecyclerView.ViewHolder): Int {
36+
return viewHolder.itemView.getTag(R.id.adapter_layout_list_position) as Int
37+
}
38+
}
39+
}

adapterlayout/src/main/java/com/commit451/adapterlayout/AdapterLayoutDelegate.java

Lines changed: 0 additions & 200 deletions
This file was deleted.

0 commit comments

Comments
 (0)