diff --git a/app/src/main/java/com/github/jsbxyyx/xbook/VideoListFragment.java b/app/src/main/java/com/github/jsbxyyx/xbook/VideoListFragment.java index 0fb23f8..12c2f42 100644 --- a/app/src/main/java/com/github/jsbxyyx/xbook/VideoListFragment.java +++ b/app/src/main/java/com/github/jsbxyyx/xbook/VideoListFragment.java @@ -9,6 +9,7 @@ import android.widget.Button; import android.widget.EditText; import android.widget.ListView; +import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -20,6 +21,8 @@ import com.github.jsbxyyx.xbook.common.LogUtil; import com.github.jsbxyyx.xbook.data.VideoNetHelper; import com.github.jsbxyyx.xbook.data.bean.QqVideo; +import com.github.jsbxyyx.xbook.data.bean.QqVideoHotRank; +import com.github.jsbxyyx.xbook.data.bean.QqVideoHotWord; import java.util.List; @@ -35,6 +38,7 @@ public class VideoListFragment extends Fragment { private ListView lv_video_list; private ListVideoAdapter listVideoAdapter; private VideoNetHelper videoNetHelper; + private AutoLinearLayout ll_hot_rank; private int page = 1; @@ -57,6 +61,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat mActivity = getActivity(); lv_video_list = view.findViewById(R.id.lv_video_list); + Button btn_video_search = view.findViewById(R.id.btn_video_search); + Button btn_hot_search = view.findViewById(R.id.btn_hot_search); + ll_hot_rank = view.findViewById(R.id.ll_hot_rank); + listVideoAdapter = new ListVideoAdapter(mActivity, null, new ListItemClickListener() { @Override public void onClick(View view, String type, int position) { @@ -72,10 +80,15 @@ public void onClick(View view, String type, int position) { }); lv_video_list.setAdapter(listVideoAdapter); - Button btn_video_search = view.findViewById(R.id.btn_video_search); btn_video_search.setOnClickListener(v -> { showListView(true); }); + + btn_hot_search.setOnClickListener(v -> { + hotSearch(); + }); + + hotSearch(); } private void showListView(boolean clear) { @@ -109,4 +122,31 @@ public void call(List list, Throwable err) { }); } + private void hotSearch() { + videoNetHelper.hotWord(new DataCallback>() { + @Override + public void call(List list, Throwable err) { + mActivity.runOnUiThread(() -> { + if (err != null) { + Toast.makeText(mActivity, "获取热搜失败", Toast.LENGTH_LONG).show(); + } + ll_hot_rank.removeAllViews(); + if (list != null && !list.isEmpty()) { + for (QqVideoHotWord hotWord : list) { + TextView tv = new TextView(mActivity); + tv.setText(hotWord.getSearchWord()); + tv.setOnClickListener(v -> { + EditText et_video_keyword = mView.findViewById(R.id.et_video_keyword); + TextView _tv = (TextView) v; + et_video_keyword.setText(_tv.getText()); + showListView(true); + }); + ll_hot_rank.addView(tv); + } + } + }); + } + }); + } + } \ No newline at end of file diff --git a/app/src/main/java/com/github/jsbxyyx/xbook/data/VideoNetHelper.java b/app/src/main/java/com/github/jsbxyyx/xbook/data/VideoNetHelper.java index 5537ba4..65486b4 100644 --- a/app/src/main/java/com/github/jsbxyyx/xbook/data/VideoNetHelper.java +++ b/app/src/main/java/com/github/jsbxyyx/xbook/data/VideoNetHelper.java @@ -12,6 +12,8 @@ import com.github.jsbxyyx.xbook.common.JsonUtil; import com.github.jsbxyyx.xbook.common.LogUtil; import com.github.jsbxyyx.xbook.data.bean.QqVideo; +import com.github.jsbxyyx.xbook.data.bean.QqVideoHotRank; +import com.github.jsbxyyx.xbook.data.bean.QqVideoHotWord; import java.io.IOException; import java.util.ArrayList; @@ -100,4 +102,110 @@ public void onResponse(@NonNull Call call, @NonNull Response response) throws IO }); } + public void hotRank(DataCallback dataCallback) { + Map object = new HashMap<>(); + + String reqUrl = "/hotrank_vqq"; + object.put("method", "POST"); + object.put("url", reqUrl); + + Map headers = new HashMap<>(); + headers.put("User-Agent", userAgent); + object.put("headers", headers); + + Map params = new HashMap<>(); + object.put("params", params); + + String s = JsonUtil.toJson(object); + LogUtil.d(TAG, "hotrank request: %s", s); + Request request = new Request.Builder() + .url(xburl) + .post(RequestBody.create(s, MediaType.parse("application/json"))) + .build(); + client.newCall(request).enqueue(new Callback() { + @Override + public void onFailure(@NonNull Call call, @NonNull IOException e) { + LogUtil.d(TAG, "onFailure: %s", LogUtil.getStackTraceString(e)); + dataCallback.call(new ArrayList<>(), e); + } + + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { + if (!response.isSuccessful()) { + dataCallback.call(new ArrayList<>(), new HttpStatusException(response.code() + "", response.code(), reqUrl)); + return; + } + String string = response.body().string(); + LogUtil.d(TAG, "hotrank response: %s", string); + try { + JsonNode jsonObject = JsonUtil.readTree(string); + int status = jsonObject.get("status").asInt(); + if (!Common.statusSuccessful(status)) { + dataCallback.call(new ArrayList<>(), new HttpStatusException(status + "", status, reqUrl)); + return; + } + JsonNode data = jsonObject.get("data"); + List list = JsonUtil.convertValue(data.get("list"), new TypeReference>() { + }); + dataCallback.call(list, null); + } catch (Exception e) { + dataCallback.call(new ArrayList<>(), e); + } + } + }); + } + + public void hotWord(DataCallback dataCallback) { + Map object = new HashMap<>(); + + String reqUrl = "/hotwordlist_vqq"; + object.put("method", "POST"); + object.put("url", reqUrl); + + Map headers = new HashMap<>(); + headers.put("User-Agent", userAgent); + object.put("headers", headers); + + Map params = new HashMap<>(); + object.put("params", params); + + String s = JsonUtil.toJson(object); + LogUtil.d(TAG, "hotrank request: %s", s); + Request request = new Request.Builder() + .url(xburl) + .post(RequestBody.create(s, MediaType.parse("application/json"))) + .build(); + client.newCall(request).enqueue(new Callback() { + @Override + public void onFailure(@NonNull Call call, @NonNull IOException e) { + LogUtil.d(TAG, "onFailure: %s", LogUtil.getStackTraceString(e)); + dataCallback.call(new ArrayList<>(), e); + } + + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { + if (!response.isSuccessful()) { + dataCallback.call(new ArrayList<>(), new HttpStatusException(response.code() + "", response.code(), reqUrl)); + return; + } + String string = response.body().string(); + LogUtil.d(TAG, "hotrank response: %s", string); + try { + JsonNode jsonObject = JsonUtil.readTree(string); + int status = jsonObject.get("status").asInt(); + if (!Common.statusSuccessful(status)) { + dataCallback.call(new ArrayList<>(), new HttpStatusException(status + "", status, reqUrl)); + return; + } + JsonNode data = jsonObject.get("data"); + List list = JsonUtil.convertValue(data.get("list"), new TypeReference>() { + }); + dataCallback.call(list, null); + } catch (Exception e) { + dataCallback.call(new ArrayList<>(), e); + } + } + }); + } + } diff --git a/app/src/main/java/com/github/jsbxyyx/xbook/data/bean/QqVideoHotRank.java b/app/src/main/java/com/github/jsbxyyx/xbook/data/bean/QqVideoHotRank.java new file mode 100644 index 0000000..9793626 --- /dev/null +++ b/app/src/main/java/com/github/jsbxyyx/xbook/data/bean/QqVideoHotRank.java @@ -0,0 +1,86 @@ +package com.github.jsbxyyx.xbook.data.bean; + +import java.util.List; + +public class QqVideoHotRank { + + private HotRankResult hotRankResult; + private String tabName; + private String tabId; + + public HotRankResult getHotRankResult() { + return hotRankResult; + } + + public void setHotRankResult(HotRankResult hotRankResult) { + this.hotRankResult = hotRankResult; + } + + public String getTabName() { + return tabName; + } + + public void setTabName(String tabName) { + this.tabName = tabName; + } + + public String getTabId() { + return tabId; + } + + public void setTabId(String tabId) { + this.tabId = tabId; + } + + public static class HotRankResult { + private List rankItemList; + private String totalSize; + + public List getRankItemList() { + return rankItemList; + } + + public void setRankItemList(List rankItemList) { + this.rankItemList = rankItemList; + } + + public String getTotalSize() { + return totalSize; + } + + public void setTotalSize(String totalSize) { + this.totalSize = totalSize; + } + } + + public static class RankItem { + private String changeOrder; + private String dataType; + private String title; + + public String getChangeOrder() { + return changeOrder; + } + + public void setChangeOrder(String changeOrder) { + this.changeOrder = changeOrder; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + } + +} diff --git a/app/src/main/java/com/github/jsbxyyx/xbook/data/bean/QqVideoHotWord.java b/app/src/main/java/com/github/jsbxyyx/xbook/data/bean/QqVideoHotWord.java new file mode 100644 index 0000000..cf5651d --- /dev/null +++ b/app/src/main/java/com/github/jsbxyyx/xbook/data/bean/QqVideoHotWord.java @@ -0,0 +1,32 @@ +package com.github.jsbxyyx.xbook.data.bean; + +public class QqVideoHotWord { + + private String searchWord; + private String subTitle; + private String type; + + public String getSearchWord() { + return searchWord; + } + + public void setSearchWord(String searchWord) { + this.searchWord = searchWord; + } + + public String getSubTitle() { + return subTitle; + } + + public void setSubTitle(String subTitle) { + this.subTitle = subTitle; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/app/src/main/res/layout/fragment_video_list.xml b/app/src/main/res/layout/fragment_video_list.xml index 42ef1b1..78d011a 100644 --- a/app/src/main/res/layout/fragment_video_list.xml +++ b/app/src/main/res/layout/fragment_video_list.xml @@ -31,6 +31,40 @@ + + + + + +