发布网友 发布时间:2022-04-24 14:30
共1个回答
热心网友 时间:2022-04-20 11:24
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.google.gson.reflect.TypeToken;
import com.lingnet.app.tv.R;
import com.lingnet.app.tv.adapter.LeftTypeListAdapter;
import com.lingnet.app.tv.adapter.ResourceVideoAdapter;
import com.lingnet.app.tv.bean.BaseBean;
import com.lingnet.app.tv.constant.Const;
import com.lingnet.app.tv.constant.RequestType;
import com.lingnet.app.tv.utill.ExitSystemTask;
import com.lingnet.app.tv.view.GridSpacingItemDecoration;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;
public class ResourceDemandActivity extends BaseAutoActivity {
// @BindView(R.id.refresh_layout)
// SwipeRefreshLayout mRefreshLayout;
// @BindView(R.id.recyclerview)
// SwipeMenuRecyclerView recyclerView;
ResourceVideoAdapter videoAdapter;
@BindView(R.id.recyclerview)
RecyclerView recyclerView;
// @BindView(R.id.id_flowlayout)
// TagFlowLayout mFlowLayout;
String id;
int currentPage = 0;
// private LayoutInflater mInflater;
private String typeId = "全部";
@BindView(R.id.left_recyclerview)
RecyclerView leftrecyclerView;
LeftTypeListAdapter mLeftTypeListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resource_demand);
ButterKnife.bind(this);
// mInflater = LayoutInflater.from(this);
ExitSystemTask.getInstance().putActivity("ResourceDemandActivity", this);
// mRefreshLayout.setOnRefreshListener(mRefreshListener); // 刷新监听。
initRecyclerView();
sendTypeRequest();
}
private void sendTypeRequest() {
Call<BaseBean> call = client.resourseCategory();
sendRequestAsContr(call, RequestType.resourseCategory, false);
}
private void sendRequest() {
Map<String, String> params = new HashMap<>();
params.put("pageSize", "" + Const.PAGESIZE);
params.put("pageIndex", "" + currentPage);
params.put("categoryId", typeId);
//categoryId
Call<BaseBean> call = client.resourceDemand(params);
sendRequest(call, RequestType.resourceDemand);
}
// @OnClick({R.id.btn_left, R.id.btn_right_1})
// void onClick(View v) {
// switch (v.getId()) {
// case R.id.btn_left:
// super.onBackPressed();
// break;
// }
// }
/**
* 刷新。
*/
private SwipeRefreshLayout.OnRefreshListener mRefreshListener = new SwipeRefreshLayout
.OnRefreshListener() {
@Override
public void onRefresh() {
videoAdapter.notifyDataSetChanged(null);//先清空数据
currentPage = 0;
sendRequest();
// mRefreshLayout.setRefreshing(false);
}
};
/**
* 加载更多。
*/
private SwipeMenuRecyclerView.LoadMoreListener mLoadMoreListener = new SwipeMenuRecyclerView
.LoadMoreListener() {
@Override
public void onLoadMore() {
currentPage++;
sendRequest();
}
};
@Override
public void configActionBar() {
}
private void initRecyclerView() {
final GridLayoutManager mGridLayoutManager = new GridLayoutManager(mActivity, 2);
recyclerView.setLayoutManager(mGridLayoutManager);
recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setItemAnimator(null);
recyclerView.addItemDecoration(new GridSpacingItemDecoration(2, 10, false));
// recyclerView.setSwipeItemClickListener(new SwipeItemClickListener() {
// @Override
// public void onItemClick(View itemView, int position) {
//// startNextActivity(null, BookDeatilActivity.class);
// Map<String,String> book= videoAdapter.dataList.get(position);
// Bundle bundle=new Bundle();
// bundle.putString("id",book.get("id"));
// startNextActivity(bundle, ResourceDetailActivity.class);
// }
// });
// recyclerView.useDefaultLoadMore();
// recyclerView.setLoadMoreListener(mLoadMoreListener);
videoAdapter = new ResourceVideoAdapter(mActivity);
videoAdapter.setHasStableIds(true);
videoAdapter.setmOnBindListener(new ResourceVideoAdapter.OnBindListener() {
@Override
public void onBind(int i) {
Map<String, String> book = videoAdapter.dataList.get(i);
Bundle bundle = new Bundle();
bundle.putString("id", book.get("id"));
// startNextActivity(bundle, ResourceDetailActivity.class);
startNextActivity(bundle, DetailResourceActivity.class);
}
});
recyclerView.setAdapter(videoAdapter);
leftrecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
leftrecyclerView.setHasFixedSize(true);
leftrecyclerView.setNestedScrollingEnabled(false);
mLeftTypeListAdapter = new LeftTypeListAdapter(mActivity);
leftrecyclerView.setAdapter(mLeftTypeListAdapter);
mLeftTypeListAdapter.setmIOnLeftClicListener(new LeftTypeListAdapter.IOnLeftClicListener() {
@Override
public void onLeftClick(int pos) {
mLeftTypeListAdapter.setSelectPos(pos);
mLeftTypeListAdapter.notifyDataSetChanged();
typeId = mLeftTypeListAdapter.dataList.get(pos).get("name");
videoAdapter.notifyDataSetChanged(null);//先清空数据
currentPage = 0;
sendRequest();
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
int lastVisiblePosition = mGridLayoutManager.findLastVisibleItemPosition();
if (lastVisiblePosition >= mGridLayoutManager.getItemCount() - 1) {
currentPage++;
sendRequest();
// System.out.println("====自动加载");
}
}
}
});
}
@Override
public void requestCallBack(String jsonData, RequestType type) {
switch (type) {
case resourceDemand:
List<Map<String, String>> dataList = mGson.fromJson(jsonData, new
TypeToken<List<Map<String, String>>>() {
}.getType());
videoAdapter.notifyDataSetChanged(dataList);
// recyclerView.loadMoreFinish((dataList == null || dataList.size() == 0), true);
break;
case resourseCategory:
Map<String, String[]> data = mGson.fromJson(jsonData, new TypeToken<Map<String, String[]>>() {
}.getType());
// addTopType1(data.get("name"));
List<Map<String, String>> dataLists = new ArrayList<>();
if (data.get("name") != null && data.get("name").length > 0) {
for (int i = 0; i < data.get("name").length; i++) {
Map<String, String> kk = new HashMap<>();
kk.put("name", data.get("name")[i]);
dataLists.add(kk);
}
mLeftTypeListAdapter.setSelectPos(0);
mLeftTypeListAdapter.notifyDataSetChanged(dataLists);
this.typeId = data.get("name")[0];
}
sendRequest();
// mLeftTypeListAdapter.setSelectPos(0);
// mLeftTypeListAdapter.notifyDataSetChanged(da);
break;
}
}
// private void addTopType1(final String[] mVals) {
// final TagAdapter<String> mAdapter;
// mFlowLayout.setAdapter(mAdapter = new TagAdapter<String>(mVals) {
//
// @Override
// public View getView(FlowLayout parent, int position, String s) {
// TextView tv = (TextView) mInflater.inflate(
// R.layout.layout_label_tv, mFlowLayout, false);
// tv.setText(s);
// return tv;
// }
// });
// mAdapter.setSelectedList(0);
// mFlowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
// @Override
// public boolean onTagClick(View view, int position, FlowLayout
// parent) {
//// Toast.makeText(FeiyiListActivity.this, mVals[position], Toast.LENGTH_SHORT).show();
// typeId=mVals[position];
// currentPage = 0;
// videoAdapter.notifyDataSetChanged(null);//先清空数据
// sendRequest();
// return true;
// }
// });
//
//
// mFlowLayout.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
// @Override
// public void onSelected(Set<Integer> selectPosSet) {
// }
// });
// }
@Override
public void requestFailed(String error, RequestType type) {
}
}