Ver código fonte

ad bug fixed

billyyoyo 6 anos atrás
pai
commit
9186deef50

+ 8 - 3
app/src/main/java/com/sheep/gamegroup/module/home/fragment/FgtMainHeader.java

@@ -29,6 +29,7 @@ import com.sheep.gamegroup.view.fragment.FgtPersonalCenter;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.base.BaseFragment;
+import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 import com.sheep.gamegroup.util.DownloadUtil;
 
@@ -236,10 +237,14 @@ public class FgtMainHeader extends BaseFragment {
             case DOWNLOAD_RUNNING:
             case DOWNLOAD_STOP:
             case DOWNLOAD_COMPLETE:
-            case DOWNLOAD_FAIL:
             case DOWNLOAD_CANCEL:
-                LogUtil.logI(event.getData().toString());
-                showDownloadInfo();
+                if (event.getData() != null) {
+                    LogUtil.logI(event.getData().toString());
+                    showDownloadInfo();
+                }
+                break;
+            case DOWNLOAD_FAIL:
+                G.showToast("下载失败");
                 break;
         }
     }

+ 21 - 9
app/src/main/java/com/sheep/jiuyan/samllsheep/service/DownloadService.java

@@ -150,7 +150,9 @@ public class DownloadService extends Service {
                 case "apk":
                 default:
                     DownLoadInfo downloadInfo = downloadUtil.setDownloadTaskTotal(task.getUrl(), totalLength);
-                    EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_START).setData(downloadInfo));
+                    if (downloadInfo != null) {
+                        EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_START).setData(downloadInfo));
+                    }
                     break;
             }
         }
@@ -170,7 +172,9 @@ public class DownloadService extends Service {
                 case "apk":
                 default:
                     DownLoadInfo downloadInfo = downloadUtil.setDownloadTaskPercent(currentOffset, taskSpeed.averageSpeed(), task.getId(), task.getUrl());
-                    EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_RUNNING).setData(downloadInfo));
+                    if (downloadInfo != null) {
+                        EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_RUNNING).setData(downloadInfo));
+                    }
                     break;
             }
         }
@@ -197,8 +201,10 @@ public class DownloadService extends Service {
                         case COMPLETED://下载完成
                             if (task.getFile() != null) {
                                 downLoadInfo = downloadUtil.setDownloadTaskFinish(task.getUrl(), task.getFile().getAbsolutePath());
+                                if (downLoadInfo != null) {
+                                    EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_COMPLETE).setData(downLoadInfo));
+                                }
                                 ApkUtils.installApk(getApplicationContext(), task.getFile().getAbsolutePath());
-                                EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_COMPLETE).setData(downLoadInfo));
                             }
                             break;
                         case PRE_ALLOCATE_FAILED://预先分配失败
@@ -209,11 +215,13 @@ public class DownloadService extends Service {
                                 e.printStackTrace();
                             }
                             downLoadInfo = downloadUtil.getDownloadTaskByUrl(task.getUrl());
-                            downLoadInfo.setMStatus(DownloadUtil.STATUS_FAIL);
-                            if (realCause != null)
-                                downLoadInfo.setRealCauseMsg(realCause.getMessage());
-                            DDProviderHelper.getInstance().updateDownload(downLoadInfo);
-                            EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_FAIL).setData(downLoadInfo));
+                            if (downLoadInfo != null) {
+                                downLoadInfo.setMStatus(DownloadUtil.STATUS_FAIL);
+                                if (realCause != null)
+                                    downLoadInfo.setRealCauseMsg(realCause.getMessage());
+                                DDProviderHelper.getInstance().updateDownload(downLoadInfo);
+                                EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_FAIL).setData(downLoadInfo));
+                            }
                             break;
                         case FILE_BUSY:
                         case ERROR://下载错误
@@ -236,12 +244,16 @@ public class DownloadService extends Service {
                             } else {
                                 if (downLoadInfo != null) {
                                     EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_FAIL).setData(downLoadInfo));
+                                } else {
+                                    EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_FAIL));
                                 }
                             }
                             break;
                         case CANCELED://取消下载
                             downLoadInfo = downloadUtil.setDownloadTaskStatus(task.getUrl(), DownloadUtil.STATUS_PAUSE);
-                            EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_STOP).setData(downLoadInfo));
+                            if (downLoadInfo != null) {
+                                EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DOWNLOAD_STOP).setData(downLoadInfo));
+                            }
                             break;
                         case SAME_TASK_BUSY:
                             break;