From 399ac289f80b7a40aa4210341db6b447cacdcf14 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 09 八月 2022 17:42:33 +0800
Subject: [PATCH] 广告升级,隐私政策整改

---
 app/src/main/java/com/tejia/lijin/app/ui/recommend/GoodsDetailActivity.java |  356 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 319 insertions(+), 37 deletions(-)

diff --git a/app/src/main/java/com/tejia/lijin/app/ui/recommend/GoodsDetailActivity.java b/app/src/main/java/com/tejia/lijin/app/ui/recommend/GoodsDetailActivity.java
index 11a8975..4bebab3 100644
--- a/app/src/main/java/com/tejia/lijin/app/ui/recommend/GoodsDetailActivity.java
+++ b/app/src/main/java/com/tejia/lijin/app/ui/recommend/GoodsDetailActivity.java
@@ -1,5 +1,6 @@
 package com.tejia.lijin.app.ui.recommend;
 
+import android.app.Dialog;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
@@ -8,6 +9,7 @@
 import android.graphics.Typeface;
 import android.graphics.drawable.AnimationDrawable;
 import android.graphics.drawable.GradientDrawable;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
@@ -23,6 +25,8 @@
 import android.view.animation.Animation;
 import android.view.animation.AnimationUtils;
 import android.view.animation.DecelerateInterpolator;
+import android.webkit.WebChromeClient;
+import android.webkit.WebResourceRequest;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
@@ -42,14 +46,19 @@
 import com.tejia.lijin.app.BasicTextHttpResponseHandler;
 import com.tejia.lijin.app.R;
 import com.tejia.lijin.app.ShoppingApi;
+import com.tejia.lijin.app.entity.CouponInfo;
 import com.tejia.lijin.app.entity.CouponUser;
 import com.tejia.lijin.app.entity.GoodsDetail;
 import com.tejia.lijin.app.entity.PushEventData;
 import com.tejia.lijin.app.entity.TaoBaoGoodsBrief;
 import com.tejia.lijin.app.entity.common.ImageShowEntity;
 import com.tejia.lijin.app.entity.goods.GoodsDetailVO;
+import com.tejia.lijin.app.entity.user.UserLijinLevelInfoVO;
 import com.tejia.lijin.app.ui.BaseActivity;
 import com.tejia.lijin.app.ui.dialog.GoodsDetailHongBaoAndCouponSelectDialog;
+import com.tejia.lijin.app.ui.dialog.GoodsDetailJumpLoaingDialog;
+import com.tejia.lijin.app.ui.dialog.GoodsDetailNoLoginFailiDialog;
+import com.tejia.lijin.app.ui.dialog.GoodsDetailNotifyDialog;
 import com.tejia.lijin.app.ui.dialog.JumpTaoBaoDialog;
 import com.tejia.lijin.app.ui.goods.GoodsDetailHongBaoListAdapter;
 import com.tejia.lijin.app.ui.goods.GoodsDetailPreEventManager;
@@ -61,15 +70,19 @@
 import com.tejia.lijin.app.util.FlowLayout;
 import com.tejia.lijin.app.util.GlideCircleTransform;
 import com.tejia.lijin.app.util.GlideRoundTransform;
+import com.tejia.lijin.app.util.GoodsBuyJumpUtil;
 import com.tejia.lijin.app.util.ImageUtil;
 import com.tejia.lijin.app.util.SetLabels;
 import com.tejia.lijin.app.util.Toast_Dialog;
 import com.tejia.lijin.app.util.TopStatusSettings;
 import com.tejia.lijin.app.util.clipboard.ClipboardUtil;
+import com.tejia.lijin.app.util.goods.GoodsBuyUtil;
 import com.tejia.lijin.app.util.ui.GoodsDetailUtil;
+import com.tejia.lijin.app.util.ui.dialog.DialogUtil;
 import com.tejia.lijin.app.util.umengCustomEvent.GoodsCustomEvent;
 import com.tejia.lijin.app.util.user.LoginAndInviteStatusUtil;
 import com.tejia.lijin.app.util.user.UserUtil;
