package com.tejia.lijin.app.util;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
|
import org.json.JSONArray;
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
/**
|
* 记录 图文视频 链接地址
|
*/
|
public class RecordImageTextVideo {
|
private Context mcontext;
|
|
public RecordImageTextVideo(Context context) {
|
mcontext = context;
|
}
|
|
/**
|
* 开始记录
|
*
|
* @param object 传入json
|
*/
|
public void isRecord(JSONObject object) throws JSONException {
|
JSONArray List = object.optJSONObject("data").optJSONArray("systemClientParamsList");
|
SharedPreferences sp = mcontext.getSharedPreferences("guide", Context.MODE_PRIVATE);
|
|
for (int i = 0; i < List.length(); i++) {
|
JSONObject info = (JSONObject) List.get(i);
|
//图文视频教程
|
if (info.optString("key").equalsIgnoreCase("gonglue_cource_info")) {
|
JSONObject data = info.optJSONObject("value");
|
SharedPreferences.Editor editor = sp.edit();
|
//视频封面图
|
if (data.optString("videoPicture") != null) {
|
editor.putString("videoPicture", data.optString("videoPicture"));
|
} else {
|
editor.putString("videoPicture", "");
|
}
|
//点击封面图跳转的链接
|
if (data.optString("videoUrl") != null) {
|
editor.putString("videoUrl", data.optString("videoUrl"));
|
} else {
|
editor.putString("videoUrl", "");
|
}
|
//点击更多视频跳转的链接
|
if (data.optString("videoMoreUrl") != null) {
|
editor.putString("videoMoreUrl", data.optString("videoMoreUrl"));
|
} else {
|
editor.putString("videoMoreUrl", "");
|
}
|
//图文更多跳转的链接
|
if (data.optString("txtImgUtl") != null) {
|
editor.putString("txtImgUtl", data.optString("txtImgUtl"));
|
} else {
|
editor.putString("txtImgUtl", "");
|
}
|
editor.commit();
|
// break;
|
}
|
//购物车状态 显示或不显示 0不显示购物车 1显示购物车
|
if (info.optString("key").equalsIgnoreCase("cart_float")) {
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putString("cart_float", info.optString("value"));
|
editor.commit();
|
}
|
}
|
}
|
|
/**
|
* 取出 视频封面图地址
|
*
|
* @return
|
*/
|
public String getvideoPicture() {
|
if (mcontext != null) {
|
return mcontext.getSharedPreferences("guide", Context.MODE_PRIVATE).getString("videoPicture", "");
|
} else {
|
return "";
|
}
|
}
|
|
/**
|
* 取出 点击封面图跳转的链接
|
*
|
* @return
|
*/
|
public String getvideoUrl() {
|
if (mcontext != null) {
|
return mcontext.getSharedPreferences("guide", Context.MODE_PRIVATE).getString("videoUrl", "");
|
} else {
|
return "";
|
}
|
}
|
|
/**
|
* 取出 点击更多视频跳转的链接
|
*
|
* @return
|
*/
|
public String getvideoMoreUrl() {
|
if (mcontext != null) {
|
return mcontext.getSharedPreferences("guide", Context.MODE_PRIVATE).getString("videoMoreUrl", "");
|
} else {
|
return "";
|
}
|
}
|
|
/**
|
* 取出 图文更多跳转的链接
|
*
|
* @return
|
*/
|
public String gettxtImgUtl() {
|
if (mcontext != null) {
|
return mcontext.getSharedPreferences("guide", Context.MODE_PRIVATE).getString("txtImgUtl", "");
|
} else {
|
return "";
|
}
|
}
|
|
/**
|
* 取出购物车 显示或隐藏状态(服务器控制)(服务器让显示才会又本地控制否则不会有本地控制)
|
*
|
* @return
|
*/
|
public String getCart_float() {
|
if (mcontext != null) {
|
return mcontext.getSharedPreferences("guide", Context.MODE_PRIVATE).getString("cart_float", "1");//默认显示
|
} else {
|
return "";
|
}
|
}
|
|
/**
|
* 取出购物车 显示或隐藏状态(前提是服务器让显示 本地控制)
|
*
|
* @return
|
*/
|
public int getLocalCart_float() {
|
if (mcontext != null) {
|
return mcontext.getSharedPreferences("guide", Context.MODE_PRIVATE).getInt("locacart_float", 0);//默认显示
|
} else {
|
return 1;
|
}
|
}
|
|
/**
|
* 设置购物车 显示或隐藏状态(前提是服务器让显示 本地控制)
|
*
|
* @param control 传入显示或隐藏 大于等于0 显示 1表示点击过隐藏 2表示点击过显示
|
*/
|
public void setLocalCart_float(int control) {
|
if (mcontext != null) {
|
SharedPreferences sp = mcontext.getSharedPreferences("guide", Context.MODE_PRIVATE);
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putInt("locacart_float", control);
|
editor.apply();
|
//apply没有返回值而commit返回boolean表明修改是否提交成功
|
//apply是将修改数据原子提交到内存, 而后异步真正提交到硬件磁盘,
|
// 而commit是同步的提交到硬件磁盘,因此,在多个并发的提交commit的时候,
|
// 他们会等待正在处理的commit保存到磁盘后在操作,从而降低了效率。
|
// 而apply只是原子的提交到内容,后面有调用apply的函数的将会直接覆盖前面的内存数据,这样从一定程度上提高了很多效率。
|
}
|
}
|
}
|