refactor: Kotlin 重写
This commit is contained in:
parent
ada00cfed8
commit
4879f9d3fc
|
|
@ -2,47 +2,43 @@ package com.huanchengfly.tieba.post.api.models
|
|||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class SearchThreadBean {
|
||||
data class SearchThreadBean(
|
||||
@SerializedName("no")
|
||||
val errorCode: Int? = null
|
||||
|
||||
val errorCode: Int,
|
||||
@SerializedName("error")
|
||||
val errorMsg: String? = null
|
||||
val errorMsg: String,
|
||||
val data: DataBean? = null
|
||||
|
||||
class DataBean {
|
||||
) {
|
||||
data class DataBean(
|
||||
@SerializedName("has_more")
|
||||
val hasMore: Int? = null
|
||||
|
||||
val hasMore: Int? = null,
|
||||
@SerializedName("current_page")
|
||||
val currentPage: Int? = null
|
||||
|
||||
val currentPage: Int? = null,
|
||||
@SerializedName("post_list")
|
||||
val postList: List<ThreadInfoBean>? = null
|
||||
}
|
||||
)
|
||||
|
||||
class ThreadInfoBean {
|
||||
val tid: String? = null
|
||||
val pid: String? = null
|
||||
val title: String? = null
|
||||
val content: String? = null
|
||||
val time: String? = null
|
||||
data class ThreadInfoBean(
|
||||
val tid: String? = null,
|
||||
val pid: String? = null,
|
||||
val title: String? = null,
|
||||
val content: String? = null,
|
||||
val time: String? = null,
|
||||
|
||||
@SerializedName("post_num")
|
||||
val postNum: String? = null
|
||||
val postNum: String? = null,
|
||||
|
||||
@SerializedName("forum_name")
|
||||
val forumName: String? = null
|
||||
val user: UserInfoBean? = null
|
||||
val forumName: String? = null,
|
||||
val user: UserInfoBean? = null,
|
||||
val type: Int? = null
|
||||
}
|
||||
)
|
||||
|
||||
class UserInfoBean {
|
||||
data class UserInfoBean(
|
||||
@SerializedName("user_name")
|
||||
val userName: String? = null
|
||||
|
||||
val userName: String? = null,
|
||||
@SerializedName("user_id")
|
||||
val userId: String? = null
|
||||
val userId: String? = null,
|
||||
val portrait: String? = null
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -26,21 +26,17 @@ object FailureResponseInterceptor : Interceptor {
|
|||
it.request(Long.MAX_VALUE)
|
||||
}.buffer.clone().inputStream().reader(charset)
|
||||
|
||||
val jsonObject = try {
|
||||
gson.fromJson<CommonResponse>(
|
||||
gson.newJsonReader(inputStreamReader),
|
||||
CommonResponse::class.java
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
//如果返回内容解析失败, 说明它不是一个合法的 json
|
||||
//如果在拦截器抛出 MalformedJsonException 会导致 Retrofit 的异步请求一直卡着直到超时
|
||||
return response
|
||||
} finally {
|
||||
inputStreamReader.close()
|
||||
}
|
||||
val commonResponse = inputStreamReader.use {
|
||||
runCatching {
|
||||
gson.fromJson<CommonResponse>(
|
||||
gson.newJsonReader(inputStreamReader),
|
||||
CommonResponse::class.java
|
||||
)
|
||||
}.getOrNull()
|
||||
} ?: return response
|
||||
|
||||
if (jsonObject?.errorCode != null && jsonObject.errorCode != 0) {
|
||||
throw TiebaApiException(jsonObject)
|
||||
if (commonResponse.errorCode != null && commonResponse.errorCode != 0) {
|
||||
throw TiebaApiException(commonResponse)
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import androidx.compose.material.icons.rounded.Download
|
|||
import androidx.compose.material.icons.rounded.Share
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
|
|
@ -164,9 +163,7 @@ class PhotoViewActivity : BaseComposeActivityWithParcelable<PhotoViewData>() {
|
|||
prop1 = PhotoViewUiState::hasNext,
|
||||
initial = false
|
||||
)
|
||||
val pageCount by derivedStateOf {
|
||||
items.size
|
||||
}
|
||||
val pageCount = items.size
|
||||
Surface(color = Color.Black) {
|
||||
if (items.isNotEmpty()) {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
|
|
|||
Loading…
Reference in New Issue