ソースを参照

增加链接下载功能,发布2.1.9版本,版本号45

xieshengqi 5 年 前
コミット
d8a0522598

+ 6 - 2
app/build.gradle

@@ -215,14 +215,18 @@ dependencies {
215 215
     implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.6'
216 216
 
217 217
 
218
-
219 218
     implementation 'com.alibaba:fastjson:1.2.54'
220 219
     implementation 'com.alibaba:fastjson:1.1.70.android'
221
- implementation 'com.android.support:multidex:1.0.0'
220
+    implementation 'com.android.support:multidex:1.0.0'
222 221
 
223 222
     //数据库依赖
224 223
     implementation 'org.greenrobot:greendao-generator:3.2.2'
225 224
     implementation 'org.greenrobot:greendao:3.2.2'
226 225
     implementation 'com.github.yuweiguocn:GreenDaoUpgradeHelper:v2.0.2'
226
+//下载工具类
227
+    implementation 'com.allenliu.versionchecklib:library:2.2.0'
228
+
229
+    implementation 'com.liulishuo.filedownloader:library:1.7.6'
230
+
227 231
 
228 232
 }

+ 9 - 1
app/proguard-rules.pro

@@ -468,4 +468,12 @@ public static java.lang.String TABLENAME;
468 468
 -keep class com.huawei.updatesdk.**{*;}
469 469
 -keep class com.huawei.hms.**{*;}
470 470
 
471
--keep class com.huawei.android.hms.agent.**{*;}
471
+-keep class com.huawei.android.hms.agent.**{*;}
472
+
473
+
474
+#下载工具类
475
+-keepattributes Annotation
476
+   -keepclassmembers class * {    @org.greenrobot.eventbus.Subscribe ;}
477
+   -keep enum org.greenrobot.eventbus.ThreadMode { *; }
478
+   -keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {    (java.lang.Throwable);}
479
+   -keep class com.allenliu.versionchecklib.**{*;}

+ 41 - 32
app/src/main/java/com/kuxuan/moneynote/SplashActivity.java

@@ -134,30 +134,39 @@ public class SplashActivity extends FragmentActivity implements WeakHandler.IHan
134 134
             getChannleStatus(false);
135 135
             goToMainActivity();
136 136
         } else {
137
-            //step2:创建TTAdNative对象
138
-            mTTAdNative = TTAdManagerHolder.get().createAdNative(this);
139
-            //在合适的时机申请权限,如read_phone_state,防止获取不了imei时候,下载类广告没有填充的问题
140
-            //在开屏时候申请不太合适,因为该页面倒计时结束或者请求超时会跳转,在该页面申请权限,体验不好
141
-            // TTAdManagerHolder.getInstance(this).requestPermissionIfNecessary(this);
137
+
138
+
142 139
             if (LoginStatusUtil.isLoginin()) {
143 140
                 sendData();
144 141
             }
145 142
 //            boolean isAD = (boolean) SPUtil.get(this, Constant.System.SWITCH_AD, false);
143
+//            isAD = true;
146 144
 //            if (isAD) {
147
-//                //加载开屏广告
145
+            //加载穿山甲开屏广告
146
+            //step2:创建TTAdNative对象
147
+            mTTAdNative = TTAdManagerHolder.get().createAdNative(this);
148
+            //在合适的时机申请权限,如read_phone_state,防止获取不了imei时候,下载类广告没有填充的问题
149
+            //在开屏时候申请不太合适,因为该页面倒计时结束或者请求超时会跳转,在该页面申请权限,体验不好
150
+            // TTAdManagerHolder.getInstance(this).requestPermissionIfNecessary(this);
151
+            loadSplashAd();
148 152
 //            } else {
149 153
 //                //加载自己的广告
150
-//
154
+//                loadLocationAd();
151 155
 //            }
152
-            loadSplashAd();
156
+//
153 157
             getChannleStatus(false);
154 158
 
155 159
         }
156 160
     }
157 161
 
158
-    private void loadLocationAd(){
159
-        String imageurl = (String) SPUtil.get(this,Constant.System.IMAGE_URL,"");
160
-        Glide.with(this).load(imageurl).into(new SimpleTarget<GlideDrawable>() {
162
+    /**
163
+     * 加载自己的广告
164
+     */
165
+    private void loadLocationAd() {
166
+        //获取保存的url
167
+        String imageUrl = (String) SPUtil.get(this, Constant.System.IMAGE_URL, "");
168
+        final String linkUrl = (String) SPUtil.get(this, Constant.System.LINK_URL, "");
169
+        Glide.with(this).load(imageUrl).into(new SimpleTarget<GlideDrawable>() {
161 170
             @Override
162 171
             public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
163 172
                 //加载完成后的处理
@@ -168,7 +177,6 @@ public class SplashActivity extends FragmentActivity implements WeakHandler.IHan
168 177
                 //把SplashView 添加到ViewGroup中,注意开屏广告view:width >=70%屏幕宽;height >=50%屏幕宽
169 178
                 ImageView imageView = (ImageView) getImageView(resource);
170 179
                 mSplashContainer.addView(imageView);
171
-
172 180
 //添加一个自定义倒计时功能
173 181
                 mSplashContainer.addView(getCountTimeView());
174 182
                 imageView.setOnClickListener(new View.OnClickListener() {
@@ -177,20 +185,20 @@ public class SplashActivity extends FragmentActivity implements WeakHandler.IHan
177 185
                         //跳转链接
178 186
                         isClickAd = true;
179 187
                         Intent intent = new Intent(SplashActivity.this, WebviewActivity.class);
180
-                        intent.putExtra(WebviewActivity.TITLE,"ceshi");
181
-                        intent.putExtra(WebviewActivity.URL,"https://www.baidu.com");
188
+                        intent.putExtra(WebviewActivity.TITLE, "广告");
189
+                        intent.putExtra(WebviewActivity.URL, linkUrl);
182 190
                         startActivity(intent);
183 191
 
184 192
                     }
185 193
                 });
186 194
             }
187
-        } );
195
+        });
188 196
 
189
-}
197
+    }
190 198
 
191 199
     private View getImageView(GlideDrawable resource) {
192 200
         ImageView imageView = new ImageView(this);
193
-        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,FrameLayout.LayoutParams.MATCH_PARENT);
201
+        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.MATCH_PARENT);
194 202
         imageView.setScaleType(ImageView.ScaleType.FIT_XY);
195 203
         imageView.setLayoutParams(layoutParams);
196 204
         imageView.setImageDrawable(resource);
