修复删除下载中的游戏连续两次调用onCancelTask回掉的bug https://github.com/AriaLyy/Aria/issues/33

pull/330/head
AriaLyy 8 years ago
parent 431fc35deb
commit 04354a81d0
  1. 4
      Aria/build.gradle
  2. 16
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  3. 2
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java

@ -23,8 +23,8 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1'
// compile project(':AriaCompiler') compile project(':AriaCompiler')
compile project(':AriaAnnotations') // compile project(':AriaAnnotations')
} }
//apply from: 'jcenter.gradle' //apply from: 'jcenter.gradle'

@ -133,17 +133,19 @@ public class DownloadTask extends AbsTask<DownloadTaskEntity, DownloadEntity> {
*/ */
@Override public void cancel() { @Override public void cancel() {
if (!mEntity.isDownloadComplete()) { if (!mEntity.isDownloadComplete()) {
if (!mUtil.isDownloading()) {
if (mOutHandler != null) {
mOutHandler.obtainMessage(DownloadSchedulers.CANCEL, this).sendToTarget();
}
//发送取消下载的广播
Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_CANCEL);
intent.putExtra(Aria.DOWNLOAD_ENTITY, mEntity);
mContext.sendBroadcast(intent);
}
mUtil.cancelDownload(); mUtil.cancelDownload();
mUtil.delConfigFile(); mUtil.delConfigFile();
mUtil.delTempFile(); mUtil.delTempFile();
mEntity.deleteData(); mEntity.deleteData();
if (mOutHandler != null) {
mOutHandler.obtainMessage(DownloadSchedulers.CANCEL, this).sendToTarget();
}
//发送取消下载的广播
Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_CANCEL);
intent.putExtra(Aria.DOWNLOAD_ENTITY, mEntity);
mContext.sendBroadcast(intent);
} }
} }

@ -183,12 +183,14 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Download.onTaskStop void taskStop(DownloadTask task) { @Download.onTaskStop void taskStop(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP); mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP);
L.d(TAG, "task__stop");
} }
} }
@Download.onTaskCancel void taskCancel(DownloadTask task) { @Download.onTaskCancel void taskCancel(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL); mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL);
L.d(TAG, "task__cancel");
} }
} }

Loading…
Cancel
Save