Explorar o código

下载文件的名字中添加下载地址的hashCode(可能存在两个地方都要下载同一个包名的应用,这时可能不能正常下载第二个)

zengjiebin %!s(int64=7) %!d(string=hai) anos
pai
achega
6322505c68

+ 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://已经安装,可以试玩

+ 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

+ 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;
                 }

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

@@ -664,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) {
@@ -874,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());

+ 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;
                 }

+ 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();
         }
     }