Skip to content

Commit

Permalink
add qq video hot rank
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbxyyx committed Jul 9, 2024
1 parent ae4ea11 commit 3dd1e10
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -109,4 +122,31 @@ public void call(List<QqVideo> list, Throwable err) {
});
}

private void hotSearch() {
videoNetHelper.hotWord(new DataCallback<List<QqVideoHotWord>>() {
@Override
public void call(List<QqVideoHotWord> 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);
}
}
});
}
});
}

}
108 changes: 108 additions & 0 deletions app/src/main/java/com/github/jsbxyyx/xbook/data/VideoNetHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,4 +102,110 @@ public void onResponse(@NonNull Call call, @NonNull Response response) throws IO
});
}

public void hotRank(DataCallback dataCallback) {
Map<String, Object> object = new HashMap<>();

String reqUrl = "/hotrank_vqq";
object.put("method", "POST");
object.put("url", reqUrl);

Map<String, Object> headers = new HashMap<>();
headers.put("User-Agent", userAgent);
object.put("headers", headers);

Map<String, Object> 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<QqVideoHotRank> list = JsonUtil.convertValue(data.get("list"), new TypeReference<List<QqVideoHotRank>>() {
});
dataCallback.call(list, null);
} catch (Exception e) {
dataCallback.call(new ArrayList<>(), e);
}
}
});
}

public void hotWord(DataCallback dataCallback) {
Map<String, Object> object = new HashMap<>();

String reqUrl = "/hotwordlist_vqq";
object.put("method", "POST");
object.put("url", reqUrl);

Map<String, Object> headers = new HashMap<>();
headers.put("User-Agent", userAgent);
object.put("headers", headers);

Map<String, Object> 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<QqVideoHotWord> list = JsonUtil.convertValue(data.get("list"), new TypeReference<List<QqVideoHotWord>>() {
});
dataCallback.call(list, null);
} catch (Exception e) {
dataCallback.call(new ArrayList<>(), e);
}
}
});
}

}
Original file line number Diff line number Diff line change
@@ -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<RankItem> rankItemList;
private String totalSize;

public List<RankItem> getRankItemList() {
return rankItemList;
}

public void setRankItemList(List<RankItem> 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;
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
34 changes: 34 additions & 0 deletions app/src/main/res/layout/fragment_video_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@

</LinearLayout>

<LinearLayout
android:layout_margin="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="热搜" />
<Button
android:id="@+id/btn_hot_search"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="@android:drawable/ic_menu_search" />

</LinearLayout>


<com.github.jsbxyyx.xbook.AutoLinearLayout
android:id="@+id/ll_hot_rank"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>



<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 3dd1e10

Please sign in to comment.