+import com.tejia.lijin.app.util.web.RebateJavaInterfaceBS;
 import com.wang.avi.AVLoadingIndicatorView;
 import com.wpc.library.content.ConnectivityChangeHelper;
 import com.wpc.library.recyclerviewhelper.DividerItemDecoration;
@@ -86,10 +99,12 @@
 import java.util.List;
 import java.util.Timer;
 
+import androidx.annotation.RequiresApi;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
 import androidx.viewpager.widget.PagerAdapter;
 import androidx.viewpager.widget.ViewPager;
+import wendu.dsbridge.DWebView;
 
 /**
  * Created by weikou2015 on 2018/5/11.
@@ -146,10 +161,11 @@
     //鍥炬枃璇︽儏
     private FrameLayout fl_goods_detail;
     private ImageView iv_imgtext_status;
-    private WebView webView;
+    private DWebView webView;
     private LinearLayout ll_loading;
     private ImageView iv_loading;
     private TextView tv_loading;
+    private View view_goods_imgs_tag;//鐢ㄦ潵鏍囪瘑瀵艰埅鏍忛�変腑
 
     //鐚滀綘鍠滄
     private LinearLayout ll_guess_like;
@@ -220,6 +236,7 @@
         tv_loading = findViewById(R.id.tv_loading);
         iv_loading = findViewById(R.id.iv_loading);
         webView = findViewById(R.id.webView);
+        view_goods_imgs_tag = findViewById(R.id.view_goods_imgs_tag);
 
 
         vp_goods_detail = findViewById(R.id.vp_goods_img);
@@ -301,13 +318,18 @@
         webView.setWebViewClient(new MWebviewClient());
         WebSettings settings = webView.getSettings();
         settings.setJavaScriptEnabled(true);
+        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
+        settings.setUseWideViewPort(true);
         webView.setInitialScale(100);
+        RebateJavaInterfaceBS javaInterface1 = new RebateJavaInterfaceBS(GoodsDetailActivity.this,
+                null, null, new TextView(this), null, webView, null);
+        webView.addJavascriptObject(javaInterface1, "yestv");
+
         ll_loading.setVisibility(View.VISIBLE);
 
         avLoadingIndicatorView.setVisibility(View.VISIBLE);
         Animation ani = AnimationUtils.loadAnimation(this, R.anim.touming); //鐢虫槑涓�涓姩鐢�
         avLoadingIndicatorView.setAnimation(ani);//涓哄浘鐗囩粦瀹氬姩鐢�
-        ll_content.setVisibility(View.GONE);
         fl_face.setVisibility(View.VISIBLE);
         bannerAdapter = new ImageAdapter(mBanners, this);
         vp_goods_detail.setAdapter(bannerAdapter);
@@ -402,10 +424,8 @@
                 if (scrollY < fl_goods_detail.getTop()) {//澶撮儴
                     setPosition(1);
                 } else if (scrollY >= (fl_goods_detail.getTop() - titleHeight)
-                        && scrollY < ll_guess_like.getTop()) {//璇︽儏鍥剧墖
+                        && scrollY < view_goods_imgs_tag.getTop()) {//璇︽儏鍥剧墖
                     setPosition(2);
-                } else if (scrollY >= ll_guess_like.getTop() - titleHeight) {//鐚滀綘鍠滄
-                    setPosition(4);
                 } else {
                     setPosition(4);
                 }
@@ -554,6 +574,8 @@
     }
 
 
+    GoodsDetailNotifyDialog notifyDialog;
+
     @Override
     protected void onCreate(Bundle arg0) {
         super.onCreate(arg0);
@@ -565,6 +587,40 @@
         initView();
         initData();
         getAppPageNotification();
+
+
+//        notifyDialog = new GoodsDetailNotifyDialog.Builder(GoodsDetailActivity.this).setMessage("娴嬭瘯12123123").setOnButtonClickListener(new GoodsDetailNotifyDialog.Builder.IDialogButtonClick() {
+//            @Override
+//            public void onLeftClick() {
+//            }
+//
+//            @Override
+//            public void onRightClick() {
+//                DialogUtil.dismiss(notifyDialog);
+//                goFanli();
+//            }
+//        }).create();
+//
+//        DialogUtil.show(notifyDialog);
+
+    }
+
+    public void showNotifyDialog(String btnName, String link) {
+        DialogUtil.dismiss(notifyDialog);
+
+        notifyDialog = new GoodsDetailNotifyDialog.Builder(this).setIconResource(R.drawable.icon_goods_detail_notify).setLeftBtnInfo(btnName, link).setOnButtonClickListener(new GoodsDetailNotifyDialog.Builder.IDialogButtonClick() {
+            @Override
+            public void onLeftClick() {
+                DialogUtil.dismiss(notifyDialog);
+            }
+
+            @Override
+            public void onRightClick() {
+                DialogUtil.dismiss(notifyDialog);
+                goFanli();
+            }
+        }).create();
+        DialogUtil.show(notifyDialog);
     }
 
 
@@ -595,11 +651,23 @@
             if (null != url && url.startsWith("yestv://webviewHeight#")) {
                 int height = Integer.parseInt(url.replace("yestv://webviewHeight#", ""));
                 Log.i("mResult", "webView鐨勯珮搴︿负:" + height + "");
-                //TODO 娴嬭瘯
                 webView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));
                 return true;
             }
             return super.shouldOverrideUrlLoading(view, url);
+        }
+
+        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+        @Override
+        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
+            String url = request.getUrl().toString();
+            if (null != url && url.startsWith("yestv://webviewHeight#")) {
+                int height = Integer.parseInt(url.replace("yestv://webviewHeight#", ""));
+                Log.i("mResult", "webView鐨勯珮搴︿负:" + height + "");
+                webView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));
+                return true;
+            }
+            return super.shouldOverrideUrlLoading(view, request);
         }
 
         @Override
@@ -612,6 +680,7 @@
                 }
             }, 3000);
         }
+
     }
 
     private void getAppPageNotification() {
@@ -710,7 +779,10 @@
 
                     tv_name.setText(mInfo.getGoods().getTitle());
                     webView.loadUrl(mInfo.getExtra().getDetailUrl());
-                    tv_sales_num.setText(GoodsDetailUtil.getSalesTypeDesc(mInfo.getGoods().getSalesType()) + " " + mInfo.getGoods().getSalesCount());
+                    if (StringUtils.isNullOrEmpty(mInfo.getGoods().getSalesCount())) {
+                        tv_sales_num.setText("");
+                    } else
+                        tv_sales_num.setText(GoodsDetailUtil.getSalesTypeDesc(mInfo.getGoods().getSalesType()) + " " + mInfo.getGoods().getSalesCount());
 
                     if (mInfo.getGoods().getShopInfo() != null) {
                         ll_shop.setVisibility(View.VISIBLE);
@@ -722,7 +794,7 @@
                         tv_shop_name.setText(mInfo.getGoods().getShopInfo().getShopName());
 
                         try {
-                            GoodsDetailUtil.fillShopType(tv_shop_type, mInfo.getGoods().getShopInfo().getUserType());
+                            GoodsDetailUtil.fillShopType(tv_shop_type, mInfo.getGoods().getShopType());
 
                             if (!StringUtils.isNullOrEmpty(mInfo.getGoods().getShopInfo().getScoreGoods())) {
                                 tv_shop_des.setText("瀹濊礉鎻忚堪: " + mInfo.getGoods().getShopInfo().getScoreGoods());
@@ -781,10 +853,7 @@
                     initFanliAndBuyBtn(mInfo.getExtra().isBuyValid(), mInfo.getExtra().isFanliValid());
                     requestState(0);
                     sv_goods.scrollTo(0, 0);
-//                    ll_content.setVisibility(View.VISIBLE);
-//                    fl_face.setVisibility(View.GONE);
                 } else if (jsonObject.optString("code").equalsIgnoreCase("2")) {
-                    ll_content.setVisibility(View.GONE);
                     findViewById(R.id.ll_goods_nothing).setVisibility(View.VISIBLE);
                     fl_face.setVisibility(View.VISIBLE);
                 }
@@ -1101,10 +1170,15 @@
      * @param state
      */
     private void requestState(int state) {
-        ll_content.setVisibility(state == 0 ? View.VISIBLE : View.GONE);
+//        fl_face.setVisibility(state != 0 ? View.VISIBLE : View.GONE);
         ll_no_data.setVisibility(state == 1 ? View.VISIBLE : View.GONE);
         ll_request_failture.setVisibility(state == 2 ? View.VISIBLE : View.GONE);
         ll_no_net.setVisibility(state == 3 ? View.VISIBLE : View.GONE);
+        if (mInfo == null) {
+            fl_face.setVisibility(View.VISIBLE);
+        } else {
+            fl_face.setVisibility(View.GONE);
+        }
     }
 
     @Override
