package com.bigdo.app; 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.common.VideoDownHelper; 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.DialogInterface; 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.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.animation.LinearInterpolator; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.ScrollView; import android.widget.TextView; public class Video_Detail_Activity extends BaseActivity { int idvideo, idtype, idteacher = -1, idcollect = -1, paycount, score; String title = "", teacher = "", taptitudes = "", timg = "",// , desc = "", video = "", img = "", paytime = "", table, where; String[] field, fieldValue; boolean isLoadData = false, free = false, iscache = true, faving = false, paying = false, isync = false; RelativeLayout video_list_host; VdieoBll vbll; ImageView video_img, teacher_img; AsyncImgDown imgDown; LinearLayout title_fav_host; TextView title_fav; View com_title; Animation operatingAnim = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.video_detail_activity); com_title = findViewById(R.id.com_title_host); operatingAnim = AnimationUtils.loadAnimation(this, R.anim.ra_rotate); LinearInterpolator lin = new LinearInterpolator(); operatingAnim.setInterpolator(lin); initInfo(); vbll = new VdieoBll(this); vbll.onCreate(savedInstanceState); final TextView down = (TextView) findViewById(R.id.vdieo_info_down); int dr = VideoDownHelper.isExist(idtype, idvideo, video, true); if (dr == 0) { down.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { int dr = VideoDownHelper.down(Video_Detail_Activity.this, idtype, idvideo, title, video); if (dr == 1) { down.setText("缓存中"); down.setOnClickListener(null); } else if (dr == 2) { down.setText("已缓存"); down.setOnClickListener(null); } } }); } else { if (dr == 1) { down.setText("缓存中"); } else if (dr == 2) { down.setText("已缓存"); } } RelativeLayout teacher_host = (RelativeLayout) findViewById(R.id.vdieo_teacher_host); teacher_host.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { goTeacherSingle(); } }); video_img = (ImageView) findViewById(R.id.video_img); teacher_img = (ImageView) findViewById(R.id.vdieo_teacher_img); imgDown = new ImgDown(this); LoadVideoImg(); LoadTeacherImg(); Button share = (Button) com_title .findViewById(R.id.sub_com_title_share); share.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { doShare(); } }); } private void doShare() { String app = getString(R.string.app_name); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, "分享"); intent.putExtra(Intent.EXTRA_TEXT, "我正在" + app + "看 \"" + title + "\" ,感觉很精彩,快来看吧. " + RConfig.getBaseUrl(this)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // | Intent.FLAG_ACTIVITY_SINGLE_TOP startActivityForResult(Intent.createChooser(intent, app + "分享"), 99887766); } private void LoadVideoImg() { if (idvideo >= 0 && idtype >= 0 && img != null && !img.equals("")) { String img_name = imgDown.handleImgName(idtype + idvideo + img); String sd = imgDown.sdDir(0); String img_path = sd + img_name + ".r"; String error = ""; boolean isHasImg = imgDown.loadImg(video_img, img_path, error, 0); if (!isHasImg) { AsyncImgDownInfo img_info = new AsyncImgDownInfo(); img_info.cacheName = img_name; img_info.downName = img; img_info.pos = 0; img_info.param = "l"; img_info.requestCode = 0; img_info._img = video_img; error = imgDown.startGetImg(img_info); } return; } imgDown.loadImg(video_img, "", "", 0); } private void LoadTeacherImg() { if (idteacher >= 0 && timg != null && !timg.equals("")) { String img_name = imgDown.handleImgName(idteacher + timg); String sd = imgDown.sdDir(1); String img_path = sd + img_name + ".r"; String error = ""; boolean isHasImg = imgDown.loadImg(teacher_img, img_path, error, 1); if (!isHasImg) { AsyncImgDownInfo img_info = new AsyncImgDownInfo(); img_info.cacheName = img_name; img_info.downName = timg; img_info.pos = 1; img_info.param = ""; img_info.requestCode = 1; img_info._img = teacher_img; error = imgDown.startGetImg(img_info); } return; } imgDown.loadImg(teacher_img, "", "", 1); } private void goTeacherSingle() { if (idteacher >= 0) { Intent i = new Intent(); i.putExtra("idteacher", idteacher); i.putExtra("teacher", teacher); i.putExtra("taptitudes", taptitudes); i.putExtra("img", timg); i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); i.setClass(this, TeacherSingleActivity.class); startActivityForResult(i, 1); } else { showInfo("没有发现该老师哦."); } } public class VdieoBll extends SingleImgVideo { public VdieoBll(BaseActivity v) { super(v); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RelativeLayout tag_1 = (RelativeLayout) findViewById(R.id.vdieo_tag_1); RelativeLayout tag_2 = (RelativeLayout) findViewById(R.id.vdieo_tag_2); final ScrollView detail = (ScrollView) findViewById(R.id.vdieo_detail_host); video_list_host = (RelativeLayout) findViewById(R.id.video_list_host); final FrameLayout detail_host = (FrameLayout) findViewById(R.id.detail_info_host); RelativeLayout v = (RelativeLayout) findViewById(R.id.vdieo_v); final View vline1 = findViewById(R.id.vdieo_tag_1_vline); final View vline2 = findViewById(R.id.vdieo_tag_2_vline); detail.setVisibility(ScrollView.VISIBLE); video_list_host.setVisibility(ListView.GONE); vline1.setBackgroundColor(0xffC0C280); vline2.setBackgroundColor(0x77cbcbcb); tag_1.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { vline1.setBackgroundColor(0xffC0C280); vline2.setBackgroundColor(0x77cbcbcb); video_list.setVisibility(XListView.GONE); video_list_host.setVisibility(RelativeLayout.GONE); video_list_host.invalidate(); detail.setVisibility(ScrollView.VISIBLE); detail.invalidate(); detail_host.invalidate(); } }); tag_2.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { vline1.setBackgroundColor(0x77cbcbcb); vline2.setBackgroundColor(0xffC0C280); detail.setVisibility(ScrollView.GONE); detail.invalidate(); video_list.setVisibility(XListView.VISIBLE); video_list_host.setVisibility(RelativeLayout.VISIBLE); video_list_host.invalidate(); detail_host.invalidate(); if (!isLoadData && data != null && data.size() <= 0) { isLoadData = true; loadData(); } } }); v.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { payVideo(); } }); } @Override protected String orderBy(int op) { // TODO Auto-generated method stub return "idvideo desc"; } @Override protected String table() { // TODO Auto-generated method stub return "relate"; } @Override protected String service() { // TODO Auto-generated method stub return RConfig.getRelatedVideo(Video_Detail_Activity.this); } @Override protected boolean free() { // TODO Auto-generated method stub return false; } @Override protected JSONObject param(int op) { // TODO Auto-generated method stub JSONObject jresult = new JSONObject(); try { // jresult.put("idrelate", idvideo); jresult.put("idrtype", idtype); } catch (Exception e) { } return jresult; } @Override protected void wsCall(WSResult result) { // TODO Auto-generated method stub } @Override protected int count() { // TODO Auto-generated method stub return 20; } @Override protected boolean loadMore() { // TODO Auto-generated method stub return true; } @Override protected String updateWhere(int op) { // TODO Auto-generated method stub return " idrelate = ? "; } @Override protected String selectWhere(int op) { // TODO Auto-generated method stub return " idrelate = ? "; } @Override protected String[] updateField(int op) { // TODO Auto-generated method stub return new String[] { "idrelate" }; } @Override protected String[] updateVal(int op) { // TODO Auto-generated method stub return new String[] { idvideo + "" }; } @Override protected String[] selectField(int op) { // TODO Auto-generated method stub return new String[] { "idrelate" }; } @Override protected String[] selectVal(int op) { // TODO Auto-generated method stub return new String[] { idvideo + "" }; } @Override protected boolean batch(int op) { // TODO Auto-generated method stub return false; } @Override protected XListView videoList() { // TODO Auto-generated method stub return (XListView) findViewById(R.id.video_list); } @Override protected TextView noData() { // TODO Auto-generated method stub return (TextView) findViewById(R.id.video_list_no_data); } @Override protected boolean isCache() { // TODO Auto-generated method stub return true; } @Override protected boolean refresh() { // TODO Auto-generated method stub return true; } @Override protected boolean onGoVideoDetail(int pos) { // TODO Auto-generated method stub return false; } @Override protected ExtensionColumn[] extensionColumn() { // TODO Auto-generated method stub return null; } } private void initInfo() { iscache = getIntent().getBooleanExtra("iscache", true); idvideo = getIntent().getIntExtra("idvideo", 0); idtype = getIntent().getIntExtra("idtype", 0); if (iscache) { free = getIntent().getBooleanExtra("free", false); table = getIntent().getStringExtra("table"); where = getIntent().getStringExtra("where"); field = getIntent().getStringArrayExtra("field"); fieldValue = getIntent().getStringArrayExtra("fieldValue"); getVideo(); } else { title = getIntent().getStringExtra("title"); idteacher = getIntent().getIntExtra("idteacher", -1); teacher = getIntent().getStringExtra("teacher"); taptitudes = getIntent().getStringExtra("taptitudes"); timg = getIntent().getStringExtra("timg"); // desc = getIntent().getStringExtra("desc"); video = getIntent().getStringExtra("video"); paytime = getIntent().getStringExtra("paytime"); if (!free) { score = getIntent().getIntExtra("score", 0); } paycount = getIntent().getIntExtra("paycount", 0); img = getIntent().getStringExtra("img"); } setControlsInfo(); checkCollect(); } private void setControlsInfo() { Button back = (Button) com_title.findViewById(R.id.sub_com_title_back); back.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { finish(); } }); TextView title_msg = (TextView) com_title .findViewById(R.id.sub_com_title_context); title_msg.setText(title); // TextView detail_desc = (TextView) // findViewById(R.id.video_detail_desc); // detail_desc.setText(desc); TextView paytime_obj = (TextView) findViewById(R.id.vdieo_info_paytime); paytime_obj.setText("时长:" + paytime); TextView score_obj = (TextView) findViewById(R.id.vdieo_info_score); score_obj.setText("积分:" + score + "分"); TextView teacher_name = (TextView) findViewById(R.id.vdieo_teacher_name); teacher_name.setText(teacher); TextView vdieo_teacher_aptitude = (TextView) findViewById(R.id.vdieo_teacher_aptitude); vdieo_teacher_aptitude.setText(taptitudes); } private void checkCollect() { isCollect(); if (title_fav_host == null || title_fav == null) { title_fav_host = (LinearLayout) com_title .findViewById(R.id.sub_com_title_fav_host); title_fav = (TextView) com_title .findViewById(R.id.sub_com_title_fav); } User user = Login.get(this); if (user != null) { title_fav_host.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { addCollect(); } }); if (idcollect >= 0) { title_fav.setCompoundDrawablesWithIntrinsicBounds( R.drawable.head_fav, 0, 0, 0); } else { title_fav.setCompoundDrawablesWithIntrinsicBounds( R.drawable.head_no_fav, 0, 0, 0); startGetCollectSingle(); } } else { title_fav_host.setVisibility(LinearLayout.GONE); } } private void startGetCollectSingle() { if (!faving) { User user = Login.get(this); if (user != null) { if (idvideo >= 0 && idtype >= 0) { JSONObject jparam = new JSONObject(); try { jparam.put("idvideo", idvideo); jparam.put("idtype", idtype); jparam.put("user", user.user); } catch (Exception e) { faving = false; return; } title_fav.clearAnimation(); title_fav.setAnimation(operatingAnim); faving = true; String data = jparam.toString(); String url = RConfig.collectSingle(this); WSHelper ws = new WSHelper(this, "", false, handler, url, "", WSHelper.getStringEntity(data), 1, 0, 0, 0, WSHelper.POST); ws.start(); Log.e("startGetCollectSingle", url); Log.e("startGetCollectSingle_data", data); } else { faving = false; title_fav.clearAnimation(); } } } } private void addCollect() { if (!isync) { messageBox("收藏还没同步成功!您还继续吗?", "继续", "取消", new android.content.DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { doAddCollect(); } }, null); } else { doAddCollect(); } } private void doAddCollect() { if (!faving) { User user = Login.get(this); if (user != null) { if (idvideo >= 0 && idtype >= 0 && title != null && !title.equals("")) { JSONObject jparam = new JSONObject(); try { jparam.put("idvideo", idcollect); jparam.put("idvideo", idvideo); jparam.put("idtype", idtype); jparam.put("video", title); jparam.put("user", user.user); } catch (Exception e) { faving = false; showInfo("准备请求参数出错."); return; } if (idcollect >= 0) { showProgress("取消收藏中..."); } else { showProgress("收藏中..."); } faving = true; String data = jparam.toString(); String url = RConfig.addCollect(this); WSHelper ws = new WSHelper(this, "", false, handler, url, "", WSHelper.getStringEntity(data), 0, 0, 0, 0, WSHelper.POST); ws.start(); Log.e("addCollect", url); Log.e("addCollect_data", data); } else { faving = false; showInfo("视频信息有误"); } } else { showInfo("请先登录"); } } else { showInfo("已经开始了哦"); } } private void payVideo() { User user = Login.get(this); if (user != null) { if (!free) { if (!paying) { if (idvideo >= 0 && idtype >= 0) { JSONObject jparam = new JSONObject(); try { jparam.put("idvideo", idvideo); jparam.put("user", user.user); } catch (Exception e) { paying = false; showInfo("准备请求参数出错."); return; } showProgress("获取视频信息中..."); paying = true; String data = jparam.toString(); String url = RConfig.payVideo(this); WSHelper ws = new WSHelper(this, "", false, handler, url, "", WSHelper.getStringEntity(data), 6688, 0, 0, 0, WSHelper.POST); ws.start(); Log.e("payVideo", url); Log.e("payVideo_data", data); } else { paying = false; showInfo("获取视频信息有误"); } } else { showInfo("获取视频信息中"); } } else { doPayVideo(); } } else { showInfo("请先登录"); } } private void doPayVideo() { Intent i = new Intent(); i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); i.setClass(this, Video_Pay_Activity.class); i.putExtra("idtype", idtype); i.putExtra("idvideo", idvideo); i.putExtra("title", title); i.putExtra("video", video); this.startActivityForResult(i, 1); } private void getVideo() { BDSQLiteHelper sqlobj = null; SQLiteDatabase sqlobj_r = null; Cursor cu = null; try { sqlobj = new BDSQLiteHelper(this); sqlobj_r = sqlobj.getReadableDatabase(); String wr = where; if (wr != null && !wr.equals("")) { wr = " and " + wr + " "; } else { wr = " "; } String[] w = null; if (fieldValue != null) { w = new String[fieldValue.length + 2]; for (int i = 0; i < fieldValue.length; i++) { w[i + 2] = fieldValue[i]; } } else { w = new String[2]; } w[0] = idvideo + ""; w[1] = idtype + ""; String sqlt = "select * from " + table + " where (idvideo = ? and idtype = ?) " + wr + " limit 0,1"; cu = sqlobj_r.rawQuery(sqlt, w); while (cu.moveToNext()) { title = cu.getString(cu.getColumnIndex("title")); idteacher = cu.getInt(cu.getColumnIndex("idteacher")); teacher = cu.getString(cu.getColumnIndex("teacher")); taptitudes = cu.getString(cu.getColumnIndex("taptitudes")); timg = cu.getString(cu.getColumnIndex("timg")); // desc = cu.getString(cu.getColumnIndex("desc")); video = cu.getString(cu.getColumnIndex("video")); paytime = cu.getString(cu.getColumnIndex("paytime")); if (!free) { score = cu.getInt(cu.getColumnIndex("score")); } paycount = cu.getInt(cu.getColumnIndex("paycount")); img = cu.getString(cu.getColumnIndex("img")); } } catch (Exception e2) { this.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) { } } private void updateVideo(JSONObject json) { try { if (json != null) { JSONObject vo = json.getJSONObject("video"); int 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"); String createtime = vo.getString("createtime"); String updatetime = vo.getString("updatetime"); taptitudes = vo.getString("taptitudes"); timg = vo.getString("timg"); if (iscache) { BDSQLiteHelper sqlobj = null; SQLiteDatabase sqlobj_w = null; try { sqlobj = new BDSQLiteHelper(this); sqlobj_w = sqlobj.getWritableDatabase(); String wr = where; if (wr != null && !wr.equals("")) { wr = " and " + wr + " "; } else { wr = " "; } String[] w = null; if (fieldValue != null) { w = new String[fieldValue.length + 2]; for (int i = 0; i < fieldValue.length; i++) { w[i + 2] = fieldValue[i]; } } else { w = new String[2]; } w[0] = idvideo + ""; w[1] = idtype + ""; ContentValues cv = new ContentValues(); cv.put("idvideo", idvideo); cv.put("idtype", idtype); 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); sqlobj_w.update(table, cv, "(idvideo = ? and idtype = ?) " + wr, w); } catch (Exception e2) { } 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) { } } } } catch (Exception e) { } } private class ImgDown extends AsyncImgDown { public ImgDown(BaseActivity v) { super(v); } @Override protected void finishGetImg(String path, AsyncImgDownInfo info) { imgDown.loadImg(info._img, path, "", info.requestCode); } @Override protected String imgDir(int requestCode) { if (requestCode == 0) { return RConfig.Big_Img_Dir; } else { return RConfig.Teacher_Img_Dir; } } @Override protected int imgFailure(int requestCode) { if (requestCode == 0) { return 0; } else { return R.drawable.menu_me; } } @Override protected int imgLoading(int requestCode) { if (requestCode == 0) { return 0; } else { return R.drawable.menu_me; } } } @Override public void onClearData() { // TODO Auto-generated method stub } @Override public void onVideoBroadcast(Intent intent) { // TODO Auto-generated method stub } @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 == 0) { addFavFinish(result); hiddenProgress(); faving = false; } else if (result.RequestCode == 1) { chechFavFinish(result); title_fav.clearAnimation(); faving = false; } else if (result.RequestCode == 6688) { payFinish(result); hiddenProgress(); paying = false; } } } }; private void payFinish(WSResult result) { JSONObject json = WSCheck.Json(Video_Detail_Activity.this, result); if (json != null && title_fav_host != null) { int free = 0; try { free = json.getInt("free"); } catch (Exception e) { } int richerScore = 0; try { richerScore = json.getInt("richerScore"); } catch (Exception e) { } updateVideo(json); setLogin(json); setControlsInfo(); if (free == 1 || richerScore == 1) { doPayVideo(); } else { messageBox("你的积分不够,请先充值。"); } } } private void setLogin(JSONObject json) { if (json != null) { try { JSONObject user = json.getJSONObject("user"); if (user != null) { User ld = new User(); ld.iduser = user.getInt("iduser"); ld.user = user.getString("user"); ld.alias = user.getString("alias"); ld.sex = user.getInt("sex"); ld.birthday = user.getString("birthday"); ld.email = user.getString("email"); ld.company = user.getString("company"); ld.teamcount = user.getString("teamcount"); ld.level = user.getInt("level"); ld.score = user.getInt("score"); ld.score2 = user.getInt("score2"); ld.vip_stime = user.getString("vip_stime"); ld.vip_entime = user.getString("vip_entime"); if (Login.set(this, ld)) { return; } else { return; } } } catch (Exception e) { return; } } } private void addFavFinish(WSResult result) { JSONObject json = WSCheck.Json(Video_Detail_Activity.this, result); if (json != null && title_fav_host != null && title_fav != null) { JSONObject collect = null; try { collect = json.getJSONObject("collect"); } catch (Exception e) { collect = null; } int has = 0; try { has = json.getInt("has"); } catch (Exception e) { has = 0; } // if (collect != null) { updateCollect(collect, has); // } if (has == 0) { messageBox("收藏成功"); } else { messageBox("取消收藏成功"); } } checkCollect(); } private void chechFavFinish(WSResult result) { JSONObject json = WSCheck .Json(Video_Detail_Activity.this, result, null); if (json != null && title_fav_host != null && title_fav != null) { updateCollect(json, 0); showInfo("收藏同步成功!"); isync = true; } checkCollect(); } private void isCollect() { idcollect = -1; BDSQLiteHelper sqlobj = null; SQLiteDatabase sqlobj_r = null; Cursor cu = null; try { User user = Login.get(this); if (user != null && idvideo >= 0) { sqlobj = new BDSQLiteHelper(this); sqlobj_r = sqlobj.getReadableDatabase(); cu = sqlobj_r .rawQuery( "select idcollect from collect where idvideo=? and user = ?", new String[] { idvideo + "", user.user }); if (cu.moveToLast()) { idcollect = cu.getInt(cu.getColumnIndex("idcollect")); isync = true; } } } catch (Exception e) { } 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) { } } private void updateCollect(JSONObject collect, int has) { BDSQLiteHelper sqlobj = null; SQLiteDatabase sqlobj_w = null; Cursor cu = null; try { User user = Login.get(this); if (user != null) { sqlobj = new BDSQLiteHelper(this); sqlobj_w = sqlobj.getWritableDatabase(); if (has == 1) { sqlobj_w.delete("collect", "idvideo = ? and user = ?", new String[] { idvideo + "", user.user }); } else if (collect != null) { JSONArray item = collect.getJSONArray("item"); if (item != null) { String title = "", teacher = "", taptitudes = "", timg = ""; String desc = "", img = "", video = "", createtime = "", updatetime = "", paytime = ""; int idvideo, idtype, idptype, score, paycount, idteacher; int lg = item.length(); for (int i = 0; i < lg; i++) { JSONObject vo = item.getJSONObject(i); if (vo != null) { idvideo = vo.getInt("idvideo"); idtype = vo.getInt("idtype"); if (idvideo >= 0 && idtype >= 0) { ContentValues cv = new ContentValues(); 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", 1); cv.put("idcollect", vo.getInt("idcollect")); cv.put("user", user.user); 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); cu = sqlobj_w .rawQuery( "select idvideo from collect where (idvideo = ? and idtype = ?) ", new String[] { idvideo + "", idtype + "" }); int c = cu.getCount(); try { if (cu != null) { cu.close(); } } catch (Exception ex) { } if (c <= 0) { cv.put("idvideo", idvideo); cv.put("idtype", idtype); sqlobj_w.insert("collect", "", cv); } else { sqlobj_w.update("collect", cv, "(idvideo = ? and idtype = ?)", new String[] { idvideo + "", idtype + "" }); } cv = null; } } } } } } } catch (Exception e) { collect = null; } 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) { } } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); } }