From 3595485efbfeb0db8c0e719e34aac022af284754 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 22 五月 2021 18:14:40 +0800
Subject: [PATCH] 特价完善

---
 app/src/main/java/com/tejia/lijin/app/util/web/RebateJavaInterfaceBS.java |  232 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 200 insertions(+), 32 deletions(-)

diff --git a/app/src/main/java/com/tejia/lijin/app/util/RebateJavaInterface.java b/app/src/main/java/com/tejia/lijin/app/util/web/RebateJavaInterfaceBS.java
similarity index 72%
copy from app/src/main/java/com/tejia/lijin/app/util/RebateJavaInterface.java
copy to app/src/main/java/com/tejia/lijin/app/util/web/RebateJavaInterfaceBS.java
index bba76dd..d33a6c6 100644
--- a/app/src/main/java/com/tejia/lijin/app/util/RebateJavaInterface.java
+++ b/app/src/main/java/com/tejia/lijin/app/util/web/RebateJavaInterfaceBS.java
@@ -1,4 +1,4 @@
-package com.tejia.lijin.app.util;
+package com.tejia.lijin.app.util.web;
 
 import android.Manifest;
 import android.app.Activity;
@@ -12,34 +12,47 @@
 import android.os.Environment;
 import android.os.Handler;
 import android.os.Message;
-import androidx.core.content.ContextCompat;
 import android.util.Log;
+import android.view.Gravity;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.webkit.JavascriptInterface;
 import android.webkit.WebView;
 import android.widget.ImageView;
+import android.widget.LinearLayout;
 import android.widget.TextView;
 import android.widget.Toast;
 
 import com.bumptech.glide.Glide;
+import com.bytedance.sdk.openadsdk.AdSlot;
+import com.bytedance.sdk.openadsdk.TTAdConstant;
+import com.bytedance.sdk.openadsdk.TTAdNative;
+import com.bytedance.sdk.openadsdk.TTAdSdk;
+import com.bytedance.sdk.openadsdk.TTRewardVideoAd;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.reflect.TypeToken;
 import com.kepler.jd.Listener.OpenAppAction;
 import com.kepler.jd.login.KeplerApiManager;
 import com.kepler.jd.sdk.bean.KeplerAttachParameter;
-import com.wpc.library.util.common.StringUtils;
-import com.wpc.library.util.security.MD5Utils;
 import com.tejia.lijin.app.Interface.WebInterface;
+import com.tejia.lijin.app.R;
 import com.tejia.lijin.app.callBack.GeneralBackCallback;
 import com.tejia.lijin.app.callBack.PermissionInterface;
 import com.tejia.lijin.app.entity.ImgText;
 import com.tejia.lijin.app.entity.share.ShareImageEntity;
 import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
 import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
+import com.tejia.lijin.app.util.JumpActivityUtil;
+import com.tejia.lijin.app.util.PermissionHelper;
+import com.tejia.lijin.app.util.ToastUtil;
+import com.tejia.lijin.app.util.Tools;
 import com.tejia.lijin.app.util.baichuan.AlibcTradeUtil;
 import com.tejia.lijin.app.util.share.ShareImageUtil;
 import com.tejia.lijin.app.util.share.ShareTextUtil;
+import com.wpc.library.util.common.DimenUtils;
+import com.wpc.library.util.common.StringUtils;
+import com.wpc.library.util.security.MD5Utils;
 import com.ysh.wpc.appupdate.download.DownLoadFile;
 
 import org.json.JSONArray;
@@ -56,7 +69,10 @@
 import java.util.Iterator;
 import java.util.List;
 
