Преглед изворни кода

Merge remote-tracking branch 'origin/sheep_develop' into sheep_develop

liujiangyao пре 7 година
родитељ
комит
41807f59c7
18 измењених фајлова са 306 додато и 235 уклоњено
  1. 2 2
      app/src/main/java/com/sheep/gamegroup/helper/DownloadHelper.java
  2. 6 0
      app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java
  3. 64 52
      app/src/main/java/com/sheep/gamegroup/util/CommonUtil.java
  4. 4 3
      app/src/main/java/com/sheep/gamegroup/util/DeviceUtil.java
  5. 29 26
      app/src/main/java/com/sheep/gamegroup/util/DownloadUtil.java
  6. 3 3
      app/src/main/java/com/sheep/gamegroup/view/activity/ActFindGame.java
  7. 3 3
      app/src/main/java/com/sheep/gamegroup/view/activity/ActFindInformation.java
  8. 2 2
      app/src/main/java/com/sheep/gamegroup/view/activity/ActPlayGameDetail.java
  9. 11 17
      app/src/main/java/com/sheep/gamegroup/view/activity/ActReservation.java
  10. 12 9
      app/src/main/java/com/sheep/gamegroup/view/activity/ActSignCard.java
  11. 24 9
      app/src/main/java/com/sheep/gamegroup/view/activity/SplashAct.java
  12. 20 3
      app/src/main/java/com/sheep/gamegroup/view/activity/TaskDetailAct.java
  13. 0 13
      app/src/main/java/com/sheep/gamegroup/view/activity/TaskDetailCreditCardAct.java
  14. 3 3
      app/src/main/java/com/sheep/gamegroup/view/adapter/TryMakeMoneyAdp.java
  15. 11 18
      app/src/main/java/com/sheep/gamegroup/view/fragment/FgtFindChild.java
  16. 68 14
      app/src/main/java/com/sheep/jiuyan/samllsheep/service/DownloadService.java
  17. 42 50
      app/src/main/java/com/sheep/jiuyan/samllsheep/utils/ClassFileHelper.java
  18. 2 8
      app/src/main/java/com/sheep/jiuyan/samllsheep/utils/PackageUtil.java

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/helper/DownloadHelper.java

@@ -110,7 +110,7 @@ public class DownloadHelper {
                 }
                 break;
             case DownloadUtil.STATUS_FINISH://已经下载完成,可以安装
