继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

三级目录数据存取

繁华开满天机
关注TA
已关注
手记 134
粉丝 15
获赞 68

 */5bac9eaa00019daf10801920.jpg

//数据的存储解析

public ResData parClassVideo(String strJson,String uid) {

ResData res = null;

boolean result = false;

try {

res = parsResJson(strJson, "");

if (res.getStatus() == Constants.STATUS_SUCCESS) {

db.deleteAll(ClassVideoInfo.class);

db.deleteAll(ClassVideoInfoSecond.class);

db.deleteAll(ClassVideoInfoThird.class);

JSONObject jsonObject = new JSONObject(res.getData());

JSONArray jsonArray = jsonObject.getJSONArray("data");

// JSONArray jsonArray = new JSONArray(res.getData());

for (int i = 0; i < jsonArray.length(); i++) {

JSONObject jsonItem = (JSONObject) jsonArray.opt(i);

ClassVideoInfo cvinfo = new ClassVideoInfo();

cvinfo.setId(jsonItem.optString("id"));

cvinfo.setName(jsonItem.optString("name"));

cvinfo.setRecommandCourseId(jsonItem.optString("recommandCourseId"));

cvinfo.setRecommandCoursePicUrl(jsonItem.optString("recommandCoursePicUrl"));

cvinfo.setLevel(jsonItem.optString("level"));

//二级目录

// JSONArray jsonArrayS = new JSONArray("data");

JSONArray jsonArrayS = jsonItem.getJSONArray("data");

for (int j = 0; j < jsonArrayS.length(); j++) {

JSONObject jsonItemj = (JSONObject) jsonArrayS.opt(j);

ClassVideoInfoSecond cvinfoj = new ClassVideoInfoSecond();

cvinfoj.setId(cvinfo.getId()+"-"+jsonItemj.optString("id"));

cvinfoj.setName(jsonItemj.optString("name"));

cvinfoj.setLevel(jsonItemj.optString("level"));

List<ClassVideoInfoThird> list=new ArrayList<ClassVideoInfoThird>();

//三级目录

// JSONArray jsonArrayT = new JSONArray("data");

JSONArray jsonArrayT = jsonItemj.getJSONArray("data");

for (int k = 0; k < jsonArrayT.length(); k++) {

JSONObject jsonItemk = (JSONObject) jsonArrayT.opt(k);

ClassVideoInfoThird cvinfok = new ClassVideoInfoThird();

cvinfok.setId(cvinfoj.getId()+"_"+jsonItemk.optString("id"));

cvinfok.setName(jsonItemk.optString("name"));

cvinfok.setLevel(jsonItemk.optString("level"));

cvinfok.setSecId(cvinfoj.getId());

// ClassVideoInfoThird classVideoInfoThird=dbUtil.findClassVideoThrid(cvinfok.getIdT());

// System.out.print(classVideoInfoThird);

// list.add(cvinfok);

// cvinfoj.setClaTList(cvinfok);

if (dbUtil.findClassVideoThrid(cvinfok.getId()) != null) {

db.update(cvinfok);

}else {

dbUtil.saveData(cvinfok);

}

}

if (dbUtil.findClassVideoSecond(cvinfoj.getId()) != null) {

db.update(cvinfoj);

}else {

dbUtil.saveData(cvinfoj);

}

}

if (dbUtil.findClassVideo(cvinfo.getId()) != null) {

db.update(cvinfo);

}else {

dbUtil.saveData(cvinfo);

}

}

result = true;

} else {

result = false;

}

} catch (JSONException e) {

e.printStackTrace();

result = false;

}

res.setObj(result);

return res;

}

//数据的取出

public void showRightPage(String firid)

