任务组bug fix

This commit is contained in:
AriaLyy
2017-07-11 17:26:33 +08:00
parent bc48fd5b4d
commit 375eb25499
27 changed files with 523 additions and 240 deletions

View File

@ -16,15 +16,10 @@
package com.arialyy.simple.download;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -36,18 +31,15 @@ import butterknife.Bind;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.FileUtil;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivitySingleBinding;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
import java.io.File;
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
public static final int DOWNLOAD_PRE = 0x01;
@ -65,7 +57,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
//"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt";
//"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815";
"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk";
//"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk";
"https://d.pcs.baidu.com/file/bc7334aba5443c2596d905a0bcf9e734?fid=2852548966-250528-290956601240893&time=1499758796&rt=sh&sign=FDTAERVY-DCb740ccc5511e5e8fedcff06b081203-HO8uC%2FT83oxUXZdObsg3b54%2Bzv8%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=4444968052010847094&dp-callid=0&r=463246632";
//"http://oqcpqqvuf.bkt.clouddn.com/ceshi.txt";
//"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1";
//不支持断点的链接
@ -75,8 +68,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@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.speed) TextView mSpeed;
@Bind(R.id.speeds) RadioGroup mRg;
private Handler mUpdateHandler = new Handler() {
@ -92,13 +83,13 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} else {
mPb.setProgress((int) ((current * 100) / len));
}
mSpeed.setText(task.getConvertSpeed());
getBinding().setSpeed(task.getConvertSpeed());
break;
case DOWNLOAD_PRE:
setBtState(false);
break;
case DOWNLOAD_START:
mSize.setText(CommonUtil.formatFileSize((Long) msg.obj));
getBinding().setFileSize(CommonUtil.formatFileSize((Long) msg.obj));
break;
case DOWNLOAD_FAILE:
Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
@ -241,7 +232,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} else if (target.isDownloading()) {
setBtState(false);
}
mSize.setText(target.getConvertFileSize());
getBinding().setFileSize(target.getConvertFileSize());
}
public void onClick(View view) {

View File

@ -38,25 +38,20 @@ import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
* Created by Aria.Lao on 2017/1/4.
*/
public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber 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.speed) TextView mSpeed;
private static final String DOWNLOAD_URL =
"http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk";
private static final String DOWNLOAD_URL = "http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk";
@Override protected void init(Bundle savedInstanceState) {
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p);
getBinding().setProgress(target.getPercent());
}
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
if (entity != null) {
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
int state = entity.getState();
setBtState(state != DownloadEntity.STATE_RUNNING);
} else {
@ -83,30 +78,29 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
}
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
getBinding().setFileSize(task.getConvertFileSize());
setBtState(false);
}
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
setBtState(true);
mSpeed.setText("0.0kb/s");
getBinding().setSpeed("0.0kb/s");
}
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
setBtState(true);
mPb.setProgress(0);
mSpeed.setText("0.0kb/s");
getBinding().setProgress(0);
getBinding().setSpeed("0.0kb/s");
}
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
long current = task.getCurrentProgress();
long len = task.getFileSize();
if (len == 0) {
mPb.setProgress(0);
getBinding().setProgress(0);
} else {
mPb.setProgress((int) ((current * 100) / len));
getBinding().setProgress(task.getPercent());
}
mSpeed.setText(task.getConvertSpeed());
getBinding().setSpeed(task.getConvertSpeed());
}
@Override protected void onDelayLoad() {

View File

@ -19,16 +19,18 @@ import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import butterknife.Bind;
import com.arialyy.annotations.DownloadGroup;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityDownloadGroupBinding;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
import java.util.List;
/**
@ -36,12 +38,9 @@ import java.util.List;
*/
public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBinding> {
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber 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.speed) TextView mSpeed;
List<String> mUrls;
@Override protected void init(Bundle savedInstanceState) {
@ -49,6 +48,13 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
Aria.download(this).register();
setTitle("任务组");
mUrls = getModule(GroupModule.class).getUrls();
DownloadGroupTaskEntity entity = Aria.download(this).getDownlaodGroupTask(mUrls);
if (entity != null) {
DownloadGroupEntity groupEntity = entity.getEntity();
getBinding().setFileSize(groupEntity.getConvertFileSize());
getBinding().setProgress(
(int) (groupEntity.getCurrentProgress() * 100 / groupEntity.getFileSize()));
}
}
@Override protected int setLayoutId() {
@ -58,17 +64,16 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
//String text = ((TextView) view).getText().toString();
Aria.download(this)
.load(mUrls)
.setDownloadDirPath(Environment.getExternalStorageDirectory().getPath() + "/group_test")
.start();
break;
case R.id.stop:
//Aria.download(this).load(DOWNLOAD_URL).pause();
Aria.download(this).load(mUrls).stop();
break;
case R.id.cancel:
//Aria.download(this).load(DOWNLOAD_URL).cancel();
Aria.download(this).load(mUrls).cancel();
break;
}
}
@ -79,6 +84,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
@DownloadGroup.onTaskPre() protected void onTaskPre(DownloadGroupTask task) {
L.d(TAG, "group task pre");
getBinding().setFileSize(task.getConvertFileSize());
}
@DownloadGroup.onTaskStart() void taskStart(DownloadGroupTask task) {
@ -86,7 +92,8 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
}
@DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) {
L.d(TAG, "group task running ==> " + task.getPercent());
getBinding().setProgress(task.getPercent());
getBinding().setSpeed(task.getConvertSpeed());
}
@DownloadGroup.onTaskResume() void taskResume(DownloadGroupTask task) {
@ -95,10 +102,12 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
@DownloadGroup.onTaskStop() void taskStop(DownloadGroupTask task) {
L.d(TAG, "group task stop");
getBinding().setSpeed("");
}
@DownloadGroup.onTaskCancel() void taskCancel(DownloadGroupTask task) {
L.d(TAG, "group task cancel");
getBinding().setSpeed("");
getBinding().setProgress(0);
}
@DownloadGroup.onTaskFail() void taskFail(DownloadGroupTask task) {
@ -106,6 +115,6 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
}
@DownloadGroup.onTaskComplete() void taskComplete(DownloadGroupTask task) {
L.d(TAG, "group task complete");
T.showShort(this, "任务组下载完成");
}
}