@@ -1125,43 +1199,82 @@
 
 
     private void goFanli() {
-        new GoodsDetailHongBaoAndCouponSelectDialog.Builder(this).setCouponList(mInfo.getGoods().getCouponInfoList()).setItemClickListener(new GoodsDetailHongBaoAndCouponSelectDialog.OnItemClickListener() {
-            @Override
-            public void onClick(int p) {
-                goodsDetailPreEventManager.startClick(0, new GoodsDetailPreEventManager.IPreEventListener() {
-                    @Override
-                    public void onPreSuccess() {
-
-                        //TODO 杩斿埄
-                    }
-                });
-            }
-        }).create().show();
+        if (mInfo.getGoods().getCouponInfoList() != null && mInfo.getGoods().getCouponInfoList().size() > 1) {
+            new GoodsDetailHongBaoAndCouponSelectDialog.Builder(this).setCouponList(mInfo.getGoods().getCouponInfoList()).setItemClickListener(new GoodsDetailHongBaoAndCouponSelectDialog.OnItemClickListener() {
+                @Override
+                public void onClick(int p) {
+                    goFanli(mInfo.getGoods().getCouponInfoList().get(p));
+                }
+            }).create().show();
+        } else {
+            goFanli(null);
+        }
         //鍒ゆ柇鏄惁鏈夊寮犲埜鎯呭喌
     }
 
