33
This commit is contained in:
@@ -0,0 +1,292 @@
|
||||
package cn.shangyu.gdxzExpert.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.shangyu.gdxzExpert.R;
|
||||
import cn.shangyu.gdxzExpert.base.BaseActivity;
|
||||
import cn.shangyu.gdxzExpert.bean.CircleCollectBIngliBean;
|
||||
import cn.shangyu.gdxzExpert.bean.CircleCollectBIngliBean.Collection;
|
||||
import cn.shangyu.gdxzExpert.http.OnCallBackFromNet;
|
||||
import cn.shangyu.gdxzExpert.pulltorefreshview.PullToRefreshBase;
|
||||
import cn.shangyu.gdxzExpert.pulltorefreshview.PullToRefreshBase.Mode;
|
||||
import cn.shangyu.gdxzExpert.pulltorefreshview.PullToRefreshBase.OnRefreshListener2;
|
||||
import cn.shangyu.gdxzExpert.pulltorefreshview.PullToRefreshListView;
|
||||
import cn.shangyu.gdxzExpert.utils.CommonUtil;
|
||||
import cn.shangyu.gdxzExpert.utils.GsonTools;
|
||||
import cn.shangyu.gdxzExpert.utils.LogUtil;
|
||||
import cn.shangyu.gdxzExpert.utils.SharePrefUtil;
|
||||
import cn.shangyu.gdxzExpert.utils.StringUtil;
|
||||
import cn.shangyu.gdxzExpert.utils.ToastUtil;
|
||||
import cn.shangyu.gdxzExpert.utils.UIUtils;
|
||||
import cn.shangyu.gdxzExpert.utils.Url;
|
||||
import cn.shangyu.gdxzExpert.widget.LoadingPage.ResultState;
|
||||
|
||||
public class CoollectCourseActivity extends BaseActivity implements
|
||||
OnItemClickListener, OnCallBackFromNet {
|
||||
private View view;
|
||||
private PullToRefreshListView ptrLv;
|
||||
private TextView load_empty;
|
||||
private CoollectCourseActivity mActivity;
|
||||
private String expert_uuid;
|
||||
private ArrayList<Collection> DataList = new ArrayList<Collection>();
|
||||
private int page = 1;
|
||||
private CourseCoolenctAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
public void setTitle() {
|
||||
// TODO Auto-generated method stub
|
||||
top_title.setText("课件文档");
|
||||
if(CommonUtil.BigModule())
|
||||
{
|
||||
top_title.setTextSize(23);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateSuccessedView() {
|
||||
// TODO Auto-generated method stub
|
||||
ImmersionBar.with(this).keyboardEnable(true).statusBarDarkFont(true).titleBar(mToolbar).init();
|
||||
view = UIUtils.inflate(R.layout.activity_my_download);
|
||||
ptrLv = (PullToRefreshListView) view.findViewById(R.id.lv_item_down);// 下拉刷新的listview控件
|
||||
mActivity = this;
|
||||
// 处理正在加载,空,错误的布局
|
||||
load_empty = (TextView) view.findViewById(R.id.load_empty);
|
||||
ll_loading = (FrameLayout) view.findViewById(R.id.ll_loading);
|
||||
ll_load_progress = (LinearLayout) view
|
||||
.findViewById(R.id.ll_load_progress);
|
||||
tv_load_fail = (TextView) view.findViewById(R.id.tv_load_fail);
|
||||
load_empty.setText("您暂未收藏课件");
|
||||
// 设置只有下拉刷新
|
||||
ptrLv.setMode(Mode.DISABLED);
|
||||
// 得到实际的ListView 设置点击
|
||||
ptrLv.getRefreshableView().setOnItemClickListener(this);
|
||||
ptrLv.setOnRefreshListener(new OnRefreshListener2() {
|
||||
public void onPullDownToRefresh(PullToRefreshBase refreshView) {
|
||||
// TODO Auto-generated method stub
|
||||
page = 1;
|
||||
CollectListDate();
|
||||
}
|
||||
|
||||
public void onPullUpToRefresh(PullToRefreshBase refreshView) {
|
||||
// TODO Auto-generated method stub
|
||||
page = page + 1;
|
||||
CollectListDate();
|
||||
}
|
||||
});
|
||||
expert_uuid = SharePrefUtil.getString(mActivity, "uuid", "");
|
||||
CollectListDate();
|
||||
return view;
|
||||
}
|
||||
@Override
|
||||
public ResultState onLoad() {
|
||||
// TODO Auto-generated method stub
|
||||
return ResultState.STATE_SUCCESSED;
|
||||
}
|
||||
|
||||
public void CollectListDate() {
|
||||
StringBuffer Keyword = new StringBuffer();
|
||||
Map<String, String> param = new HashMap<String, String>();
|
||||
param.put("user_uuid", expert_uuid);
|
||||
param.put("type", "6");
|
||||
param.put("page", page + "");
|
||||
sendParamtoNet(Url.getcollectionList, param, 106, mActivity, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
||||
// TODO Auto-generated method stub
|
||||
Intent intent = new Intent(mActivity, CourseUrlDetailActivity.class);
|
||||
intent.putExtra("url", DataList.get(arg2-1).path);
|
||||
Log.d("gdxzfile ","url1 "+DataList.get(arg2-1).path);
|
||||
intent.putExtra("uuid", DataList.get(arg2-1).other_uuid);
|
||||
intent.putExtra("title", DataList.get(arg2-1).title);
|
||||
intent.putExtra("collect", "collect");
|
||||
this.startActivityForResult(intent, 201);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCallbackFromThread(String resultJson) {
|
||||
// TODO Auto-generated method stub
|
||||
Log.d("gdxzfile ",resultJson);
|
||||
processData(resultJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCallBackFromThread(String resultJson, int resultCode) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新最后时间 setLastUpdateTime
|
||||
*
|
||||
* void
|
||||
*/
|
||||
private void setLastUpdateTime() {
|
||||
String text = CommonUtil.getStringDate();
|
||||
ptrLv.getLoadingLayoutProxy().setLastUpdatedLabel(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新完成 onLoaded
|
||||
*
|
||||
* void
|
||||
*/
|
||||
private void onLoaded() {
|
||||
closeProgressDialog();
|
||||
dismissLoadingProgress();
|
||||
ptrLv.onRefreshComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析并处理数据
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
private void processData(String result) {
|
||||
|
||||
CircleCollectBIngliBean bean = GsonTools.fromGsonToBean(result,
|
||||
CircleCollectBIngliBean.class);
|
||||
closeProgressDialog();
|
||||
if (StringUtil.isOneToCode(bean.code)) {
|
||||
ToastUtil.showToast(bean.message);
|
||||
return;
|
||||
}
|
||||
// 判断是下拉刷新还是加载更多,true表示是下拉刷新
|
||||
if (page == 1) {
|
||||
// 初始化消息列表的数据
|
||||
DataList.clear();
|
||||
// 数据为空
|
||||
LogUtil.i("size:" + bean.data);
|
||||
|
||||
if (bean.data == null || bean.data.size() == 0) {
|
||||
load_empty.setVisibility(View.VISIBLE);
|
||||
load_empty.setText("您暂未收藏课件");
|
||||
} else {
|
||||
load_empty.setVisibility(View.GONE);
|
||||
DataList.addAll(bean.data);
|
||||
}
|
||||
} else {
|
||||
// 加载更多下一页时候e
|
||||
DataList.addAll(bean.data);
|
||||
|
||||
}
|
||||
// 实例化适配器
|
||||
if (mAdapter == null) {
|
||||
mAdapter = new CourseCoolenctAdapter();
|
||||
ptrLv.getRefreshableView().setAdapter(mAdapter);
|
||||
} else {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
// 完成刷新
|
||||
onLoaded();
|
||||
// 得到总页码数
|
||||
int totalPage = bean.totalPage;
|
||||
// 是否有更多
|
||||
if (totalPage <= 1 || totalPage < page) {
|
||||
|
||||
if (page != 1) {
|
||||
ToastUtil.showMessage("没有更多收藏了");
|
||||
}
|
||||
|
||||
ptrLv.setMode(Mode.PULL_FROM_START);
|
||||
} else {
|
||||
ptrLv.setMode(Mode.BOTH);
|
||||
}
|
||||
// 设置刷新的时间
|
||||
setLastUpdateTime();
|
||||
}
|
||||
|
||||
public class CourseCoolenctAdapter extends BaseAdapter {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
// TODO Auto-generated method stub
|
||||
return DataList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
// TODO Auto-generated method stub
|
||||
return DataList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
// TODO Auto-generated method stub
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
// TODO Auto-generated method stub
|
||||
ViewHolder vh = null;
|
||||
if (convertView == null) {
|
||||
if(CommonUtil.BigModule())
|
||||
{
|
||||
convertView = UIUtils
|
||||
.inflate(R.layout.activity_download_course_big);
|
||||
}
|
||||
else
|
||||
{
|
||||
convertView = UIUtils
|
||||
.inflate(R.layout.activity_download_course);
|
||||
}
|
||||
vh = new ViewHolder();
|
||||
vh.mTv = (TextView) convertView
|
||||
.findViewById(R.id.tv_download_course);
|
||||
convertView.setTag(vh);
|
||||
} else {
|
||||
vh = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
vh.mTv.setText(DataList.get(position).title);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public class ViewHolder {
|
||||
TextView mTv;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// TODO Auto-generated method stub
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if(data!=null){
|
||||
if(resultCode==201){
|
||||
String uuid=data.getStringExtra("uuid");
|
||||
for (int i = 0; i < DataList.size(); i++) {
|
||||
if(uuid.equals(DataList.get(i).other_uuid)){
|
||||
DataList.remove(i);
|
||||
if (DataList.size()==0){
|
||||
load_empty.setVisibility(View.VISIBLE);
|
||||
load_empty.setText("您暂未收藏课件");
|
||||
}
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user