| | |
| | | package com.weikou.beibeivideo.util; |
| | | |
| | | import android.content.Context; |
| | | import android.content.SharedPreferences; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.lcjian.library.util.common.StringUtils; |
| | | import com.weikou.beibeivideo.entity.VideoDetailInfo; |
| | | |
| | |
| | | |
| | | public final static List<VideoDetailInfo> videoEpisodeList = new ArrayList<>(); |
| | | |
| | | /** |
| | | * 保存临时剧集 |
| | | * |
| | | * @param context |
| | | * @param episodeList |
| | | * @param append |
| | | */ |
| | | public static void saveVideoEpisodeList(Context context, List<VideoDetailInfo> episodeList, boolean append) { |
| | | if (episodeList == null) |
| | | episodeList = new ArrayList<>(); |
| | | if (!append) |
| | | videoEpisodeList.clear(); |
| | | videoEpisodeList.addAll(episodeList); |
| | | saveTempVideoDetailList(context, videoEpisodeList); |
| | | } |
| | | |
| | | /** |
| | | * 清除临时剧集 |
| | | * |
| | | * @param context |
| | | */ |
| | | public static void clearVideoEpisodeList(Context context) { |
| | | videoEpisodeList.clear(); |
| | | saveTempVideoDetailList(context, new ArrayList<>()); |
| | | } |
| | | |
| | | |
| | | public static String getWatchCountShortName(String watchCount) { |
| | | DecimalFormat df = new DecimalFormat("###.0"); |
| | |
| | | } |
| | | |
| | | |
| | | private static void saveTempVideoDetailList(Context context, List<VideoDetailInfo> detailInfos) { |
| | | SharedPreferences sharedPreferences = context.getSharedPreferences("videoTempInfo", Context.MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sharedPreferences.edit(); |
| | | editor.putString("videoDetailInfoList", new Gson().toJson(detailInfos)); |
| | | editor.commit(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取临时剧集 |
| | | * |
| | | * @param context |
| | | * @return |
| | | */ |
| | | private static List<VideoDetailInfo> getTempVideoDetailList(Context context) { |
| | | SharedPreferences sharedPreferences = context.getSharedPreferences("videoTempInfo", Context.MODE_PRIVATE); |
| | | String content = sharedPreferences.getString("videoDetailInfoList", ""); |
| | | if (!StringUtils.isEmpty(content)) { |
| | | return new Gson().fromJson(content, new TypeToken<List<VideoDetailInfo>>() { |
| | | }.getType()); |
| | | } |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | /** |
| | | * 从缓存中加载 |
| | | * |
| | | * @param context |
| | | */ |
| | | public static void loadVideoEpisodeListCache(Context context) { |
| | | List<VideoDetailInfo> detailList = getTempVideoDetailList(context); |
| | | VideoUtil.videoEpisodeList.clear(); |
| | | if (detailList != null && detailList.size() > 0) |
| | | VideoUtil.videoEpisodeList.addAll(detailList); |
| | | } |
| | | |
| | | |
| | | } |