From 1981dee5aec45793d3c4ebdbc4e637528c71b3c5 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 03 二月 2021 19:20:47 +0800
Subject: [PATCH] 'PPTV'

---
 BuWanVideo/src/com/weikou/beibeivideo/ui/main/HomeFragment.java |  164 ++++++++++++++++++++++++++++++++----------------------
 1 files changed, 96 insertions(+), 68 deletions(-)

diff --git a/BuWanVideo/src/com/weikou/beibeivideo/ui/main/HomeFragment.java b/BuWanVideo/src/com/weikou/beibeivideo/ui/main/HomeFragment.java
index 0962b84..0c088a2 100644
--- a/BuWanVideo/src/com/weikou/beibeivideo/ui/main/HomeFragment.java
+++ b/BuWanVideo/src/com/weikou/beibeivideo/ui/main/HomeFragment.java
@@ -5,7 +5,10 @@
 import android.content.SharedPreferences;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
+import android.graphics.Bitmap;
+import android.graphics.drawable.Drawable;
 import android.os.Bundle;
+import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
@@ -14,26 +17,32 @@
 import android.view.View;
 import android.widget.FrameLayout;
 
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.request.target.SimpleTarget;
+import com.bumptech.glide.request.transition.Transition;
 import com.google.gson.FieldNamingPolicy;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.reflect.TypeToken;
-import com.lcjian.library.util.cache.DiskLruCache;
 import com.lcjian.library.util.common.StorageUtils;
+import com.lcjian.library.util.common.StringUtils;
 import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
 import com.viewpagerindicator.IconPagerAdapter;
 import com.viewpagerindicator.MainTabPageIndicator;
 import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
 import com.weikou.beibeivideo.BeibeiVideoAPI;
+import com.weikou.beibeivideo.BeibeiVideoApplication;
 import com.weikou.beibeivideo.R;
+import com.weikou.beibeivideo.entity.JumpDetail;
 import com.weikou.beibeivideo.entity.VideoType;
 import com.weikou.beibeivideo.entity.recommend.HomeClass;
 import com.weikou.beibeivideo.ui.MyRetainViewFragment;
+import com.weikou.beibeivideo.ui.dialog.FloatADDialog;
 import com.weikou.beibeivideo.ui.dialog.UserProtocolDialog;
-import com.weikou.beibeivideo.ui.recommend.NovelJNZFragment;
 import com.weikou.beibeivideo.ui.recommend.RecommendFragment;
 import com.weikou.beibeivideo.util.BeibeiConstant;
 import com.weikou.beibeivideo.util.UserUtil;
+import com.weikou.beibeivideo.util.cache.DiskLruCacheManager;
 
 import org.apache.http.Header;
 import org.json.JSONObject;
@@ -63,55 +72,78 @@
 
     FrameLayout fl_indicator;
 
-    private DiskLruCache cache;
 
     public HomeFragment() {
-        super(HomeFragment.class.getClass().getName());
+        super();
+        setName(HomeFragment.class.getClass().getName());
     }
 
 
     @Override
     public void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        try {
-            cache = DiskLruCache.open(
-                    new File(StorageUtils.getCacheDirectory(getContext())
-                            .toString(), "http"), getVersionNum(getContext()),
-                    1, 1024 * 1024);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
         if (!BeibeiConstant.IS_TEST)
-            showProtocol();
+            showFloatImgAd();
     }
 
 