-                String path = PackageUtil.isExistsFile(task.getPackage_names());
+                String path = PackageUtil.isExistsFile(task.getPackage_names(), task.getDownload_link());
                 if(TextUtils.isEmpty(path)){//数据库保存有下载完成的状态,但是应用已经被删除,需要修复其下载状态
                     if(TextUtils.isEmpty(task.getDownload_link()) || !task.getDownload_link().contains("http")){
                         G.showToast(R.string.error_download_link);
@@ -125,7 +125,7 @@ public class DownloadHelper {
                         downLoadType = DownloadUtil.STATUS_INIT;
                     }
                 } else {
-                    ApkUtils.installApk(activity, PackageUtil.isExistsFile(task.getPackage_names()));
+                    ApkUtils.installApk(activity, PackageUtil.isExistsFile(task.getPackage_names(), task.getDownload_link()));
                 }
                 break;
             case DownloadUtil.STATUS_INSTALLED://已经安装,可以试玩

+ 6 - 0
app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java

@@ -1005,4 +1005,10 @@ public interface ApiService {
      */
     @GET("app/sdk/{game_key}")
     Observable<BaseMessage> verifactionAuth(@Path("game_key") String game_key);
+    /**
+     * 判断是否是第一次运行的设备
+     * @return
+     */
+    @GET("app/event_tracking/check_user_first")
+    Observable<BaseMessage> checkUserFirst();
 }

+ 64 - 52
app/src/main/java/com/sheep/gamegroup/util/CommonUtil.java

@@ -239,7 +239,6 @@ public class CommonUtil {
      */
     public DownLoadInfo addNewDownloadTask(String gameName, String downloadUrl, String packageName,
                                            int versionCode, String iconUrl, String size, Integer gameId, int whereFrom) {
-
         DownLoadInfo task = new DownLoadInfo();
         task.setMIconUrl(iconUrl);
         task.setMGameName(gameName);
@@ -249,7 +248,7 @@ public class CommonUtil {
         task.setMTotalSize(Double.valueOf(size));
         task.setMGameID(gameId);
         task.setWhereFrom(whereFrom);
-        task.setMApkPath(DIR + File.separator + packageName + ClassFileHelper.FILE_SUFFIX);
+        task.setMApkPath(DIR + File.separator + packageName + downloadUrl.hashCode() + ClassFileHelper.FILE_SUFFIX);
         return task;
     }
 
@@ -502,7 +501,7 @@ public class CommonUtil {
                 break;
             default:
                 String url = entity.getUrl();
-                if(TextUtils.isEmpty(url))
+                if (TextUtils.isEmpty(url))
                     G.showToast(R.string.coming_soon);
                 else//有链接直接跳转内部h5
                     Jump2View.getInstance().goWeb(context, entity.getUrl(), entity.getTitle());
@@ -597,7 +596,7 @@ public class CommonUtil {
      * 更新用户信息
      */
     public void getUserInfo(Context context) {
-       SheepApp.getInstance()
+        SheepApp.getInstance()
                 .getNetComponent()
                 .getApiService()
                 .getInfo()
@@ -850,11 +849,11 @@ public class CommonUtil {
 
     public void shareBySysSend(Activity activity) {
         PackageInfo packageInfo = ApkUtils.getPackageInfo(SheepApp.getInstance().getPackageName());
-        if(packageInfo != null && packageInfo.applicationInfo != null && !TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)){
+        if (packageInfo != null && packageInfo.applicationInfo != null && !TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)) {
             String dir = DIR;
             //File dir = SheepApp.getInstance().getDir("apk", Context.MODE_PRIVATE);
             File file = new File(dir, String.format(Locale.CHINA, "sheep_release_v%s_%d-%s.apk", packageInfo.versionName, packageInfo.versionCode, DataUtil.getInstance().getInvitationCode()));
-            if(!file.exists()){
+            if (!file.exists()) {
                 try {
                     FileUtil.copyFile(new File(packageInfo.applicationInfo.sourceDir), file);
                     ZipChannelUtil.writeQUA(file, DataUtil.getInstance().getInvitationCode());
@@ -862,7 +861,7 @@ public class CommonUtil {
                     e.printStackTrace();
                 }
             }
-            if(file.exists())
+            if (file.exists())
                 shareFile(activity, file);
             else
                 G.showToast("暂不支持,或未打开权限");
@@ -903,6 +902,7 @@ public class CommonUtil {
         }
         return mime;
     }
+
     /**
      * 分享
      *
@@ -916,6 +916,7 @@ public class CommonUtil {
 
     /**
      * 把homeList列表分开,例如:超维对决显示的图片是充满的,并且在绵羊头条下面
+     *
      * @param allList
      * @param homeList
      * @param fullHomeList
@@ -925,19 +926,20 @@ public class CommonUtil {
             @Override
             public Boolean call(HomeListEntity item) {
                 boolean result = "1024".equals(item.getDesc()) || "17".equals(item.getJump());//描述为1024或者jump为17的跳转超维对决
-                if(result){
+                if (result) {
                     fullHomeList.add(item);
                 }
                 return !result;
             }
         }));
     }
+
     //尝试直接分享小绵羊
     public void tryShowShareDialog(final Activity activity) {
-       callActionWithFriendCountAndAward(new Action1<FriendAndAwardEntity>() {
+        callActionWithFriendCountAndAward(new Action1<FriendAndAwardEntity>() {
             @Override
             public void call(FriendAndAwardEntity result) {
-                if(result != null) {
+                if (result != null) {
                     tryShowShareDialog(activity, result.getShare_desc());
                 } else {
                     G.showToast("分享功能调试中");
@@ -945,12 +947,13 @@ public class CommonUtil {
             }
         });
     }
+
     //显示分享对话框
     public void tryShowShareDialog(final Activity activity, final String description) {
         CommonUtil.getInstance().callActionWithUserInfo(new Action1<UserEntity>() {
             @Override
             public void call(UserEntity userEntity) {
-                if(userEntity == null) {
+                if (userEntity == null) {
                     G.showToast("分享功能调试中");
                     return;
                 }
@@ -1089,7 +1092,7 @@ public class CommonUtil {
                 .showProgress(context);
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("status", status);
-       SheepApp.getInstance()
+        SheepApp.getInstance()
                 .getNetComponent()
                 .getApiService()
                 .gameTaskPayOrGiveUp(id, jsonObject)
@@ -1156,7 +1159,7 @@ public class CommonUtil {
      * 获取代理是否显示
      */
     public void getAgencyState(final Context context, final Action1<BaseMessage> action1) {
-       SheepApp.getInstance()
+        SheepApp.getInstance()
                 .getNetComponent()
                 .getApiService()
                 .agentRegion()
@@ -1237,12 +1240,13 @@ public class CommonUtil {
                     }
                 });
     }
+
     public void callActionWithUserInfo(final Action1<UserEntity> action1) {
         UserEntity userEntity = DataUtil.getInstance().getUserEntity();
-        if(userEntity == null) {
+        if (userEntity == null) {
             updateUserInfo(action1);
         } else {
-            if(action1 != null){
+            if (action1 != null) {
                 action1.call(userEntity);
             }
         }
@@ -1285,14 +1289,14 @@ public class CommonUtil {
                                                 action1.call(1);
                                         }
                                     }));
-                        } else if(baseMessage.getCode() == 0){
+                        } else if (baseMessage.getCode() == 0) {
                             try {
                                 if (action1 != null)
-                                    action1.call(TextUtils.isEmpty(baseMessage.getData()+"")?0:Integer.valueOf(baseMessage.getData()+""));
+                                    action1.call(TextUtils.isEmpty(baseMessage.getData() + "") ? 0 : Integer.valueOf(baseMessage.getData() + ""));
                             } catch (Exception e) {
                                 e.printStackTrace();
                             }
-                        }else {
+                        } else {
                             G.showToast(baseMessage.getMsg());
                         }
                     }
@@ -1303,6 +1307,7 @@ public class CommonUtil {
                     }
                 });
     }
+
     public void acceptedTask(final Context context, final GameEntity gameEntity, final Action1<Integer> action1) {
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("device_id", DeviceUtil.getDeviceId(context));
@@ -1316,7 +1321,7 @@ public class CommonUtil {
                         try {
                             String acceptId = baseMessage.getData(String.class);
                             try {
-                                if(!TextUtils.isEmpty(acceptId))
+                                if (!TextUtils.isEmpty(acceptId))
                                     gameEntity.setAccepted_task_id(Integer.valueOf(acceptId));
                             } catch (Exception e) {
                                 e.printStackTrace();
@@ -1333,19 +1338,21 @@ public class CommonUtil {
                     }
                 });
     }
+
     //对---游戏任务中的领取奖励
     public void receiveAward(final Context context, final GameEntity gameEntity, final Action1<Integer> action1) {
         RECEIVE_AWARD_GAME_TASK.onEvent();
-        if(gameEntity.getAccepted_task_id() < 1){
-            acceptedTask(context,gameEntity,action1);
-        }else {
+        if (gameEntity.getAccepted_task_id() < 1) {
+            acceptedTask(context, gameEntity, action1);
+        } else {
             receiveAwards(context, gameEntity, action1);
         }
 
 
     }
+
     //领取奖励
-    public void receiveAwards(final Context context, final GameEntity gameEntity, final Action1<Integer> action1){
+    public void receiveAwards(final Context context, final GameEntity gameEntity, final Action1<Integer> action1) {
         SheepApp.getInstance()
                 .getNetComponent()
                 .getApiService()
@@ -1778,7 +1785,7 @@ public class CommonUtil {
 
     //设置无数据显示
     public void updateEmptyView(View empty_view, boolean showEmpty, boolean isNetImg) {
-        if(empty_view == null){
+        if (empty_view == null) {
             return;
         }
         if (showEmpty) {
@@ -1843,7 +1850,7 @@ public class CommonUtil {
                     jsonObject.put("id", ((XiaomiGameEntity) items).getId());
                 } else if (items instanceof FindApp) {
                     jsonObject.put("id", ((FindApp) items).getId());
-                } else if(items instanceof PlayGameEntity){
+                } else if (items instanceof PlayGameEntity) {
                     jsonObject.put("id", ((PlayGameEntity) items).getId());
                 }
 
@@ -2218,11 +2225,12 @@ public class CommonUtil {
     }
 
     /**
-     *tag 标签绘制
-     R.drawable.shape_blue_stroke_rectangle_no_lb
-     @param i -1:不限制 否者限制tag 个数
+     * tag 标签绘制
+     * R.drawable.shape_blue_stroke_rectangle_no_lb
+     *
+     * @param i -1:不限制 否者限制tag 个数
      */
-    public void paintLineaLayout(Context activity, GameEntity gameEntity, LinearLayout ll_game_tag, int i, int color, int drawable){
+    public void paintLineaLayout(Context activity, GameEntity gameEntity, LinearLayout ll_game_tag, int i, int color, int drawable) {
         String game_tag = gameEntity.getApp().getGame_tag();
         if (!TextUtils.isEmpty(game_tag)) {
             ll_game_tag.removeAllViews();
@@ -2249,31 +2257,32 @@ public class CommonUtil {
             }
         }
     }
+
     /**
      * 玩转游戏 按钮设置
      * type 1
      * 0,--------1,已接受任务 2,正在进行中,3完成任务,4放弃任务,5任务失败,6审核失败,7提交审核,8任务已下线,9至少完成了一个任务了
      */
-    public void palyGameDetailBtnValue(final Context context, final GameEntity gameEntity, final TextView detail_task_tv_center, final int type){
+    public void palyGameDetailBtnValue(final Context context, final GameEntity gameEntity, final TextView detail_task_tv_center, final int type) {
         final TaskReleaseEty releaseEty = gameEntity.getRelease_task();
-        final TaskEty taskEty = releaseEty != null?releaseEty.getTask():null;
-        if(releaseEty != null && taskEty != null) {//游戏任务
+        final TaskEty taskEty = releaseEty != null ? releaseEty.getTask() : null;
+        if (releaseEty != null && taskEty != null) {//游戏任务
 
             if (taskEty.isGameReservationCantDownload()) {//预约
-                if(gameEntity.getStatus() == 1 || gameEntity.getStatus() == 2 || gameEntity.getStatus() == 3){
+                if (gameEntity.getStatus() == 1 || gameEntity.getStatus() == 2 || gameEntity.getStatus() == 3) {
                     detail_task_tv_center.setText("已经预约");
                     detail_task_tv_center.setEnabled(false);
-                }else {
+                } else {
                     detail_task_tv_center.setText("预约下载");
                     detail_task_tv_center.setEnabled(true);
-                    if(type == 0){
+                    if (type == 0) {
                         detail_task_tv_center.setOnClickListener(new View.OnClickListener() {
                             @Override
                             public void onClick(View view) {
                                 CommonUtil.getInstance().reservationGameTask(context, releaseEty, new Action1<Integer>() {
                                     @Override
                                     public void call(Integer integer) {
-                                        if(integer > 0){
+                                        if (integer > 0) {
                                             gameEntity.setAccepted_task_id(integer);
                                             detail_task_tv_center.setText("已预约");
                                             detail_task_tv_center.setEnabled(false);
@@ -2290,7 +2299,7 @@ public class CommonUtil {
             } else {
                 releaseEty.getDownloadHelper().updateDownloadTaskView((Activity) context, taskEty, detail_task_tv_center, null, type);
             }
-        }else if (gameEntity.getApp().isCanDonload()) {//可下载
+        } else if (gameEntity.getApp().isCanDonload()) {//可下载
             gameEntity.getApp().getFindAppHelper().updateDownloadTaskView((Activity) context, gameEntity.getApp(), detail_task_tv_center, type);
             detail_task_tv_center.setTag("PUBLIC_TAG_PREFIX_TEXTVIEW_LIST" + gameEntity.getApp().getDownload_link());
         } else {//预约下载
@@ -2301,6 +2310,7 @@ public class CommonUtil {
 
     /**
      * 领取礼包
+     *
      * @param item
      */
     public void receiveGiftById(final Context context, final GiftBagApp item, final Action1<Integer> action1, final String packageName) {
@@ -2312,7 +2322,7 @@ public class CommonUtil {
                     public void onNext(BaseMessage baseMessage) {
                         String code = baseMessage.getData(String.class);
                         item.setCode(code);
-                        if(action1 != null)
+                        if (action1 != null)
                             action1.call(TO_REFRESH);
                         ViewUtil.showGetWelfareDialog((Activity) context, item, packageName);
                     }
@@ -2327,25 +2337,26 @@ public class CommonUtil {
     /**
      * 判断是否 安装应用
      */
-    public boolean isInstallApp(String packageName, String name){
+    public boolean isInstallApp(String packageName, String name) {
         boolean isInstalled = PackageUtil.isAppInstalled(SheepApp.getInstance(), packageName);
-        if(!isInstalled){
-            G.showToast("还未安装"+name);
+        if (!isInstalled) {
+            G.showToast("还未安装" + name);
             return false;
         }
         return true;
     }
+
     /**
      * 抢任务
      */
-    public void robTask(final Action1<RobTask> action1){
+    public void robTask(final Action1<RobTask> action1) {
         SheepApp.getInstance().getNetComponent().getApiService().getNewTask(SpUtils.getOrder("order"))
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                     @Override
                     public void onNext(BaseMessage baseMessage) {
-                        if(action1 != null){
+                        if (action1 != null) {
                             mRobTask = baseMessage.getData(RobTask.class);
                             action1.call(mRobTask);
                         }
@@ -2353,7 +2364,7 @@ public class CommonUtil {
 
                     @Override
                     public void onError(BaseMessage baseMessage) {
-                        if(action1 != null){
+                        if (action1 != null) {
                             action1.call(null);
                         }
                     }
@@ -2362,24 +2373,24 @@ public class CommonUtil {
 
     public void callActionWithFriendCountAndAward(final Action1<FriendAndAwardEntity> action1) {
         FriendAndAwardEntity friendAndAwardEntity = DataUtil.getInstance().getCacheResult(ApiKey.friend_count_and_award, FriendAndAwardEntity.class);
-        if(friendAndAwardEntity == null)
+        if (friendAndAwardEntity == null)
             SheepApp.getInstance().getNetComponent().getApiService().FriendCountAndAward()
                     .subscribeOn(Schedulers.io())
                     .observeOn(AndroidSchedulers.mainThread())
                     .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                         @Override
                         public void onError(BaseMessage baseMessage) {
-                            if(action1 != null)
+                            if (action1 != null)
                                 action1.call(null);
                         }
 
                         @Override
                         public void onNext(BaseMessage baseMessage) {
-                            if(action1 != null)
+                            if (action1 != null)
                                 action1.call(baseMessage.getData(FriendAndAwardEntity.class));
                         }
                     });
-        else if(action1 != null)
+        else if (action1 != null)
             action1.call(friendAndAwardEntity);
 
     }
@@ -2387,11 +2398,11 @@ public class CommonUtil {
     /**
      * 获取时间
      */
-    public long[] getLastMonth(){
-        Calendar c=Calendar.getInstance();
+    public long[] getLastMonth() {
+        Calendar c = Calendar.getInstance();
         c.add(Calendar.MONTH, -1);
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
-        int lastMonthMaxDay=c.getActualMaximum(Calendar.DAY_OF_MONTH);
+        int lastMonthMaxDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
         c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), lastMonthMaxDay, 23, 59, 59);
         //按格式输出
         String endtime = sdf.format(c.getTime()); //上月最后一天
@@ -2401,7 +2412,7 @@ public class CommonUtil {
             Date dateStart = sdf.parse(starttime);
             Date datEnd = sdf.parse(endtime);
             return new long[]{dateStart.getTime(), datEnd.getTime()};
-        }catch (Exception e){
+        } catch (Exception e) {
 
         }
         return null;
@@ -2409,6 +2420,7 @@ public class CommonUtil {
 
     /**
      * 幂动btn赋值
+     *
      * @param activity
      * @param btnInstall
      * @param data

+ 4 - 3
app/src/main/java/com/sheep/gamegroup/util/DeviceUtil.java

@@ -25,9 +25,10 @@ public class DeviceUtil {
     }
 
     public static String getDeviceId(Context context) {
-        if(BuildConfig.DEBUG){//debug状态下可以任意接任务
-            return getInstance().getRandomId();
-        }
+        //这里的代码造成了切到正式服时刷设备的bug,现在修改为在测试服才可以,先注释掉,以后测试任务时再开启
+//        if(TestUtil.isTest() && BuildConfig.DEBUG){//debug状态下可以任意接任务
+//            return getInstance().getRandomId();
+//        }
         String deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
         if(TextUtils.isEmpty(deviceId)){
             try {

+ 29 - 26
app/src/main/java/com/sheep/gamegroup/util/DownloadUtil.java

@@ -149,19 +149,20 @@ public class DownloadUtil {
 
     public DownLoadInfo getDownloadTaskByUrl(IDownload taskEty) {
         DownLoadInfo downLoadInfo = getDownloadTaskByUrl(taskEty.getDownload_link());
-        if(downLoadInfo == null){
+        if (downLoadInfo == null) {
             downLoadInfo = CommonUtil.getInstance()
                     .addNewDownloadTask(taskEty.getTask_name(), taskEty.getDownload_link(), taskEty.getPackage_names(),
                             Build.VERSION.SDK_INT, taskEty.getIcon(), taskEty.getPackage_size(), taskEty.getAcceptedTaskId(), 1);
         }
         return downLoadInfo;
     }
+
     public DownLoadInfo getDownloadTaskByUrl(OrienteeringDetail taskEty) {
         DownLoadInfo downLoadInfo = getDownloadTaskByUrl(taskEty.getDownload_url());
-        if(downLoadInfo == null){
+        if (downLoadInfo == null) {
             downLoadInfo = CommonUtil.getInstance()
                     .addNewDownloadTask(taskEty.getName(), taskEty.getDownload_url(), taskEty.getPackage_name(),
-                            Build.VERSION.SDK_INT, taskEty.getIcon(), 10+"", taskEty.getGame_id().hashCode(), 1);
+                            Build.VERSION.SDK_INT, taskEty.getIcon(), 10 + "", taskEty.getGame_id().hashCode(), 1);
         }
         return downLoadInfo;
     }
@@ -212,7 +213,7 @@ public class DownloadUtil {
         if (task.getMStatus() == null) {
             task.setMStatus(0);
         }
-        if(!TextUtils.isEmpty(task.getMDownloadUrl())){
+        if (!TextUtils.isEmpty(task.getMDownloadUrl())) {
             return DDProviderHelper.getInstance().addOrUpDataDownloadTask(ctx, task);
         }
         return false;
@@ -255,6 +256,7 @@ public class DownloadUtil {
         int delete = where.delete(contentResolver);*/
         return DDProviderHelper.getInstance().deleteDownloadTaskByUrl(ctx, downloadUrl);
     }
+
     /**
      * Delete all task
      *
@@ -359,29 +361,30 @@ public class DownloadUtil {
 
 
     public void start(DownLoadInfo downLoadInfo) {
-
-                if(SpUtils.getDownNotice(SheepApp.getInstance()) == 0
-                       && NetUtil.isConnected(SheepApp.getInstance())
-                       && NetUtil.isMobile(SheepApp.getInstance())){
-                    SpUtils.saveDownNotice(SheepApp.getInstance(), 0);
-
-                    Jump2View.getInstance()
-                            .goNoticeAct(SheepApp.getInstance(), new DialogEntity(null,
-                                    "当前网络处于非WIFI状态,确定下载吗?",
-                                    "不再提示",
-                                    "确定",
-                                    null,
-                                    null,
-                                    downLoadInfo));
-                    return;
-                }
-                if(SpUtils.getDownNotice(SheepApp.getInstance()) == 1){//第一次不提示
-                    SpUtils.saveDownNotice(SheepApp.getInstance(), 0);
-                }
+        if (SpUtils.getDownNotice(SheepApp.getInstance()) == 0
+                && NetUtil.isConnected(SheepApp.getInstance())
+                && NetUtil.isMobile(SheepApp.getInstance())) {
+            SpUtils.saveDownNotice(SheepApp.getInstance(), 0);
+
+            Jump2View.getInstance()
+                    .goNoticeAct(SheepApp.getInstance(), new DialogEntity(null,
+                            "当前网络处于非WIFI状态,确定下载吗?",
+                            "不再提示",
+                            "确定",
+                            null,
+                            null,
+                            downLoadInfo));
+            return;
+        }
+        if (SpUtils.getDownNotice(SheepApp.getInstance()) == 1) {//第一次不提示
+            SpUtils.saveDownNotice(SheepApp.getInstance(), 0);
+        }
         DownloadTarget task = Aria.download(SheepApp.getInstance()).load(downLoadInfo.getMDownloadUrl()).addHeader("User-Agent", SysAppUtil.getUserAgent());
-        String filePath = DIR+ File.separator+downLoadInfo.getMPackageName()+ ClassFileHelper.FILE_SUFFIX;
-        if(TextUtils.isEmpty(downLoadInfo.getMPackageName())){
-            filePath = DIR+ File.separator+downLoadInfo.getMGameName()+ ClassFileHelper.FILE_SUFFIX;
+        String filePath;
+        if (TextUtils.isEmpty(downLoadInfo.getMPackageName())) {
+            filePath = DIR + File.separator + downLoadInfo.getMGameName() + downLoadInfo.getMDownloadUrl().hashCode() + ClassFileHelper.FILE_SUFFIX;
+        } else {
+            filePath = DIR + File.separator + downLoadInfo.getMPackageName() + downLoadInfo.getMDownloadUrl().hashCode() + ClassFileHelper.FILE_SUFFIX;
         }
         task.setFilePath(filePath).start();
     }

+ 3 - 3
app/src/main/java/com/sheep/gamegroup/view/activity/ActFindGame.java

@@ -622,13 +622,13 @@ public class ActFindGame extends BaseActivity {
             String packageName = intent.getDataString().replace("package:", "");
 
             TextView textView = getTextViewByKey(packageName);
-            if (textView != null) {
+            if (textView != null && findApp != null) {
                 switch (intent.getAction()) {
                     case ACTION_PACKAGE_ADDED:
                         textView.setText(CommonUtil.GAME_OPEN);
                         break;
                     case ACTION_PACKAGE_REMOVED:
-                        String path = PackageUtil.isExistsFile(packageName);
+                        String path = PackageUtil.isExistsFile(packageName, findApp.getDownload_url());
                         if (TextUtils.isEmpty(path)) {
                             textView.setText(CommonUtil.START_DOWNLOAD);
                         } else {
@@ -644,7 +644,7 @@ public class ActFindGame extends BaseActivity {
                         findApp.updateState(DownloadUtil.STATUS_INSTALLED);
                         break;
                     case ACTION_PACKAGE_REMOVED:
-                        String path = PackageUtil.isExistsFile(packageName);
+                        String path = PackageUtil.isExistsFile(packageName, findApp.getDownload_url());
                         if (TextUtils.isEmpty(path)) {
                             findApp.updateState(DownloadUtil.STATUS_INIT);
                         } else {

+ 3 - 3
app/src/main/java/com/sheep/gamegroup/view/activity/ActFindInformation.java

@@ -584,13 +584,13 @@ public class ActFindInformation extends BaseActivity implements Action1<Integer>
             String packageName = intent.getDataString().replace("package:", "");
 
             TextView textView = getTextViewByKey(packageName);
-            if (textView != null) {
+            if (textView != null && findApp != null) {
                 switch (intent.getAction()) {
                     case ACTION_PACKAGE_ADDED:
                         textView.setText(CommonUtil.GAME_OPEN);
                         break;
                     case ACTION_PACKAGE_REMOVED:
-                        String path = PackageUtil.isExistsFile(packageName);
+                        String path = PackageUtil.isExistsFile(packageName, findApp.getDownload_url());
                         if (TextUtils.isEmpty(path)) {
                             textView.setText(CommonUtil.START_DOWNLOAD);
                         } else {
@@ -606,7 +606,7 @@ public class ActFindInformation extends BaseActivity implements Action1<Integer>
                         findApp.updateState(DownloadUtil.STATUS_INSTALLED);
                         break;
                     case ACTION_PACKAGE_REMOVED:
-                        String path = PackageUtil.isExistsFile(packageName);
+                        String path = PackageUtil.isExistsFile(packageName, findApp.getDownload_url());
                         if (TextUtils.isEmpty(path)) {
                             findApp.updateState(DownloadUtil.STATUS_INIT);
                         } else {

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/view/activity/ActPlayGameDetail.java

@@ -439,7 +439,7 @@ public class ActPlayGameDetail extends BaseActivity implements Action1<Integer>
                         find_game_down_tv.setText(CommonUtil.GAME_OPEN);
                         break;
                     case ACTION_PACKAGE_REMOVED:
-                        String path = PackageUtil.isExistsFile(packageName);
+                        String path = PackageUtil.isExistsFile(packageName, playGameEntity.getDownload_url());
                         if (TextUtils.isEmpty(path)) {
                             find_game_down_tv.setText(CommonUtil.START_DOWNLOAD);
                         } else {
@@ -458,7 +458,7 @@ public class ActPlayGameDetail extends BaseActivity implements Action1<Integer>
                             gameEntity.getRelease_task().getDownloadHelper().updateState(DownloadUtil.STATUS_INSTALLED);
                         break;
                     case ACTION_PACKAGE_REMOVED:
-                        String path = PackageUtil.isExistsFile(packageName);
+                        String path = PackageUtil.isExistsFile(packageName, playGameEntity.getDownload_url());
                         if (TextUtils.isEmpty(path)) {
                             if(playGameEntity != null)
                                 playGameEntity.updateState(DownloadUtil.STATUS_INIT);

+ 11 - 17
app/src/main/java/com/sheep/gamegroup/view/activity/ActReservation.java

@@ -348,34 +348,28 @@ public class ActReservation extends BaseActivity {
         if(intent != null && intent.getAction() != null && intent.getDataString() != null && intent.getDataString().contains("package:")){
             String packageName = intent.getDataString().replace("package:","");
 
-            TextView textView = getTextViewByKey(packageName);
-            if(textView != null) {
-                switch (intent.getAction()){
-                    case ACTION_PACKAGE_ADDED:
-                        textView.setText(CommonUtil.GAME_OPEN);
-                        break;
-                    case ACTION_PACKAGE_REMOVED:
-                        String path = PackageUtil.isExistsFile(packageName);
-                        if(TextUtils.isEmpty(path)) {
-                            textView.setText(CommonUtil.START_DOWNLOAD);
-                        } else {
-                            textView.setText(CommonUtil.START_INSTALL);
-                        }
-                        break;
-                }
-            }
             FindApp findApp = getFindAppByKey(packageName);
+            TextView textView = getTextViewByKey(packageName);
             if(findApp != null) {
                 switch (intent.getAction()){
                     case ACTION_PACKAGE_ADDED:
+                        if(textView != null) {
+                            textView.setText(CommonUtil.GAME_OPEN);
+                        }
                         findApp.updateState(DownloadUtil.STATUS_INSTALLED);
                         break;
                     case ACTION_PACKAGE_REMOVED:
-                        String path = PackageUtil.isExistsFile(packageName);
+                        String path = PackageUtil.isExistsFile(packageName, findApp.getDownload_url());
                         if(TextUtils.isEmpty(path)) {
                             findApp.updateState(DownloadUtil.STATUS_INIT);
+                            if(textView != null) {
+                                textView.setText(CommonUtil.START_DOWNLOAD);
+                            }
                         } else {
                             findApp.updateState(DownloadUtil.STATUS_FINISH);
+                            if(textView != null) {
+                                textView.setText(CommonUtil.START_INSTALL);
+                            }
                         }
                         break;
                 }

+ 12 - 9
app/src/main/java/com/sheep/gamegroup/view/activity/ActSignCard.java

@@ -240,7 +240,7 @@ public class ActSignCard extends BaseActivity {
                         }
                         sign_card_users.setLayoutManager(new GridLayoutManager(SheepApp.getInstance(), userList.size()));
                         sign_card_users.getAdapter().notifyDataSetChanged();
-                        ViewUtil.setText(sign_card_total_bonus, punchAndSign.getSign_up_count());
+                        ViewUtil.setText(sign_card_total_bonus, String.format(Locale.CHINA, "%s元", punchAndSign.getSign_up_count()));
                         ViewUtil.setText(sign_card_total_people, String.format(Locale.CHINA, "当前参与人数%s人", punchAndSign.getSign_up_count()));
                         ViewUtil.setText(sign_card_success_people, punchAndSign.getPunch_count());
                         ViewUtil.setText(sign_card_fail_people, punchAndSign.getNoPunch_count());
@@ -430,17 +430,20 @@ public class ActSignCard extends BaseActivity {
     };
     private long totalTime = INIT;
     private void initBtnState() {
-        if (punchType == 3) {//可以打卡
-            sign_card_join.setEnabled(true);
-            sign_card_join.setText("参加打卡挑战");
-        } else if (initCanSignUp == SUCCESS && isCanSignUp) {//可以报名
-            sign_card_join.setEnabled(true);
-            sign_card_join.setText("报名打卡");
-        } else if(punchAndSign != null && punchAndSign.getCountdown() > 0 && initCanSignUp == SUCCESS && punchType > 2){
-            if(totalTime == INIT) {//只设置一次
+        if(punchAndSign != null && initCanSignUp == SUCCESS && punchType > SUCCESS){//初始化成功
+            if (punchType == 3) {//可以打卡
+                sign_card_join.setEnabled(true);
+                sign_card_join.setText("参加打卡挑战");
+            } else if (isCanSignUp) {//可以报名
+                sign_card_join.setEnabled(true);
+                sign_card_join.setText("报名打卡");
+            } else if(totalTime == INIT) {//只设置一次
                 sign_card_join.setEnabled(false);
                 totalTime = punchAndSign.getCountdown();
                 handler.sendEmptyMessage(0);//开始计时
+            } else {
+                sign_card_join.setEnabled(false);
+                sign_card_join.setText(R.string.service_data_error);
             }
         } else {
             sign_card_join.setEnabled(false);

+ 24 - 9
app/src/main/java/com/sheep/gamegroup/view/activity/SplashAct.java

@@ -14,7 +14,6 @@ import android.provider.Settings;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AlertDialog;
-import android.text.TextUtils;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.TextView;
@@ -31,7 +30,6 @@ import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.gamegroup.util.RxjavaCountDownTimer;
 import com.sheep.gamegroup.util.SysAppUtil;
-import com.sheep.jiuyan.samllsheep.BuildConfig;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 
@@ -119,19 +117,19 @@ public class SplashAct extends BaseActivity implements EasyPermissions.Permissio
             super.handleMessage(msg);
             switch (msg.what){
                 case 0:
-                    if(!isRequestCodePermissions && !isLoaddingData && timerIsFinish())
+                    if(!isRequestCodePermissions && !isLoadingData && timerIsFinish())
                         gotoNext();
                     else
                         sendHandlerMessages(100);
                     break;
                 case 1:
                     if(SysAppUtil.isNewSmallSheep()){//新版本只显示引导页面,不展示弹窗和开屏广告
-                        isLoaddingData = false;
+                        isLoadingData = false;
                         sendHandlerMessages(200);
                     } else {
                         Advertising cacheAdvertising = DataUtil.getInstance().getCacheResult(ApiKey.advertisements(1), Advertising.class);
                         if (cacheAdvertising != null) {
-                            isLoaddingData = false;
+                            isLoadingData = false;
                             advertising = cacheAdvertising;
                             try {
                                 loadAdvertising();
@@ -146,7 +144,7 @@ public class SplashAct extends BaseActivity implements EasyPermissions.Permissio
                                         @Override
                                         public void onNext(BaseMessage baseMessage) {
                                             DataUtil.getInstance().resetCacheTime(ApiKey.advertisements(1), 3600*5);//开屏广告最多缓存5个小时
-                                            isLoaddingData = false;
+                                            isLoadingData = false;
                                             advertising = baseMessage.getData(Advertising.class);
                                             try {
                                                 loadAdvertising();
@@ -157,7 +155,7 @@ public class SplashAct extends BaseActivity implements EasyPermissions.Permissio
 
                                         @Override
                                         public void onError(BaseMessage baseMessage) {
-                                            isLoaddingData = false;
+                                            isLoadingData = false;
                                             sendHandlerMessages(10);
                                         }
                                     });
@@ -196,17 +194,34 @@ public class SplashAct extends BaseActivity implements EasyPermissions.Permissio
 //        } else {
 //            mHandler.sendEmptyMessageDelayed(1, 500);
 //        }
-        mHandler.sendEmptyMessageDelayed(1, 500);
     }
 
     @Override
     public void initListener() {
 
     }
-    private boolean isLoaddingData = true;//是否正在获取开屏广告数据
+    private boolean isLoadingData = true;//是否正在获取开屏广告数据
     private Advertising advertising;
     @Override
     public void initData() {
+        SheepApp.getInstance().getNetComponent().getApiService().checkUserFirst()
+                        .subscribeOn(Schedulers.io())
+                        .observeOn(AndroidSchedulers.mainThread())
+                        .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                            @Override
+                            public void onNext(BaseMessage baseMessage) {
+                                boolean isNewSmallSheep = baseMessage.getData(Boolean.class);
+                                DataUtil.getInstance().setIsNewSmallSheep(isNewSmallSheep);
+                                mHandler.sendEmptyMessageDelayed(1, 300);
+                            }
+
+                            @Override
+                            public void onError(BaseMessage baseMessage) {
+                                //访问出错时,认为不是新设备
+                                DataUtil.getInstance().setIsNewSmallSheep(false);
+                                mHandler.sendEmptyMessageDelayed(1, 300);
+                            }
+                        });
     }
 
     private void loadAdvertising() {

+ 20 - 3
app/src/main/java/com/sheep/gamegroup/view/activity/TaskDetailAct.java

@@ -322,6 +322,8 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
     }
     private static final int TASK_TYPE_INIT = -1;//初始化状态,可能是未领取,如果不是请让第一按钮处于不可见或者不可操作状态
     private static final int TASK_TYPE_H5 = 10;//h5任务标志
+    private static final int TASK_TYPE_SUCCESSION_H5_OUT = 13;//连续任务中的h5任务标志
+    private static final int TASK_TYPE_SUCCESSION_H5_IN = 12;//连续任务中的h5任务标志
     private static final int TASK_TYPE_RESERVATION = 11;//游戏任务中还不可以下载任务(预约任务)-->预约游戏
     /**
      * 用户操作按钮状态与文字设置
@@ -351,13 +353,13 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
                     switch (taskEty.getOpen_mode()){//连续任务的打开方式 1:打开应用 2:H5内部 3:H5外部
                         case 2:
                         case 3:
+                            type = TASK_TYPE_H5 + taskEty.getOpen_mode();
                             btnTaskItem.setText(START_TASK);
                             break;
                         case 1:
                         default:
                             setFirstBtnState();
                             break;
-
                     }
                     int failChildPosition = taskEty.getFailChildPosition();//获取第一个审核失败子任务的位置
                     if (type == DownloadUtil.STATUS_INSTALLED && gettaskAcceptedEty != null && failChildPosition > -1) {//已经安装并且有任务未完成的情况下
@@ -436,6 +438,7 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
                         switch (taskEty.getOpen_mode()){//连续任务的打开方式 1:打开应用 2:H5内部 3:H5外部
                             case 2:
                             case 3:
+                                type = TASK_TYPE_H5 + taskEty.getOpen_mode();
                                 btnTaskItem.setText(START_TASK);
                                 break;
                             case 1:
@@ -661,7 +664,7 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
 
     public static void setBtnStr(IDownload taskEty, DownloadUtil mDownloadTaskService, Action1<Object> action1) {
         boolean isInstalled = PackageUtil.isAppInstalled(SheepApp.getInstance(), taskEty.getPackage_names());
-        boolean isExistApk = !TextUtils.isEmpty(PackageUtil.isExistsFile(taskEty.getPackage_names()));
+        boolean isExistApk = !TextUtils.isEmpty(PackageUtil.isExistsFile(taskEty.getPackage_names(), taskEty.getDownload_link()));
         String buttonStr;
         action1.call(true);
         if (isInstalled) {
@@ -871,7 +874,7 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
                 UMConfigUtils.onEvent(UMConfigUtils.Event.TASK_DOWNLOAD);
                 break;
             case DownloadUtil.STATUS_FINISH:
-                ApkUtils.installApk(SheepApp.getInstance(), PackageUtil.isExistsFile(taskEty.getPackage_names()));
+                ApkUtils.installApk(SheepApp.getInstance(), PackageUtil.isExistsFile(taskEty.getPackage_names(), taskEty.getDownload_link()));
                 break;
             case DownloadUtil.STATUS_INSTALLED:
                 PackageUtil.startApp(SheepApp.getInstance(), taskEty.getPackage_names());
@@ -884,6 +887,20 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
                     Jump2View.getInstance().goWeb(activity, ext.getUrl());
                 }
                 break;
+            case TASK_TYPE_SUCCESSION_H5_OUT://连续任务中的h5任务跳转h5页面,这里服务器返回的连接放到了下载链接里
+                if (taskEty == null || TextUtils.isEmpty(taskEty.getDownload_link())) {
+                    G.showToast(R.string.service_data_error);
+                } else {
+                    Jump2View.getInstance().goWeb(activity, taskEty.getDownload_link());
+                }
+                break;
+            case TASK_TYPE_SUCCESSION_H5_IN://连续任务中的h5任务跳转h5页面,这里服务器返回的连接放到了下载链接里
+                if (taskEty == null || TextUtils.isEmpty(taskEty.getDownload_link())) {
+                    G.showToast(R.string.service_data_error);
+                } else {
+                    Jump2View.getInstance().goWeb(activity, taskEty.getDownload_link(), taskEty.getTask_name());
+                }
+                break;
         }
     }
 

+ 0 - 13
app/src/main/java/com/sheep/gamegroup/view/activity/TaskDetailCreditCardAct.java

@@ -169,19 +169,6 @@ public class TaskDetailCreditCardAct extends AbsChooseImageActivity {
         detail_task_listview.setVisibility(View.GONE);
         if (taskEty.getTask_type() == 2) {
             btnTaskItem.setText("信用卡注册");
-        } else if (PackageUtil.isAppInstalled(SheepApp.getInstance(), taskEty.getPackage_names())) {
-            btnTaskItem.setText("开始游戏");
-        } else if (!TextUtils.isEmpty(PackageUtil.isExistsFile(taskEty.getPackage_names()))) {
-            btnTaskItem.setText("开始安装");
-        } else {
-            DownLoadInfo downLoadInfo = DDProviderHelper.getInstance()
-                    .getDownloadTaskToPackname(activity, taskEty.getPackage_names());
-            if (downLoadInfo != null && !TextUtils.isEmpty(downLoadInfo.getMApkPath())) {
-                btnTaskItem.setText("开始安装");
-            } else {
-                btnTaskItem.setText("下载游戏");
-            }
-
         }
     }
 

+ 3 - 3
app/src/main/java/com/sheep/gamegroup/view/adapter/TryMakeMoneyAdp.java

@@ -254,7 +254,7 @@ public class TryMakeMoneyAdp extends AdbCommonRecycler<RecyleObj> {
                 detail_task_tv.setBackground(context.getResources().getDrawable(R.drawable.sp_bg_gradient_rectangle_blue));
                 //领取任务
                 final boolean isInstall = PackageUtil.isAppInstalled(SheepApp.getInstance(), item.getPackage_name());
-                boolean isExistApk = !TextUtils.isEmpty(PackageUtil.isExistsFile(item.getPackage_name()));
+                boolean isExistApk = !TextUtils.isEmpty(PackageUtil.isExistsFile(item.getPackage_name(), item.getDownload_url()));
                 final DownloadUtil mDownloadTaskService = new DownloadUtil(context);
 
                 String taskTypeTvValue;
@@ -301,11 +301,11 @@ public class TryMakeMoneyAdp extends AdbCommonRecycler<RecyleObj> {
                         try{
                             switch (task_type_tv.getText().toString().trim() +""){
                                 case "安装游戏":
-                                    ApkUtils.installApk(SheepApp.getInstance(), PackageUtil.isExistsFile(item.getPackage_name()));
+                                    ApkUtils.installApk(SheepApp.getInstance(), PackageUtil.isExistsFile(item.getPackage_name(), item.getDownload_url()));
                                     PackageUtil.startApp(SheepApp.getInstance(), item.getPackage_name());
                                     break;
                                 case "启动游戏":
-                                    ApkUtils.installApk(SheepApp.getInstance(), PackageUtil.isExistsFile(item.getPackage_name()));
+                                    ApkUtils.installApk(SheepApp.getInstance(), PackageUtil.isExistsFile(item.getPackage_name(), item.getDownload_url()));
                                     PackageUtil.startApp(SheepApp.getInstance(), item.getPackage_name());
                                     break;
                                 default:

+ 11 - 18
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtFindChild.java

@@ -358,35 +358,28 @@ public class FgtFindChild extends BaseListFragment<FindItem> {
         if(intent != null && intent.getAction() != null && intent.getDataString() != null && intent.getDataString().contains("package:")){
             String packageName = intent.getDataString().replace("package:","");
 
-            TextView textView = getTextViewByKey(packageName);
-            if(textView != null) {
-                switch (intent.getAction()){
-                    case ACTION_PACKAGE_ADDED:
-                        textView.setText(CommonUtil.GAME_OPEN);
-                        break;
-                    case ACTION_PACKAGE_REMOVED:
-                        String path = PackageUtil.isExistsFile(packageName);
-                        if(TextUtils.isEmpty(path)) {
-                            textView.setText(CommonUtil.START_DOWNLOAD);
-                        } else {
-                            textView.setText(CommonUtil.START_INSTALL);
-                        }
-                        break;
-                }
-            }
-
             FindApp findApp = getFindAppByKey(packageName);
+            TextView textView = getTextViewByKey(packageName);
             if(findApp != null) {
                 switch (intent.getAction()){
                     case ACTION_PACKAGE_ADDED:
+                        if(textView != null) {
+                            textView.setText(CommonUtil.GAME_OPEN);
+                        }
                         findApp.updateState(DownloadUtil.STATUS_INSTALLED);
                         break;
                     case ACTION_PACKAGE_REMOVED:
-                        String path = PackageUtil.isExistsFile(packageName);
+                        String path = PackageUtil.isExistsFile(packageName, findApp.getDownload_url());
                         if(TextUtils.isEmpty(path)) {
                             findApp.updateState(DownloadUtil.STATUS_INIT);
+                            if(textView != null) {
+                                textView.setText(CommonUtil.START_DOWNLOAD);
+                            }
                         } else {
                             findApp.updateState(DownloadUtil.STATUS_FINISH);
+                            if(textView != null) {
+                                textView.setText(CommonUtil.START_INSTALL);
+                            }
                         }
                         break;
                 }

+ 68 - 14
app/src/main/java/com/sheep/jiuyan/samllsheep/service/DownloadService.java

@@ -4,28 +4,44 @@ import android.app.Service;
 import android.content.Intent;
 import android.os.IBinder;
 import android.support.annotation.Nullable;
+import android.view.View;
 
 import com.arialyy.annotations.Download;
 import com.arialyy.aria.core.Aria;
 import com.arialyy.aria.core.download.DownloadTask;
 import com.sheep.gamegroup.event.BigEvent;
 import com.sheep.gamegroup.event.EventTypes;
+import com.sheep.gamegroup.model.entity.DialogConfig;
+import com.sheep.gamegroup.util.ActivityManager;
 import com.sheep.gamegroup.util.DownloadUtil;
 import com.kfzs.duanduan.utils.ApkUtils;
 import com.kfzs.duanduan.view.DialogStorageLow;
 import com.sheep.gamegroup.util.LogUtil;
+import com.sheep.gamegroup.util.TestUtil;
+import com.sheep.gamegroup.util.ViewUtil;
+import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
 
 import org.greenrobot.eventbus.EventBus;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import rx.Observable;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.functions.Action1;
+import rx.schedulers.Schedulers;
+
 /**
- *  @auther realicing
+ * @auther realicing
  * 自动更新的Service
  */
 
-public class DownloadService extends Service{
+public class DownloadService extends Service {
 
     private DownloadUtil mDownloadTaskService;
+
     @Override
     public void onCreate() {
         super.onCreate();
@@ -33,57 +49,95 @@ public class DownloadService extends Service{
         mDownloadTaskService = new DownloadUtil(this);
     }
 
-    @Download.onPre void onPre(DownloadTask task) {
+    private Map<String, DownloadTask> downloadTaskMap = new HashMap<>();
+
+    @Download.onPre
+    void onPre(final DownloadTask task) {
         LogUtil.println("DownloadService", "onPre", task.getKey(), task.getTaskName());
+        downloadTaskMap.put(task.getKey(), task);
+
+        Observable.just(1).delay(5000L, TimeUnit.MILLISECONDS)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new Action1<Integer>() {
+                    @Override
+                    public void call(Integer integer) {
+                        if (downloadTaskMap.containsKey(task.getKey())) {
+                            ViewUtil.showMsgDialog(ActivityManager.getInstance().currentActivity(), new DialogConfig().setTitle("提示")
+                                    .setMsg("下载无响应,是否使用其它下载方式(在列表中长按任务也可选择其它下载方式)").setBtnLeftText("取消").setBtnRightText("确定")
+                                    .setBtnRightOnClickListener(new View.OnClickListener() {
+                                        @Override
+                                        public void onClick(View view) {
+                                            TestUtil.sysDownload(SheepApp.getInstance(), task.getKey(), task.getTaskName(), "下载小绵羊任务中的apk:" + task.getTaskName(), task.getTaskName()+task.getKey().hashCode() + ".apk", "正在下载");
+                                        }
+                                    }));
+                        }
+                    }
+                });
     }
-    @Download.onTaskStart void taskStart(DownloadTask task) {
+
+    @Download.onTaskStart
+    void taskStart(DownloadTask task) {
         LogUtil.println("DownloadService", "taskStart", task.getKey(), task.getTaskName());
     }
-    @Download.onTaskResume void taskResume(DownloadTask task) {
+
+    @Download.onTaskResume
+    void taskResume(DownloadTask task) {
         LogUtil.println("DownloadService", "taskResume", task.getKey(), task.getTaskName());
     }
+
     //在这里处理任务执行中的状态,如进度进度条的刷新
-    @Download.onTaskRunning protected void running(DownloadTask task) {
+    @Download.onTaskRunning
+    protected void running(DownloadTask task) {
         LogUtil.println("DownloadService", "running", task.getKey(), task.getTaskName(), task.getPercent());
-        mDownloadTaskService.setDownloadTaskPercent(task.getPercent(), task.getCurrentProgress()/1024d/1024d,task.getFileSize()/1024d/1024d,0,task.getKey());
+        if (downloadTaskMap.containsKey(task.getKey())) {
+            downloadTaskMap.remove(task.getKey());
+        }
+        mDownloadTaskService.setDownloadTaskPercent(task.getPercent(), task.getCurrentProgress() / 1024d / 1024d, task.getFileSize() / 1024d / 1024d, 0, task.getKey());
         EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.GENERATION_ACCOUNT_REFRESH_ADAPTER).setData(task));
     }
 
-    @Download.onTaskStop void taskStop(DownloadTask task) {
+    @Download.onTaskStop
+    void taskStop(DownloadTask task) {
         LogUtil.println("DownloadService", "taskStop", task.getKey(), task.getTaskName());
         mDownloadTaskService.setDownloadTaskStatus(task.getKey(), DownloadUtil.STATUS_PAUSE);
         EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_STOP).setData(task));
     }
 
-    @Download.onNoSupportBreakPoint void onNoSupportBreakPoint(DownloadTask task) {
+    @Download.onNoSupportBreakPoint
+    void onNoSupportBreakPoint(DownloadTask task) {
     }
 
-    @Download.onTaskCancel void taskCancel(DownloadTask task) {
+    @Download.onTaskCancel
+    void taskCancel(DownloadTask task) {
         LogUtil.println("DownloadService", "taskCancel", task.getKey(), task.getTaskName());
         mDownloadTaskService.deleteDownloadTaskByDownloadUrl(task.getKey());
         EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_CANCEL).setData(task));
     }
 
-    @Download.onTaskFail void taskFail(DownloadTask task) {
+    @Download.onTaskFail
+    void taskFail(DownloadTask task) {
         LogUtil.println("DownloadService", "taskFail", task.getKey(), task.getTaskName());
         mDownloadTaskService.setDownloadTaskStatus(task.getKey(), DownloadUtil.STATUS_FAIL);
         EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_FAIL).setData(task));
         //空间不足,弹框提示
-        try{
+        try {
             if (0 <= task.getFileSize() && task.getFileSize() > G.getFreeSpaceB()) {
                 DialogStorageLow.showDialog(DownloadService.this);
             }
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
         }
     }
 
-    @Download.onTaskComplete void taskComplete(DownloadTask task) {
+    @Download.onTaskComplete
+    void taskComplete(DownloadTask task) {
         LogUtil.println("DownloadService", "taskComplete", task.getKey(), task.getTaskName());
         mDownloadTaskService.setDownloadTaskFinish(task.getKey(), task.getDownloadPath());
         ApkUtils.installApk(getApplicationContext(), task.getDownloadPath());
         EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_COMPLETE).setData(task));
     }
+
     @Nullable
     @Override
     public IBinder onBind(Intent intent) {

+ 42 - 50
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/ClassFileHelper.java

@@ -1,12 +1,12 @@
 package com.sheep.jiuyan.samllsheep.utils;
 
+import android.os.Environment;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 
-import android.os.Environment;
-
 /**
  * Created by d on 2016/11/10.
  * Method:
@@ -14,7 +14,7 @@ import android.os.Environment;
  * getSDCardTotal() 总容量
  * getSDCardFree() 可用容量
  * createSDDirection()   创建目录
- *deleteSDDirection  删除目录
+ * deleteSDDirection  删除目录
  * isFileExist 文件是否存在
  * deleteSDFile  删除文件
  * renameSDFile 修改文件或目录
@@ -35,30 +35,30 @@ import android.os.Environment;
  * copyFilesTo
  * moveFileTo 移动
  * moveFilesTo
- *
  */
 public class ClassFileHelper {
-    private static  String SDPATH= Environment.getExternalStorageDirectory().getAbsolutePath();
-    public  static  String FILE_SUFFIX=".apk";
-    public static   String DIR=Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"Sheep";
-    public  static  ClassFileHelper INSTANCE=new ClassFileHelper();
+    private static String SD_PATH = Environment.getExternalStorageDirectory().getAbsolutePath();
+    public static String FILE_SUFFIX = ".apk";
+    public static String DIR = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Sheep";
+    public static ClassFileHelper INSTANCE = new ClassFileHelper();
 
-    private ClassFileHelper( ){
+    private ClassFileHelper() {
     }
-    public  static ClassFileHelper   getInstance( ){
-      return  INSTANCE;
+
+    public static ClassFileHelper getInstance() {
+        return INSTANCE;
     }
 
     //表示SDCard存在并且可以读写
-    public boolean isSDCardState(){
-        if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
+    public boolean isSDCardState() {
+        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
             return true;
-        }else{
+        } else {
             return false;
         }
     }
 
-    public  String gbEncoding(final String gbString) {
+    public String gbEncoding(final String gbString) {
         char[] utfBytes = gbString.toCharArray();   //utfBytes = [测, 试]
         StringBuilder unicodeBytes = new StringBuilder();
         for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) {
@@ -75,8 +75,9 @@ public class ClassFileHelper {
 
     /**
      * 在SD卡上创建目录
+     * <p>
+     * 要创建的目录名
      *
-     *            要创建的目录名
      * @return 创建得到的目录
      */
     public void createSDDirection() {
@@ -90,23 +91,22 @@ public class ClassFileHelper {
     }
 
 
+    public boolean isInstallFile(String fileName) {
+        File file = new File(DIR);
 
-   public  boolean  isInstallFile(String  fileName){
-       File  file=new File(DIR);
-
-       File[] fileArray = file.listFiles();
+        File[] fileArray = file.listFiles();
 
-       for (File f : fileArray) {
-           if (f.isFile()) {
-               if(f.getName().equals(fileName+".apk")){
-                   return  true;
-               }
-           }
+        for (File f : fileArray) {
+            if (f.isFile()) {
+                if (f.getName().equals(fileName + ".apk")) {
+                    return true;
+                }
+            }
 
-       }
-         return false;
+        }
+        return false;
 
-       }
+    }
 
 
     /**
@@ -115,15 +115,14 @@ public class ClassFileHelper {
      * @param dirName
      */
     public boolean deleteSDDirection(String dirName) {
-        File dir = new File(SDPATH + dirName);
+        File dir = new File(SD_PATH + dirName);
         return deleteDirection(dir);
     }
 
     /**
      * 判断文件是否已经存在
      *
-     * @param fileName
-     *         要检查的文件名
+     * @param fileName 要检查的文件名
      * @return boolean, true表示存在,false表示不存在
      */
     public boolean isFileExist(String fileName) {
@@ -137,7 +136,7 @@ public class ClassFileHelper {
      * @param fileName
      */
     public boolean deleteSDFile(String fileName) {
-        File file = new File(SDPATH + fileName);
+        File file = new File(SD_PATH + fileName);
         if (file == null || !file.exists() || file.isDirectory())
             return false;
         file.delete();
@@ -151,8 +150,8 @@ public class ClassFileHelper {
      * @param
      */
     public boolean renameSDFile(String oldfileName, String newFileName) {
-        File oleFile = new File(SDPATH + oldfileName);
-        File newFile = new File(SDPATH + newFileName);
+        File oleFile = new File(SD_PATH + oldfileName);
+        File newFile = new File(SD_PATH + newFileName);
         return oleFile.renameTo(newFile);
     }
 
@@ -165,13 +164,12 @@ public class ClassFileHelper {
      */
 
     public boolean copySDFileTo(String srcFileName, String destFileName) throws IOException {
-        File srcFile = new File(SDPATH + srcFileName);
-        File destFile = new File(SDPATH + destFileName);
+        File srcFile = new File(SD_PATH + srcFileName);
+        File destFile = new File(SD_PATH + destFileName);
         return copyFileTo(srcFile, destFile);
     }
 
 
-
     /**
      * 拷贝SD卡上指定目录的所有文件
      *
@@ -181,13 +179,12 @@ public class ClassFileHelper {
      * @throws IOException
      */
     public boolean copySDFilesTo(String srcDirName, String destDirName) throws IOException {
-        File srcDir = new File(SDPATH + srcDirName);
-        File destDir = new File(SDPATH + destDirName);
+        File srcDir = new File(SD_PATH + srcDirName);
+        File destDir = new File(SD_PATH + destDirName);
         return copyFilesTo(srcDir, destDir);
     }
 
 
-
     /**
      * 移动SD卡上的单个文件
      *
@@ -198,13 +195,12 @@ public class ClassFileHelper {
      */
 
     public boolean moveSDFileTo(String srcFileName, String destFileName) throws IOException {
-        File srcFile = new File(SDPATH + srcFileName);
-        File destFile = new File(SDPATH + destFileName);
+        File srcFile = new File(SD_PATH + srcFileName);
+        File destFile = new File(SD_PATH + destFileName);
         return moveFileTo(srcFile, destFile);
     }
 
 
-
     /**
      * 移动SD卡上的指定目录的所有文件
      *
@@ -215,13 +211,12 @@ public class ClassFileHelper {
      */
 
     public boolean moveSDFilesTo(String srcDirName, String destDirName) throws IOException {
-        File srcDir = new File(SDPATH + srcDirName);
-        File destDir = new File(SDPATH + destDirName);
+        File srcDir = new File(SD_PATH + srcDirName);
+        File destDir = new File(SD_PATH + destDirName);
         return moveFilesTo(srcDir, destDir);
     }
 
 
-
     /**
      * 删除一个文件
      *
@@ -360,9 +355,6 @@ public class ClassFileHelper {
         }
         return true;
     }
-    public static String getFilePathByPackageName(String packgeName){
-        return DIR+ File.separator+packgeName+ FILE_SUFFIX;
-    }
 
     public void clearDir() {
         File dir = new File(DIR);

+ 2 - 8
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/PackageUtil.java

@@ -12,7 +12,6 @@ import android.content.pm.ResolveInfo;
 import android.net.Uri;
 import android.os.Build;
 import android.support.v4.content.FileProvider;
-import android.util.Log;
 
 import com.sheep.gamegroup.util.UMConfigUtils;
 import com.sheep.jiuyan.samllsheep.SheepApp;
@@ -217,17 +216,12 @@ public class PackageUtil {
     /**
      * 通过包名、路径判断是否下载过
      */
-    public static String isExistsFile(String packName){
+    public static String isExistsFile(String packName, String downloadUrl){
         ClassFileHelper.getInstance().createSDDirection();
-        File mApkPath = new File(ClassFileHelper.DIR, packName + ClassFileHelper.FILE_SUFFIX);
+        File mApkPath = new File(ClassFileHelper.DIR, packName + downloadUrl.hashCode() + ClassFileHelper.FILE_SUFFIX);
         if (!mApkPath.exists()) {
             return null;
         }else{
-//            mApkPath.length();
-            Log.e("length-------",mApkPath.length()+"");
-            Log.e("getTotalSpace-------",mApkPath.getTotalSpace()+"");
-            Log.e("getFreeSpace-------",mApkPath.getFreeSpace()+"");
-            Log.e("getUsableSpace-------",mApkPath.getUsableSpace()+"");
             return mApkPath.getAbsolutePath();
         }
     }