|
|
@@ -2,18 +2,31 @@ package com.sheep.gamegroup.view.fragment;
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.Nullable;
|
|
|
+import android.support.v7.widget.GridLayoutManager;
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.support.v7.widget.StaggeredGridLayoutManager;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
+import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
+import com.chad.library.adapter.base.BaseViewHolder;
|
|
|
import com.sheep.gamegroup.model.api.ApiService;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
import com.sheep.gamegroup.model.entity.DiscoveryVideo;
|
|
|
+import com.sheep.gamegroup.util.ListUtil;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
import com.sheep.gamegroup.view.adapter.AdpVideo;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
|
|
|
import org.afinal.simplecache.ApiKey;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
import io.reactivex.Observable;
|
|
|
|
|
|
/**
|
|
|
@@ -22,18 +35,47 @@ import io.reactivex.Observable;
|
|
|
* 小绵羊3.4.5新增 -- 发现视频列表
|
|
|
*/
|
|
|
public class FgtArticleVideo extends BaseListFragment5<DiscoveryVideo> {
|
|
|
+
|
|
|
+ @BindView(R.id.tab_list)
|
|
|
+ protected RecyclerView tab_list;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getLayoutId() {
|
|
|
+ return R.layout.net_empty_xrecycler_rv;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> sortNameList = new ArrayList<>();
|
|
|
+ private int curPosition;//排序的位置
|
|
|
+ public static final String[] SORT_NAMES = {"最热", "最新"};
|
|
|
+ public static final int[] SORT_ID = {1, 2};
|
|
|
+ // @Param sort query int true "排序 1:最热 2:最新"
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
super.initView();
|
|
|
- view_list.setPadding(G.getRealPix(8), G.getRealPix(14), G.getRealPix(8), G.getRealPix(14));
|
|
|
+ Collections.addAll(sortNameList, SORT_NAMES);
|
|
|
+ tab_list.setLayoutManager(new GridLayoutManager(SheepApp.getInstance(), 2));
|
|
|
+ BaseQuickAdapter<String, BaseViewHolder> baseQuickAdapter = new BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_tab, sortNameList) {
|
|
|
+ @Override
|
|
|
+ protected void convert(BaseViewHolder helper, String item) {
|
|
|
+ int position = helper.getAdapterPosition();
|
|
|
+ TextView textView = helper.getView(R.id.item_tab_tv);
|
|
|
+ ViewUtil.setColorMapText(textView, item, item, curPosition == position ? "#2ebef2" : "#AFAFAF");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ baseQuickAdapter.bindToRecyclerView(tab_list);
|
|
|
+ baseQuickAdapter.setOnItemClickListener((adapter, view, position) -> {
|
|
|
+ curPosition = position;
|
|
|
+ baseQuickAdapter.notifyDataSetChanged();
|
|
|
+ refreshData();
|
|
|
+ });
|
|
|
+ view_list.setPadding(G.getRealPix(8), 0, G.getRealPix(8), G.getRealPix(14));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected RecyclerView.LayoutManager getLayoutManager() {
|
|
|
- StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
|
|
|
-// layoutManager.setItemPrefetchEnabled(true);
|
|
|
-// layoutManager.setMeasurementCacheEnabled(true);
|
|
|
- return layoutManager;
|
|
|
+// StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
|
|
|
+// return layoutManager;
|
|
|
+ return new GridLayoutManager(SheepApp.getInstance(), 2);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -43,12 +85,15 @@ public class FgtArticleVideo extends BaseListFragment5<DiscoveryVideo> {
|
|
|
|
|
|
@Override
|
|
|
protected String getKey(int page, int per_page) {
|
|
|
- return ApiKey.pageKeyUrl2(ApiKey.getVideoList, page, per_page);
|
|
|
+ return ApiKey.pageKeyUrl2(ApiKey.getVideoList, page, per_page) + "sort=" + getCurSort();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected Observable<BaseMessage> getApi(ApiService apiService) {
|
|
|
- return apiService.getVideoList(page, per_page);
|
|
|
+ return apiService.getVideoList(page, per_page, getCurSort());
|
|
|
+ }
|
|
|
+ private int getCurSort(){
|
|
|
+ return SORT_ID[curPosition % SORT_ID.length];
|
|
|
}
|
|
|
|
|
|
@Override
|