fix bug
This commit is contained in:
@ -46,8 +46,12 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
DownloadEntity entity = intent.getParcelableExtra(DownloadManager.ENTITY);
|
||||
switch (action) {
|
||||
case DownloadManager.ACTION_PRE:
|
||||
len = entity.getFileSize();
|
||||
L.d(TAG, "download pre");
|
||||
mAdapter.updateState(entity);
|
||||
break;
|
||||
case DownloadManager.ACTION_POST_PRE:
|
||||
len = entity.getFileSize();
|
||||
L.d(TAG, "download post pre");
|
||||
break;
|
||||
case DownloadManager.ACTION_START:
|
||||
L.d(TAG, "download start");
|
||||
|
@ -14,10 +14,10 @@ import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.core.command.CommandFactory;
|
||||
import com.arialyy.downloadutil.core.command.IDownloadCommand;
|
||||
import com.arialyy.downloadutil.core.DownloadEntity;
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.core.command.CmdFactory;
|
||||
import com.arialyy.downloadutil.core.command.IDownloadCmd;
|
||||
import com.arialyy.downloadutil.orm.DbEntity;
|
||||
import com.arialyy.downloadutil.util.Util;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
@ -41,7 +41,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
private Button mStart, mStop, mCancel;
|
||||
private TextView mSize;
|
||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||
private CommandFactory mFactory;
|
||||
private CmdFactory mFactory;
|
||||
private DownloadManager mManager;
|
||||
private DownloadEntity mEntity;
|
||||
|
||||
@ -97,7 +97,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
@Override public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
switch (action) {
|
||||
case DownloadManager.ACTION_PRE:
|
||||
case DownloadManager.ACTION_POST_PRE:
|
||||
DownloadEntity entity = intent.getParcelableExtra(DownloadManager.ENTITY);
|
||||
len = entity.getFileSize();
|
||||
L.d(TAG, "download pre");
|
||||
@ -168,7 +168,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
mStop = (Button) findViewById(R.id.stop);
|
||||
mCancel = (Button) findViewById(R.id.cancel);
|
||||
mSize = (TextView) findViewById(R.id.size);
|
||||
mFactory = CommandFactory.getInstance();
|
||||
mFactory = CmdFactory.getInstance();
|
||||
mManager = DownloadManager.getInstance();
|
||||
mEntity = DbEntity.findData(DownloadEntity.class, new String[] { "downloadUrl" },
|
||||
new String[] { mDownloadUrl });
|
||||
@ -190,21 +190,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
start();
|
||||
// if (PermissionManager.getInstance()
|
||||
// .checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
// start();
|
||||
// } else {
|
||||
// PermissionManager.getInstance()
|
||||
// .requestPermission(this, new OnPermissionCallback() {
|
||||
// @Override public void onSuccess(String... permissions) {
|
||||
// start();
|
||||
// }
|
||||
//
|
||||
// @Override public void onFail(String... permissions) {
|
||||
//
|
||||
// }
|
||||
// }, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
// }
|
||||
break;
|
||||
case R.id.stop:
|
||||
stop();
|
||||
@ -219,23 +204,21 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
mEntity.setFileName("test.apk");
|
||||
mEntity.setDownloadUrl(mDownloadUrl);
|
||||
mEntity.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk");
|
||||
List<IDownloadCommand> commands = new ArrayList<>();
|
||||
IDownloadCommand addCommand = mFactory.createCommand(this, mEntity, CommandFactory.TASK_CREATE);
|
||||
IDownloadCommand startCommand =
|
||||
mFactory.createCommand(this, mEntity, CommandFactory.TASK_START);
|
||||
commands.add(addCommand);
|
||||
commands.add(startCommand);
|
||||
mManager.setCommands(commands).exe();
|
||||
List<IDownloadCmd> commands = new ArrayList<>();
|
||||
IDownloadCmd addCMD = mFactory.createCmd(this, mEntity, CmdFactory.TASK_CREATE);
|
||||
IDownloadCmd startCmd = mFactory.createCmd(this, mEntity, CmdFactory.TASK_START);
|
||||
commands.add(addCMD);
|
||||
commands.add(startCmd);
|
||||
mManager.setCmds(commands).exe();
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
IDownloadCommand stopCommand = mFactory.createCommand(this, mEntity, CommandFactory.TASK_STOP);
|
||||
mManager.setCommand(stopCommand).exe();
|
||||
IDownloadCmd stopCmd = mFactory.createCmd(this, mEntity, CmdFactory.TASK_STOP);
|
||||
mManager.setCmd(stopCmd).exe();
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
IDownloadCommand cancelCommand =
|
||||
mFactory.createCommand(this, mEntity, CommandFactory.TASK_CANCEL);
|
||||
mManager.setCommand(cancelCommand).exe();
|
||||
IDownloadCmd cancelCmd = mFactory.createCmd(this, mEntity, CmdFactory.TASK_CANCEL);
|
||||
mManager.setCmd(cancelCmd).exe();
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import com.arialyy.absadapter.common.AbsHolder;
|
||||
import com.arialyy.absadapter.recycler_view.AbsRVAdapter;
|
||||
import com.arialyy.downloadutil.core.DownloadEntity;
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.core.command.CommandFactory;
|
||||
import com.arialyy.downloadutil.core.command.IDownloadCommand;
|
||||
import com.arialyy.downloadutil.core.command.CmdFactory;
|
||||
import com.arialyy.downloadutil.core.command.IDownloadCmd;
|
||||
import com.arialyy.downloadutil.util.Util;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
@ -28,18 +28,21 @@ import java.util.Set;
|
||||
public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> {
|
||||
private static final String TAG = "DownloadAdapter";
|
||||
private DownloadManager mManager;
|
||||
private CommandFactory mFactory;
|
||||
private CmdFactory mFactory;
|
||||
private Map<String, Integer> mPositions = new HashMap<>();
|
||||
|
||||
public DownloadAdapter(Context context, List<DownloadEntity> data) {
|
||||
super(context, data);
|
||||
int i = 0;
|
||||
mFactory = CmdFactory.getInstance();
|
||||
mManager = DownloadManager.getInstance();
|
||||
List<IDownloadCmd> addCmd = new ArrayList<>();
|
||||
int i = 0;
|
||||
for (DownloadEntity entity : data) {
|
||||
mPositions.put(entity.getDownloadUrl(), i);
|
||||
addCmd.add(mFactory.createCmd(context, entity, CmdFactory.TASK_CREATE));
|
||||
i++;
|
||||
}
|
||||
mFactory = CommandFactory.getInstance();
|
||||
mManager = DownloadManager.getInstance();
|
||||
mManager.setCmds(addCmd).exe();
|
||||
}
|
||||
|
||||
@Override protected MyHolder getViewHolder(View convertView, int viewType) {
|
||||
@ -105,6 +108,8 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
|
||||
str = "恢复";
|
||||
color = android.R.color.holo_blue_light;
|
||||
break;
|
||||
case DownloadEntity.STATE_PRE:
|
||||
case DownloadEntity.STATE_POST_PRE:
|
||||
case DownloadEntity.STATE_DOWNLOAD_ING:
|
||||
str = "暂停";
|
||||
color = android.R.color.holo_red_light;
|
||||
@ -122,9 +127,8 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
|
||||
@Override public void onClick(View v) {
|
||||
mData.remove(item);
|
||||
notifyDataSetChanged();
|
||||
IDownloadCommand cancelCommand =
|
||||
mFactory.createCommand(getContext(), item, CommandFactory.TASK_CANCEL);
|
||||
mManager.setCommand(cancelCommand).exe();
|
||||
IDownloadCmd cancelCmd = mFactory.createCmd(getContext(), item, CmdFactory.TASK_CANCEL);
|
||||
mManager.setCmd(cancelCmd).exe();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -163,20 +167,13 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
|
||||
}
|
||||
|
||||
private void start(DownloadEntity entity) {
|
||||
List<IDownloadCommand> commands = new ArrayList<>();
|
||||
IDownloadCommand addCommand =
|
||||
mFactory.createCommand(getContext(), entity, CommandFactory.TASK_CREATE);
|
||||
IDownloadCommand startCommand =
|
||||
mFactory.createCommand(getContext(), entity, CommandFactory.TASK_START);
|
||||
commands.add(addCommand);
|
||||
commands.add(startCommand);
|
||||
mManager.setCommands(commands).exe();
|
||||
IDownloadCmd startCmd = mFactory.createCmd(getContext(), entity, CmdFactory.TASK_START);
|
||||
mManager.setCmd(startCmd).exe();
|
||||
}
|
||||
|
||||
private void stop(DownloadEntity entity) {
|
||||
IDownloadCommand stopCommand =
|
||||
mFactory.createCommand(getContext(), entity, CommandFactory.TASK_STOP);
|
||||
mManager.setCommand(stopCommand).exe();
|
||||
IDownloadCmd stopCmd = mFactory.createCmd(getContext(), entity, CmdFactory.TASK_STOP);
|
||||
mManager.setCmd(stopCmd).exe();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@ package com.arialyy.simple.module;
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Environment;
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.core.DownloadEntity;
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.util.Util;
|
||||
import com.arialyy.frame.util.AndroidUtils;
|
||||
import com.arialyy.frame.util.StringUtil;
|
||||
@ -26,7 +26,7 @@ public class DownloadModule extends BaseModule {
|
||||
* 设置下载数据
|
||||
*/
|
||||
public List<DownloadEntity> getDownloadData() {
|
||||
List<DownloadEntity> list = DownloadEntity.findAllData(DownloadEntity.class);
|
||||
List<DownloadEntity> list = DownloadEntity.findAllData(DownloadEntity.class);
|
||||
if (list == null || list.size() == 0) {
|
||||
list = createNewDownload();
|
||||
}
|
||||
@ -63,16 +63,18 @@ public class DownloadModule extends BaseModule {
|
||||
*/
|
||||
private List<DownloadEntity> createNewDownload() {
|
||||
List<DownloadEntity> list = new ArrayList<>();
|
||||
String[] urls =
|
||||
getContext().getResources().getStringArray(R.array.test_apk_download_url);
|
||||
String[] urls = getContext().getResources().getStringArray(R.array.test_apk_download_url);
|
||||
int i = 0;
|
||||
for (String url : urls) {
|
||||
String fileName = Util.keyToHashCode(url) + ".apk";
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
entity.setDownloadUrl(url);
|
||||
entity.setDownloadPath(getDownloadPath(url));
|
||||
entity.setFileName(fileName);
|
||||
//entity.setFileName(fileName);
|
||||
entity.setFileName("taskName_________" + i);
|
||||
entity.save();
|
||||
list.add(entity);
|
||||
i++;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@ -84,6 +86,7 @@ public class DownloadModule extends BaseModule {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addDataScheme(getContext().getPackageName());
|
||||
filter.addAction(DownloadManager.ACTION_PRE);
|
||||
filter.addAction(DownloadManager.ACTION_POST_PRE);
|
||||
filter.addAction(DownloadManager.ACTION_RESUME);
|
||||
filter.addAction(DownloadManager.ACTION_START);
|
||||
filter.addAction(DownloadManager.ACTION_RUNNING);
|
||||
|
Reference in New Issue
Block a user