fix: 尝试修复楼中楼无法加载更多

This commit is contained in:
HuanChengFly 2020-04-16 22:48:30 +08:00
parent 9256016baa
commit ad01280ff7
5 changed files with 84 additions and 86 deletions

View File

@ -162,49 +162,52 @@ class FloorActivity : BaseActivity() {
private fun refresh() { private fun refresh() {
refreshLayout.isRefreshing = true refreshLayout.isRefreshing = true
TiebaApi.getInstance().floor(tid!!, pn, pid, spid).enqueue(object : Callback<SubFloorListBean> { TiebaApi.getInstance()
override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) { .floor(tid!!, pn, pid, spid)
Toast.makeText(this@FloorActivity, t.message, Toast.LENGTH_SHORT).show() .enqueue(object : Callback<SubFloorListBean> {
recyclerViewAdapter!!.loadFailed() override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) {
refreshLayout.isRefreshing = false Toast.makeText(this@FloorActivity, t.message, Toast.LENGTH_SHORT).show()
} recyclerViewAdapter!!.loadFailed()
refreshLayout.isRefreshing = false
}
override fun onResponse(call: Call<SubFloorListBean>, response: Response<SubFloorListBean>) { override fun onResponse(call: Call<SubFloorListBean>, response: Response<SubFloorListBean>) {
val subFloorListBean = response.body() ?: return val subFloorListBean = response.body() ?: return
pid = subFloorListBean.post!!.id dataBean = subFloorListBean
spid = null recyclerViewAdapter!!.setData(subFloorListBean)
if (Integer.valueOf(subFloorListBean.page!!.currentPage) >= Integer.valueOf(subFloorListBean.page.totalPage)) { pid = subFloorListBean.post!!.id
hasMore = false spid = null
recyclerViewAdapter!!.loadEnd() hasMore = subFloorListBean.page!!.currentPage.toInt() < subFloorListBean.page.totalPage.toInt()
} if (!hasMore) {
toolbar.title = getString(R.string.title_floor_loaded, subFloorListBean.post.floor) recyclerViewAdapter!!.loadEnd()
dataBean = subFloorListBean }
recyclerViewAdapter!!.setData(subFloorListBean) toolbar.title = getString(R.string.title_floor_loaded, subFloorListBean.post.floor)
refreshLayout.isRefreshing = false refreshLayout.isRefreshing = false
} }
}) })
} }
private fun loadMore() { private fun loadMore() {
if (hasMore) { if (!hasMore) return
TiebaApi.getInstance().floor(tid!!, pn, pid, spid).enqueue(object : Callback<SubFloorListBean> { TiebaApi.getInstance()
override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) { .floor(tid!!, pn, pid, spid)
recyclerViewAdapter!!.loadFailed() .enqueue(object : Callback<SubFloorListBean> {
} override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) {
recyclerViewAdapter!!.loadFailed()
override fun onResponse(call: Call<SubFloorListBean>, response: Response<SubFloorListBean>) {
val subFloorListBean = response.body()!!
pid = subFloorListBean.post!!.id
spid = null
if (Integer.valueOf(subFloorListBean.page!!.currentPage) >= Integer.valueOf(subFloorListBean.page.totalPage)) {
hasMore = false
recyclerViewAdapter!!.loadEnd()
} }
pn += 1
dataBean = subFloorListBean override fun onResponse(call: Call<SubFloorListBean>, response: Response<SubFloorListBean>) {
recyclerViewAdapter!!.addData(subFloorListBean) val subFloorListBean = response.body() ?: return
} dataBean = subFloorListBean
}) recyclerViewAdapter!!.addData(subFloorListBean)
} pid = subFloorListBean.post!!.id
spid = null
hasMore = subFloorListBean.page!!.currentPage.toInt() < subFloorListBean.page.totalPage.toInt()
if (!hasMore) {
recyclerViewAdapter!!.loadEnd()
}
pn += 1
}
})
} }
} }

View File