+    private GoodsDetailNoLoginFailiDialog mGoodsDetailNoLoginFailiDialog;
+
+    private void goFanli(final CouponInfo couponInfo) {
+
+        if (UserUtil.isLogin(getApplicationContext())) {
+            goodsDetailPreEventManager.startClick(0, true, new GoodsDetailPreEventManager.IPreEventListener() {
+                @Override
+                public void onPreSuccess() {
+                    fanliRequest(couponInfo);
+                }
+            });
+        } else {
+            DialogUtil.dismiss(mGoodsDetailNoLoginFailiDialog);
+            mGoodsDetailNoLoginFailiDialog = new GoodsDetailNoLoginFailiDialog.Builder(this).setOnButtonClickListener(new GoodsDetailNoLoginFailiDialog.Builder.IDialogButtonClick() {
+                @Override
+                public void onLeftClick() {
+                    DialogUtil.dismiss(mGoodsDetailNoLoginFailiDialog);
+                    fanliRequest(couponInfo);
+                }
+
+                @Override
+                public void onRightClick() {
+                    DialogUtil.dismiss(mGoodsDetailNoLoginFailiDialog);
+                    goodsDetailPreEventManager.startClick(0, true, new GoodsDetailPreEventManager.IPreEventListener() {
+                        @Override
+                        public void onPreSuccess() {
+                            fanliRequest(couponInfo);
+                        }
+                    });
+                }
+            }).create();
+            mGoodsDetailNoLoginFailiDialog.show();
+        }
+    }
+
     private void goBuy() {
-        List<GoodsDetailVO.GoodsHongBaoListVO> hongBaoList = new ArrayList<>();
+        final List<GoodsDetailVO.GoodsHongBaoListVO> hongBaoList = new ArrayList<>();
         hongBaoList.addAll(mInfo.getGoods().getPriceList());
         for (int i = 0; i < hongBaoList.size(); i++) {
             if (hongBaoList.get(i).getType() != 2) {
                 hongBaoList.remove(i--);
             }
         }
+        if (hongBaoList.size() > 1) {
+            new GoodsDetailHongBaoAndCouponSelectDialog.Builder(this).setHongBaoList(hongBaoList).setItemClickListener(new GoodsDetailHongBaoAndCouponSelectDialog.OnItemClickListener() {
+                @Override
+                public void onClick(int p) {
+                    goBuy(hongBaoList.get(p));
+                }
+            }).create().show();
+        } else {
+            if (hongBaoList.size() > 0)
+                goBuy(hongBaoList.get(0));
+        }
+    }
 