-    private void showProtocol() {
-        String data = "鎰熻阿鎮ㄥ" + getResources().getString(R.string.app_name) + "涓�鐩翠互鏉ョ殑淇′换锛�<br>";
-        data += "鎴戜滑渚濈収鏂扮殑鐩戠瑕佹眰鏉′緥鏇存柊浜�";
-        data += String.format("<a href='%s'>銆婇殣绉佹斂绛栥��</a>鍜�", BeibeiConstant.PRIVACY_POLICY);
-        data += String.format("<a href='%s'>銆婄敤鎴峰崗璁��</a>", BeibeiConstant.USER_AGREEMENT);
-        data += "涓洪噰鍙栫浉搴斿畨鍏ㄤ繚鎶ゆ帾鏂斤紝灏藉姏淇濇姢鎮ㄧ殑涓汉淇℃伅瀹夊叏鍙帶锛岀壒鍚戜綘璇存槑濡備笅锛�<br>" +
-                "1銆佹偍鍦ㄤ娇鐢�" + getResources().getString(R.string.app_name) + "鍚勯」浜у搧鎴栨湇鍔℃椂锛屽皢浼氭彁渚涗笌鍏蜂綋鍔熻兘鐩稿叧鐨勪釜浜轰俊鎭紙鍙兘娑夊強甯愬彿銆佷綅缃�佸瓨鍌ㄧ瓑淇℃伅锛夈��<br>" +
-                "2銆佹偍鍙互闅忔椂鏌ヨ銆佹洿姝c�佸垹闄ゆ偍鐨勪釜浜轰俊鎭紝鎴戜滑涔熸彁渚涜处鎴锋敞閿�鐨勬笭閬撱��<br>" +
-                "3銆佹湭缁忔偍鐨勫啀娆″悓鎰忥紝鎴戜滑涓嶄細灏嗕笂杩颁俊鎭敤浜庢偍鏈巿鏉冪殑鍏朵粬鐢ㄩ�旀垨鐩殑銆�<br>" +
-                "4銆佹湭缁忕洃鎶や汉鍚屾剰锛屾垜浠笉浼氭敹闆嗕娇鐢�14鍛ㄥ瞾浠ヤ笅锛堝惈14鍛ㄥ瞾锛夋湭鎴愬勾浜轰釜浜轰俊鎭紝涓斾笉浼氬埄鐢ㄥ叾淇℃伅鎺ㄩ�佹柊闂汇�佹椂鏀夸俊鎭�佸箍鍛婄瓑瀹氬悜鎺ㄩ�佹椿鍔ㄣ��";
+    /**
+     * 灞曠ず鎮诞骞垮憡
+     */
+    private void showFloatImgAd() {
+        BeibeiVideoAPI.getHomeConfig(getContext(), new BasicTextHttpResponseHandler() {
+            @Override
+            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
+                if (jsonObject.optBoolean("IsPost")) {
+                    JSONObject data = jsonObject.optJSONObject("Data");
+                    if (data != null) {
 
-        if (!UserUtil.isAgreeUserProtocol(getContext())) {
-            new UserProtocolDialog.Builder(getActivity()).setNegativeButton("涓嶅悓鎰�", new DialogInterface.OnClickListener() {
-                @Override
-                public void onClick(DialogInterface dialog, int which) {
-                    getActivity().finish();
+                        JSONObject ad = data.optJSONObject("floatAD");
+                        if (ad != null) {
+                            String id = ad.optString("id");
+                            if (FloatADDialog.Builder.canShow(getContext(), id)) {
+                                String picture = ad.optString("picture");
+                                Glide.with(getContext()).load(picture).into(new SimpleTarget<Drawable>() {
+                                    @Override
+                                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
+                                        JSONObject jumpDetailJSON = ad.optJSONObject("jumpDetail");
+                                        JSONObject params = ad.optJSONObject("params");
+                                        JumpDetail jumpDetail = new Gson().fromJson(jumpDetailJSON.toString(), JumpDetail.class);
+                                        final FloatADDialog.Builder builder = new FloatADDialog.Builder(getActivity())
+                                                .setId(id).setImage(resource);
+                                        if (params != null) {
+                                            builder.setJump(jumpDetail, com.alibaba.fastjson.JSONObject.parseObject(params.toString()));
+                                        }
+
+                                        fl_indicator.postDelayed(new Runnable() {
+                                            @Override
+                                            public void run() {
+                                                try {
+                                                    builder.create().show();
+                                                } catch (Exception e) {
+
+                                                }
+                                            }
+                                        }, 2000);
+
+
+                                    }
+
+                                    @Override
+                                    public void onLoadCleared(@Nullable Drawable placeholder) {
+
+                                    }
+
+                                });
+                            }
+                        }
+                    }
                 }
-            }).setPositiveButton("鍚屾剰", new DialogInterface.OnClickListener() {
-                @Override
-                public void onClick(DialogInterface dialog, int which) {
-                    dialog.dismiss();
-                    UserUtil.agreeUserProtocol(getContext());
-                }
-            }).setData(data).create().show();
-        }
+
+            }
+        });
     }
+
 
     public static int getVersionNum(Context context) {
         try {
@@ -136,26 +168,23 @@
         if (fl_indicator.getChildCount() > 0) {
             fl_indicator.removeAllViews();
         }
-        DiskLruCache.Snapshot snapshot = null;
-        try {
-            if (cache != null) {
-                snapshot = cache.get(getKey("getCategories"));
-                if (snapshot != null) {
-                    Gson gson = new GsonBuilder().setFieldNamingPolicy(
-                            FieldNamingPolicy.UPPER_CAMEL_CASE).create();
-                    List<VideoType> list = gson.fromJson(
-                            snapshot.getString(0),
-                            new TypeToken<List<VideoType>>() {
-                            }.getType());
-//                    categories.addAll(list);
+
+        String cacheValue = DiskLruCacheManager.getInstance(BeibeiVideoApplication.application).getCache(getKey("getCategories"));
+        if (!StringUtils.isBlank(cacheValue)) {
+            Gson gson = new GsonBuilder().setFieldNamingPolicy(
+                    FieldNamingPolicy.UPPER_CAMEL_CASE).create();
+            List<HomeClass> list = gson.fromJson(
+                    cacheValue,
+                    new TypeToken<List<HomeClass>>() {
+                    }.getType());
+            if (list != null)
+                for (int i = 0; i < list.size(); i++) {
+                    if (list.get(i).getDataType().equalsIgnoreCase("novel")) {
+                        list.remove(i--);
+                    }
                 }
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            if (snapshot != null) {
-                snapshot.close();
-            }
+
+            categories.addAll(list);
         }
 
         adapter = new HomePageAdapter(
@@ -223,6 +252,13 @@
                                     }.getType());
 
                             categories.addAll(list);
+                            if (categories != null)
+                                for (int i = 0; i < categories.size(); i++) {
+                                    if (categories.get(i).getDataType().equalsIgnoreCase("novel")) {
+                                        categories.remove(i--);
+                                    }
+                                }
+
                             adapter.notifyDataSetChanged();
                             indicator.notifyDataSetChanged();
 
@@ -230,13 +266,7 @@
 
 
                             count++;
-                            try {
-                                DiskLruCache.Editor editor = cache
-                                        .edit(getKey("getCategories"));
-                                editor.set(0, gson.toJson(categories));
-                                editor.commit();
-                            } catch (IOException e) {
-                            }
+                            DiskLruCacheManager.getInstance(BeibeiVideoApplication.application).cache(getKey("getCategories"), gson.toJson(categories));
                         }
                     }
 
@@ -262,12 +292,10 @@
 
         @Override
         public Fragment getItem(int position) {
-            if ("novel".equalsIgnoreCase(mlist.get(position).getDataType())) {
-                return NovelJNZFragment.newInstance();
-            } else {
-                Fragment fragment = RecommendFragment.newInstance(mlist.get(position), position + "");
-                return fragment;
-            }
+
+            Fragment fragment = RecommendFragment.newInstance(mlist.get(position), position + "");
+            return fragment;
+
         }
 
         @Override

--
Gitblit v1.8.0