@ -92,19 +92,16 @@ public class RecyclerFloorAdapter extends CommonBaseAdapter<SubFloorListBean.Pos
defaultRequestOptions = new RequestOptions() defaultRequestOptions = new RequestOptions()
.placeholder(R.drawable.bg_placeholder) .placeholder(R.drawable.bg_placeholder)
.skipMemoryCache(true); .skipMemoryCache(true);
openAutoLoadMore();
} }
public void setData(SubFloorListBean data) { public void setData(SubFloorListBean data) {
dataBean = data; dataBean = data;
data.getSubPostList().add(0, data.getPost()); data.getSubPostList().add(0, data.getPost());
openAutoLoadMore();
setNewData(data.getSubPostList()); setNewData(data.getSubPostList());
} }
public void addData(SubFloorListBean data) { public void addData(SubFloorListBean data) {
dataBean = data; dataBean = data;
openAutoLoadMore();
setLoadMoreData(data.getSubPostList()); setLoadMoreData(data.getSubPostList());
} }

View File

@ -5,7 +5,6 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
@ -115,7 +114,6 @@ class FloorFragment : BaseBottomSheetDialogFragment() {
appBarLayout.setBackgroundResource(R.drawable.bg_toolbar) appBarLayout.setBackgroundResource(R.drawable.bg_toolbar)
mLayoutManager = MyLinearLayoutManager(attachContext) mLayoutManager = MyLinearLayoutManager(attachContext)
recyclerViewAdapter = RecyclerFloorAdapter(attachContext).apply { recyclerViewAdapter = RecyclerFloorAdapter(attachContext).apply {
openAutoLoadMore()
setLoadingView(R.layout.layout_footer_loading) setLoadingView(R.layout.layout_footer_loading)
setLoadEndView(R.layout.layout_footer_loadend) setLoadEndView(R.layout.layout_footer_loadend)
setLoadFailedView(R.layout.layout_footer_load_failed) setLoadFailedView(R.layout.layout_footer_load_failed)
@ -126,7 +124,7 @@ class FloorFragment : BaseBottomSheetDialogFragment() {
layoutManager = mLayoutManager layoutManager = mLayoutManager
addItemDecoration(ThreadDivider(attachContext)) addItemDecoration(ThreadDivider(attachContext))
} }
if (!TextUtils.isEmpty(tid) && !TextUtils.isEmpty(pid)) { if (tid.isNotEmpty() && (pid.isNotEmpty() || !spid.isNullOrEmpty())) {
refresh(jump) refresh(jump)
} }
} }
@ -155,53 +153,53 @@ class FloorFragment : BaseBottomSheetDialogFragment() {
} }
private fun refresh(jump: Boolean = false) { private fun refresh(jump: Boolean = false) {
TiebaApi.getInstance().floor(tid, pn, pid, spid).enqueue(object : Callback<SubFloorListBean> { TiebaApi.getInstance()
override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) { .floor(tid, pn, pid, spid)
Toast.makeText(attachContext, t.message, Toast.LENGTH_SHORT).show() .enqueue(object : Callback<SubFloorListBean> {
recyclerViewAdapter!!.loadFailed() override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) {
} Toast.makeText(attachContext, t.message, Toast.LENGTH_SHORT).show()
recyclerViewAdapter!!.loadFailed()
}
override fun onResponse(call: Call<SubFloorListBean>, response: Response<SubFloorListBean>) { override fun onResponse(call: Call<SubFloorListBean>, response: Response<SubFloorListBean>) {
val subFloorListBean = response.body()!! val subFloorListBean = response.body() ?: return
if (Integer.valueOf(subFloorListBean.page!!.currentPage) >= Integer.valueOf(subFloorListBean.page.totalPage)) { dataBean = subFloorListBean
hasMore = false recyclerViewAdapter!!.setData(subFloorListBean)
recyclerViewAdapter!!.loadEnd() hasMore = subFloorListBean.page!!.currentPage.toInt() < subFloorListBean.page.totalPage.toInt()
} else { if (!hasMore) {
hasMore = true recyclerViewAdapter!!.loadEnd()
} }
toolbar.title = attachContext.getString(R.string.title_floor_loaded, subFloorListBean.post!!.floor) toolbar.title = attachContext.getString(R.string.title_floor_loaded, subFloorListBean.post!!.floor)
dataBean = subFloorListBean if (jump) {
recyclerViewAdapter!!.setData(subFloorListBean) mLayoutManager!!.scrollToPositionWithOffset(1, 0)
if (jump) { }
mLayoutManager!!.scrollToPositionWithOffset(1, 0) }
} })
}
})
} }
private fun loadMore(loadMore: Boolean) { private fun loadMore(loadMore: Boolean) {
if (!hasMore) return
if (loadMore) { if (loadMore) {
pn += 1 pn += 1
} }
if (hasMore) { TiebaApi.getInstance()
TiebaApi.getInstance().floor(tid, pn, pid, spid).enqueue(object : Callback<SubFloorListBean> { .floor(tid, pn, pid, spid)
override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) { .enqueue(object : Callback<SubFloorListBean> {
recyclerViewAdapter!!.loadFailed() override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) {
} recyclerViewAdapter!!.loadFailed()
override fun onResponse(call: Call<SubFloorListBean>, response: Response<SubFloorListBean>) {
val subFloorListBean = response.body()!!
recyclerViewAdapter!!.addData(subFloorListBean)
if (Integer.valueOf(subFloorListBean.page!!.currentPage) >= Integer.valueOf(subFloorListBean.page.totalPage)) {
hasMore = false
recyclerViewAdapter!!.loadEnd()
} else {
hasMore = true
} }
}
}) override fun onResponse(call: Call<SubFloorListBean>, response: Response<SubFloorListBean>) {
} val subFloorListBean = response.body() ?: return
dataBean = subFloorListBean
recyclerViewAdapter!!.addData(subFloorListBean)
hasMore = subFloorListBean.page!!.currentPage.toInt() < subFloorListBean.page.totalPage.toInt()
if (!hasMore) {
recyclerViewAdapter!!.loadEnd()
}
}
})
} }
companion object { companion object {

View File

@ -54,7 +54,7 @@ class NotifyJobService : JobService() {
} }
override fun onResponse(call: Call<MsgBean>, response: Response<MsgBean>) { override fun onResponse(call: Call<MsgBean>, response: Response<MsgBean>) {
val msgBean = response.body()!! val msgBean = response.body() ?: return
if (notificationManager != null) { if (notificationManager != null) {
var total = 0 var total = 0
if ("0" != msgBean.message.replyMe) { if ("0" != msgBean.message.replyMe) {

View File

@ -121,7 +121,7 @@ class OKSignService : IntentService(TAG) {
} }
override fun onResponse(call: Call<SignResultBean>, response: Response<SignResultBean>) { override fun onResponse(call: Call<SignResultBean>, response: Response<SignResultBean>) {
val signResultBean = response.body()!! val signResultBean = response.body() ?: return
if (position < signData.size - 1) { if (position < signData.size - 1) {
position += 1 position += 1
if (signResultBean.userInfo != null) { if (signResultBean.userInfo != null) {
@ -154,7 +154,7 @@ class OKSignService : IntentService(TAG) {
} }
override fun onResponse(call: Call<ForumRecommend>, response: Response<ForumRecommend>) { override fun onResponse(call: Call<ForumRecommend>, response: Response<ForumRecommend>) {
val itemBeanList = response.body()!!.likeForum val itemBeanList = response.body()?.likeForum ?: return
for ((_, forumName, _, isSign) in itemBeanList) { for ((_, forumName, _, isSign) in itemBeanList) {
if ("1" != isSign) { if ("1" != isSign) {
signData.add(SignDataBean(forumName, data.data.getItbTbs())) signData.add(SignDataBean(forumName, data.data.getItbTbs()))