-
-        new GoodsDetailHongBaoAndCouponSelectDialog.Builder(this).setHongBaoList(hongBaoList).setItemClickListener(new GoodsDetailHongBaoAndCouponSelectDialog.OnItemClickListener() {
+    private void goBuy(final GoodsDetailVO.GoodsHongBaoListVO lijinVO) {
+        goodsDetailPreEventManager.startClick(1, false, new GoodsDetailPreEventManager.IPreEventListener() {
             @Override
-            public void onClick(int p) {
-                goodsDetailPreEventManager.startClick(1, new GoodsDetailPreEventManager.IPreEventListener() {
-                    @Override
-                    public void onPreSuccess() {
-                        //TODO 璐拱
-                    }
-                });
+            public void onPreSuccess() {
+                buyRequest(lijinVO);
             }
-        }).create().show();
-
+        });
     }
 
 
@@ -1239,7 +1352,11 @@
 
             @Override
             public void onHongBaoClick(int p, GoodsDetailVO.GoodsHongBaoListVO info) {
-
+                if (info.getType() == 4) {
+                    goFanli(null);
+                } else {
+                    goBuy(info);
+                }
             }
 
             @Override
@@ -1292,4 +1409,169 @@
         });
     }
 
+
+    private void buyRequest(GoodsDetailVO.GoodsHongBaoListVO goodsHongBaoListVO) {
+
+        ShoppingApi.buyWithLijin(getApplicationContext(), mInfo.getGoods().getGoodsId(), mInfo.getGoods().getGoodsType(), goodsHongBaoListVO.getId(), UserUtil.getUid(getApplicationContext()), from, new BasicTextHttpResponseHandler() {
+
+            @Override
+            public void onStart() {
+                super.onStart();
+                DialogUtil.show(loadingDialog);
+            }
+
+            @Override
+            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
+                super.onSuccessPerfect(statusCode, headers, jsonObject);
+                int code = jsonObject.optInt("code");
+                if (code == 0) {
+                    JSONObject data = jsonObject.optJSONObject("data");
+                    JSONObject link = data.optJSONObject("link");
+                    UserLijinLevelInfoVO userLevel = null;
+                    if (data.optJSONObject("userLevel") != null) {
+                        userLevel = new Gson().fromJson(data.optJSONObject("userLevel").toString(), UserLijinLevelInfoVO.class);
+                    }
+
+                    if (link != null) {
+                        final String linkUrl = link.optString("clickUrl");
+                        GoodsBuyJumpUtil.jumpTB(GoodsDetailActivity.this, null, linkUrl, linkUrl, userLevel, null);
+                    }
+                    String todayLeftCount = data.optString("todayLeftCount");
+                    if (!StringUtils.isNullOrEmpty(todayLeftCount)) {
+                        Toast.makeText(GoodsDetailActivity.this, todayLeftCount, Toast.LENGTH_SHORT).show();
+                    }
+
+
+                } else {
+                    if (code == 2001) {
+                        //鐢ㄦ埛鏈轰細宸茬粡鐢ㄥ畬浜�
+                        getBuyChanceInfoRequest();
+                    } else {
+                        notifyDialog = new GoodsDetailNotifyDialog.Builder(GoodsDetailActivity.this).setMessage(jsonObject.optString("msg")).setOnButtonClickListener(new GoodsDetailNotifyDialog.Builder.IDialogButtonClick() {
+                            @Override
+                            public void onLeftClick() {
+                            }
+
+                            @Override
+                            public void onRightClick() {
+                                DialogUtil.dismiss(notifyDialog);
+                                goFanli();
+                            }
+                        }).create();
+                        DialogUtil.show(notifyDialog);
+                    }
+                }
+            }
+
+            @Override
+            public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
+                super.onFailure(statusCode, headers, jsonObject, e);
+            }
+
+            @Override
+            public void onFinish() {
+                super.onFinish();
+                DialogUtil.dismiss(loadingDialog);
+            }
+        });
+
+    }
+
+    private void fanliRequest(CouponInfo couponInfo) {
+        GoodsBuyUtil.GoodsBuyRequestInfo requestInfo = new GoodsBuyUtil.GoodsBuyRequestInfo();
+        requestInfo.setGoodsId(mInfo.getGoods().getGoodsId());
+        requestInfo.setGoodsType(mInfo.getGoods().getGoodsType());
+        if (couponInfo != null)
+            requestInfo.setCouponLink(couponInfo.getLink());
+        requestInfo.setUid(UserUtil.getUid(getApplicationContext()));
+        requestInfo.setFrom(from);
+
+        //杩斿埄
+        GoodsBuyUtil.fanli(this, getApplicationContext(), requestInfo, new GoodsBuyUtil.IBuyGoodsResultListener() {
+            @Override
+            public void onConvertLinkStart() {
+                DialogUtil.show(loadingDialog);
+            }
+
+            @Override
+            public void onConvertLinkSuccess() {
+                DialogUtil.dismiss(loadingDialog);
+            }
+
+            @Override
+            public void onConvertLinkFail(String msg) {
+                DialogUtil.dismiss(loadingDialog);
+            }
+
+            @Override
+            public void onConvertLinkComplete() {
+                DialogUtil.dismiss(loadingDialog);
+            }
+
+            @Override
+            public void onJumpThirdAppStart() {
+
+            }
+
+            @Override
+            public void onJumpThirdAppSuccess() {
+
+            }
+
+            @Override
+            public void onJumpThirdAppFail() {
+
+            }
+        });
+
+    }
+
+
+    /**
+     * 鑾峰彇璐拱鏈轰細淇℃伅
+     */
+    private void getBuyChanceInfoRequest() {
+        ShoppingApi.getUserLijinCreatedInfo(getApplicationContext(), mInfo.getGoods().getGoodsId(), mInfo.getGoods().getGoodsType(), UserUtil.getUid(getApplicationContext()), new BasicTextHttpResponseHandler() {
+            @Override
+            public void onStart() {
+                super.onStart();
+            }
+
+            @Override
+            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
+                super.onSuccessPerfect(statusCode, headers, jsonObject);
+                if (jsonObject.optInt("code") == 0) {
+                    JSONObject data = jsonObject.optJSONObject("data");
+                    int leftCount = data.optInt("leftCount");
+//                    if (leftCount <= 0) {
+                    JSONObject openInfo = data.optJSONObject("openInfo");
+                    if (openInfo != null) {
+                        showNotifyDialog(openInfo.optString("btnName"), openInfo.optString("vipLink"));
+                    } else {
+                        showNotifyDialog(null, null);
+                    }
+//                    }
+
+
+                } else {
+                    Toast.makeText(GoodsDetailActivity.this, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
+                }
+            }
+
+            @Override
+            public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
+                super.onFailure(statusCode, headers, jsonObject, e);
+                Toast.makeText(GoodsDetailActivity.this, "缃戠粶璇锋眰鍑洪敊", Toast.LENGTH_SHORT).show();
+            }
+
+            @Override
+            public void onFinish() {
+                super.onFinish();
+                DialogUtil.dismiss(loadingDialog);
+            }
+        });
+
+
+    }
+
 }

--
Gitblit v1.8.0