下载任务数支持修改

pull/2/head
lyy 8 years ago
parent 493810d0b0
commit bd94e7dd27
  1. 15
      app/src/main/java/com/arialyy/simple/activity/MultiTaskActivity.java
  2. 4
      app/src/main/java/com/arialyy/simple/adapter/DownloadAdapter.java
  3. 18
      app/src/main/java/com/arialyy/simple/base/BaseDialog.java
  4. 46
      app/src/main/java/com/arialyy/simple/dialog/DownloadNumDialog.java
  5. 17
      app/src/main/res/layout/activity_multi.xml
  6. 85
      app/src/main/res/layout/dialog_download_num.xml
  7. 2
      downloadutil/src/main/java/com/arialyy/downloadutil/core/queue/DownloadTaskQueue.java
  8. 2
      downloadutil/src/main/java/com/arialyy/downloadutil/core/queue/pool/ExecutePool.java

@ -7,6 +7,8 @@ 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.DownloadEntity;
import com.arialyy.downloadutil.core.DownloadManager;
@ -15,6 +17,7 @@ import com.arialyy.simple.R;
import com.arialyy.simple.adapter.DownloadAdapter;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMultiBinding;
import com.arialyy.simple.dialog.DownloadNumDialog;
import com.arialyy.simple.module.DownloadModule;
/**
@ -86,6 +89,11 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
}
};
public void onClick(View view){
DownloadNumDialog dialog = new DownloadNumDialog();
dialog.show(getSupportFragmentManager(), "download_num");
}
@Override protected void onResume() {
super.onResume();
registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
@ -95,4 +103,11 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
super.onDestroy();
unregisterReceiver(mReceiver);
}
@Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data);
if (result == DownloadNumDialog.RESULT_CODE){
mAdapter.setDownloadNum(Integer.parseInt(data + ""));
}
}
}

@ -133,6 +133,10 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
});
}
public void setDownloadNum(int num) {
mManager.getTaskQueue().setDownloadNum(num);
}
private String covertCurrentSize(long currentSize) {
String size = CommonUtil.formatFileSize(currentSize);
return size.substring(0, size.length() - 1);

@ -0,0 +1,18 @@
package com.arialyy.simple.base;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import com.arialyy.frame.core.AbsDialogFragment;
/**
* Created by AriaLyy@outlook.com on 2016/11/14.
*/
public abstract class BaseDialog<VB extends ViewDataBinding> extends AbsDialogFragment<VB>{
@Override protected void init(Bundle savedInstanceState) {
}
@Override protected void dataCallback(int result, Object data) {
}
}

@ -0,0 +1,46 @@
package com.arialyy.simple.dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import butterknife.Bind;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseDialog;
import com.arialyy.simple.databinding.DialogDownloadNumBinding;
/**
* Created by AriaLyy@outlook.com on 2016/11/14.
* 设置下载数量对话框
*/
public class DownloadNumDialog extends BaseDialog<DialogDownloadNumBinding> implements RadioGroup.OnCheckedChangeListener{
public static final int RESULT_CODE = 1001;
@Bind(R.id.cancel) Button mCancel;
@Bind(R.id.rg) RadioGroup mRg;
@Override protected int setLayoutId() {
return R.layout.dialog_download_num;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
mCancel.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
dismiss();
}
});
for (int i = 0, count = mRg.getChildCount(); i < count; i++) {
RadioButton rb = (RadioButton) mRg.getChildAt(i);
rb.setId(i);
}
mRg.setOnCheckedChangeListener(this);
}
@Override public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton rb = (RadioButton) group.getChildAt(checkedId);
if (rb.isChecked()) {
getSimplerModule().onDialog(RESULT_CODE, rb.getTag());
}
}
}

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<LinearLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
@ -14,7 +15,19 @@
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
/>
</LinearLayout>
<Button
android:onClick="onClick"
android:id="@+id/num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="下载数设置"
android:layout_margin="16dp"
/>
</RelativeLayout>
</layout>

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="设置下载数"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<View
android:background="@color/black"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<RadioGroup
android:id="@+id/rg"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RadioButton
android:tag="2"
android:text="下载线程数:2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:textAlignment="textStart"
android:layout_gravity="start"
/>
<RadioButton
android:tag="3"
android:text="下载线程数:3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:textAlignment="textStart"
android:layout_gravity="start"
/>
<RadioButton
android:tag="4"
android:text="下载线程数:4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:textAlignment="textStart"
android:layout_gravity="start"
/>
</RadioGroup>
<View
android:background="@color/black"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<Button
android:id="@+id/cancel"
android:text="取消"
style="?buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</layout>

@ -95,7 +95,7 @@ public class DownloadTaskQueue implements ITaskQueue {
}
@Override public void setDownloadNum(int downloadNum) {
mExecutePool.setDownloadNum(downloadNum);
}
@Override public Task createTask(DownloadEntity entity) {

@ -65,7 +65,7 @@ public class ExecutePool implements IPool {
*
* @param downloadNum 下载数
*/
private void setDownloadNum(int downloadNum) {
public void setDownloadNum(int downloadNum) {
try {
ArrayBlockingQueue<Task> temp = new ArrayBlockingQueue<>(downloadNum);
Task task;

Loading…
Cancel
Save