View File

@ -32,7 +32,7 @@ public class GroupModule extends BaseModule {
List<String> getUrls() {
List<String> urls = new ArrayList<>();
String[] str = getContext().getResources().getStringArray(R.array.group_urls);
String[] str = getContext().getResources().getStringArray(R.array.download_url);
Collections.addAll(urls, str);
return urls;
}

View File

@ -1,5 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto"
>
<data>
<variable
name="fileSize"
type="String"
/>
<variable
name="speed"
type="String"
/>
<variable
name="progress"
type="int"
/>
</data>
<LinearLayout
android:layout_width="match_parent"
@ -9,10 +25,16 @@
<include layout="@layout/layout_bar"/>
<include layout="@layout/content_single"/>
<include
layout="@layout/content_single"
bind:fileSize="@{fileSize}"
bind:progress="@{progress}"
bind:speed="@{speed}"
/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
/>
</LinearLayout>
</layout>

View File

@ -1,5 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto"
>
<data>
<variable
name="fileSize"
type="String"
/>
<variable
name="speed"
type="String"
/>
<variable
name="progress"
type="int"
/>
</data>
<android.support.design.widget.CoordinatorLayout
xmlns:tools="http://schemas.android.com/tools"
@ -18,7 +35,12 @@
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_single"/>
<include
layout="@layout/content_single"
bind:fileSize="@{fileSize}"
bind:progress="@{progress}"
bind:speed="@{speed}"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"

View File

@ -1,135 +1,155 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.arialyy.simple.download.SingleTaskActivity"
tools:showIn="@layout/activity_single"
>
<com.arialyy.simple.widget.HorizontalProgressBarWithNumber
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="16dp"
android:layout_toLeftOf="@+id/size"
android:max="100"
style="?android:attr/progressBarStyleHorizontal"
/>
<data>
<variable
name="fileSize"
type="String"
/>
<variable
name="speed"
type="String"
/>
<variable
name="progress"
type="int"
/>
</data>
<TextView
android:id="@+id/size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/progressBar"
android:layout_marginRight="16dp"
android:text="0mb"
android:textSize="16sp"
/>
<LinearLayout
android:id="@+id/handle_bar"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/progressBar"
android:orientation="horizontal"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.arialyy.simple.download.SingleTaskActivity"
tools:showIn="@layout/activity_single"
>
<com.arialyy.simple.widget.HorizontalProgressBarWithNumber
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="16dp"
android:layout_toLeftOf="@+id/size"
android:max="100"
android:progress="@{progress}"
style="?android:attr/progressBarStyleHorizontal"
/>
<TextView
android:id="@+id/speed"
android:id="@+id/size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="0kb/s"
android:textColor="@color/black"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/progressBar"
android:layout_marginRight="16dp"
android:text="@{fileSize}"
android:textSize="16sp"
/>
<Button
android:id="@+id/start"
android:layout_width="0dp"
<LinearLayout
android:id="@+id/handle_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="开始"
style="?buttonBarButtonStyle"
/>
android:layout_below="@+id/progressBar"
android:orientation="horizontal"
>
<TextView
android:id="@+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="@{speed}"
android:textColor="@color/black"
/>
<Button
android:id="@+id/stop"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="暂停"
style="?buttonBarButtonStyle"
/>
<Button
android:id="@+id/start"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="开始"
style="?buttonBarButtonStyle"
/>
<Button
android:id="@+id/cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="删除任务"
style="?buttonBarButtonStyle"
/>
</LinearLayout>
<Button
android:id="@+id/stop"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="暂停"
style="?buttonBarButtonStyle"
/>
<TextView
android:id="@+id/speed_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/handle_bar"
/>
<Button
android:id="@+id/cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:text="删除任务"
style="?buttonBarButtonStyle"
/>
</LinearLayout>
<RadioGroup
android:visibility="gone"
android:id="@+id/speeds"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/speed_hint"
android:orientation="horizontal"
>
<RadioButton
<TextView
android:id="@+id/speed_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="256kb"
android:layout_below="@+id/handle_bar"
/>
<RadioButton
android:layout_width="wrap_content"
<RadioGroup
android:id="@+id/speeds"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="512kb"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1mb"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2mb"
/>
android:layout_below="@+id/speed_hint"
android:orientation="horizontal"
android:visibility="gone"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="max"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="256kb"
/>
</RadioGroup>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="512kb"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1mb"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2mb"
/>
</RelativeLayout>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="max"
/>
</RadioGroup>
</RelativeLayout>
</layout>

View File

@ -1,12 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto"
>
<data>
<variable
name="fileSize"
type="String"
/>
<variable
name="speed"
type="String"
/>
<variable
name="progress"
type="int"
/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include layout="@layout/dialog_download"/>
<include
layout="@layout/dialog_download"
bind:fileSize="@{fileSize}"
bind:progress="@{progress}"
bind:speed="@{speed}"
/>
</LinearLayout>
</layout>

View File

@ -46,7 +46,7 @@
<string-array name="group_urls">
<item>http://img.sc115.com/uploads/allimg/110420/20110420225600154.jpg</item>
<item>https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQv8s5M31tFNvbjtGgxqmx14eh2h2651gkbrx-kN0cNYPD0qvRi</item>
<item>http://img05.tooopen.com/images/20160121/tooopen_sy_155168162826.jpg</item>
<item>http://img03.tooopen.com/images/20130811/tooopen_15265353.jpg</item>
<!--<item></item>-->
<!--<item></item>-->