修复不能在线程中使用Aria的问题 https://github.com/AriaLyy/Aria/issues/89

pull/330/head
AriaLyy 7 years ago
parent a8f183363e
commit 335a14dfc4
  1. 12
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java
  2. 7
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  3. 9
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  4. 2
      app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java
  5. 7
      aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
  6. 2
      build.gradle

@ -16,10 +16,11 @@
package com.arialyy.aria.core.download; package com.arialyy.aria.core.download;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.IUtil;
import com.arialyy.aria.core.download.downloader.DownloadGroupUtil; import com.arialyy.aria.core.download.downloader.DownloadGroupUtil;
import com.arialyy.aria.core.download.downloader.FtpDirDownloadUtil; import com.arialyy.aria.core.download.downloader.FtpDirDownloadUtil;
import com.arialyy.aria.core.common.IUtil;
import com.arialyy.aria.core.inf.AbsGroupTask; import com.arialyy.aria.core.inf.AbsGroupTask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
@ -44,7 +45,7 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity, Dow
case AbsTaskEntity.HTTP: case AbsTaskEntity.HTTP:
mUtil = new DownloadGroupUtil(mListener, mTaskEntity); mUtil = new DownloadGroupUtil(mListener, mTaskEntity);
break; break;
case AbsTaskEntity.FTP_DIR: case AbsTaskEntity.FTP_DIR:
mUtil = new FtpDirDownloadUtil(mListener, mTaskEntity); mUtil = new FtpDirDownloadUtil(mListener, mTaskEntity);
break; break;
} }
@ -93,7 +94,12 @@ public class DownloadGroupTask extends AbsGroupTask<DownloadGroupTaskEntity, Dow
* @param schedulers {@link ISchedulers} * @param schedulers {@link ISchedulers}
*/ */
public DownloadGroupTask.Builder setOutHandler(ISchedulers schedulers) { public DownloadGroupTask.Builder setOutHandler(ISchedulers schedulers) {
this.outHandler = new Handler(schedulers); try {
outHandler = new Handler(schedulers);
} catch (Exception e) {
e.printStackTrace();
outHandler = new Handler(Looper.getMainLooper(), schedulers);
}
return this; return this;
} }

@ -164,7 +164,12 @@ public class DownloadTask extends AbsNormalTask<DownloadEntity> {
* @param schedulers {@link ISchedulers} * @param schedulers {@link ISchedulers}
*/ */
public Builder setOutHandler(ISchedulers schedulers) { public Builder setOutHandler(ISchedulers schedulers) {
this.outHandler = new Handler(schedulers); try {
outHandler = new Handler(schedulers);
} catch (Exception e) {
e.printStackTrace();
outHandler = new Handler(Looper.getMainLooper(), schedulers);
}
return this; return this;
} }

@ -18,7 +18,6 @@ package com.arialyy.simple.download;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.Handler;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -27,11 +26,10 @@ import android.widget.RadioGroup;
import android.widget.Toast; import android.widget.Toast;
import butterknife.Bind; import butterknife.Bind;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T; import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
@ -114,7 +112,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
setBtState(false); setBtState(false);
} }
@Download.onTaskStart(DOWNLOAD_URL) void taskStart(DownloadTask task) { @Download.onTaskStart void taskStart(DownloadTask task) {
getBinding().setFileSize(task.getConvertFileSize()); getBinding().setFileSize(task.getConvertFileSize());
} }
@ -188,11 +186,12 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
Aria.download(this) Aria.download(SingleTaskActivity.this)
.load(DOWNLOAD_URL) .load(DOWNLOAD_URL)
.addHeader("groupName", "value") .addHeader("groupName", "value")
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/gggg.apk") .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/gggg.apk")
.start(); .start();
break; break;
case R.id.stop: case R.id.stop:
Aria.download(this).load(DOWNLOAD_URL).stop(); Aria.download(this).load(DOWNLOAD_URL).stop();

@ -48,7 +48,7 @@ public class HttpUploadActivity extends BaseActivity<ActivityUploadBinding> {
} }
@OnClick(R.id.upload) void upload() { @OnClick(R.id.upload) void upload() {
Aria.upload(this) Aria.upload(HttpUploadActivity.this)
.load(FILE_PATH) .load(FILE_PATH)
.setUploadUrl("http://172.18.104.66:8080/upload/sign_file") .setUploadUrl("http://172.18.104.66:8080/upload/sign_file")
.setAttachment("file") .setAttachment("file")

@ -83,7 +83,12 @@ public class UploadTask extends AbsNormalTask<UploadEntity> {
private String mTargetName; private String mTargetName;
public void setOutHandler(ISchedulers outHandler) { public void setOutHandler(ISchedulers outHandler) {
mOutHandler = new Handler(outHandler); try {
mOutHandler = new Handler(outHandler);
} catch (Exception e) {
e.printStackTrace();
mOutHandler = new Handler(Looper.getMainLooper(), outHandler);
}
} }
public void setUploadTaskEntity(UploadTaskEntity taskEntity) { public void setUploadTaskEntity(UploadTaskEntity taskEntity) {

@ -37,7 +37,7 @@ task clean(type: Delete) {
ext { ext {
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
publishVersion = '3.2.16' publishVersion = '3.2.17'
repoName='maven' repoName='maven'
desc = 'android 下载框架' desc = 'android 下载框架'
website = 'https://github.com/AriaLyy/Aria' website = 'https://github.com/AriaLyy/Aria'

Loading…
Cancel
Save