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,7 +162,9 @@ 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()
.floor(tid!!, pn, pid, spid)
.enqueue(object : Callback<SubFloorListBean> {
override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) { override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) {
Toast.makeText(this@FloorActivity, t.message, Toast.LENGTH_SHORT).show() Toast.makeText(this@FloorActivity, t.message, Toast.LENGTH_SHORT).show()
recyclerViewAdapter!!.loadFailed() recyclerViewAdapter!!.loadFailed()
@ -171,40 +173,41 @@ class FloorActivity : BaseActivity() {
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
dataBean = subFloorListBean
recyclerViewAdapter!!.setData(subFloorListBean)
pid = subFloorListBean.post!!.id pid = subFloorListBean.post!!.id
spid = null spid = null
if (Integer.valueOf(subFloorListBean.page!!.currentPage) >= Integer.valueOf(subFloorListBean.page.totalPage)) { hasMore = subFloorListBean.page!!.currentPage.toInt() < subFloorListBean.page.totalPage.toInt()
hasMore = false if (!hasMore) {
recyclerViewAdapter!!.loadEnd() recyclerViewAdapter!!.loadEnd()
} }
toolbar.title = getString(R.string.title_floor_loaded, subFloorListBean.post.floor) toolbar.title = getString(R.string.title_floor_loaded, subFloorListBean.post.floor)
dataBean = subFloorListBean
recyclerViewAdapter!!.setData(subFloorListBean)
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()
.floor(tid!!, pn, pid, spid)
.enqueue(object : Callback<SubFloorListBean> {
override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) { override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) {
recyclerViewAdapter!!.loadFailed() 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
dataBean = subFloorListBean
recyclerViewAdapter!!.addData(subFloorListBean)
pid = subFloorListBean.post!!.id pid = subFloorListBean.post!!.id
spid = null spid = null
if (Integer.valueOf(subFloorListBean.page!!.currentPage) >= Integer.valueOf(subFloorListBean.page.totalPage)) { hasMore = subFloorListBean.page!!.currentPage.toInt() < subFloorListBean.page.totalPage.toInt()
hasMore = false if (!hasMore) {
recyclerViewAdapter!!.loadEnd() recyclerViewAdapter!!.loadEnd()
} }
pn += 1 pn += 1
dataBean = subFloorListBean
recyclerViewAdapter!!.addData(subFloorListBean)
} }
}) })
} }
}
} }

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,23 +153,23 @@ 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()
.floor(tid, pn, pid, spid)
.enqueue(object : Callback<SubFloorListBean> {
override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) { override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) {
Toast.makeText(attachContext, t.message, Toast.LENGTH_SHORT).show() Toast.makeText(attachContext, t.message, Toast.LENGTH_SHORT).show()
recyclerViewAdapter!!.loadFailed() 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)) {
hasMore = false
recyclerViewAdapter!!.loadEnd()
} else {
hasMore = true
}
toolbar.title = attachContext.getString(R.string.title_floor_loaded, subFloorListBean.post!!.floor)
dataBean = subFloorListBean dataBean = subFloorListBean
recyclerViewAdapter!!.setData(subFloorListBean) recyclerViewAdapter!!.setData(subFloorListBean)
hasMore = subFloorListBean.page!!.currentPage.toInt() < subFloorListBean.page.totalPage.toInt()
if (!hasMore) {
recyclerViewAdapter!!.loadEnd()
}
toolbar.title = attachContext.getString(R.string.title_floor_loaded, subFloorListBean.post!!.floor)
if (jump) { if (jump) {
mLayoutManager!!.scrollToPositionWithOffset(1, 0) mLayoutManager!!.scrollToPositionWithOffset(1, 0)
} }
@ -180,29 +178,29 @@ class FloorFragment : BaseBottomSheetDialogFragment() {
} }
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)
.enqueue(object : Callback<SubFloorListBean> {
override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) { override fun onFailure(call: Call<SubFloorListBean>, t: Throwable) {
recyclerViewAdapter!!.loadFailed() 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
dataBean = subFloorListBean
recyclerViewAdapter!!.addData(subFloorListBean) recyclerViewAdapter!!.addData(subFloorListBean)
if (Integer.valueOf(subFloorListBean.page!!.currentPage) >= Integer.valueOf(subFloorListBean.page.totalPage)) { hasMore = subFloorListBean.page!!.currentPage.toInt() < subFloorListBean.page.totalPage.toInt()
hasMore = false if (!hasMore) {
recyclerViewAdapter!!.loadEnd() recyclerViewAdapter!!.loadEnd()
} else {
hasMore = true
} }
} }
}) })
} }
}
companion object { companion object {
const val PARAM_TID = "tid" const val PARAM_TID = "tid"

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()))