打招呼列表增加分页加载

This commit is contained in:
huangjian
2023-02-02 17:08:55 +08:00
parent 4b374fc3fb
commit aad121c2b3
3 changed files with 21 additions and 10 deletions

View File

@@ -35,6 +35,9 @@ class SayHelloListActivity : BaseViewBindingActivity<ActivitySayHelloListBinding
}
}
private var page = 1
private val pageSize = 20
@SuppressLint("CheckResult", "SetTextI18n")
override fun init() {
initTitleBar("打招呼")
@@ -43,6 +46,7 @@ class SayHelloListActivity : BaseViewBindingActivity<ActivitySayHelloListBinding
.setLayoutManager(LinearLayoutManager(this))
.setRecyclerView(binding.recyclerView)
.setAdapter(SayHelloListAdapter())
.setPageSize(pageSize)
.setEmptyView(EmptyViewHelper.createEmptyView(this, "暂无用户"))
.build()
@@ -69,9 +73,9 @@ class SayHelloListActivity : BaseViewBindingActivity<ActivitySayHelloListBinding
}
binding.swipeRefresh.setOnRefreshListener {
loadData()
loadData(true)
}
rvDelegate.adapter.setOnLoadMoreListener({ loadData(false) }, binding.recyclerView)
UserModel.get().sayHelloInfo
.compose(bindToLifecycle())
.subscribe({
@@ -87,15 +91,20 @@ class SayHelloListActivity : BaseViewBindingActivity<ActivitySayHelloListBinding
throwable.printStackTrace()
})
loadData(true)
}
@SuppressLint("CheckResult")
private fun loadData() {
UserModel.get().sayHelloList
private fun loadData(refresh: Boolean) {
if (refresh) {
page = 1
} else {
page++
}
UserModel.get().getSayHelloList(page, pageSize)
.compose(bindToLifecycle())
.subscribe({
rvDelegate.setNewData(it)
rvDelegate.loadData(it, refresh)
}, {
it.printStackTrace()
})

View File

@@ -255,7 +255,7 @@ public interface IUserModel extends IModel {
*
* @return -
*/
Single<List<HelloUserInfo>> getSayHelloList();
Single<List<HelloUserInfo>> getSayHelloList(int page, int size);
/**
* 点击私聊按钮

View File

@@ -825,8 +825,8 @@ public final class UserModel extends BaseModel implements IUserModel {
}
@Override
public Single<List<HelloUserInfo>> getSayHelloList() {
return api.getSayHelloList()
public Single<List<HelloUserInfo>> getSayHelloList(int page, int size) {
return api.getSayHelloList(page,size)
.compose(RxHelper.handleBeanData())
.compose(RxHelper.handleSchedulers());
}
@@ -1084,8 +1084,10 @@ public final class UserModel extends BaseModel implements IUserModel {
*
* @return -
*/
@FormUrlEncoded
@POST("shunt/list")
Single<ServiceResult<List<HelloUserInfo>>> getSayHelloList();
Single<ServiceResult<List<HelloUserInfo>>> getSayHelloList(@Field("page") int page,
@Field("size") int size);
/**
* 点击私聊按钮