-public class RebateJavaInterface extends BaseRebateJavaInterface implements PermissionInterface {
+import androidx.core.content.ContextCompat;
+import wendu.dsbridge.CompletionHandler;
+
+public class RebateJavaInterfaceBS extends BaseRebateJavaInterfaceBS implements PermissionInterface {
 
     Activity mContext;
     TextView tv_top_bar_middle, tv_top_bar_left2, tv_top_bar_right;
@@ -66,14 +82,14 @@
     private boolean boo = false;
     private PermissionHelper mPermissionsChecker; // 鏉冮檺妫�娴嬪櫒
 
-    public RebateJavaInterface(Activity activity, WebView webview) {
+    public RebateJavaInterfaceBS(Activity activity, WebView webview) {
         super(activity);
         mContext = activity;
         this.webview = webview;
         boo = true;
     }
 
-    public RebateJavaInterface(Activity activity, TextView tv_top_bar_middle
+    public RebateJavaInterfaceBS(Activity activity, TextView tv_top_bar_middle
             , TextView tv_top_bar_left2, TextView tv_top_bar_right
             , ImageView iv_right, WebView webview, ShapeLoadingDialog pd) {
         super(activity);
@@ -87,14 +103,14 @@
     }
 
     @JavascriptInterface
-    public void setTitle(final String title) {
+    public void setTitle(final Object title) {
 //            tv_top_bar_middle.setText(title);
         if (!boo)
             tv_top_bar_middle.post(new Runnable() {
                 @Override
                 public void run() {
-                    if (null != title && !StringUtils.isEmpty(title.trim()))
-                        tv_top_bar_middle.setText(title);
+                    if (null != title && !StringUtils.isEmpty((title + "").trim()))
+                        tv_top_bar_middle.setText(title + "");
                 }
             });
     }
@@ -103,22 +119,21 @@
      * 淇濆瓨缃戠粶鍥剧墖
      *
      * @param url
-     * @param name
      */
     @JavascriptInterface
-    public void savePicture(String url, String name) {
+    public void savePicture(Object url) {
         if (mPermissionsChecker == null)
             mPermissionsChecker = new PermissionHelper(mContext, this);
         if (mPermissionsChecker.lacksPermissions(getPermissions())) { //瀛樺偍鏉冮檺鏈紑鍚�
             mPermissionsChecker.showNormalDialog();
         } else {//瀛樺偍鏉冮檺宸插紑
-            String md5 = MD5Utils.getMD532(url);
+            String md5 = MD5Utils.getMD532(url.toString());
             String path = com.wpc.library.util.Environment.getExternalStorageDirectory()
                     + "/blksapp";
             File file = new File(path + "/" + md5 + ".jpg");
             if (!file.exists()) {
                 try {
-                    File resultFile = Tools.saveImageFromPathToSdCard(mContext, url, path, md5 + ".jpg");
+                    File resultFile = Tools.saveImageFromPathToSdCard(mContext, url.toString(), path, md5 + ".jpg");
                     if (resultFile != null) {
                         Toast.makeText(mContext, "鍥剧墖淇濆瓨鍒扮浉鍐屾垚鍔�", Toast.LENGTH_LONG).show();
                     }
@@ -136,7 +151,7 @@
 
 
     @JavascriptInterface
-    public void savePictures(String urls) {
+    public void savePictures(Object urls) {
         if (mPermissionsChecker == null)
             mPermissionsChecker = new PermissionHelper(mContext, this);
         if (mPermissionsChecker.lacksPermissions(getPermissions())) { //瀛樺偍鏉冮檺鏈紑鍚�
@@ -144,7 +159,7 @@
         } else {//瀛樺偍鏉冮檺宸插紑
             List<String> urlList = new ArrayList<>();
             try {
-                JSONArray array = new JSONArray(urls);
+                JSONArray array = new JSONArray(urls.toString());
                 for (int i = 0; i < array.length(); i++) {
                     urlList.add(array.optString(i));
                 }
@@ -162,7 +177,11 @@
 
 
     @JavascriptInterface
-    public void setTopMenuRightIcon(final String picUrl, final String jsCallback) {
+    public void setTopMenuRightIcon(Object args) throws JSONException {
+        JSONObject json = new JSONObject(args.toString());
+        final String picUrl = json.optString("picUrl");
+        final String jsCallback = json.optString("jsCallback");
+
         if (!boo)
             iv_right.post(new Runnable() {
                 @Override
@@ -181,7 +200,12 @@
     }
 
     @JavascriptInterface
-    public void jumpPageWithFinishCurrentPage(String pageClassName, String paramJson) {
+    public void jumpPageWithFinishCurrentPage(Object args) throws JSONException {
+        JSONObject json = new JSONObject(args.toString());
+        final String pageClassName = json.optString("pageClassName");
+        final String paramJson = json.optString("paramJson");
+
+
         Intent intent = null;
         JSONObject param = null;
         try {
@@ -266,7 +290,11 @@
 
 
     @JavascriptInterface
-    public void setTopMenuRightText(final String text, final String callbackMethod) {
+    public void setTopMenuRightText(Object args) throws JSONException {
+        JSONObject json = new JSONObject(args.toString());
+        final String callbackMethod = json.optString("callbackMethod");
+        final String text = json.optString("text");
+
         if (!boo)
             tv_top_bar_right.post(new Runnable() {
                 @Override
@@ -286,9 +314,9 @@
     public List<ImgText> mList = new ArrayList<>();
 
     @JavascriptInterface
-    public void addMenu(String str) {
+    public void addMenu(Object str) {
         Gson gson = new GsonBuilder().serializeNulls().create();
-        List<ImgText> list = gson.fromJson(str, new TypeToken<List<ImgText>>() {
+        List<ImgText> list = gson.fromJson(str + "", new TypeToken<List<ImgText>>() {
         }.getType());
         if (mList.size() > 0)
             mList.clear();
@@ -303,7 +331,11 @@
 
     //鏂囨湰鍒嗕韩
     @JavascriptInterface
-    public void shareText(int type, String text) {
+    public void shareText(Object args) throws JSONException {
+        JSONObject json = new JSONObject(args.toString());
+        int type = json.optInt("type");
+        final String text = json.optString("text");
+
         if (type == 1) {
             ShareTextUtil.shareWXTextByIntent(mContext, text);
         } else if (type == 2) {
@@ -319,7 +351,12 @@
 
     //鍥剧墖鍒嗕韩  "type":1,//1-寰俊  2-鏈嬪弸鍦�  3-QQ  4-绌洪棿  5-寰崥 6-鏇村
     @JavascriptInterface
-    public void shareImg(int type, final String url) {
+    public void shareImg(Object args) throws JSONException {
+
+        JSONObject json = new JSONObject(args.toString());
+        int type = json.optInt("type");
+        final String url = json.optString("url");
+
         //妫�娴嬫潈闄�
         String[] str = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
                 Manifest.permission.WRITE_EXTERNAL_STORAGE};
@@ -346,11 +383,15 @@
     /**
      * 澶氬浘鍒嗕韩
      *
-     * @param type
-     * @param urls
+     * @param args
      */
     @JavascriptInterface
-    public void shareImgs(int type, final String urls) {
+    public void shareImgs(Object args) throws JSONException {
+        JSONObject json = new JSONObject(args.toString());
+        int type = json.optInt("type");
+        final String urls = json.optString("urls");
+
+
         String[] str = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
                 Manifest.permission.WRITE_EXTERNAL_STORAGE};
         if (lacksPermissions(str)) {//缂哄皯鏉冮檺
@@ -381,10 +422,10 @@
      * @param url
      */
     @JavascriptInterface
-    public void tbAuth(String url) {
-        if (StringUtils.isEmpty(url))
+    public void tbAuth(Object url) {
+        if (StringUtils.isEmpty(url + ""))
             return;
-        AlibcTradeUtil.openAuthLink(mContext, url);
+        AlibcTradeUtil.openAuthLink(mContext, url + "");
     }
 
     /**
@@ -393,10 +434,10 @@
      * @param url
      */
     @JavascriptInterface
-    public void jumpJD(String url) {
-        if (StringUtils.isEmpty(url))
+    public void jumpJD(Object url) {
+        if (StringUtils.isEmpty(url + ""))
             return;
-        KeplerApiManager.getWebViewService().openAppWebViewPage(mContext, url, new KeplerAttachParameter(), new OpenAppAction() {
+        KeplerApiManager.getWebViewService().openAppWebViewPage(mContext, url + "", new KeplerAttachParameter(), new OpenAppAction() {
             @Override
             public void onStatus(final int status, final String url) {
                 mContext.runOnUiThread(new Runnable() {
@@ -421,6 +462,133 @@
         });
     }
 
+
+    private TTRewardVideoAd mttRewardVideoAd;
+
+    @JavascriptInterface
+    public void showAwardAd(Object args, final CompletionHandler handler) throws JSONException {
+        JSONObject json = new JSONObject(args.toString());
+        String type = json.optString("type");
+        final String pid = json.optString("pid");
+        final com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
+
+        webview.post(new Runnable() {
+            @Override
+            public void run() {
+
+                TTAdNative mTTAdNative = TTAdSdk.getAdManager().createAdNative(mContext);
+                AdSlot adSlot = new AdSlot.Builder()
+                        .setCodeId(pid)
+                        .setRewardName("閲戝竵") //濂栧姳鐨勫悕绉� 閫夊~
+                        .setRewardAmount(3)  //濂栧姳鐨勬暟閲� 閫夊~
+//                        .setUserID("tag123")//tag_id
+                        .setMediaExtra("media_extra") //闄勫姞鍙傛暟
+                        .setOrientation(TTAdConstant.VERTICAL) //蹇呭~鍙傛暟锛屾湡鏈涜棰戠殑鎾斁鏂瑰悜锛歍TAdConstant.HORIZONTAL 鎴� TTAdConstant.VERTICAL
+                        .build();
+
+                mTTAdNative.loadRewardVideoAd(adSlot, new TTAdNative.RewardVideoAdListener() {
+                    //璇锋眰骞垮憡澶辫触
+                    @Override
+                    public void onError(int code, String message) {
+                        result.put("code", 1);
+                        result.put("msg", message);
+                        handler.complete(result);
+                    }
+
+                    //瑙嗛骞垮憡鍔犺浇鍚庯紝瑙嗛璧勬簮缂撳瓨鍒版湰鍦扮殑鍥炶皟锛屽湪姝ゅ洖璋冨悗锛屾挱鏀炬湰鍦拌棰戯紝娴佺晠涓嶉樆濉炪��
+                    @Override
+                    public void onRewardVideoCached() {
+                        //寮�鍙戣�呭仛涓�涓爣璇�
+                        if (mttRewardVideoAd != null) {
+                            mttRewardVideoAd.showRewardVideoAd(mContext, TTAdConstant.RitScenes.CUSTOMIZE_SCENES, "scenes_test");
+                            mttRewardVideoAd = null;
+                        }
+                    }
+
+                    //瑙嗛骞垮憡鐨勭礌鏉愬姞杞藉畬姣曪紝姣斿瑙嗛url绛夛紝鍦ㄦ鍥炶皟鍚庯紝鍙互鎾斁鍦ㄧ嚎瑙嗛锛岀綉缁滀笉濂藉彲鑳藉嚭鐜板姞杞界紦鍐诧紝褰卞搷浣撻獙銆�
+                    @Override
+                    public void onRewardVideoAdLoad(TTRewardVideoAd ad) {
+                        //寮�鍙戣�呭仛涓�涓爣璇�
+                        mttRewardVideoAd = ad;
+                        mttRewardVideoAd.setRewardAdInteractionListener(new TTRewardVideoAd.RewardAdInteractionListener() {
+                            @Override
+                            public void onAdShow() {
+
+                            }
+
+                            @Override
+                            public void onAdVideoBarClick() {
+
+                            }
+
+                            @Override
+                            public void onAdClose() {
+
+                            }
+
+                            @Override
+                            public void onVideoComplete() {
+
+                            }
+
+                            @Override
+                            public void onVideoError() {
+                                result.put("code", 2);
+                                result.put("msg", "瑙嗛鍑洪敊");
+                                handler.complete(result);
+                            }
+
+                            @Override
+                            public void onRewardVerify(boolean b, int i, String s, int i1, String s1) {
+                                result.put("code", 0);
+                                result.put("msg", "骞垮憡灞曠ず瀹屾垚");
+                                handler.complete(result);
+                            }
+
+                            @Override
+                            public void onSkippedVideo() {
+
+                            }
+                        });
+                    }
+                });
+
+            }
+        });
+
+    }
+
+
+    @JavascriptInterface
+    public void toastAwardSuccess(final Object msg) {
+
+        webview.post(new Runnable() {
+            @Override
+            public void run() {
+                View view = LayoutInflater.from(mContext).inflate(R.layout.item_reward_ad_success, null);
+                TextView tv_content = view.findViewById(R.id.tv_content);
+                tv_content.setText(msg + "");
+                ToastUtil.showToast(view, view.getContext(), Toast.LENGTH_SHORT, Gravity.CENTER);
+            }
+        });
+    }
+
+    @JavascriptInterface
+    public void toastAwardFail(final Object msg) {
+        webview.post(new Runnable() {
+            @Override
+            public void run() {
+                View view = LayoutInflater.from(mContext).inflate(R.layout.item_reward_ad_fail, null);
+                LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(DimenUtils.getScreenWidth(mContext)*4/5,LinearLayout.LayoutParams.WRAP_CONTENT);
+                view.setLayoutParams(params);
+                TextView tv_content = view.findViewById(R.id.tv_content);
+                tv_content.setText(msg + "");
+                ToastUtil.showToast(view, view.getContext(), Toast.LENGTH_SHORT, Gravity.CENTER);
+            }
+        });
+    }
+
+
     int type;
     String imgurl;
     Handler handler = new Handler() {

--
Gitblit v1.8.0