@@ -276,9 +284,9 @@ public class SplashActivity extends FragmentActivity implements WeakHandler.IHan
276 284
         RetrofitClient.getApiService().getAdstatus().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new MyObsever<BaseJson<AdStatus>>() {
277 285
             @Override
278 286
             public void onError(ExceptionHandle.ResponeThrowable e) {
279
-if(isGomain){
280
-    goToMainActivity();
281
-}
287
+                if (isGomain) {
288
+                    goToMainActivity();
289
+                }
282 290
             }
283 291
 
284 292
             @Override
@@ -287,7 +295,7 @@ if(isGomain){
287 295
                     if (!SplashActivity.this.isFinishing())
288 296
                         AdStatusManager.getInstance(SplashActivity.this).setAdStatus(adStatusBaseJson.getData());
289 297
                 }
290
-                if(isGomain){
298
+                if (isGomain) {
291 299
                     goToMainActivity();
292 300
                 }
293 301
             }
@@ -309,7 +317,7 @@ if(isGomain){
309 317
     @Override
310 318
     protected void onStop() {
311 319
         super.onStop();
312
-        Log.e("splashActivity","stop");
320
+        Log.e("splashActivity", "stop");
313 321
         mForceGoMain = true;
314 322
     }
315 323
 
@@ -370,10 +378,10 @@ if(isGomain){
370 378
                         Log.e(TAG, "onAdClicked");
371 379
 //                        showToast("开屏广告点击");
372 380
 //                        goToMainActivity();
373
-                        if(ad.getInteractionType() == TTAdConstant.INTERACTION_TYPE_DOWNLOAD){
381
+                        if (ad.getInteractionType() == TTAdConstant.INTERACTION_TYPE_DOWNLOAD) {
374 382
                             //下载类广告直接不处理
375 383
                             isClickAd = false;
376
-                        }else{
384
+                        } else {
377 385
                             isClickAd = true;
378 386
                         }
379 387
 
@@ -407,6 +415,7 @@ if(isGomain){
407 415
 
408 416
     /**
409 417
      * 自定义倒计时
418
+     *
410 419
      * @return
411 420
      */
412 421
     private View getCountTimeView() {
@@ -428,10 +437,10 @@ if(isGomain){
428 437
         CountDownTimer countDownTimer = new CountDownTimer(4000, 1000) {
429 438
             @Override
430 439
             public void onTick(long millisUntilFinished) {
431
-                Log.e("millisUntilFinished",millisUntilFinished+"");
440
+                Log.e("millisUntilFinished", millisUntilFinished + "");
432 441
                 tv_count.setText(millisUntilFinished / 1000 + "s");
433
-                if(millisUntilFinished / 1000==1){
434
-                    if(!isClickAd&&!SplashActivity.this.isFinishing())
442
+                if (millisUntilFinished / 1000 == 1) {
443
+                    if (!isClickAd && !SplashActivity.this.isFinishing())
435 444
                         goToMainActivity();
436 445
                 }
437 446
 
@@ -440,7 +449,7 @@ if(isGomain){
440 449
 
441 450
             @Override
442 451
             public void onFinish() {
443
-                Log.e("millisUntilFinished","onFinish");
452
+                Log.e("millisUntilFinished", "onFinish");
444 453
 
445 454
             }
446 455
         };
@@ -472,7 +481,6 @@ if(isGomain){
472 481
     }
473 482
 
474 483
 
475
-
476 484
     private void showToast(String msg) {
477 485
         TToast.show(this, msg);
478 486
     }
@@ -496,7 +504,8 @@ if(isGomain){
496 504
             initDB(true);
497 505
         }
498 506
     }
499
-//private  long time = 0;
507
+
508
+    //private  long time = 0;
500 509
     private void initDB(final boolean goMain) {
501 510
 //        time = System.currentTimeMillis();
502 511
         //首次进去添加类别数据库
@@ -582,7 +591,7 @@ if(isGomain){
582 591
         BillCategoreDaoOperator billCategoreDaoOperator = BillCategoreDaoOperator.newInstance();
583 592
         boolean haveData = billCategoreDaoOperator.isHaveData();
584 593
         if (haveData) {
585
-Log.e("BillCategoreDaoOperator","have");
594
+            Log.e("BillCategoreDaoOperator", "have");
586 595
         } else {
587 596
             String json = Tools.getJson("categore.txt", getApplicationContext());
588 597
 
@@ -687,7 +696,7 @@ Log.e("BillCategoreDaoOperator","have");
687 696
     @Override
688 697
     public void onPause() {
689 698
         super.onPause();
690
-        Log.e("onPause","onPause");
699
+        Log.e("onPause", "onPause");
691 700
         MobclickAgent.onPause(this);
692 701
     }
693 702
 }

+ 8 - 0
app/src/main/java/com/kuxuan/moneynote/api/ApiService.java

@@ -31,6 +31,7 @@ import com.kuxuan.moneynote.json.UploadBeanJson;
31 31
 import com.kuxuan.moneynote.json.UserAllBillJson;
32 32
 import com.kuxuan.moneynote.json.UserCoinJson;
33 33
 import com.kuxuan.moneynote.json.UserJson;
34
+import com.kuxuan.moneynote.json.netbody.ADBody;
34 35
 import com.kuxuan.moneynote.json.netbody.Acticlebody;
35 36
 import com.kuxuan.moneynote.json.netbody.AliBody;
36 37
 import com.kuxuan.moneynote.json.netbody.AllCategoryBody;
@@ -766,6 +767,13 @@ public interface ApiService {
766 767
     @POST("V3/uploadUserPushToken")
767 768
     Observable<BaseJson<Object>> uploadUserPushToken(@Body PushTokenBody body);
768 769
 
770
+    /**
771
+     * 获取广告
772
+     * @return
773
+     */
774
+    @POST("Advert/V1/getAdvert")
775
+    Observable<Object> getAdvert(@Body ADBody aDbody);
776
+
769 777
 }
770 778
 
771 779
 

+ 47 - 0
app/src/main/java/com/kuxuan/moneynote/api/MyOkClient.java

@@ -17,6 +17,53 @@ import okhttp3.logging.HttpLoggingInterceptor;
17 17
 public class MyOkClient {
18 18
     static OkHttpClient client;
19 19
     static OkHttpClient tokenclient;
20
+    static OkHttpClient adClient;
21
+
22
+
23
+    @NonNull
24
+    public static OkHttpClient getAdClient() {
25
+        if (adClient != null) {
26
+            return adClient;
27
+        }
28
+        OkHttpClient.Builder builder = new OkHttpClient.Builder();
29
+//        if (AppConstants.sDebug) {
30
+        // Log信息拦截器
31
+        //          HttpLoggingInterceptor loggingInterceptorhead = new HttpLoggingInterceptor();
32
+        //          loggingInterceptorhead.setLevel(HttpLoggingInterceptor.Level.BODY);
33
+//            MyHttpLoggingInterceptor loggingInterceptorhead = new MyHttpLoggingInterceptor();
34
+//        if(AppConstants.sDebug){
35
+        CustormInterceptor loggingInterceptorhead = new CustormInterceptor();
36
+        loggingInterceptorhead.setLevel(CustormInterceptor.Level.BODY);
37
+        builder.addInterceptor(loggingInterceptorhead);
38
+//        }
39
+        builder.addInterceptor(new QueryParameterInterceptor());
40
+        builder.addInterceptor(new TokenInterceptor());
41
+//        }
42
+        //设置cookie
43
+        CookieManager cookieManager = new CookieManager();
44
+        cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
45
+        builder.cookieJar(new JavaNetCookieJar(cookieManager));
46
+        //公共参数
47
+//        builder.addInterceptor(new QueryParameterInterceptor());
48
+        //Gzip压缩
49
+//        builder.addInterceptor(new GzipRequestInterceptor());
50
+        //开启缓存
51
+//        File cacheFile = new File(RockContextUtils.getApplicationContext().getExternalCacheDir(), "appCache");
52
+//        Cache cache = new Cache(cacheFile, 1024 * 1024 * 30);
53
+//        builder.cache(cache).addInterceptor(new CacheInterceptor());
54
+        //开启facebook sDebug
55
+//        builder.addNetworkInterceptor(new StethoInterceptor());
56
+        //设置超时
57
+        builder.connectTimeout(50, TimeUnit.SECONDS);
58
+        builder.readTimeout(50, TimeUnit.SECONDS);
59
+        builder.writeTimeout(50, TimeUnit.SECONDS);
60
+        //错误重连
61
+        builder.retryOnConnectionFailure(false);
62
+        adClient = builder.build();
63
+        return adClient;
64
+    }
65
+
66
+
20 67
 
21 68
     @NonNull
22 69
     public static OkHttpClient getOkHttpClient() {

+ 21 - 0
app/src/main/java/com/kuxuan/moneynote/api/RetrofitClient.java

@@ -29,11 +29,26 @@ public class RetrofitClient {
29 29
                 .build();
30 30
     }
31 31
 
32
+    /**
33
+     * 广告ad
34
+     * @return
35
+     */
36
+    public static Retrofit getAdRetrofit(){
37
+        Gson gson = MyGson.get();
38
+        OkHttpClient client = MyOkClient.getOkHttpClient();
39
+        return new Retrofit.Builder().baseUrl("http://ads.726p.com/api/")
40
+                .addConverterFactory(GsonConverterFactory.create(gson))
41
+                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
42
+                .client(client)
43
+                .build();
44
+    }
45
+
32 46
     public static <T> T createApi(Class<T> clazz, Retrofit retrofit) {
33 47
         return retrofit.create(clazz);
34 48
     }
35 49
 
36 50
     private static ApiService mCCApiService;
51
+    private static ApiService mAdApiService;
37 52
 
38 53
     public static ApiService getApiService() {
39 54
         if (mCCApiService == null) {
@@ -41,6 +56,12 @@ public class RetrofitClient {
41 56
         }
42 57
         return mCCApiService;
43 58
     }
59
+    public static ApiService getAdApiService() {
60
+        if (mAdApiService == null) {
61
+            mAdApiService = createApi(ApiService.class, getAdRetrofit());
62
+        }
63
+        return mAdApiService;
64
+    }
44 65
 
45 66
     /**
46 67
      * 文件body

+ 12 - 5
app/src/main/java/com/kuxuan/moneynote/common/Constant.java

@@ -16,6 +16,7 @@ public class Constant {
16 16
 //    public static final String BASE_URL = "http://develop.money.726p.com/api/";
17 17
     //线上环境
18 18
     public static final String BASE_URL = "https://accountapi.726p.com/api/";
19
+//    public static final String BASE_URL = "http://47.93.190.105:2796/api/";
19 20
     //获取token必须使用这个url
20 21
     public static final String TOKEN_BASE_URL = "https://apimoney.726p.com/api/";
21 22
     public static final String MD5 = "b4b80c2676828f1df375684100f56d48";
@@ -54,9 +55,11 @@ public class Constant {
54 55
         //任务列表引导页
55 56
         public static final String SWITCH_GOLD = "switch_gold";
56 57
         //广告展示
57
-        public static final String SWITCH_AD="switch_ad";
58
-        //自己的广告url
59
-        public static final String IMAGE_URL="image_url_ad";
58
+        public static final String SWITCH_AD = "switch_ad";
59
+        //自己的广告的图片url
60
+        public static final String IMAGE_URL = "image_url_ad";
61
+        //自己广告的跳转链接
62
+        public static final String LINK_URL = "link_url_ad";
60 63
         //默认预算
61 64
         public static final long NORMAL_NUM = 3000;
62 65
         public static final String CURRENT_YEAR = "current_year";
@@ -69,8 +72,8 @@ public class Constant {
69 72
 
70 73
         //当前缓存的金币数量
71 74
         public static final String CURRENT_GOLD = "current_gold";
72
-//首页打开设置
73
-        public static final String SWITCH_SETTING ="switch_setting" ;
75
+        //首页打开设置
76
+        public static final String SWITCH_SETTING = "switch_setting";
74 77
     }
75 78
 
76 79
     /**
@@ -251,4 +254,8 @@ public class Constant {
251 254
         public static final String PUSH_OPPO_NOTICEOPEN = "push_oppo_notice_open";
252 255
     }
253 256
 
257
+    public static class Download {
258
+        public static final String IS_DOWN = "is_down";
259
+    }
260
+
254 261
 }

+ 18 - 0
app/src/main/java/com/kuxuan/moneynote/json/GameGoldInfo.java

@@ -23,6 +23,24 @@ public class GameGoldInfo {
23 23
     private String desc;
24 24
     private String button;
25 25
     private int top;
26
+    private int link_type;
27
+    private String apk_name;
28
+
29
+    public String getApk_name() {
30
+        return apk_name;
31
+    }
32
+
33
+    public void setApk_name(String apk_name) {
34
+        this.apk_name = apk_name;
35
+    }
36
+
37
+    public int getLink_type() {
38
+        return link_type;
39
+    }
40
+
41
+    public void setLink_type(int link_type) {
42
+        this.link_type = link_type;
43
+    }
26 44
 
27 45
     public String getUrl() {
28 46
         if(id!=null&&!id.equals("")){

+ 14 - 0
app/src/main/java/com/kuxuan/moneynote/json/netbody/ADBody.java

@@ -0,0 +1,14 @@
1
+package com.kuxuan.moneynote.json.netbody;
2
+
3
+/**
4
+ * create by ${xieshengqi}
5
+ * create time 2019-08-20
6
+ */
7
+public class ADBody {
8
+
9
+    private String space_sign;
10
+
11
+    public ADBody(String space_sign) {
12
+        this.space_sign = space_sign;
13
+    }
14
+}

+ 76 - 32
app/src/main/java/com/kuxuan/moneynote/ui/activitys/MainActivity.java

@@ -28,6 +28,8 @@ import android.widget.RelativeLayout;
28 28
 import android.widget.TextView;
29 29
 import android.widget.Toast;
30 30
 
31
+import com.allenliu.versionchecklib.callback.APKDownloadListener;
32
+import com.allenliu.versionchecklib.v2.callback.ForceUpdateListener;
31 33
 import com.androidquery.callback.AQuery2;
32 34
 import com.androidquery.callback.AjaxStatus;
33 35
 import com.androidquery.callback.BitmapAjaxCallback;
@@ -44,6 +46,7 @@ import com.bytedance.sdk.openadsdk.TTImage;
44 46
 import com.bytedance.sdk.openadsdk.TTNativeAd;
45 47
 
46 48
 import com.coloros.mcssdk.PushManager;
49
+import com.google.gson.Gson;
47 50
 import com.huawei.android.hms.agent.HMSAgent;
48 51
 import com.huawei.android.hms.agent.common.handler.ConnectHandler;
49 52
 import com.huawei.android.hms.agent.push.handler.GetTokenHandler;
@@ -54,8 +57,11 @@ import com.kuxuan.moneynote.SplashActivity;
54 57
 import com.kuxuan.moneynote.ad.ADConstants;
55 58
 import com.kuxuan.moneynote.ad.AdDialog;
56 59
 import com.kuxuan.moneynote.ad.TTAdManagerHolder;
60
+import com.kuxuan.moneynote.api.ApiService;
57 61
 import com.kuxuan.moneynote.api.ExceptionHandle;
62
+import com.kuxuan.moneynote.api.MyGson;
58 63
 import com.kuxuan.moneynote.api.MyObsever;
64
+import com.kuxuan.moneynote.api.MyOkClient;
59 65
 import com.kuxuan.moneynote.api.RetrofitClient;
60 66
 import com.kuxuan.moneynote.base.BaseFragmentActivity;
61 67
 import com.kuxuan.moneynote.common.Constant;
@@ -66,6 +72,7 @@ import com.kuxuan.moneynote.json.BaseJson;
66 72
 import com.kuxuan.moneynote.json.GlodJson;
67 73
 import com.kuxuan.moneynote.json.UploadBeanJson;
68 74
 import com.kuxuan.moneynote.json.UploadDbjson;
75
+import com.kuxuan.moneynote.json.netbody.ADBody;
69 76
 import com.kuxuan.moneynote.json.netbody.GlodBody;
70 77
 import com.kuxuan.moneynote.json.netbody.GoldHaveBody;
71 78
 import com.kuxuan.moneynote.listener.OnAdDialogClickListener;
@@ -93,8 +100,10 @@ import com.kuxuan.moneynote.ui.weight.CustormDialog;
93 100
 import com.kuxuan.moneynote.ui.weight.NavigationLayout;
94 101
 import com.kuxuan.moneynote.utils.ButtonUtils;
95 102
 import com.kuxuan.moneynote.utils.DisplayUtil;
103
+import com.kuxuan.moneynote.utils.DownLoadManager;
96 104
 import com.kuxuan.moneynote.utils.DrawableUtil;
97 105
 import com.kuxuan.moneynote.utils.LoginStatusUtil;
106
+import com.kuxuan.moneynote.utils.MyNotificationUtils;
98 107
 import com.kuxuan.moneynote.utils.NetWorkUtil;
99 108
 import com.kuxuan.moneynote.utils.PhoneUtil;
100 109
 import com.kuxuan.moneynote.utils.SPUtil;
@@ -111,6 +120,7 @@ import org.greenrobot.eventbus.EventBus;
111 120
 import org.greenrobot.eventbus.Subscribe;
112 121
 import org.greenrobot.eventbus.ThreadMode;
113 122
 
123
+import java.io.File;
114 124
 import java.util.ArrayList;
115 125
 import java.util.List;
116 126
 
@@ -122,6 +132,10 @@ import io.reactivex.Observer;
122 132
 import io.reactivex.android.schedulers.AndroidSchedulers;
123 133
 import io.reactivex.disposables.Disposable;
124 134
 import io.reactivex.schedulers.Schedulers;
135
+import okhttp3.OkHttpClient;
136
+import retrofit2.Retrofit;
137
+import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
138
+import retrofit2.converter.gson.GsonConverterFactory;
125 139
 import social.milin.tech.mylove.DetailActivity;
126 140
 import social.milin.tech.mylove.utils.MyDialog;
127 141
 
@@ -145,7 +159,8 @@ public class MainActivity extends BaseFragmentActivity implements MineFragment.o
145 159
         super.onPause();
146 160
     }
147 161
 
148
-    private long time=0;
162
+    private long time = 0;
163
+
149 164
     @Override
150 165
     protected void onCreate(Bundle savedInstanceState) {
151 166
         super.onCreate(savedInstanceState);
@@ -182,40 +197,68 @@ public class MainActivity extends BaseFragmentActivity implements MineFragment.o
182 197
             });
183 198
         }
184 199
         GoldManager.getInstance().getUserCoin();
185
-//        Log.e("时间差",System.currentTimeMillis()-time+"");
200
+//        getSplashAd();
201
+    }
202
+
203
+    /**
204
+     * 获取开屏广告
205
+     */
206
+    private void getSplashAd() {
207
+//        final Gson gson = MyGson.get();
208
+//        OkHttpClient client = MyOkClient.getAdClient();
209
+//        Retrofit retrofit = new Retrofit.Builder().baseUrl("http://ads.726p.com/api/")
210
+//                .addConverterFactory(GsonConverterFactory.create(gson))
211
+//                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
212
+//                .client(client)
213
+//                .build();
214
+//        ApiService apiService = retrofit.create(ApiService.class);
215
+       RetrofitClient.getAdApiService().getAdvert(new ADBody("22")).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new MyObsever<Object>() {
216
+            @Override
217
+            public void onError(ExceptionHandle.ResponeThrowable e) {
218
+
219
+
220
+            }
221
+
222
+            @Override
223
+            public void onSuccess(Object o) {
224
+
225
+            }
226
+        });
227
+
186 228
     }
187 229
 
188 230
     /**
189 231
      * 打开oppo消息通知设置
190 232
      */
191
-    private void openNoticeSetting(){
192
-       boolean isOpen = (boolean) SPUtil.get(this, Constant.Push.PUSH_OPPO_NOTICEOPEN,false);
193
-       if(!isOpen){
194
-           boolean isOpenSetting = (boolean) SPUtil.get(this,Constant.System.SWITCH_SETTING,false);
195
-           if(isOpenSetting){
196
-               return;
197
-           }
198
-           SPUtil.putAndApply(this,Constant.System.SWITCH_SETTING,true);
233
+    private void openNoticeSetting() {
234
+        boolean isOpen = (boolean) SPUtil.get(this, Constant.Push.PUSH_OPPO_NOTICEOPEN, false);
235
+        if (!isOpen) {
236
+            boolean isOpenSetting = (boolean) SPUtil.get(this, Constant.System.SWITCH_SETTING, false);
237
+            if (isOpenSetting) {
238
+                return;
239
+            }
240
+            SPUtil.putAndApply(this, Constant.System.SWITCH_SETTING, true);
199 241
             CustormDialog custormDialog = new CustormDialog(this).builder().setTitle("提示").setMsg("请打开通知栏通知,方便接收消息提示").setNegativeButton("取消", new View.OnClickListener() {
200
-               @Override
201
-               public void onClick(View view) {
202
-
203
-               }
204
-           }).setPositiveButton("去设置", new View.OnClickListener() {
205
-               @Override
206
-               public void onClick(View view) {
207
-                   try {
208
-                       //防止出现没注册成功的时候,会抛出异常
209
-                   PushManager.getInstance().openNotificationSettings();
210
-                   }catch (Exception e){
211
-                   }
212
-               }
213
-           }).setCancelable(false);
242
+                @Override
243
+                public void onClick(View view) {
244
+
245
+                }
246
+            }).setPositiveButton("去设置", new View.OnClickListener() {
247
+                @Override
248
+                public void onClick(View view) {
249
+                    try {
250
+                        //防止出现没注册成功的时候,会抛出异常
251
+                        PushManager.getInstance().openNotificationSettings();
252
+                    } catch (Exception e) {
253
+                    }
254
+                }
255
+            }).setCancelable(false);
214 256
             custormDialog.show();
215 257
 
216
-       }
258
+        }
217 259
 
218 260
     }
261
+
219 262
     /**
220 263
      * 开启推送,如果是华为需要连接
221 264
      */
@@ -235,7 +278,7 @@ public class MainActivity extends BaseFragmentActivity implements MineFragment.o
235 278
 //        }
236 279
         if (PhoneUtil.isEmui()) {
237 280
             startHuaweiPush();
238
-        }else if(PhoneUtil.isOppo()){
281
+        } else if (PhoneUtil.isOppo()) {
239 282
             openNoticeSetting();
240 283
         }
241 284
     }
@@ -273,6 +316,7 @@ public class MainActivity extends BaseFragmentActivity implements MineFragment.o
273 316
 
274 317
         });
275 318
     }
319
+
276 320
     Controller show;
277 321
 
278 322
     //初始化蒙版
@@ -617,7 +661,7 @@ public class MainActivity extends BaseFragmentActivity implements MineFragment.o
617 661
      * @param coin
618 662
      */
619 663
     public void updataGoldForNet(final int type, final String advert_id, final String coin) {
620
-        GoldManager.getInstance().getGoldForNet(MainActivity.this,type, advert_id, new OnGoldGetListener() {
664
+        GoldManager.getInstance().getGoldForNet(MainActivity.this, type, advert_id, new OnGoldGetListener() {
621 665
             @Override
622 666
             public void onGetSuccess(String coins) {
623 667
                 showDialogForGold(coins);
@@ -725,12 +769,12 @@ public class MainActivity extends BaseFragmentActivity implements MineFragment.o
725 769
                 MobclickAgent.onEvent(this, "tab_cashCheckIn");
726 770
                 fragment = mFragmensts[2];
727 771
                 if (fragment == null) {
728
-//                    boolean isOpen = (boolean) SPUtil.get(MainActivity.this, Constant.ChannelStatus.STATUS, false);
729
-//                    if (isOpen) {
730
-//                        mFragmensts[2] = new FindFragment();
731
-//                    } else {
772
+                    boolean isOpen = (boolean) SPUtil.get(MainActivity.this, Constant.ChannelStatus.STATUS, false);
773
+                    if (isOpen) {
774
+                        mFragmensts[2] = new FindFragment();
775
+                    } else {
732 776
                     mFragmensts[2] = new NewsFindFragment();
733
-//                    }
777
+                    }
734 778
 
735 779
 //                    mFragmensts[2] = new ReportSingleFragment();
736 780
                     getSupportFragmentManager().beginTransaction().add(R.id.activity_main_content, mFragmensts[2]).commitAllowingStateLoss();

+ 157 - 36
app/src/main/java/com/kuxuan/moneynote/ui/fragments/MoneyTaskFragmentActivity.java

@@ -9,6 +9,7 @@ import android.graphics.drawable.GradientDrawable;
9 9
 import android.net.Uri;
10 10
 import android.os.Build;
11 11
 import android.os.Bundle;
12
+import android.os.Environment;
12 13
 import android.util.Log;
13 14
 import android.view.KeyEvent;
14 15
 import android.view.View;
@@ -25,6 +26,7 @@ import android.widget.FrameLayout;
25 26
 import android.widget.ImageView;
26 27
 import android.widget.LinearLayout;
27 28
 import android.widget.RelativeLayout;
29
+import android.widget.ScrollView;
28 30
 import android.widget.TextView;
29 31
 import android.widget.Toast;
30 32
 
@@ -72,10 +74,14 @@ import com.kuxuan.moneynote.ui.activitys.login.PhoneLoginActivity;
72 74
 import com.kuxuan.moneynote.ui.activitys.news.NewsWebActivity;
73 75
 import com.kuxuan.moneynote.ui.activitys.news.ScrollWebview;
74 76
 import com.kuxuan.moneynote.ui.activitys.wallet.WalletActivity;
77
+import com.kuxuan.moneynote.utils.DownLoadManager;
75 78
 import com.kuxuan.moneynote.utils.DrawableUtil;
76 79
 import com.kuxuan.moneynote.utils.LoginStatusUtil;
77 80
 import com.kuxuan.moneynote.utils.SPUtil;
78 81
 import com.kuxuan.moneynote.utils.UIHelper;
82
+import com.liulishuo.filedownloader.BaseDownloadTask;
83
+import com.liulishuo.filedownloader.FileDownloadListener;
84
+import com.liulishuo.filedownloader.FileDownloader;
79 85
 import com.umeng.analytics.MobclickAgent;
80 86
 
81 87
 import net.qiujuer.genius.ui.Ui;
@@ -100,10 +106,14 @@ import io.reactivex.schedulers.Schedulers;
100 106
 public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
101 107
     @Bind(R.id.fragment_moneytask_webview)
102 108
     WebView mWebview;
109
+    @Bind(R.id.fragment_moneytask_third_webview)
110
+    WebView mWebview_third;
103 111
     @Bind(R.id.fragment_moneytask_ad_layout)
104 112
     LinearLayout ad_layout;
105 113
     @Bind({R.id.fragment_moneytask_layout})
106 114
     FrameLayout mRootView;
115
+    @Bind(R.id.fragment_moneytask_scrollView)
116
+    ScrollView scrollWebview;
107 117
 
108 118
     private BaseFragmentActivity activity;
109 119
     TTAdNative mTTAdNative;
@@ -114,12 +124,11 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
114 124
     public static final String URL = "url";
115 125
 
116 126
 
117
-
118
-
119 127
     @Override
120 128
     protected void onCreate(Bundle savedInstanceState) {
121 129
         super.onCreate(savedInstanceState);
122 130
         onBaseCreate(savedInstanceState);
131
+        FileDownloader.setup(this);
123 132
     }
124 133
 
125 134
     //判断是不是第三方游戏
@@ -137,17 +146,72 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
137 146
         TTAdManagerHolder.get().requestPermissionIfNecessary(activity);
138 147
         this.mAQuery = new AQuery2(activity);
139 148
         if (isThirdGame) {
140
-            ViewCalculateUtil.setViewLinearLayoutParam(findViewById(R.id.fragment_moneytask_layout), LinearLayout.LayoutParams.MATCH_PARENT, 800, 0, 0, 0, 0, true);
141
-            ad_layout.setVisibility(View.GONE);
142
-            ViewCalculateUtil.setViewFrameLayoutParam(mWebview, FrameLayout.LayoutParams.MATCH_PARENT, 800, 0, 0, 0, 0, true);
149
+            scrollWebview.setVisibility(View.GONE);
150
+            mWebview_third.setVisibility(View.VISIBLE);
151
+            initthirdView();
152
+            if (mLoadUrl != null)
153
+                mWebview_third.loadUrl(mLoadUrl);
143 154
         } else {
155
+            scrollWebview.setVisibility(View.VISIBLE);
156
+            mWebview_third.setVisibility(View.GONE);
144 157
             loadAd(ADConstants.AD_FULLSCREEN_VEDIEO, TTAdConstant.VERTICAL, false);
158
+            initWebView();
159
+            if (mLoadUrl != null)
160
+                mWebview.loadUrl(mLoadUrl);
145 161
         }
146
-        initWebView();
147
-        if (mLoadUrl != null)
148
-            mWebview.loadUrl(mLoadUrl);
149
-//            mWebview.loadUrl("http://182.92.118.1:8060/qianduo/games_h5/moveAgain.html?id=undefined");
150
-//            mWebview.loadUrl("http://192.168.22.39/other/qianduo/games_h5/rotateCircle.html?id=8");
162
+
163
+
164
+    }
165
+
166
+    private void initthirdView() {
167
+        WebSettings webSettings = mWebview_third.getSettings();
168
+        webSettings.setBuiltInZoomControls(true);
169
+        webSettings.setJavaScriptEnabled(true);
170
+        webSettings.setLoadWithOverviewMode(true);
171
+        webSettings.setAllowContentAccess(true);
172
+        webSettings.setUseWideViewPort(true);
173
+        mWebview_third.setInitialScale(57);
174
+        mWebview_third.addJavascriptInterface(new MyJs(this), "taskObj");
175
+//        test();
176
+        mWebview_third.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
177
+        //   支持弹窗式 显示 div
178
+        mWebview_third.getSettings().setDomStorageEnabled(true);
179
+        mWebview_third.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
180
+        mWebview_third.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
181
+        mWebview_third.getSettings().setLayoutAlgorithm(
182
+                WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
183
+        mWebview_third.getSettings().setSupportZoom(false);
184
+        mWebview_third.getSettings().setPluginState(WebSettings.PluginState.ON);
185
+        mWebview_third.getSettings().setLoadWithOverviewMode(true);
186
+
187
+//        //图片不显示问题
188
+        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
189
+
190
+            mWebview_third.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
191
+        }
192
+        mWebview_third.getSettings().setBlockNetworkImage(false);
193
+//
194
+////        mWebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
195
+////        mWebview.getSettings().setSupportMultipleWindows(true);
196
+        mWebview_third.setWebViewClient(mClient);
197
+        mWebview_third.setDownloadListener(new DownloadListener() {
198
+            @Override
199
+            public void onDownloadStart(String s, String s1, String s2, String s3, long l) {
200
+//                Log.e("onDownloadStart",s+":"+s1+":"+s2+":"+s3);
201
+                DownLoadManager.downLoadForNoMsg(MoneyTaskFragmentActivity.this, s);
202
+//                try {
203
+//                    Uri uri = Uri.parse(s);
204
+//                    Intent intent = new Intent(Intent.ACTION_VIEW,uri);
205
+//                    startActivity(intent);
206
+//                }catch (Exception e){
207
+//
208
+//                }
209
+//                String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.apk";
210
+//                Log.e("path", path);
211
+//                downLoad(s, path);
212
+            }
213
+        });
214
+        mWebview_third.setWebChromeClient(new WebChromeClient());
151 215
     }
152 216
 
153 217
     @Override
@@ -160,12 +224,16 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
160 224
             CookieManager cookieManager = CookieManager.getInstance(); // the singleton CookieManager instance
161 225
             cookieManager.removeAllCookie();// Removes all cookies.
162 226
             CookieSyncManager.getInstance().sync(); // forces sync manager to sync now
163
-
164 227
             mWebview.setWebChromeClient(null);
165 228
             mWebview.setWebViewClient(null);
166 229
             mWebview.getSettings().setJavaScriptEnabled(false);
167 230
             mWebview.clearCache(true);
168
-        }catch (Exception e){
231
+
232
+            mWebview_third.setWebChromeClient(null);
233
+            mWebview_third.setWebViewClient(null);
234
+            mWebview_third.getSettings().setJavaScriptEnabled(false);
235
+            mWebview_third.clearCache(true);
236
+        } catch (Exception e) {
169 237
 
170 238
         }
171 239
 
@@ -282,19 +350,64 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
282 350
             @Override
283 351
             public void onDownloadStart(String s, String s1, String s2, String s3, long l) {
284 352
 //                Log.e("onDownloadStart",s+":"+s1+":"+s2+":"+s3);
285
-                try {
286
-                    Uri uri = Uri.parse(s);
287
-                    Intent intent = new Intent(Intent.ACTION_VIEW,uri);
288
-                    startActivity(intent);
289
-                }catch (Exception e){
290
-
291
-                }
292
-
353
+                DownLoadManager.downLoadForNoMsg(MoneyTaskFragmentActivity.this, s);
354
+//                try {
355
+//                    Uri uri = Uri.parse(s);
356
+//                    Intent intent = new Intent(Intent.ACTION_VIEW,uri);
357
+//                    startActivity(intent);
358
+//                }catch (Exception e){
359
+//
360
+//                }
361
+//                String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.apk";
362
+//                Log.e("path", path);
363
+//                downLoad(s, path);
293 364
             }
294 365
         });
295 366
         mWebview.setWebChromeClient(new WebChromeClient());
296 367
     }
297 368
 
369
+    private void downLoad(String url, String path) {
370
+        FileDownloader.getImpl().create(url)
371
+                .setPath(path)
372
+                .setListener(new FileDownloadListener() {
373
+                    @Override
374
+                    protected void pending(BaseDownloadTask task, int soFarBytes, int totalBytes) {
375
+                    }
376
+
377
+                    @Override
378
+                    protected void connected(BaseDownloadTask task, String etag, boolean isContinue, int soFarBytes, int totalBytes) {
379
+                    }
380
+
381
+                    @Override
382
+                    protected void progress(BaseDownloadTask task, int soFarBytes, int totalBytes) {
383
+                    }
384
+
385
+                    @Override
386
+                    protected void blockComplete(BaseDownloadTask task) {
387
+                    }
388
+
389
+                    @Override
390
+                    protected void retry(final BaseDownloadTask task, final Throwable ex, final int retryingTimes, final int soFarBytes) {
391
+                    }
392
+
393
+                    @Override
394
+                    protected void completed(BaseDownloadTask task) {
395
+                    }
396
+
397
+                    @Override
398
+                    protected void paused(BaseDownloadTask task, int soFarBytes, int totalBytes) {
399
+                    }
400
+
401
+                    @Override
402
+                    protected void error(BaseDownloadTask task, Throwable e) {
403
+                    }
404
+
405
+                    @Override
406
+                    protected void warn(BaseDownloadTask task) {
407
+                    }
408
+                }).start();
409
+    }
410
+
298 411
     View bg_view;
299 412
     TextView ad_content_text;
300 413
     ImageView adIcon_img;
@@ -630,9 +743,9 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
630 743
         }
631 744
 
632 745
         @JavascriptInterface
633
-        public void checkAd(int width,int height){
634
-            if(isInit){
635
-                Log.e("h5","checkAd:");
746
+        public void checkAd(int width, int height) {
747
+            if (isInit) {
748
+                Log.e("h5", "checkAd:");
636 749
                 loadInteractionAd(ADConstants.AD_H5_GAME, width, height);
637 750
             }
638 751
 
@@ -742,27 +855,28 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
742 855
          */
743 856
         @JavascriptInterface
744 857
         public void game_done(final int id, final int score, final boolean isRight, final int quesition_id) {
745
-            Log.e("h5","game_done:"+id+":"+score+":"+isRight+":"+quesition_id);
858
+            Log.e("h5", "game_done:" + id + ":" + score + ":" + isRight + ":" + quesition_id);
746 859
             //弹出全屏广告
747 860
             mWebview.post(new Runnable() {
748 861
                 @Override
749 862
                 public void run() {
750
-                    getDialogConfig(id, 0, score, isRight, quesition_id,1);
863
+                    getDialogConfig(id, 0, score, isRight, quesition_id, 1);
751 864
                 }
752 865
             });
753 866
         }
867
+
754 868
         /**
755 869
          * H5弹出游戏领取金币框
756 870
          */
757 871
         @JavascriptInterface
758
-        public void new_game_done(final int id, final int score, final boolean isRight, final int quesition_id,final int count) {
759
-           Log.e("h5","new_game_done:"+id+":"+score+":"+isRight+":"+quesition_id+":"+count);
872
+        public void new_game_done(final int id, final int score, final boolean isRight, final int quesition_id, final int count) {
873
+            Log.e("h5", "new_game_done:" + id + ":" + score + ":" + isRight + ":" + quesition_id + ":" + count);
760 874
             //弹出全屏广告
761 875
             mWebview.post(new Runnable() {
762 876
                 @Override
763 877
                 public void run() {
764 878
 
765
-                    getDialogConfig(id, 0, score, isRight, quesition_id,count);
879
+                    getDialogConfig(id, 0, score, isRight, quesition_id, count);
766 880
                 }
767 881
             });
768 882
 
@@ -814,6 +928,7 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
814 928
 
815 929
     /**
816 930
      * 获取游戏配置
931
+     *
817 932
      * @param id
818 933
      * @param startScore
819 934
      * @param endScore
@@ -821,7 +936,7 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
821 936
      * @param quesition_id
822 937
      * @param count
823 938
      */
824
-    private void getDialogConfig(final int id, final int startScore, final int endScore, final boolean isRight, final int quesition_id,final int count) {
939
+    private void getDialogConfig(final int id, final int startScore, final int endScore, final boolean isRight, final int quesition_id, final int count) {
825 940
         RetrofitClient.getApiService().getGameHtmlInfo(new GamePostBody(id, 1)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new MyObsever<BaseJson<GameHtmlInfo>>() {
826 941
             @Override
827 942
             public void onError(ExceptionHandle.ResponeThrowable e) {
@@ -831,7 +946,7 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
831 946
             @Override
832 947
             public void onSuccess(BaseJson<GameHtmlInfo> glodJsonBaseJson) {
833 948
                 if (glodJsonBaseJson != null && glodJsonBaseJson.getCode() == Constant.Code_Request.SUCCESS_CODE) {
834
-                    showGameDialog(startScore, endScore, isRight, id, quesition_id, glodJsonBaseJson.getData(),count);
949
+                    showGameDialog(startScore, endScore, isRight, id, quesition_id, glodJsonBaseJson.getData(), count);
835 950
                 }
836 951
             }
837 952
         });
@@ -864,11 +979,11 @@ public class MoneyTaskFragmentActivity extends BaseFragmentActivity {
864 979
      * @param isRight
865 980
      * @param gameHtmlInfo
866 981
      */
867
-    private void showGameDialog(int startScore, int endScore, boolean isRight, int id, int quesiton_id, GameHtmlInfo gameHtmlInfo,final int count) {
982
+    private void showGameDialog(int startScore, int endScore, boolean isRight, int id, int quesiton_id, GameHtmlInfo gameHtmlInfo, final int count) {
868 983
         EventBus.getDefault().post(new GoldGetForNetEvent());
869
-if(this.isFinishing()){
870
-    return;
871
-}
984
+        if (this.isFinishing()) {
985
+            return;
986
+        }
872 987
         final AdDialog adDialog = new AdDialog(this).builder().preprearToShowGameInfo(ADConstants.AD_OPEN_APP_TIMER, id, startScore, endScore, isRight, quesiton_id, gameHtmlInfo).setOnGoldGetListener(new AdDialog.OnGoldGetListener() {
873 988
             @Override
874 989
             public void getGoldDouble(int task_type, String pk) {
@@ -892,7 +1007,7 @@ if(this.isFinishing()){
892 1007
 //                if (adDialog.isGetDoubleCoin()) {
893 1008
 //                    reloadUrl();
894 1009
 //                }
895
-                if(count%5==0){
1010
+                if (count % 5 == 0) {
896 1011
                     //展示限时领取的dialog
897 1012
                     showLimitDialog();
898 1013
                 }
@@ -1081,7 +1196,13 @@ if(this.isFinishing()){
1081 1196
         @Override
1082 1197
         public void onPageFinished(WebView view, String url) {
1083 1198
             activity.closeProgressDialog();
1084
-            mWebview.setVisibility(View.VISIBLE);
1199
+            if (isThirdGame) {
1200
+
1201
+                mWebview_third.setVisibility(View.VISIBLE);
1202
+            } else {
1203
+
1204
+                mWebview.setVisibility(View.VISIBLE);
1205
+            }
1085 1206
 //            ad_layout.setVisibility(View.VISIBLE);
1086 1207
 
1087 1208
         }

+ 51 - 29
app/src/main/java/com/kuxuan/moneynote/ui/fragments/goldtab/GoldFragment.java

@@ -24,6 +24,7 @@ import android.widget.LinearLayout;
24 24
 import android.widget.RelativeLayout;
25 25
 import android.widget.TextView;
26 26
 
27
+import com.allenliu.versionchecklib.callback.APKDownloadListener;
27 28
 import com.app.hubert.guide.NewbieGuide;
28 29
 import com.app.hubert.guide.core.Builder;
29 30
 import com.app.hubert.guide.core.Controller;
@@ -66,8 +67,10 @@ import com.kuxuan.moneynote.ui.fragments.MoneyTaskFragmentActivity;
66 67
 import com.kuxuan.moneynote.ui.view.CountDownTimeTextView;
67 68
 import com.kuxuan.moneynote.ui.weight.CustormFontsTextView;
68 69
 import com.kuxuan.moneynote.utils.ButtonUtils;
70
+import com.kuxuan.moneynote.utils.DownLoadManager;
69 71
 import com.kuxuan.moneynote.utils.DrawableUtil;
70 72
 import com.kuxuan.moneynote.utils.LoginStatusUtil;
73
+import com.kuxuan.moneynote.utils.MyNotificationUtils;
71 74
 import com.kuxuan.moneynote.utils.SPUtil;
72 75
 import com.kuxuan.moneynote.utils.ToastUtil;
73 76
 import com.kuxuan.moneynote.utils.UIHelper;
@@ -77,6 +80,7 @@ import org.greenrobot.eventbus.EventBus;
77 80
 import org.greenrobot.eventbus.Subscribe;
78 81
 import org.greenrobot.eventbus.ThreadMode;
79 82
 
83
+import java.io.File;
80 84
 import java.text.DecimalFormat;
81 85
 import java.util.ArrayList;
82 86
 import java.util.HashMap;
@@ -85,7 +89,12 @@ import java.util.Map;
85 89
 import butterknife.Bind;
86 90
 import butterknife.ButterKnife;
87 91
 import butterknife.OnClick;
92
+import io.reactivex.Observable;
93
+import io.reactivex.ObservableEmitter;
94
+import io.reactivex.ObservableOnSubscribe;
95
+import io.reactivex.Observer;
88 96
 import io.reactivex.android.schedulers.AndroidSchedulers;
97
+import io.reactivex.disposables.Disposable;
89 98
 import io.reactivex.schedulers.Schedulers;
90 99
 import pl.droidsonroids.gif.GifImageView;
91 100
 
@@ -277,6 +286,7 @@ public class GoldFragment extends BaseFragment {
277 286
 
278 287
     GoldAdapter mAdapter;
279 288
 
289
+
280 290
     private void initRecyclerView() {
281 291
         mAdapter = new GoldAdapter(getActivity());
282 292
         LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
@@ -286,21 +296,31 @@ public class GoldFragment extends BaseFragment {
286 296
         mAdapter.setOnItemClickListener(new OnItemClickListener() {
287 297
             @Override
288 298
             public void onItemClick(View view, int position) {
289
-
290 299
                 Intent intent = new Intent(getActivity(), MoneyTaskFragmentActivity.class);
291 300
                 GameGoldInfo gameGoldInfo = mAdapter.getmList().get(position);
292
-                if (TextUtils.isEmpty(gameGoldInfo.getId())) {
293
-                    intent.putExtra("isThirdGame", true);
301
+                if (gameGoldInfo.getLink_type() == 2) {
302
+                    //直接下载
303
+                    try {
304
+                        DownLoadManager.downLoadForNoMsg(getActivity(), gameGoldInfo.getUrl());
305
+                    } catch (Exception e) {
306
+
307
+                    }
308
+
294 309
                 } else {
295
-                    intent.putExtra("isThirdGame", false);
310
+                    if (TextUtils.isEmpty(gameGoldInfo.getId())) {
311
+                        intent.putExtra("isThirdGame", true);
312
+                    } else {
313
+                        intent.putExtra("isThirdGame", false);
314
+                    }
315
+                    intent.putExtra(MoneyTaskFragmentActivity.URL, mAdapter.getmList().get(position).getUrl());
316
+                    onEventUmeng(mAdapter.getmList().get(position).getTitle());
317
+                    startActivityForResult(intent, Constant.Code_Request.REQUESTCODE);
296 318
                 }
297
-                intent.putExtra(MoneyTaskFragmentActivity.URL, mAdapter.getmList().get(position).getUrl());
298
-                onEventUmeng(mAdapter.getmList().get(position).getTitle());
299
-                startActivityForResult(intent, Constant.Code_Request.REQUESTCODE);
300 319
             }
301 320
         });
302 321
     }
303 322
 
323
+
304 324
     Controller show;
305 325
 
306 326
 
@@ -513,23 +533,23 @@ public class GoldFragment extends BaseFragment {
513 533
     private void setUserCoin(UserCoinJson locaUserCoin) {
514 534
         if (locaUserCoin == null)
515 535
             return;
516
-        float startMoney =0;
517
-        try{
536
+        float startMoney = 0;
537
+        try {
518 538
             startMoney = Float.parseFloat(goldUserText.getText().toString());
519
-        }catch (Exception e){
539
+        } catch (Exception e) {
520 540
 
521 541
         }
522
-        float endMoney =0;
542
+        float endMoney = 0;
523 543
         try {
524
-            endMoney =   Float.parseFloat(locaUserCoin.getMoney());
525
-        }catch (Exception e){
544
+            endMoney = Float.parseFloat(locaUserCoin.getMoney());
545
+        } catch (Exception e) {
526 546
 
527 547
         }
528
-        if(startMoney==endMoney&&startMoney==0){
548
+        if (startMoney == endMoney && startMoney == 0) {
529 549
             goldUserText.setText("0");
530
-        }else{
550
+        } else {
531 551
 
532
-            moneyAnimation(startMoney,endMoney,goldUserText,"");
552
+            moneyAnimation(startMoney, endMoney, goldUserText, "");
533 553
         }
534 554
 //        goldUserText.setText(locaUserCoin.getMoney());
535 555
         goldUserAllText.setText(locaUserCoin.getGold());
@@ -610,7 +630,7 @@ public class GoldFragment extends BaseFragment {
610 630
             @Override
611 631
             public void onSuccess(BaseJson<Object> objectBaseJson) {
612 632
                 if (objectBaseJson != null && objectBaseJson.getCode() == Constant.Code_Request.SUCCESS_CODE) {
613
-                    ToastUtil.show(getActivity(),"兑换成功");
633
+                    ToastUtil.show(getActivity(), "兑换成功");
614 634
                     EventBus.getDefault().post(new GoldGetForNetEvent());
615 635
                     //跳转我的钱包
616 636
                     goToWallet(true);
@@ -642,15 +662,17 @@ public class GoldFragment extends BaseFragment {
642 662
             UIHelper.openActivityWithBundle(getActivity(), PhoneLoginActivity.class, bundle);
643 663
             return;
644 664
         }
645
-        if (isNeedRefresh){
665
+        if (isNeedRefresh) {
646 666
             getUserCoinInfo(true, false);
647 667
         }
648 668
         Intent itnent = new Intent(getActivity(), WalletActivity.class);
649 669
         itnent.putExtra("isGoFromMoney", true);
650 670
         startActivity(itnent);
651 671
     }
672
+
652 673
     DecimalFormat df = new DecimalFormat("0.00");
653 674
     ValueAnimator valueAnimator;
675
+
654 676
     /**
655 677
      * 金币滚动动画
656 678
      *
@@ -658,17 +680,17 @@ public class GoldFragment extends BaseFragment {
658 680
      * @param endScore
659 681
      */
660 682
     private void moneyAnimation(float startScore, float endScore, final TextView textView, final String indexString) {
661
-        if(startScore==endScore){
683
+        if (startScore == endScore) {
662 684
             return;
663 685
         }
664
-        if(valueAnimator!=null){
665
-            if(valueAnimator.isRunning()){
666
-valueAnimator.cancel();
686
+        if (valueAnimator != null) {
687
+            if (valueAnimator.isRunning()) {
688
+                valueAnimator.cancel();
667 689
             }
668 690
             valueAnimator.cancel();
669
-            valueAnimator .setFloatValues(startScore, endScore);
691
+            valueAnimator.setFloatValues(startScore, endScore);
670 692
             valueAnimator.start();
671
-        }else{
693
+        } else {
672 694
             valueAnimator = ValueAnimator.ofFloat(startScore, endScore);
673 695
             valueAnimator.setDuration(500);
674 696
             valueAnimator.setInterpolator(new LinearInterpolator());
@@ -702,12 +724,12 @@ valueAnimator.cancel();
702 724
                     if (glodJsonBaseJson.getData() != null) {
703 725
                         //展示定时任务弹窗
704 726
                         long time = 0;
705
-                        try{
706
-time = Long.parseLong(glodJsonBaseJson.getData().getSeconds());
707
-                        }catch (Exception e){
727
+                        try {
728
+                            time = Long.parseLong(glodJsonBaseJson.getData().getSeconds());
729
+                        } catch (Exception e) {
708 730
 
709 731
                         }
710
-                        time = time*1000;
732
+                        time = time * 1000;
711 733
                         setTImerCount(time, glodJsonBaseJson.getData().getCoin(), glodJsonBaseJson.getData().getDays(), isNeedShow);
712 734
                     } else {
713 735
                         isRunning = false;
@@ -785,7 +807,7 @@ time = Long.parseLong(glodJsonBaseJson.getData().getSeconds());
785 807
         if (time == 0) {
786 808
             goldCountdownText.setText("00:00");
787 809
             //弹出定时领红包金币框
788
-            GoldManager.getInstance().getGoldForNet(getActivity(),2, null, new OnGoldGetListener() {
810
+            GoldManager.getInstance().getGoldForNet(getActivity(), 2, null, new OnGoldGetListener() {
789 811
                 @Override
790 812
                 public void onGetSuccess(String coins) {
791 813
                     //弹出领取金币框

+ 119 - 0
app/src/main/java/com/kuxuan/moneynote/utils/DownLoadManager.java

@@ -0,0 +1,119 @@
1
+package com.kuxuan.moneynote.utils;
2
+
3
+
4
+import android.app.NotificationManager;
5
+import android.content.Context;
6
+import android.support.v4.app.NotificationCompat;
7
+import android.util.Log;
8
+
9
+import com.allenliu.versionchecklib.callback.APKDownloadListener;
10
+import com.allenliu.versionchecklib.v2.AllenVersionChecker;
11
+import com.allenliu.versionchecklib.v2.builder.DownloadBuilder;
12
+import com.allenliu.versionchecklib.v2.builder.NotificationBuilder;
13
+import com.allenliu.versionchecklib.v2.builder.UIData;
14
+import com.allenliu.versionchecklib.v2.callback.ForceUpdateListener;
15
+import com.kuxuan.moneynote.R;
16
+
17
+import java.io.File;
18
+
19
+/**
20
+ * 下载管理类
21
+ */
22
+public class DownLoadManager {
23
+
24
+
25
+    public static void downLoad(Context context, String url) {
26
+
27
+        DownloadBuilder downloadBuilder = AllenVersionChecker.getInstance().downloadOnly(UIData.create().setDownloadUrl(url).setTitle("ceshi").setContent("cessds"));
28
+        //是否显示通知栏
29
+        downloadBuilder.setShowNotification(true);
30
+        //是否静默下载
31
+        downloadBuilder.setSilentDownload(true);
32
+        //是否下载忽略本地缓存
33
+        downloadBuilder.setForceRedownload(true);
34
+        //是否显示下载失败框
35
+        downloadBuilder.setShowDownloadFailDialog(false);
36
+        downloadBuilder.setShowDownloadingDialog(false);
37
+        downloadBuilder.setApkDownloadListener(new APKDownloadListener() {
38
+            @Override
39
+            public void onDownloading(int progress) {
40
+                Log.e("download_progress", progress + "");
41
+            }
42
+
43
+            @Override
44
+            public void onDownloadSuccess(File file) {
45
+
46
+            }
47
+
48
+            @Override
49
+            public void onDownloadFail() {
50
+
51
+            }
52
+        });
53
+        downloadBuilder.executeMission(context);
54
+    }
55
+
56
+
57
+    /**
58
+     * 静默下载+直接安装
59
+     *
60
+     * @param context
61
+     * @param url
62
+     */
63
+    public static void downLoadForNoMsg(Context context, String url) {
64
+        ToastUtil.show(context, "正在下载");
65
+        DownloadBuilder builder = AllenVersionChecker.getInstance().downloadOnly(UIData.create().setDownloadUrl(url));
66
+        builder.setDirectDownload(true);
67
+        builder.setShowNotification(false);
68
+        builder.setShowDownloadingDialog(false);
69
+        builder.setShowDownloadFailDialog(false);
70
+        builder.setForceRedownload(false);
71
+        builder.executeMission(context);
72
+    }
73
+
74
+    /**
75
+     * 自定义下载监听
76
+     *
77
+     * @param context
78
+     * @param url
79
+     * @param downloadListener
80
+     */
81
+    public static void downLoadForNoticeation(Context context, String url, String apkName, String apk, APKDownloadListener downloadListener) {
82
+        ToastUtil.show(context, "正在下载");
83
+        DownloadBuilder builder = AllenVersionChecker.getInstance().downloadOnly(UIData.create().setDownloadUrl(url).setTitle("title").setContent("content"));
84
+        builder.setShowNotification(true);
85
+        NotificationBuilder notificationBuilder = NotificationBuilder.create();
86
+        notificationBuilder.setRingtone(true);
87
+        notificationBuilder.setContentTitle("下载任务");
88
+        notificationBuilder.setContentText(apkName);
89
+        notificationBuilder.setTicker("qianduo");
90
+        builder.setNotificationBuilder(notificationBuilder);
91
+        builder.setDirectDownload(true);
92
+        builder.setShowDownloadingDialog(false);
93
+        builder.setShowDownloadFailDialog(false);
94
+        builder.setApkName(apk);
95
+        builder.setApkDownloadListener(downloadListener);
96
+        builder.executeMission(context);
97
+
98
+    }
99
+
100
+    /**
101
+     * 更新版本
102
+     *
103
+     * @param context
104
+     * @param isForce 是否强制安装
105
+     * @param url
106
+     */
107
+    public static void updataVersion(Context context, boolean isForce, String url, ForceUpdateListener listener) {
108
+        DownloadBuilder builder = AllenVersionChecker.getInstance().downloadOnly(UIData.create().setDownloadUrl(url).setTitle("版本更新").setContent("有新版本发布,是否更新?"));
109
+        if (isForce) {
110
+            builder.setForceUpdateListener(listener);
111
+        }
112
+//        builder.setNotificationBuilder(NotificationBuilder.create().setIcon(R.mipmap.app_icon).setRingtone(true).setContentText("ss").setContentTitle("custormTitle").setTicker("ticker"));
113
+        builder.setForceRedownload(true);
114
+        builder.setShowDownloadingDialog(true);
115
+        builder.executeMission(context);
116
+
117
+    }
118
+
119
+}

+ 101 - 0
app/src/main/java/com/kuxuan/moneynote/utils/MyNotificationUtils.java

@@ -0,0 +1,101 @@
1
+package com.kuxuan.moneynote.utils;
2
+
3
+import android.app.Notification;
4
+import android.app.NotificationChannel;
5
+import android.app.NotificationManager;
6
+import android.content.Context;
7
+import android.graphics.Color;
8
+import android.os.Build;
9
+import android.support.v4.app.NotificationCompat;
10
+
11
+import com.kuxuan.moneynote.R;
12
+
13
+/**
14
+ * 自定义通知栏
15
+ */
16
+public class MyNotificationUtils {
17
+
18
+    private String title;
19
+    private String content;
20
+    private int manageId;
21
+    private String channelId ;
22
+    private int currentProgress=0;
23
+    private int maxProgress =100;
24
+
25
+    private MyNotificationUtils(String title, String content, int manageId,String channelId) {
26
+        this.title = title;
27
+        this.content = content;
28
+        this.manageId = manageId;
29
+        this.channelId = channelId;
30
+    }
31
+
32
+    public static MyNotificationUtils newInstance( String title, String content, int manageId,String channelId){
33
+return new MyNotificationUtils(title,content,manageId,channelId);
34
+    }
35
+
36
+        private   NotificationManager getManager(Context  context) {
37
+        return (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
38
+    }
39
+    private  NotificationCompat.Builder getNotificationBuilder(Context mContext, String title
40
+            , String content) {
41
+        //大于8.0
42
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
43
+            //id随便指定
44
+            NotificationChannel channel = new NotificationChannel(channelId
45
+                    , mContext.getPackageName(), NotificationManager.IMPORTANCE_DEFAULT);
46
+            channel.canBypassDnd();//可否绕过,请勿打扰模式
47
+            channel.enableLights(true);//闪光
48
+            channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);//锁屏显示通知
49
+            channel.setLightColor(Color.RED);//指定闪光是的灯光颜色
50
+            channel.canShowBadge();//桌面laucher消息角标
51
+            channel.enableVibration(true);//是否允许震动
52
+            channel.setSound(null, null);
53
+            //channel.getAudioAttributes();//获取系统通知响铃声音配置
54
+            channel.getGroup();//获取通知渠道组
55
+            channel.setBypassDnd(true);//设置可以绕过,请勿打扰模式
56
+            channel.setVibrationPattern(new long[]{100, 100, 200});//震动的模式,震3次,第一次100,第二次100,第三次200毫秒
57
+            channel.shouldShowLights();//是否会闪光
58
+            //通知管理者创建的渠道
59
+            getManager(mContext).createNotificationChannel(channel);
60
+
61
+        }
62
+
63
+        return new NotificationCompat.Builder(mContext,channelId).setAutoCancel(true)
64
+                .setContentTitle(title)
65
+                .setContentText(content).setSmallIcon(R.mipmap.ic_launcher);
66
+
67
+    }
68
+
69
+    /**
70
+     */
71
+    public  void showNotificationProgress(Context mContext) {
72
+        final NotificationCompat.Builder builder = getNotificationBuilder(mContext,title,content);
73
+       /* Intent intent = new Intent(this, SecondeActivity.class);
74
+        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
75
+        builder.setContentIntent(pendingIntent);*/
76
+        builder.setOnlyAlertOnce(true);
77
+        builder.setDefaults(Notification.FLAG_ONLY_ALERT_ONCE);
78
+        builder.setProgress(maxProgress, currentProgress, false);
79
+        builder.setWhen(System.currentTimeMillis());
80
+        getManager(mContext).notify(manageId, builder.build());
81
+    }
82
+
83
+    /**
84
+     * 设置进度条
85
+     * @param mContext
86
+     * @param progress
87
+     */
88
+    public  void showNotificationProgressApkDown(Context mContext
89
+            , int progress) {
90
+         NotificationCompat.Builder builder = getNotificationBuilder(mContext,title,content);
91
+        builder.setOnlyAlertOnce(true);
92
+        builder.setDefaults(Notification.FLAG_ONLY_ALERT_ONCE);
93
+        builder.setProgress(maxProgress, progress, false);
94
+        builder.setWhen(System.currentTimeMillis());
95
+        getManager(mContext).notify(manageId, builder.build());
96
+    }
97
+
98
+    public  void cancleNotification(Context mContext,int manageId) {
99
+        getManager(mContext).cancel(manageId);
100
+    }
101
+}

+ 21 - 4
app/src/main/res/layout/fragment_moneytask_layout.xml

@@ -1,10 +1,19 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 
3
+<FrameLayout
4
+    xmlns:android="http://schemas.android.com/apk/res/android"
5
+    xmlns:tools="http://schemas.android.com/tools"
6
+    android:layout_width="match_parent"
7
+    android:id="@+id/fragment_moneytasklayout"
8
+    android:layout_height="match_parent">
3 9
 
4
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
10
+
11
+
12
+<ScrollView
5 13
     xmlns:tools="http://schemas.android.com/tools"
6 14
     android:layout_width="match_parent"
7 15
     android:scrollbars="none"
16
+    android:id="@+id/fragment_moneytask_scrollView"
8 17
     android:layout_height="match_parent">
9 18
 
10 19
     <LinearLayout
@@ -34,10 +43,18 @@
34 43
 
35 44
                 <include layout="@layout/layout_chuanshanjia_ad" />
36 45
             </LinearLayout>
37
-
38
-
39 46
         </FrameLayout>
40 47
     </LinearLayout>
41 48
 
42 49
 
43
-</ScrollView>
50
+</ScrollView>
51
+
52
+
53
+    <WebView
54
+        android:id="@+id/fragment_moneytask_third_webview"
55
+        android:layout_width="match_parent"
56
+        android:visibility="gone"
57
+        android:layout_height="match_parent" />
58
+
59
+
60
+</FrameLayout>

+ 2 - 2
build.gradle

@@ -31,8 +31,8 @@ task clean(type: Delete) {
31 31
     delete rootProject.buildDir
32 32
 }
33 33
 ext {
34
-    versionCode = 43
35
-    versionName = "2.1.7"
34
+    versionCode = 45
35
+    versionName = "2.1.9"
36 36
     minSdkVersion = 19
37 37
     targetSdkVersion = 28
38 38
     compileSdkVersion = 28