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

尝试优化崩溃的问题

zengjiebin пре 8 година
родитељ
комит
4044310ff8

+ 48 - 32
app/src/main/java/com/kfzs/duanduan/ActDownloadMgr.java

@@ -407,22 +407,26 @@ public class ActDownloadMgr extends BaseCompatActivity {
     }
     //在这里处理任务执行中的状态,如进度进度条的刷新
     @Download.onTaskRunning protected void running(DownloadTask task) {
-        int p = task.getPercent();    //任务进度百分比
 //        downloadTaskService.setDownloadTaskPercent(p, task.getCurrentProgress()/1024d/1024d,task.getFileSize()/1024d/1024d,0,task.getKey());
-        String speed = task.getConvertSpeed();    //转换单位后的下载速度,单位转换需要在配置文件中打开
-        System.out.println("Aria "+task.getKey()+",p " + p + ", speed = " + speed);
-        String url = task.getKey();
-        KFProgressButton targetBtn = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_BUTTON + url);
-        ProgressBar pbProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_PROGRESS + url);
-        TextView tvProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_TEXTVIEW + url);
-        if (tvProgress == null) {
-            return;
-        }
-        tvProgress.setText(strFormat(this,task.getCurrentProgress()/1024d/1024d,task.getFileSize()/1024d/1024d));
-        pbProgress.setProgress(task.getPercent());
-        targetBtn.setText(R.string.downloading);
+        try {
+            int p = task.getPercent();    //任务进度百分比
+            String speed = task.getConvertSpeed();    //转换单位后的下载速度,单位转换需要在配置文件中打开
+            System.out.println("Aria "+task.getKey()+",p " + p + ", speed = " + speed);
+            String url = task.getKey();
+            KFProgressButton targetBtn = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_BUTTON + url);
+            ProgressBar pbProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_PROGRESS + url);
+            TextView tvProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_TEXTVIEW + url);
+            if (tvProgress == null) {
+                return;
+            }
+            tvProgress.setText(strFormat(this,task.getCurrentProgress()/1024d/1024d,task.getFileSize()/1024d/1024d));
+            pbProgress.setProgress(task.getPercent());
+            targetBtn.setText(R.string.downloading);
 
