From efa9c4225fe7e89c4acb1eacedd392d79aee240d Mon Sep 17 00:00:00 2001 From: admin <2780501319@qq.com> Date: 星期四, 15 四月 2021 01:59:24 +0800 Subject: [PATCH] 影视豆界面完善 --- BuWanVideo/src/com/weikou/beibeivideo/util/VideoUtil.java | 80 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 79 insertions(+), 1 deletions(-) diff --git a/BuWanVideo/src/com/weikou/beibeivideo/util/VideoUtil.java b/BuWanVideo/src/com/weikou/beibeivideo/util/VideoUtil.java index 76762c2..2cf9d43 100644 --- a/BuWanVideo/src/com/weikou/beibeivideo/util/VideoUtil.java +++ b/BuWanVideo/src/com/weikou/beibeivideo/util/VideoUtil.java @@ -1,14 +1,92 @@ 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; import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; public class VideoUtil { + 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"); - return (StringUtils.isBlank(watchCount) ? "0" : (Integer.parseInt(watchCount)) / 10000 > 0 ? df.format(Integer.parseInt(watchCount) / 10000f) + "涓�" : watchCount); + try { + return (StringUtils.isBlank(watchCount) ? "0" : (Integer.parseInt(watchCount)) / 10000 > 0 ? df.format(Integer.parseInt(watchCount) / 10000f) + "涓�" : watchCount); + } catch (Exception e) { + } + return ""; + } + + + 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); } -- Gitblit v1.8.0