package com.bigdo.app;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import com.bigdo.common.BDSQLiteHelper;
import com.bigdo.common.Login;
import com.bigdo.common.RConfig;
import com.bigdo.common.RState;
import com.bigdo.common.User;
import com.bigdo.controls.IXListViewListener;
import com.bigdo.controls.XListView;
import com.bigdo.util.WSCheck;
import com.bigdo.util.WSHelper;
import com.bigdo.util.WSResult;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public abstract class SingleImgVideo extends AsyncImgDown implements
IXListViewListener {
public final int r_c = 199990;
public final int s_a_r_c = 299990;
public final int img_r_c = 399990;
public final int op_refresh = 1;
public final int op_more = 2;
public final int op_look = 3;
protected XListView video_list;
public VideoAdapter ad = null;
public ArrayList<HashMap<String, Object>> data = null;
protected TextView no_data;
protected BaseActivity a = null;
public SingleImgVideo(BaseActivity a) {
super(a);
this.a = a;
no_data = noData();
video_list = videoList();
}
protected void onCreate(Bundle savedInstanceState) {
if (video_list != null) {
video_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
arg2--;
if (arg2 < 0) {
arg2 = 0;
}
if (!onGoVideoDetail(arg2)) {
goVideoDetail(arg2);
}
}
});
video_list.setPullRefreshEnable(refresh());
video_list.setPullLoadEnable(loadMore());
video_list.setXListViewListener(this);
data = new ArrayList<HashMap<String, Object>>();
ad = new VideoAdapter(this.a);
video_list.setAdapter(ad);
}
}
public void loadData() {
if (isCache()) {
getVideo(0, 0);
}
if (data.size() <= 0) {
video_list.startAutoHeightRefresh(1);
}
}
public void goVideoDetail(int pos) {
HashMap<String, Object> mp = data.get(pos);
int idvideo = mp.get("idvideo") != null ? (Integer) mp.get("idvideo")
: -1;
int idtype = mp.get("idtype") != null ? (Integer) mp.get("idtype") : -1;
if (idvideo >= 0 && idtype >= 0) {
Intent i = new Intent();
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
i.setClass(this.a, Video_Detail_Activity.class);
i.putExtra("idvideo", idvideo);
i.putExtra("idtype", idtype);
i.putExtra("free", free());
if (isCache()) {
i.putExtra("iscache", true);
i.putExtra("table", table());
i.putExtra("where", selectWhere(op_look));
i.putExtra("fieldValue", selectVal(op_look));
} else {
i.putExtra("iscache", false);
i.putExtra("score", (Integer) mp.get("score"));
i.putExtra("title", mp.get("title") + "");
i.putExtra("idteacher", (Integer) mp.get("idteacher"));
i.putExtra("teacher", mp.get("teacher") + "");
//i.putExtra("desc", mp.get("desc") + "");
i.putExtra("paycount", (Integer) mp.get("paycount"));
i.putExtra("paytime", mp.get("paytime") + "");
i.putExtra("img", mp.get("img") + "");
i.putExtra("video", mp.get("video") + "");
i.putExtra("createtime", mp.get("createtime") + "");
i.putExtra("updatetime", mp.get("updatetime") + "");
i.putExtra("taptitudes", mp.get("taptitudes") + "");
i.putExtra("timg", mp.get("timg") + "");
}
this.a.startActivityForResult(i, s_a_r_c);
}
}
private int[] getVideoLocalInfo(int rc) {
int count = 0, _idvideo = 0, idvideo_ = 0;
BDSQLiteHelper sqlobj = null;
SQLiteDatabase sqlobj_r = null;
Cursor cu = null;
String where = selectWhere(op_look), table = table();
if (where != null && !where.equals("")) {
where = " where " + where + " ";
} else {
where = "";
}
String[] fieldValue = selectVal(op_look);
try {
sqlobj = new BDSQLiteHelper(this.a);
sqlobj_r = sqlobj.getReadableDatabase();
cu = sqlobj_r.rawQuery("select idvideo,idbatch from " + table
+ where + " order by idvideo desc", fieldValue);
count = 0;
int _idbatch = 0, idbatch = 0;
while (cu.moveToNext()) {
if (count == 0) {
_idvideo = cu.getInt(0);
idbatch = cu.getInt(1);
_idbatch = idbatch;
} else {
idbatch = cu.getInt(1);
}
if (_idbatch != idbatch) {
break;
}
idvideo_ = cu.getInt(0);
count++;
}
Log.w("getVideoLocalInfo", count + "," + _idvideo + "," + idvideo_);
} catch (Exception e) {
count = 0;
_idvideo = 0;
idvideo_ = 0;
}
try {
if (cu != null) {
cu.close();
cu = null;
}
} catch (Exception ex) {
}
try {
if (sqlobj_r != null) {
sqlobj_r.close();
sqlobj_r = null;
}
} catch (Exception ex) {
}
try {
if (sqlobj != null) {
sqlobj.close();
sqlobj = null;
}
} catch (Exception ex) {
}
return new int[] { count, _idvideo, idvideo_ };
}
private void startGetVideo(int rc) {
checkHasData(true);
int[] info = null;
if (isCache()) {
info = getVideoLocalInfo(rc);
}
User user = Login.get(this.a);
String url = service();
JSONObject jparam = param(rc);
try {
if (jparam == null) {
jparam = new JSONObject();
}
jparam.put("__c__", 0);
jparam.put("_idvideo", 0);
jparam.put("idvideo_", 0);
if (user != null) {
jparam.put("user", user.user);
}
if (info != null && info.length >= 3) {
jparam.put("__c__", info[0]);
jparam.put("_idvideo", info[1]);
jparam.put("idvideo_", info[2]);
}
if (rc == op_refresh) {
jparam.put("__op__", "refresh");
} else if (rc == op_more) {
jparam.put("__op__", "more");
}
} catch (Exception e) {
checkHasData(false);
if (rc == op_refresh) {
video_list.stopRefresh();
} else if (rc == op_more) {
video_list.stopLoadMore();
}
this.a.showInfo("准备请求参数出错.");
return;
}
String data = jparam.toString();
WSHelper ws = new WSHelper(this.a, "", false, handler, url, "",
WSHelper.getStringEntity(data), r_c, rc, 0, 0, WSHelper.POST);
ws.start();
Log.e("startGetVideo", url);
Log.e("startGetVideo_data", data);
}
public void startRefreshVideo() {
startGetVideo(op_refresh);
}
public void startLoadMoreVideo() {
startGetVideo(op_more);
}
private int getVideo(int op, int tag) {
int count = 0;
if (data != null && ad != null) {
boolean isAddPre = false;
int _idbatch = 0, s = 0, e = count();
if (op == op_refresh) {
if (tag == 2) {
e = data.size() + count();
data.clear();
} else {
isAddPre = true;
}
} else if (op == op_more) {
if (!batch(op_more)) {
s = data.size();
e = count();
}
}
BDSQLiteHelper sqlobj = null;
SQLiteDatabase sqlobj_r = null;
Cursor cu = null;
ArrayList<HashMap<String, Object>> pre_data = null;
ExtensionColumn[] column = extensionColumn();
try {
String orderBy = orderBy(op);
if (orderBy != null && !orderBy.equals("")) {
orderBy = " order by " + orderBy;
} else {
orderBy = " ";
}
sqlobj = new BDSQLiteHelper(this.a);
sqlobj_r = sqlobj.getReadableDatabase();
String[] fieldValue = selectVal(op);
String where = selectWhere(op);
if (where != null && !where.equals("")) {
where = " where " + where + " ";
} else {
where = " ";
}
String sqlt = "select * from " + table() + where + orderBy
+ " limit " + s + "," + e;
cu = sqlobj_r.rawQuery(sqlt, fieldValue);
int idvideo, idtype, idbatch = 0;
String title, teacher, desc, img;
String fp, img_name;
float score;
int paycount;
if (isAddPre) {
pre_data = new ArrayList<HashMap<String, Object>>();
}
boolean isBatch = batch(op);
if (isBatch) {
if (data.size() > 0) {
if (op == op_refresh) {
_idbatch = (Integer) data.get(0).get("idbatch");
} else if (op == op_more) {
_idbatch = (Integer) data.get(data.size() - 1).get(
"idbatch");
}
}
}
int clg = 0;
while (cu.moveToNext()) {
idbatch = cu.getInt(cu.getColumnIndex("idbatch"));
if (isBatch) {
if (_idbatch <= 0) {
_idbatch = idbatch;
}
if (_idbatch != idbatch) {
break;
}
}
idvideo = cu.getInt(cu.getColumnIndex("idvideo"));
idtype = cu.getInt(cu.getColumnIndex("idtype"));
if (idvideo >= 0 && idtype >= 0) {
HashMap<String, Object> map = new HashMap<String, Object>();
if (column != null) {
clg = column.length;
for (int j = 0; j < clg; j++) {
ExtensionColumn co = column[j];
if (co != null) {
if (co.type == ExtensionColumn.INT) {
map.put(co.column, cu.getInt(cu
.getColumnIndex(co.column)));
} else if (co.type == ExtensionColumn.STRING) {
map.put(co.column, cu.getString(cu
.getColumnIndex(co.column)));
} else if (co.type == ExtensionColumn.DOUBLE) {
map.put(co.column, cu.getDouble(cu
.getColumnIndex(co.column)));
} else if (co.type == ExtensionColumn.LONG) {
map.put(co.column, cu.getLong(cu
.getColumnIndex(co.column)));
}
}
}
}
score = cu.getFloat(cu.getColumnIndex("score"));
title = cu.getString(cu.getColumnIndex("title"));
teacher = cu.getString(cu.getColumnIndex("teacher"));
//desc = cu.getString(cu.getColumnIndex("desc"));
//if (desc != null && !desc.equals("")
// && desc.length() > 60) {
// desc = desc.substring(0, 60) + "...";
//}
paycount = cu.getInt(cu.getColumnIndex("paycount"));
img = cu.getString(cu.getColumnIndex("img"));
if (img != null && !img.equals("")) {
img_name = handleImgName(idtype + idvideo + img);
map.put("__down__name__", img_name);
final String sd = sdDir(99998888);
if (sd == null || sd.equals("")) {
map.put("__error__", "no_exist_for_service");
} else {
fp = sd + img_name + ".r";
File im = new File(fp);
if (im.exists()) {
map.put("__path__", fp);
}
}
}
map.put("idbatch", idbatch);
map.put("idvideo", idvideo);
map.put("idtype", idtype);
map.put("score", score);
map.put("title", title);
map.put("teacher", teacher);
//map.put("desc", desc);
map.put("paycount", paycount);
map.put("img", img);
if (isAddPre) {
pre_data.add(map);
} else {
data.add(map);
}
count++;
}
}
} catch (Exception e2) {
this.a.messageBox("加载本地缓存视频出错");
}
try {
if (cu != null) {
cu.close();
cu = null;
}
} catch (Exception ex) {
}
try {
if (sqlobj_r != null) {
sqlobj_r.close();
sqlobj_r = null;
}
} catch (Exception ex) {
}
try {
if (sqlobj != null) {
sqlobj.close();
sqlobj = null;
}
} catch (Exception ex) {
}
if (isAddPre && pre_data != null) {
data.addAll(0, pre_data);
}
if (ad != null) {
ad.notifyDataSetChanged();
}
checkHasData(false);
}
return count;
}
private void updateNotCache(WSResult result) {
if (video_list != null && data != null && ad != null) {
JSONObject jresult = WSCheck.Json(this.a, result);
if (jresult != null) {
BDSQLiteHelper sqlobj = null;
try {
JSONArray item = jresult.getJSONArray("item");
if (item != null) {
try {
int clear = jresult.getInt("__clear");
if (clear == 1) {
data.clear();
}
} catch (Exception ee) {
}
int lg = item.length();
if (lg > 0) {
String title = "", teacher = "", taptitudes = "", timg = "";
String desc = "", img = "", video = "", createtime = "", updatetime = "", paytime = "";
int idvideo, idtype, idptype, score, paycount, idteacher;
for (int i = 0; i < lg; i++) {
JSONObject vo = (JSONObject) item.opt(i);
if (vo != null) {
idvideo = vo.getInt("idvideo");
idtype = vo.getInt("idtype");
if (idvideo >= 0 && idtype >= 0) {
HashMap<String, Object> mp = new HashMap<String, Object>();
idptype = vo.getInt("idptype");
score = vo.getInt("score");
title = vo.getString("title");
idteacher = vo.getInt("idteacher");
teacher = vo.getString("teacher");
//desc = vo.getString("desc");
paycount = vo.getInt("paycount");
paytime = vo.getString("paytime");
img = vo.getString("img");
video = vo.getString("video");
createtime = vo.getString("createtime");
updatetime = vo.getString("updatetime");
taptitudes = vo.getString("taptitudes");
timg = vo.getString("timg");
mp.put("idbatch", 0);
mp.put("idvideo", idvideo);
mp.put("idtype", idtype);
mp.put("idptype", idptype);
mp.put("score", score);
mp.put("title", title);
mp.put("idteacher", idteacher);
mp.put("teacher", teacher);
mp.put("taptitudes", taptitudes);
mp.put("timg", timg);
//mp.put("desc", desc);
mp.put("paycount", paycount);
mp.put("paytime", paytime);
mp.put("img", img);
if (idtype >= 0 && idvideo >= 0
&& img != null
&& !img.equals("")) {
String img_name = handleImgName(idtype
+ idvideo + img);
mp.put("__down__name__", img_name);
final String sd = sdDir(99998888);
if (sd == null || sd.equals("")) {
mp.put("__error__",
"no_exist_for_service");
} else {
String fp = sd + img_name
+ ".r";
File im = new File(fp);
if (im.exists()) {
mp.put("__path__", fp);
}
}
}
mp.put("video", video);
mp.put("createtime", createtime);
mp.put("updatetime", updatetime);
data.add(mp);
}
}
}
}
}
} catch (Exception e) {
this.a.messageBox("缓存视频数据出错.");
}
} else {
if (result.RequestCode2 == op_refresh) {
this.a.showInfo("亲!没有新视频了哦.");
} else {
this.a.showInfo("亲!没有更多视频了哦.");
}
try {
jresult.remove("item");
result.Result = jresult.toString();
} catch (Exception ex) {
}
}
ad.notifyDataSetChanged();
}
}
private int update(WSResult result) {
if (video_list != null && data != null && ad != null) {
boolean addtag = false, deltag = false, uptag = false;
JSONObject jresult = WSCheck.Json(this.a, result);
if (jresult != null) {
BDSQLiteHelper sqlobj = null;
SQLiteDatabase sqlobj_w = null;
Cursor cu = null;
try {
sqlobj = new BDSQLiteHelper(this.a);
sqlobj_w = sqlobj.getWritableDatabase();
JSONArray item = jresult.getJSONArray("item");
if (item != null) {
int add_count = 0, update_count = 0;
String[] field = updateField(result.RequestCode2);
String[] fieldValue = updateVal(result.RequestCode2);
try {
String where = updateWhere(result.RequestCode2), table = table();
if (where != null && !where.equals("")) {
where = " " + where + " ";
} else {
where = "";
}
try {
int clear = jresult.getInt("__clear");
if (clear == 1) {
if (sqlobj_w.delete(table, where,
fieldValue) > 0) {
deltag = true;
data.clear();
// ad.notifyDataSetChanged();
}
}
} catch (Exception ee) {
}
int lg = item.length();
if (lg > 0) {
if (where != null && !where.equals("")) {
where = " and " + where;
} else {
where = "";
}
int cur_idbatch = 1;
int min_idbatch = 0, max_idbatch = 0;
boolean isBatch = batch(result.RequestCode2);
if (isBatch) {
int min = jresult.getInt("min");
int max = jresult.getInt("max");
String sql = "select idbatch from " + table
+ " where idvideo = ? limit 0,1";
if (min > 0) {
cu = sqlobj_w.rawQuery(sql,
new String[] { min + "" });
if (cu.moveToNext()) {
min_idbatch = cu.getInt(0);
}
try {
if (cu != null) {
cu.close();
cu = null;
}
} catch (Exception ex) {
}
}
if (max > 0) {
cu = sqlobj_w.rawQuery(sql,
new String[] { max + "" });
if (cu.moveToNext()) {
max_idbatch = cu.getInt(0);
}
try {
if (cu != null) {
cu.close();
cu = null;
}
} catch (Exception ex) {
}
}
if (min_idbatch > 0 && max_idbatch > 0) {
cur_idbatch = min_idbatch;
} else if (min_idbatch > 0) {
cur_idbatch = min_idbatch;
} else if (max_idbatch > 0) {
cur_idbatch = max_idbatch;
} else {
sql = "select idbatch from "
+ table
+ " order by idbatch desc limit 0,1";
cu = sqlobj_w.rawQuery(sql, null);
if (cu.moveToNext()) {
cur_idbatch = cu.getInt(0) + 1;
}
try {
if (cu != null) {
cu.close();
cu = null;
}
} catch (Exception ex) {
}
}
}
String title = "", teacher = "", taptitudes = "", timg = "";
String desc = "", img = "", video = "", createtime = "", updatetime = "", paytime = "";
int idvideo, idtype, idptype, score, paycount, idteacher;
long c = 0;
String[] whereValue = null;
ContentValues cv_other = new ContentValues();
if (field != null && field.length > 0
&& fieldValue != null
&& fieldValue.length > 0) {
whereValue = new String[fieldValue.length + 2];
for (int j = 0; j < field.length; j++) {
cv_other.put(field[j], fieldValue[j]);
whereValue[j + 2] = fieldValue[j];
}
}
if (whereValue == null) {
whereValue = new String[2];
}
ExtensionColumn[] column = extensionColumn();
int clg = 0;
for (int i = 0; i < lg; i++) {
JSONObject vo = (JSONObject) item.opt(i);
if (vo != null) {
idvideo = vo.getInt("idvideo");
idtype = vo.getInt("idtype");
if (idvideo >= 0 && idtype >= 0) {
ContentValues cv = new ContentValues();
if (column != null) {
clg = column.length;
for (int j = 0; j < clg; j++) {
ExtensionColumn co = column[j];
if (co != null) {
if (co.type == ExtensionColumn.INT) {
cv.put(co.column,
vo.getInt(co.column));
} else if (co.type == ExtensionColumn.STRING) {
cv.put(co.column,
vo.getString(co.column));
} else if (co.type == ExtensionColumn.DOUBLE) {
cv.put(co.column,
vo.getDouble(co.column));
} else if (co.type == ExtensionColumn.LONG) {
cv.put(co.column,
vo.getLong(co.column));
}
}
}
}
idptype = vo.getInt("idptype");
score = vo.getInt("score");
title = vo.getString("title");
idteacher = vo.getInt("idteacher");
teacher = vo.getString("teacher");
//desc = vo.getString("desc");
paycount = vo.getInt("paycount");
paytime = vo.getString("paytime");
img = vo.getString("img");
video = vo.getString("video");
createtime = vo
.getString("createtime");
updatetime = vo
.getString("updatetime");
taptitudes = vo
.getString("taptitudes");
timg = vo.getString("timg");
cv.put("idbatch", cur_idbatch);
cv.put("idptype", idptype);
cv.put("score", score);
cv.put("title", title);
cv.put("idteacher", idteacher);
cv.put("teacher", teacher);
cv.put("taptitudes", taptitudes);
cv.put("timg", timg);
//cv.put("desc", desc);
cv.put("paycount", paycount);
cv.put("paytime", paytime);
cv.put("img", img);
cv.put("video", video);
cv.put("createtime", createtime);
cv.put("updatetime", updatetime);
whereValue[0] = idvideo + "";
whereValue[1] = idtype + "";
cu = sqlobj_w
.rawQuery(
"select idvideo from "
+ table
+ " where (idvideo = ? and idtype = ?) "
+ where,
whereValue);
c = cu.getCount();
try {
if (cu != null) {
cu.close();
}
} catch (Exception ex) {
}
cu = null;
if (c <= 0) {
cv.putAll(cv_other);
cv.put("idvideo", idvideo);
cv.put("idtype", idtype);
c = sqlobj_w.insert(table, "",
cv);
add_count++;
if (c > 0) {
addtag = true;
}
} else {
c = sqlobj_w.update(table, cv,
"(idvideo = ? and idtype = ?)"
+ where,
whereValue);
update_count += c;
if (c > 0) {
uptag = true;
}
}
cv = null;
}
}
}
if (add_count > 0 && min_idbatch > 0
&& max_idbatch > 0) {
ContentValues cv = new ContentValues();
cv.put("idbatch", cur_idbatch);
c = sqlobj_w.update(table, cv,
"idbatch = ?",
new String[] { max_idbatch + "" });
if (data != null) {
int data_lg = data.size();
HashMap<String, Object> mp = null;
for (int i = 0; i < data_lg; i++) {
mp = data.get(i);
if (mp.get("idbatch") != null
&& max_idbatch == (Integer) mp
.get("idbatch"))
mp.put("idbatch", cur_idbatch);
}
ad.notifyDataSetChanged();
}
}
}
} catch (Exception e) {
this.a.messageBox("缓存视频数据出错.");
}
String msg = "";
if (add_count > 0) {
msg = "亲!新加载了 " + add_count + " 条视频";
}
if (update_count > 0) {
if (msg.length() > 0) {
msg += ",";
} else {
msg = "亲! ";
}
msg = "更新了 " + update_count + " 条视频.";
}
if (msg.length() > 0) {
this.a.showInfo(msg);
if (uptag || deltag) {
return 2;
} else if (addtag) {
return 1;
}
}
} // else {
if (result.RequestCode2 == op_refresh) {
this.a.showInfo("亲!没有新视频了哦.");
} else {
this.a.showInfo("亲!没有更多视频了哦.");
}
// }
} catch (Exception e) {
}
try {
if (cu != null) {
cu.close();
cu = null;
}
} catch (Exception ex) {
}
try {
if (sqlobj_w != null) {
sqlobj_w.close();
sqlobj_w = null;
}
} catch (Exception ex) {
}
try {
if (sqlobj != null) {
sqlobj.close();
sqlobj = null;
}
} catch (Exception ex) {
}
try {
jresult.remove("item");
result.Result = jresult.toString();
} catch (Exception ex) {
}
}
if (uptag || deltag) {
return 2;
} else if (addtag) {
return 1;
}
}
return 0;
}
public class VideoAdapter extends BaseAdapter {
private LayoutInflater mInflater;
boolean freePay = false, isCache;
public VideoAdapter(Context context) {
this.mInflater = LayoutInflater.from(context);
freePay = free();
isCache = isCache();
}
@Override
public int getCount() {
if (data != null) {
return data.size();
}
return 0;
}
@Override
public Object getItem(int arg0) {
if (data != null) {
return data.get(arg0);
}
return null;
}
@Override
public long getItemId(int arg0) {
return arg0;
}
String img_path, img, title, idbatch, teacher, desc, error, score,
__down__name__;
boolean isHasImg;
int idvideo, idtype;
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
Holder holder = null;
if (arg1 == null) {
holder = new Holder();
arg1 = mInflater.inflate(R.layout.main_home_top10_item, null);
holder.vline = (View) arg1
.findViewById(R.id.main_home_top10_item_vline);
holder.img = (ImageView) arg1
.findViewById(R.id.main_home_top10_item_img);
holder.title = (TextView) arg1
.findViewById(R.id.main_home_top10_item_title);
holder.teacher = (TextView) arg1
.findViewById(R.id.main_home_top10_item_teacher);
holder.score = (TextView) arg1
.findViewById(R.id.main_home_top10_item_score);
//holder.desc = (TextView) arg1
// .findViewById(R.id.main_home_top10_item_desc);
arg1.setTag(holder);
} else {
holder = (Holder) arg1.getTag();
}
if (arg0 == 0 || arg0 == data.size()) {
holder.vline.setVisibility(View.GONE);
} else {
holder.vline.setVisibility(View.VISIBLE);
}
Map<String, Object> mp = data.get(arg0);
idvideo = mp.get("idvideo") != null ? (Integer) mp.get("idvideo")
: 0;
idtype = mp.get("idtype") != null ? (Integer) mp.get("idtype") : 0;
img = mp.get("img") != null ? (mp.get("img") + "") : "";
title = mp.get("title") != null ? (mp.get("title") + "") : "";
teacher = mp.get("teacher") != null ? (mp.get("teacher") + "") : "";
//idbatch = mp.get("idbatch") != null ? (mp.get("idbatch") + "") : "";
//teacher += "{" + idbatch + "}";
score = mp.get("score") != null ? (mp.get("score") + "") : "";
//desc = mp.get("desc") != null ? (mp.get("desc") + "") : "";
//if (!isCache && desc != null && !desc.equals("")
// && desc.length() > 60) {
// desc = desc.substring(0, 60) + "...";
//}
holder.title.setText(title);
if (freePay) {
holder.score.setVisibility(TextView.GONE);
} else {
holder.score.setText(score + " 积分 ");
}
holder.teacher.setText(teacher);
//holder.desc.setText(desc);
__down__name__ = mp.get("__down__name__") != null ? (mp
.get("__down__name__") + "") : "";
if (!__down__name__.equals("")) {
img_path = mp.get("__path__") != null ? (mp.get("__path__") + "")
: "";
error = mp.get("__error__") != null ? (mp.get("__error__") + "")
: "";
isHasImg = loadImg(holder.img, img_path, error, 99998888);
if (!isHasImg) {
AsyncImgDownInfo img_info = new AsyncImgDownInfo();
img_info.cacheName = __down__name__;
img_info.downName = img;
img_info.pos = arg0;
img_info.requestCode = 99998888;
error = startGetImg(img_info);
mp.put("__error__", error);
}
} else {
isHasImg = loadImg(holder.img, "", "", 99998888);
}
return arg1;
}
}
@Override
protected int imgFailure(int requestCode) {
return R.drawable.video_img_failure;
}
@Override
protected int imgLoading(int requestCode) {
return R.drawable.video_img_loading;
}
@Override
protected String imgDir(int requestCode) {
return RConfig.Img_Dir;
}
@Override
protected void finishGetImg(String path, AsyncImgDownInfo info) {
if (info != null && data != null && data.size() > info.pos
&& ad != null) {
Map<String, Object> mp = data.get(info.pos);
if (path == null || path.equals("")) {
mp.put("__error__", "no_exist_for_service");
ad.notifyDataSetChanged();
return;
}
mp.put("__error__", "");
mp.put("__path__", path);
ad.notifyDataSetChanged();
}
}
private class Holder {
ImageView img;
TextView title, teacher, desc, score;
View vline;
}
public void checkHasData(boolean isoping) {
if (no_data != null) {
if (!isoping && data.size() <= 0) {
no_data.setVisibility(LinearLayout.VISIBLE);
} else {
no_data.setVisibility(LinearLayout.GONE);
}
}
}
@Override
public void onRefresh(XListView xListView, int tag, int requestCode) {
// startGetVideo();
if (batch(op_refresh)) {
int count = getVideo(op_refresh, 0);
if (count > 0) {
this.a.showInfo("亲!新加载了 " + count + " 条视频");
xListView.stopRefresh();
return;
}
}
startRefreshVideo();
}
@Override
public void onLoadMore(XListView xListView, int tag, int requestCode) {
int count = getVideo(op_more, 0);
if (count > 0) {
this.a.showInfo("亲!加载了 " + count + " 条视频");
xListView.stopLoadMore();
return;
}
startLoadMoreVideo();
}
protected abstract ExtensionColumn[] extensionColumn();
protected abstract boolean onGoVideoDetail(int pos);
protected abstract XListView videoList();
protected abstract TextView noData();
protected abstract boolean isCache();
protected abstract boolean batch(int op);
protected abstract int count();
protected abstract boolean refresh();
protected abstract boolean loadMore();
protected abstract String updateWhere(int op);
protected abstract String selectWhere(int op);
protected abstract String[] updateField(int op);
protected abstract String[] updateVal(int op);
protected abstract String[] selectField(int op);
protected abstract String[] selectVal(int op);
protected abstract String orderBy(int op);
protected abstract String table();
protected abstract String service();
protected abstract JSONObject param(int op);
protected abstract boolean free();
protected abstract void wsCall(WSResult result);
@SuppressLint("HandlerLeak")
protected Handler handler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.arg1 == RState.WSCall) {
WSResult result = (WSResult) msg.getData().getParcelable(
WSResult.ResultKey);
if (result.RequestCode == r_c) {
if (video_list != null) {
try {
if (isCache()) {
int tag = update(result);
wsCall(result);
if (tag != 0) {
getVideo(result.RequestCode2, tag);
}
} else {
updateNotCache(result);
wsCall(result);
}
} catch (Exception e) {
}
if (result.RequestCode2 == op_refresh) {
if (refresh()) {
video_list.stopRefresh();
} else {
a.hiddenProgress();
}
} else if (result.RequestCode2 == op_more) {
if (loadMore()) {
video_list.stopLoadMore();
} else {
a.hiddenProgress();
}
}
checkHasData(false);
}
}
}
}
};
}