{

secondclasslist.clear();

secondclasslist.addAll(dbUtil.getSecLevel(firid));

mLinearLayout = (LinearLayout) view.findViewById(R.id.fragment_online_right_FrameLayout);

mLinearLayout.removeAllViews();

mListViewLeft.setOnItemClickListener(this);

// List<String> list = new ArrayList<String>();

// list.add(0,"全部");

for (int i = 0; i <secondclasslist.size(); i++) {

View view1 = LayoutInflater.from(mContext).inflate(R.layout.fragment_online_right_classes_item, null);

gridView = (MyGridView) view1.findViewById(R.id.gridview1);

gridtitle=(TextView) view1.findViewById(R.id.online_video_item_title);

gridtitle.setText(secondclasslist.get(i).getName());

final List<ClassVideoInfoThird> listT=dbUtil.getThirdLevel(secondclasslist.get(i).getId());

final List<ClassVideoInfoThird> listS=new ArrayList<ClassVideoInfoThird> ();

listS.addAll(listT);

ClassVideoInfoThird T=new ClassVideoInfoThird();

if (listT.size()>9) {

if (listT.size()%3==0) {

listS.add(T);

listS.add(T);

T.setName("show");

listS.add(T);

}

if (listT.size()%3==1) {

listS.add(T);

T.setName("show");

listS.add(T);

}

if (listT.size()%3==2) {

T.setName("show");

listS.add(T);

}

List<ClassVideoInfoThird> listN=listT.subList(0, 8);

ClassVideoInfoThird T2=new ClassVideoInfoThird();

T2.setName("less");

listN.add(T2);

ClassOnlineThridAdapter mClassOnlineThridAdapter=new ClassOnlineThridAdapter(listN, mContext);

secmap.put(secondclasslist.get(i).getId(), mClassOnlineThridAdapter);

Log.i("secondclasslist", secondclasslist.get(i).getId()+"secmap");

gridView.setAdapter(mClassOnlineThridAdapter);

System.out.print(secmap.size());

}else {

ClassOnlineThridAdapter mClassOnlineThridAdapter=new ClassOnlineThridAdapter(listT, mContext);

secmap.put(secondclasslist.get(i).getId(), mClassOnlineThridAdapter);

Log.i("secmap13123321321", secondclasslist.get(i).getId()+"secmap");

gridView.setAdapter(mClassOnlineThridAdapter);

}

gridView.setOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

Log.i("secmap13123321321", secmap.size()+"secmap");

if (listT.get(position).getName().equals("show")) {

ClassOnlineThridAdapter mClassOnlineThridAdapter=secmap.get(listT.get(0).getSecId());

mClassOnlineThridAdapter.setMlist(listT);

mClassOnlineThridAdapter.notifyDataSetChanged();

}else if (listT.get(position).getName().equals("less")) {

ClassOnlineThridAdapter mClassOnlineThridAdapter=secmap.get(listT.get(0).getSecId());

Log.i("secmap13123321321", listT.get(0).getSecId()+"secmap");

final List<ClassVideoInfoThird> listTemp=dbUtil.getThirdLevel(listT.get(0).getSecId());

mClassOnlineThridAdapter.setMlist(listTemp);

mClassOnlineThridAdapter.notifyDataSetChanged();

}else if(!listT.get(position).getId().equals("")){

String  classIdT=listT.get(position).getId();

 String tId=classIdT.substring(classIdT.indexOf("_")+1);

 String name=listT.get(position).getName();

 

Bundle bundle = new Bundle();

bundle.putSerializable(Constants.KEY_COURSE_ID,tId );

bundle.putSerializable(Constants.KEY_ORDER_ID, "");

bundle.putSerializable(Constants.KEY_ORDER_ID, name);

bundle.putString(Constants.KEY_FRAGMENT,

Constants.FRAGMENT_CLASS_VIDEO_LIST);

CenterDetailsActivity.startActivity(mContext,bundle);

}

switch (position) {

default:

break;

}

}

});

mLinearLayout.addView(view1);

}

}

原文链接:http://www.apkbus.com/blog-851511-62530.html

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP