parent
7b0d3d0be2
commit
57acb76df6
@ -0,0 +1,32 @@ |
|||||||
|
package io.legado.app.base.adapter |
||||||
|
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import androidx.recyclerview.widget.RecyclerView |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by Invincible on 2017/12/15. |
||||||
|
* |
||||||
|
* 上拉加载更多 |
||||||
|
*/ |
||||||
|
abstract class InfiniteScrollListener() : RecyclerView.OnScrollListener() { |
||||||
|
private val loadMoreRunnable = Runnable { onLoadMore() } |
||||||
|
|
||||||
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { |
||||||
|
// if (dy < 0 || dataLoading.isDataLoading()) return |
||||||
|
|
||||||
|
val layoutManager:LinearLayoutManager = recyclerView.layoutManager as LinearLayoutManager |
||||||
|
val visibleItemCount = recyclerView.childCount |
||||||
|
val totalItemCount = layoutManager.itemCount |
||||||
|
val firstVisibleItem = layoutManager.findFirstVisibleItemPosition() |
||||||
|
|
||||||
|
if (totalItemCount - visibleItemCount <= firstVisibleItem + VISIBLE_THRESHOLD) { |
||||||
|
recyclerView.post(loadMoreRunnable) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
abstract fun onLoadMore() |
||||||
|
|
||||||
|
companion object { |
||||||
|
private const val VISIBLE_THRESHOLD = 5 |
||||||
|
} |
||||||
|
} |
@ -1,2 +1,3 @@ |
|||||||
package io.legado.app.data.entities |
package io.legado.app.data.entities |
||||||
|
|
||||||
|
class SearchBook |
@ -0,0 +1,34 @@ |
|||||||
|
package io.legado.app.ui.search |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import io.legado.app.R |
||||||
|
import io.legado.app.base.adapter.ItemViewDelegate |
||||||
|
import io.legado.app.base.adapter.ItemViewHolder |
||||||
|
import io.legado.app.base.adapter.SimpleRecyclerAdapter |
||||||
|
import io.legado.app.data.entities.SearchBook |
||||||
|
import kotlinx.android.synthetic.main.item_search.view.* |
||||||
|
|
||||||
|
class SearchAdapter(context: Context) : SimpleRecyclerAdapter<SearchBook>(context) { |
||||||
|
|
||||||
|
init { |
||||||
|
addItemViewDelegate(TestItemDelegate(context)) |
||||||
|
} |
||||||
|
|
||||||
|
override val layoutID: Int |
||||||
|
get() = R.layout.item_search |
||||||
|
|
||||||
|
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) { |
||||||
|
holder.itemView.bookName.text = "我欲封天" |
||||||
|
} |
||||||
|
|
||||||
|
internal class TestItemDelegate(context: Context) : ItemViewDelegate<SearchBook>(context){ |
||||||
|
override val layoutID: Int |
||||||
|
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. |
||||||
|
|
||||||
|
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) { |
||||||
|
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout |
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content"> |
||||||
|
|
||||||
|
|
||||||
|
<TextView |
||||||
|
android:id="@+id/bookName" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
app:layout_constraintTop_toTopOf="parent" |
||||||
|
android:text="测试"/> |
||||||
|
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
Loading…
Reference in new issue