-        setTaskStatusByDownloadUrl(url, DownloadTaskService.STATUS_ING, task.getDownloadPath());
+            setTaskStatusByDownloadUrl(url, DownloadTaskService.STATUS_ING, task.getDownloadPath());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     @Download.onTaskStop void taskStop(DownloadTask task) {
@@ -435,35 +439,47 @@ public class ActDownloadMgr extends BaseCompatActivity {
 
     @Download.onTaskCancel void taskCancel(DownloadTask task) {
 //        downloadTaskService.deleteDownloadTaskByDownloadUrl(task.getKey());
-        String url = task.getKey();
-        int iTempPosition = -1;
-        for (int position = 0; position < downloadTasks.size(); position++) {
-            DownLoadInfo downLoadInfo = downloadTasks.get(position);
-            if (url.equals(downLoadInfo.getMDownloadUrl())) {
-                iTempPosition = position;
-                break;
+        try {
+            String url = task.getKey();
+            int iTempPosition = -1;
+            for (int position = 0; position < downloadTasks.size(); position++) {
+                DownLoadInfo downLoadInfo = downloadTasks.get(position);
+                if (url.equals(downLoadInfo.getMDownloadUrl())) {
+                    iTempPosition = position;
+                    break;
+                }
             }
+            if (iTempPosition < 0) {
+                return;
+            }
+            removeTask(iTempPosition);
+        } catch (Exception e) {
+            e.printStackTrace();
         }
-        if (iTempPosition < 0) {
-            return;
-        }
-        removeTask(iTempPosition);
     }
 
     @Download.onTaskFail void taskFail(DownloadTask task) {
 //        downloadTaskService.setDownloadTaskStatus(task.getKey(), DownloadTaskService.STATUS_FAIL);
-        String url = task.getKey();
-        KFProgressButton targetBtn = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_BUTTON + url);
-        targetBtn.setText(R.string.download_fail);
-        setTaskStatusByDownloadUrl(url, DownloadTaskService.STATUS_FAIL, task.getDownloadPath());
+        try {
+            String url = task.getKey();
+            KFProgressButton targetBtn = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_BUTTON + url);
+            targetBtn.setText(R.string.download_fail);
+            setTaskStatusByDownloadUrl(url, DownloadTaskService.STATUS_FAIL, task.getDownloadPath());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     @Download.onTaskComplete void taskComplete(DownloadTask task) {
 //        downloadTaskService.setDownloadTaskFinish(task.getKey(), task.getDownloadPath());
-        TextView tvProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_TEXTVIEW + task.getKey());
-        tvProgress.setText(R.string.download_completed);
+        try {
+            TextView tvProgress = lvDownloadMgr.findViewWithTag(DownloadMgrAdapter.PUBLIC_TAG_PREFIX_TEXTVIEW + task.getKey());
+            tvProgress.setText(R.string.download_completed);
 
-        setTaskStatusByDownloadUrl(task.getKey(), DownloadTaskService.STATUS_FINISH, task.getDownloadPath());
+            setTaskStatusByDownloadUrl(task.getKey(), DownloadTaskService.STATUS_FINISH, task.getDownloadPath());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         ApkUtils.installApk(ActDownloadMgr.this, task.getDownloadPath());
     }
 

+ 2 - 0
app/src/main/java/com/kfzs/duanduan/fragment/FgtSmallSheep.java

@@ -194,6 +194,8 @@ public class FgtSmallSheep extends BaseCompatFragment implements SmallSheepContr
                         tryMakeMoneyAdp.add(RecyleObj.make(RecyleType.RELEASE_TASK, releaseEtyLists), position>2?1:position);
                     }
                     tryMakeMoneyAdp.notifyDataSetChanged();
+                    if(recyclerview == null)
+                        recyclerview = mContentView.findViewById(R.id.recyclerview);
                     recyclerview.setFocusable(false);
                     scrollView.scrollTo(0,0);
                     break;

+ 4 - 1
app/src/main/java/com/sheep/gamegroup/model/util/SheepSubscriber.java

@@ -79,7 +79,10 @@ public abstract class SheepSubscriber<T> extends Subscriber<T> {
                 onError(new ExceptionHandle.ResponeThrowable(e,ExceptionHandle.ERROR.UNKNOWN));
             }
         }catch (Exception er){
-            onError(new ExceptionHandle.ResponeThrowable(e,ExceptionHandle.ERROR.UNKNOWN));
+            BaseMessage baseMessage = new BaseMessage();
+            baseMessage.setMsg(er.getMessage());
+            baseMessage.setCode(ExceptionHandle.ERROR.UNKNOWN);
+            onError(baseMessage);
             er.printStackTrace();
         }
     }

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/DialogActivity.java

@@ -482,7 +482,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
-        if(requestCode == 0 && resultCode == RESULT_OK){
+        if(requestCode == 0 && resultCode == RESULT_OK && taskEty != null){
             SheepApp.getInstance().getNetComponent().getApiService().giveUpTask(taskEty.getAcceptedTaskId())
                     .subscribeOn(Schedulers.io())
                     .observeOn(AndroidSchedulers.mainThread())

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

@@ -232,11 +232,9 @@ public class TryMakeMoneyAdp extends AdpCommonRecy<RecyleObj> {
                 viewHolder.itemView.findViewById(R.id.detail_task_tv).setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {
-//                        G.showToast("任务详情");
-//                        if(isHave){
-//                            G.showToast("请先取消已接受的任务");
-//                            return;
-//                        }
+                        if(!ListUtil.hasIndex(etyList, i)){
+                            return;
+                        }
                         TaskEty taskEty = etyList.get(i).getTask();
                         taskEty.setRunTask(0);
                         taskEty.setRelease_task_id(etyList.get(i).getId());

+ 5 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/service/FloatService.java

@@ -235,7 +235,11 @@ public class FloatService extends Service {
     @Override
     public void onDestroy() {
         if (floaticon != null) {
-            mWm.removeView(mFloatwindow);
+            try {
+                mWm.removeViewImmediate(mFloatwindow);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
         stopTimer();
         super.onDestroy();