From ad01280ff7afcf30bd3a9cb7b32373d20df1c7b1 Mon Sep 17 00:00:00 2001 From: HuanChengFly <609486518@qq.com> Date: Thu, 16 Apr 2020 22:48:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=A5=BC=E4=B8=AD=E6=A5=BC=E6=97=A0=E6=B3=95=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=9B=B4=E5=A4=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../huanchengfly/tieba/post/FloorActivity.kt | 81 ++++++++++--------- .../post/adapters/RecyclerFloorAdapter.java | 3 - .../tieba/post/fragments/FloorFragment.kt | 80 +++++++++--------- .../tieba/post/services/NotifyJobService.kt | 2 +- .../tieba/post/services/OKSignService.kt | 4 +- 5 files changed, 84 insertions(+), 86 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/FloorActivity.kt b/app/src/main/java/com/huanchengfly/tieba/post/FloorActivity.kt index 9c566d98..1b70428e 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/FloorActivity.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/FloorActivity.kt @@ -162,49 +162,52 @@ class FloorActivity : BaseActivity() { private fun refresh() { refreshLayout.isRefreshing = true - TiebaApi.getInstance().floor(tid!!, pn, pid, spid).enqueue(object : Callback { - override fun onFailure(call: Call, t: Throwable) { - Toast.makeText(this@FloorActivity, t.message, Toast.LENGTH_SHORT).show() - recyclerViewAdapter!!.loadFailed() - refreshLayout.isRefreshing = false - } + TiebaApi.getInstance() + .floor(tid!!, pn, pid, spid) + .enqueue(object : Callback { + override fun onFailure(call: Call, t: Throwable) { + Toast.makeText(this@FloorActivity, t.message, Toast.LENGTH_SHORT).show() + recyclerViewAdapter!!.loadFailed() + refreshLayout.isRefreshing = false + } - override fun onResponse(call: Call, response: Response) { - val subFloorListBean = response.body() ?: return - pid = subFloorListBean.post!!.id - spid = null - if (Integer.valueOf(subFloorListBean.page!!.currentPage) >= Integer.valueOf(subFloorListBean.page.totalPage)) { - hasMore = false - recyclerViewAdapter!!.loadEnd() - } - toolbar.title = getString(R.string.title_floor_loaded, subFloorListBean.post.floor) - dataBean = subFloorListBean - recyclerViewAdapter!!.setData(subFloorListBean) - refreshLayout.isRefreshing = false - } - }) + override fun onResponse(call: Call, response: Response) { + val subFloorListBean = response.body() ?: return + dataBean = subFloorListBean + recyclerViewAdapter!!.setData(subFloorListBean) + pid = subFloorListBean.post!!.id + spid = null + hasMore = subFloorListBean.page!!.currentPage.toInt() < subFloorListBean.page.totalPage.toInt() + if (!hasMore) { + recyclerViewAdapter!!.loadEnd() + } + toolbar.title = getString(R.string.title_floor_loaded, subFloorListBean.post.floor) + refreshLayout.isRefreshing = false + } + }) } private fun loadMore() { - if (hasMore) { - TiebaApi.getInstance().floor(tid!!, pn, pid, spid).enqueue(object : Callback { - override fun onFailure(call: Call, t: Throwable) { - recyclerViewAdapter!!.loadFailed() - } - - override fun onResponse(call: Call, response: Response) { - 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() + if (!hasMore) return + TiebaApi.getInstance() + .floor(tid!!, pn, pid, spid) + .enqueue(object : Callback { + override fun onFailure(call: Call, t: Throwable) { + recyclerViewAdapter!!.loadFailed() } - pn += 1 - dataBean = subFloorListBean - recyclerViewAdapter!!.addData(subFloorListBean) - } - }) - } + + override fun onResponse(call: Call, response: Response) { + 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 + } + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/adapters/RecyclerFloorAdapter.java b/app/src/main/java/com/huanchengfly/tieba/post/adapters/RecyclerFloorAdapter.java index 17f64b62..68fcd381 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/adapters/RecyclerFloorAdapter.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/adapters/RecyclerFloorAdapter.java @@ -92,19 +92,16 @@ public class RecyclerFloorAdapter extends CommonBaseAdapter { - override fun onFailure(call: Call, t: Throwable) { - Toast.makeText(attachContext, t.message, Toast.LENGTH_SHORT).show() - recyclerViewAdapter!!.loadFailed() - } + TiebaApi.getInstance() + .floor(tid, pn, pid, spid) + .enqueue(object : Callback { + override fun onFailure(call: Call, t: Throwable) { + Toast.makeText(attachContext, t.message, Toast.LENGTH_SHORT).show() + recyclerViewAdapter!!.loadFailed() + } - override fun onResponse(call: Call, response: Response) { - val subFloorListBean = response.body()!! - 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 - recyclerViewAdapter!!.setData(subFloorListBean) - if (jump) { - mLayoutManager!!.scrollToPositionWithOffset(1, 0) - } - } - }) + override fun onResponse(call: Call, response: Response) { + val subFloorListBean = response.body() ?: return + dataBean = 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) { + mLayoutManager!!.scrollToPositionWithOffset(1, 0) + } + } + }) } private fun loadMore(loadMore: Boolean) { + if (!hasMore) return if (loadMore) { pn += 1 } - if (hasMore) { - TiebaApi.getInstance().floor(tid, pn, pid, spid).enqueue(object : Callback { - override fun onFailure(call: Call, t: Throwable) { - recyclerViewAdapter!!.loadFailed() - } - - override fun onResponse(call: Call, response: Response) { - 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 + TiebaApi.getInstance() + .floor(tid, pn, pid, spid) + .enqueue(object : Callback { + override fun onFailure(call: Call, t: Throwable) { + recyclerViewAdapter!!.loadFailed() } - } - }) - } + override fun onResponse(call: Call, response: Response) { + 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 { diff --git a/app/src/main/java/com/huanchengfly/tieba/post/services/NotifyJobService.kt b/app/src/main/java/com/huanchengfly/tieba/post/services/NotifyJobService.kt index 04ddab02..0b9c9fe8 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/services/NotifyJobService.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/services/NotifyJobService.kt @@ -54,7 +54,7 @@ class NotifyJobService : JobService() { } override fun onResponse(call: Call, response: Response) { - val msgBean = response.body()!! + val msgBean = response.body() ?: return if (notificationManager != null) { var total = 0 if ("0" != msgBean.message.replyMe) { diff --git a/app/src/main/java/com/huanchengfly/tieba/post/services/OKSignService.kt b/app/src/main/java/com/huanchengfly/tieba/post/services/OKSignService.kt index 6acd63ce..402100e5 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/services/OKSignService.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/services/OKSignService.kt @@ -121,7 +121,7 @@ class OKSignService : IntentService(TAG) { } override fun onResponse(call: Call, response: Response) { - val signResultBean = response.body()!! + val signResultBean = response.body() ?: return if (position < signData.size - 1) { position += 1 if (signResultBean.userInfo != null) { @@ -154,7 +154,7 @@ class OKSignService : IntentService(TAG) { } override fun onResponse(call: Call, response: Response) { - val itemBeanList = response.body()!!.likeForum + val itemBeanList = response.body()?.likeForum ?: return for ((_, forumName, _, isSign) in itemBeanList) { if ("1" != isSign) { signData.add(SignDataBean(forumName, data.data.getItbTbs()))