bug fix
This commit is contained in:
@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package com.arialyy.simple.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
@ -25,6 +24,7 @@ import android.view.View;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.aria.core.AMTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
@ -33,14 +33,17 @@ import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityMultiBinding;
|
||||
import com.arialyy.simple.dialog.DownloadNumDialog;
|
||||
import com.arialyy.simple.module.DownloadModule;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Lyy on 2016/9/27.
|
||||
*/
|
||||
public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
@Bind(R.id.list) RecyclerView mList;
|
||||
@Bind(R.id.toolbar) Toolbar mBar;
|
||||
@Bind(R.id.list) RecyclerView mList;
|
||||
@Bind(R.id.toolbar) Toolbar mBar;
|
||||
DownloadAdapter mAdapter;
|
||||
List<DownloadEntity> mData = new ArrayList<>();
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_multi;
|
||||
@ -50,7 +53,8 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(mBar);
|
||||
mBar.setTitle("多任务下载");
|
||||
mAdapter = new DownloadAdapter(this, getModule(DownloadModule.class).getDownloadData());
|
||||
mData.addAll(getModule(DownloadModule.class).getDownloadData());
|
||||
mAdapter = new DownloadAdapter(this, mData);
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
}
|
||||
@ -103,8 +107,8 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
// }
|
||||
//};
|
||||
|
||||
public void onClick(View view){
|
||||
switch (view.getId()){
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.num:
|
||||
DownloadNumDialog dialog = new DownloadNumDialog(this);
|
||||
dialog.show(getSupportFragmentManager(), "download_num");
|
||||
@ -112,6 +116,10 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
case R.id.stop_all:
|
||||
Aria.get(this).stopAllTask();
|
||||
break;
|
||||
case R.id.add_task:
|
||||
mData.add(getModule(DownloadModule.class).createRandomDownloadEntity());
|
||||
mAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,12 +135,12 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
super.dataCallback(result, data);
|
||||
if (result == DownloadNumDialog.RESULT_CODE){
|
||||
if (result == DownloadNumDialog.RESULT_CODE) {
|
||||
mAdapter.setDownloadNum(Integer.parseInt(data + ""));
|
||||
}
|
||||
}
|
||||
|
||||
private class MySchedulerListener extends Aria.SimpleSchedulerListener{
|
||||
private class MySchedulerListener extends Aria.SimpleSchedulerListener {
|
||||
@Override public void onTaskPre(Task task) {
|
||||
super.onTaskPre(task);
|
||||
L.d(TAG, "download pre");
|
||||
|
@ -35,13 +35,29 @@ import com.arialyy.simple.base.BaseModule;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by Lyy on 2016/9/27.
|
||||
*/
|
||||
public class DownloadModule extends BaseModule {
|
||||
private List<String> mTestDownloadUrl = new ArrayList<>();
|
||||
|
||||
public DownloadModule(Context context) {
|
||||
super(context);
|
||||
mTestDownloadUrl.add("static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk");
|
||||
mTestDownloadUrl.add("static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk");
|
||||
mTestDownloadUrl.add("static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk");
|
||||
}
|
||||
|
||||
public String getRadomUrl() {
|
||||
Random random = new Random();
|
||||
int i = random.nextInt(2);
|
||||
return mTestDownloadUrl.get(i);
|
||||
}
|
||||
|
||||
public DownloadEntity createRandomDownloadEntity(){
|
||||
return createDownloadEntity(getRadomUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,8 +102,8 @@ public class DownloadModule extends BaseModule {
|
||||
}
|
||||
|
||||
private DownloadEntity createDownloadEntity(String url) {
|
||||
String fileName = CommonUtil.keyToHashCode(url) + ".apk";
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
String fileName = CommonUtil.keyToHashCode(url) + ".apk";
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
entity.setDownloadUrl(url);
|
||||
entity.setDownloadPath(getDownloadPath(url));
|
||||
entity.setFileName(fileName);
|
||||
|
@ -16,6 +16,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/toolbar"
|
||||
android:layout_above="@+id/num"
|
||||
/>
|
||||
|
||||
<Button
|
||||
@ -40,5 +41,17 @@
|
||||
android:text="停止所有"
|
||||
/>
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/add_task"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_margin="16dp"
|
||||
android:onClick="onClick"
|
||||
android:text="添加任务"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
</layout>
|
||||
|
Reference in New Issue
Block a user