package com.tejia.lijin.app.util.share;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
|
import com.google.gson.Gson;
|
import com.wpc.library.util.common.StringUtils;
|
|
import org.json.JSONArray;
|
|
import java.util.HashSet;
|
import java.util.Set;
|
|
import static android.content.Context.MODE_PRIVATE;
|
|
public class ShareCacheUtil {
|
|
/**
|
* 保存单品分享图片的习惯
|
*
|
* @param context
|
*/
|
public static void saveSingleGoodsShareImage(Context context, boolean allImage) {
|
SharedPreferences sharedPreferences = context.getSharedPreferences("share-single", Context.MODE_PRIVATE);
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
editor.putBoolean("allImage", allImage);
|
editor.commit();
|
}
|
|
public static boolean isSingleGoodsShareAllImage(Context context) {
|
SharedPreferences sharedPreferences = context.getSharedPreferences("share-single", Context.MODE_PRIVATE);
|
return sharedPreferences.getBoolean("allImage", false);
|
}
|
|
|
/**
|
* 保存快速分享评论选择项
|
*
|
* @param context
|
* @param currentChoicedSet
|
*/
|
public static void saveFastShareCommentChoices(Context context, Set<Integer> currentChoicedSet) {
|
SharedPreferences sp = context.getSharedPreferences("fastShare", MODE_PRIVATE);
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putString("commentChoices", new Gson().toJson(currentChoicedSet));
|
editor.commit();
|
}
|
|
/**
|
* 获取快速分享保存的选择项
|
*
|
* @param context
|
* @return
|
*/
|
public static Set<Integer> getFastCommentChoices(Context context) {
|
SharedPreferences sp = context.getSharedPreferences("fastShare", MODE_PRIVATE);
|
String commentChoices = sp.getString("commentChoices", "");
|
if (StringUtils.isBlank(commentChoices)) {
|
commentChoices = "[]";
|
}
|
Set<Integer> commentChoicesList = new HashSet<>();
|
try {
|
JSONArray array = new JSONArray(commentChoices);
|
for (int i = 0; i < array.length(); i++)
|
commentChoicesList.add(array.optInt(i));
|
} catch (Exception e) {
|
}
|
|
return commentChoicesList;
|
}
|
|
|
/**
|
* 快速分享的分享图上是是否显示邀请码
|
*
|
* @param context
|
* @param show
|
*/
|
public static void saveFastShareImageShowInviteCode(Context context, boolean show) {
|
SharedPreferences sp = context.getSharedPreferences("fastShare", MODE_PRIVATE);
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putBoolean("imgShowInviteCode", show);
|
editor.commit();
|
}
|
|
|
public static boolean isFastShareImageShowInviteCode(Context context) {
|
SharedPreferences sp = context.getSharedPreferences("fastShare", MODE_PRIVATE);
|
return sp.getBoolean("imgShowInviteCode", true);
|
}
|
}
|