ui / winkit.android.ui / PaginatedRecyclerView
PaginatedRecyclerView
class PaginatedRecyclerView : FrameLayout
An helpful View that implement a RecyclerView with pullToRefresh and Loadmore feature. This recyclerView ask in a callback the pages and allow to implement the “no data” and “error” state.
paginatedRecycler.getPageListener = getPage@{ index: Int ->
getHttpData(index) { data -> // connection error on data == null
if (data != null) {
adapter.append(data)
paginatedRecycler.haveMore = data.size < TOTAL_SIZE
adapter.notifyDataSetChanged()
} else {
if(index == 0)
adapter.showError("Connection error on first page")
else {
paginatedRecycler.haveMore = false
Toast.makeText(this, "Connection error", Toast.LENGTH_SHORT).show()
}
}
}
}
paginatedRecycler.requestFirstPage()
Attr ref R.styleable#PaginatedRecyclerView
Types
| Name | Summary |
|---|---|
| Adapter | abstract class Adapter<VH : ViewHolder> : Adapter<ViewHolder>Adapter abstraction to provide data to PaginatedRecyclerView |
Constructors
| Name | Summary |
|---|---|
| <init> | PaginatedRecyclerView(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)An helpful View that implement a RecyclerView with pullToRefresh and Loadmore feature. This recyclerView ask in a callback the pages and allow to implement the “no data” and “error” state. |
Properties
| Name | Summary |
|---|---|
| adapter | var adapter: Adapter<*>?Adapter instance to bind |
| emptyIcon | var emptyIcon: IntThe icon drawable resource to show in “no data” case. |
| emptySubtitle | var emptySubtitle: String?The subtitle to show in “no data” case. |
| emptyTitle | var emptyTitle: String?The title to show in “no data” case. |
| errorIcon | var errorIcon: IntThe icon drawable resource to show in “error” case. |
| getPageListener | var getPageListener: (index: Int) -> UnitCallback to notify the user loadMore of pullToRefresh action |
| haveMore | var haveMore: BooleanLoadMore availability |
| layoutManager | var layoutManager: LayoutManager?The wrapped recyclerView’s layout manager |
| refreshing | var refreshing: BooleanSwipeRefresh recyclerView progress visibility |
Functions
| Name | Summary |
|---|---|
| requestFirstPage | fun requestFirstPage(): UnitClean the data and request the first page (like the user pullToRefresh action), getPageListener will be called with index 0. |
Extension Functions
| Name | Summary |
|---|---|
| measure | fun View.measure(callback: (width: Int, height: Int) -> Unit): UnitCalculate the view sizes adding the a ViewTreeObserver.OnGlobalLayoutListener and removing it after the first occurrence. |
| measureIfNeeded | fun View.measureIfNeeded(callback: (width: Int, height: Int) -> Unit): UnitCall the callback if the view is already measured passing the view’s sizes, otherwise call the measure method. |