fix bug
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package com.arialyy.simple.activity;
|
||||
|
||||
import android.Manifest;
|
||||
@@ -48,22 +47,26 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(mBar);
|
||||
mBar.setTitle("多线程多任务下载");
|
||||
boolean hasPermission = PermissionManager.getInstance()
|
||||
.checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (hasPermission || Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
setEnable(true);
|
||||
} else {
|
||||
setEnable(false);
|
||||
PermissionManager.getInstance().requestPermission(this, new OnPermissionCallback() {
|
||||
@Override public void onSuccess(String... permissions) {
|
||||
setEnable(true);
|
||||
}
|
||||
} else { //6.0处理
|
||||
boolean hasPermission = PermissionManager.getInstance()
|
||||
.checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (hasPermission) {
|
||||
setEnable(true);
|
||||
} else {
|
||||
setEnable(false);
|
||||
PermissionManager.getInstance().requestPermission(this, new OnPermissionCallback() {
|
||||
@Override public void onSuccess(String... permissions) {
|
||||
setEnable(true);
|
||||
}
|
||||
|
||||
@Override public void onFail(String... permissions) {
|
||||
T.showShort(MainActivity.this, "没有文件读写权限");
|
||||
setEnable(false);
|
||||
}
|
||||
}, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
@Override public void onFail(String... permissions) {
|
||||
T.showShort(MainActivity.this, "没有文件读写权限");
|
||||
setEnable(false);
|
||||
}
|
||||
}, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,20 +17,14 @@
|
||||
|
||||
package com.arialyy.simple.activity;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.downloadutil.core.AMTarget;
|
||||
import com.arialyy.downloadutil.core.Aria;
|
||||
import com.arialyy.downloadutil.core.DownloadEntity;
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.core.task.Task;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
@@ -116,7 +110,6 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
//registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
|
||||
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.downloadutil.core.AMReceiver;
|
||||
import com.arialyy.downloadutil.core.AMTarget;
|
||||
import com.arialyy.downloadutil.core.Aria;
|
||||
import com.arialyy.downloadutil.core.DownloadEntity;
|
||||
@@ -47,11 +46,13 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
public static final int DOWNLOAD_RESUME = 0x05;
|
||||
public static final int DOWNLOAD_COMPLETE = 0x06;
|
||||
public static final int DOWNLOAD_RUNNING = 0x07;
|
||||
private ProgressBar mPb;
|
||||
private String mDownloadUrl =
|
||||
"http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
||||
private Button mStart, mStop, mCancel;
|
||||
private TextView mSize;
|
||||
private static final String DOWNLOAD_URL =
|
||||
"http://static.gaoshouyou.com/d/3a/93/573ae1db9493a801c24bf66128b11e39.apk";
|
||||
@Bind(R.id.progressBar) ProgressBar mPb;
|
||||
@Bind(R.id.start) Button mStart;
|
||||
@Bind(R.id.stop) Button mStop;
|
||||
@Bind(R.id.cancel) Button mCancel;
|
||||
@Bind(R.id.size) TextView mSize;
|
||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||
private DownloadEntity mEntity;
|
||||
private BroadcastReceiver mReceiver;
|
||||
@@ -115,15 +116,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
//IntentFilter filter = getModule(DownloadModule.class).getDownloadFilter();
|
||||
//mReceiver = getModule(DownloadModule.class).createReceiver(mUpdateHandler);
|
||||
//registerReceiver(mReceiver, filter);
|
||||
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
//unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
@@ -138,15 +135,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mPb = (ProgressBar) findViewById(R.id.progressBar);
|
||||
mStart = (Button) findViewById(R.id.start);
|
||||
mStop = (Button) findViewById(R.id.stop);
|
||||
mCancel = (Button) findViewById(R.id.cancel);
|
||||
mSize = (TextView) findViewById(R.id.size);
|
||||
//mFactory = CmdFactory.getInstance();
|
||||
//mManager = DownloadManager.getInstance();
|
||||
mEntity = DbEntity.findData(DownloadEntity.class, new String[] { "downloadUrl" },
|
||||
new String[] { mDownloadUrl });
|
||||
new String[] { DOWNLOAD_URL });
|
||||
if (mEntity != null) {
|
||||
mPb.setProgress((int) ((mEntity.getCurrentProgress() * 100) / mEntity.getFileSize()));
|
||||
mSize.setText(CommonUtil.formatFileSize(mEntity.getFileSize()));
|
||||
@@ -159,7 +149,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
} else {
|
||||
mEntity = new DownloadEntity();
|
||||
mEntity.setFileName("test.apk");
|
||||
mEntity.setDownloadUrl(mDownloadUrl);
|
||||
mEntity.setDownloadUrl(DOWNLOAD_URL);
|
||||
mEntity.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk");
|
||||
}
|
||||
}
|
||||
@@ -170,7 +160,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
String text = ((TextView) view).getText().toString();
|
||||
if (text.equals("重新开始?") || text.equals("开始")) {
|
||||
start();
|
||||
}else if (text.equals("恢复")){
|
||||
} else if (text.equals("恢复")) {
|
||||
resume();
|
||||
}
|
||||
break;
|
||||
@@ -183,14 +173,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
}
|
||||
}
|
||||
|
||||
private void resume(){
|
||||
private void resume() {
|
||||
Aria.whit(this).load(mEntity).resume();
|
||||
}
|
||||
|
||||
private void start() {
|
||||
mEntity.setFileName("test.apk");
|
||||
mEntity.setDownloadUrl(mDownloadUrl);
|
||||
mEntity.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk");
|
||||
Aria.whit(this).load(mEntity).start();
|
||||
}
|
||||
|
||||
@@ -202,7 +189,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
Aria.whit(this).load(mEntity).cancel();
|
||||
}
|
||||
|
||||
private class MySchedulerListener extends AMTarget.SimpleSchedulerListener{
|
||||
private class MySchedulerListener extends AMTarget.SimpleSchedulerListener {
|
||||
@Override public void onTaskStart(Task task) {
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize())
|
||||
.sendToTarget();
|
||||
@@ -240,5 +227,4 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user