fix: 修复搜索用户报错

This commit is contained in:
HuanChengFly 2020-05-01 18:01:44 +08:00
parent b2b875b082
commit d8323ba48b
3 changed files with 26 additions and 7 deletions

View File

@ -0,0 +1,19 @@
package com.huanchengfly.tieba.api.adapters;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.huanchengfly.tieba.api.models.SearchUserBean;
import java.lang.reflect.Type;
public class UserExactMatchAdapter implements JsonDeserializer<SearchUserBean.UserBean> {
@Override
public SearchUserBean.UserBean deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json.isJsonArray()) {
return null;
}
return context.deserialize(json, typeOfT);
}
}

View File

@ -2,7 +2,7 @@ package com.huanchengfly.tieba.api.models;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.huanchengfly.tieba.api.adapters.ExactMatchAdapter;
import com.huanchengfly.tieba.api.adapters.UserExactMatchAdapter;
import com.huanchengfly.tieba.api.adapters.UserFuzzyMatchAdapter;
import com.huanchengfly.tieba.post.models.BaseBean;
@ -32,7 +32,7 @@ public class SearchUserBean extends BaseBean {
private int pageNum;
@SerializedName("has_more")
private int hasMore;
@JsonAdapter(ExactMatchAdapter.class)
@JsonAdapter(UserExactMatchAdapter.class)
private UserBean exactMatch;
@JsonAdapter(UserFuzzyMatchAdapter.class)
private List<UserBean> fuzzyMatch;

View File

@ -116,12 +116,12 @@ class FloorFragment : BaseBottomSheetDialogFragment() {
setLoadingView(R.layout.layout_footer_loading)
setLoadEndView(R.layout.layout_footer_loadend)
setLoadFailedView(R.layout.layout_footer_load_failed)
setOnLoadMoreListener { loadMore(!it) }
setOnLoadMoreListener { load(it) }
}
recyclerView.apply {
adapter = recyclerViewAdapter
layoutManager = mLayoutManager
addItemDecoration(ThreadDivider(attachContext))
layoutManager = mLayoutManager
adapter = recyclerViewAdapter
}
if (tid.isNotEmpty() && (pid.isNotEmpty() || !spid.isNullOrEmpty())) {
refresh(jump)
@ -175,8 +175,8 @@ class FloorFragment : BaseBottomSheetDialogFragment() {
})
}
private fun loadMore(loadMore: Boolean) {
if (loadMore) {
private fun load(reload: Boolean) {
if (!reload) {
pn += 1
}
TiebaApi.getInstance()