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