demog
This commit is contained in:
@@ -87,7 +87,8 @@ class StartCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
|
||||
}
|
||||
} else {
|
||||
//任务没执行并且执行队列中没有该任务,才认为任务没有运行中
|
||||
if (!task.isRunning() && !mQueue.taskIsRunning(task.getKey())) {
|
||||
if (!task.isRunning() && !mQueue.taskIsRunning(task.getKey()) && !mQueue.taskExists(
|
||||
task.getKey())) {
|
||||
resumeTask();
|
||||
} else {
|
||||
ALog.w(TAG, String.format("任务【%s】已经在运行", task.getTaskName()));
|
||||
|
||||
@@ -71,7 +71,7 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
|
||||
}
|
||||
|
||||
@Override public boolean taskExists() {
|
||||
return DownloadGroupTaskQueue.getInstance().getTask(mEntity.getGroupHash()) != null;
|
||||
return DbEntity.checkDataExist(DownloadGroupEntity.class, "groupHash=?", mGroupHash);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -82,7 +82,7 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
||||
* @return {@code true}任务存在
|
||||
*/
|
||||
@Override public boolean taskExists() {
|
||||
return DownloadTaskQueue.getInstance().getTask(mEntity.getKey()) != null;
|
||||
return DbEntity.checkDataExist(DownloadEntity.class, "url=?", url);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,7 +164,8 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
||||
} else {
|
||||
ALog.w(TAG, "保存路径【" + filePath + "】已经被其它任务占用,当前任务将覆盖该路径的文件");
|
||||
CommonUtil.delTaskRecord(filePath, 1);
|
||||
mTaskWrapper = TaskWrapperManager.getInstance().getHttpTaskWrapper(DTaskWrapper.class, url);
|
||||
mTaskWrapper =
|
||||
TaskWrapperManager.getInstance().getHttpTaskWrapper(DTaskWrapper.class, url);
|
||||
}
|
||||
}
|
||||
File oldFile = new File(mEntity.getDownloadPath());
|
||||
|
||||
@@ -61,6 +61,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
*/
|
||||
@CheckResult
|
||||
public DownloadTarget load(DownloadEntity entity) {
|
||||
CheckUtil.checkUrlInvalidThrow(entity.getUrl());
|
||||
return new DownloadTarget(entity, targetName);
|
||||
}
|
||||
|
||||
@@ -71,6 +72,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
*/
|
||||
@CheckResult
|
||||
public DownloadTarget load(@NonNull String url) {
|
||||
CheckUtil.checkUrlInvalidThrow(url);
|
||||
return new DownloadTarget(url, targetName);
|
||||
}
|
||||
|
||||
@@ -102,6 +104,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
*/
|
||||
@CheckResult
|
||||
public FtpDownloadTarget loadFtp(DownloadEntity entity) {
|
||||
CheckUtil.checkUrlInvalidThrow(entity.getUrl());
|
||||
return new FtpDownloadTarget(entity, targetName);
|
||||
}
|
||||
|
||||
@@ -110,6 +113,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
*/
|
||||
@CheckResult
|
||||
public FtpDownloadTarget loadFtp(@NonNull String url) {
|
||||
CheckUtil.checkUrlInvalidThrow(url);
|
||||
return new FtpDownloadTarget(url, targetName);
|
||||
}
|
||||
|
||||
@@ -123,6 +127,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
@Deprecated
|
||||
@CheckResult
|
||||
public DownloadGroupTarget load(DownloadGroupEntity groupEntity) {
|
||||
CheckUtil.checkDownloadUrls(groupEntity.getUrls());
|
||||
return loadGroup(groupEntity);
|
||||
}
|
||||
|
||||
@@ -134,6 +139,7 @@ public class DownloadReceiver extends AbsReceiver {
|
||||
*/
|
||||
@CheckResult
|
||||
public DownloadGroupTarget loadGroup(DownloadGroupEntity groupEntity) {
|
||||
CheckUtil.checkDownloadUrls(groupEntity.getUrls());
|
||||
return new DownloadGroupTarget(groupEntity, targetName);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.manager.TaskWrapperManager;
|
||||
import com.arialyy.aria.core.queue.UploadTaskQueue;
|
||||
import com.arialyy.aria.orm.DbEntity;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import java.io.File;
|
||||
|
||||
@@ -32,7 +33,8 @@ abstract class BaseNormalTarget<TARGET extends AbsUploadTarget>
|
||||
protected String mTempUrl;
|
||||
|
||||
void initTarget(String filePath) {
|
||||
mTaskWrapper = TaskWrapperManager.getInstance().getHttpTaskWrapper(UTaskWrapper.class, filePath);
|
||||
mTaskWrapper =
|
||||
TaskWrapperManager.getInstance().getHttpTaskWrapper(UTaskWrapper.class, filePath);
|
||||
mEntity = mTaskWrapper.getEntity();
|
||||
File file = new File(filePath);
|
||||
mEntity.setFileName(file.getName());
|
||||
@@ -57,7 +59,7 @@ abstract class BaseNormalTarget<TARGET extends AbsUploadTarget>
|
||||
* @return {@code true}存在
|
||||
*/
|
||||
@Override public boolean taskExists() {
|
||||
return UploadTaskQueue.getInstance().getTask(mEntity.getFilePath()) != null;
|
||||
return DbEntity.checkDataExist(UploadEntity.class, "key=?", mEntity.getFilePath());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,6 +51,7 @@ dependencies {
|
||||
// compile 'com.arialyy.aria:aria-core:3.3.16'
|
||||
// annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.16'
|
||||
debugApi 'com.amitshekhar.android:debug-db:1.0.0'
|
||||
compile 'com.github.PhilJay:MPAndroidChart:v3.0.3'
|
||||
implementation project(':AppFrame')
|
||||
}
|
||||
repositories {
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.AppCompatImageView;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
@@ -62,6 +63,8 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
||||
final List<NormalTo> data = getModule(CommonModule.class).getMainData();
|
||||
getBinding().list.setAdapter(
|
||||
new Adapter(this, data));
|
||||
getBinding().list.addItemDecoration(
|
||||
new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
|
||||
RvItemClickSupport.addTo(getBinding().list).setOnItemClickListener(
|
||||
new RvItemClickSupport.OnItemClickListener() {
|
||||
@Override public void onItemClicked(RecyclerView recyclerView, int position, View v) {
|
||||
@@ -125,18 +128,19 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
||||
}
|
||||
|
||||
@Override protected void bindData(Holder holder, int position, NormalTo item) {
|
||||
holder.text.setText(item.title);
|
||||
Log.d(TAG, item.icon + "");
|
||||
holder.title.setText(item.title);
|
||||
holder.desc.setText(item.desc);
|
||||
holder.image.setImageResource(item.icon);
|
||||
}
|
||||
|
||||
private static class Holder extends AbsHolder {
|
||||
TextView text;
|
||||
TextView title, desc;
|
||||
AppCompatImageView image;
|
||||
|
||||
Holder(View itemView) {
|
||||
super(itemView);
|
||||
text = findViewById(R.id.text);
|
||||
title = findViewById(R.id.title);
|
||||
desc = findViewById(R.id.desc);
|
||||
image = findViewById(R.id.image);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
private void setBtState(boolean state) {
|
||||
//mStart.setEnabled(state);
|
||||
//mStop.setEnabled(!state);
|
||||
}
|
||||
}DelegateUpdate
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
@@ -168,6 +168,8 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
|
||||
int color = android.R.color.holo_green_light;
|
||||
switch (entity.getState()) {
|
||||
case IEntity.STATE_WAIT:
|
||||
str = "等待中";
|
||||
break;
|
||||
case IEntity.STATE_OTHER:
|
||||
case IEntity.STATE_FAIL:
|
||||
str = "开始";
|
||||
|
||||
@@ -76,6 +76,10 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
|
||||
Log.d(TAG, task.getTaskName() + ", " + task.getState());
|
||||
}
|
||||
|
||||
@Download.onWait void onWait(DownloadTask task){
|
||||
mAdapter.updateState(task.getEntity());
|
||||
}
|
||||
|
||||
@Download.onTaskStart void taskStart(DownloadTask task) {
|
||||
Log.d(TAG, task.getTaskName() + ", " + task.getState());
|
||||
mAdapter.updateState(task.getEntity());
|
||||
|
||||
@@ -17,10 +17,12 @@ package com.arialyy.simple.modlue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.frame.module.AbsModule;
|
||||
import com.arialyy.simple.MainActivity;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.to.NormalTo;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -28,6 +30,9 @@ import java.util.List;
|
||||
* 通用Modle块
|
||||
*/
|
||||
public class CommonModule extends AbsModule {
|
||||
|
||||
private int mPosition;
|
||||
|
||||
public CommonModule(Context context) {
|
||||
super(context);
|
||||
}
|
||||
@@ -38,6 +43,21 @@ public class CommonModule extends AbsModule {
|
||||
getContext().startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建图表实体
|
||||
*/
|
||||
public Entry createNewEntry(DownloadEntity entity) {
|
||||
long speed = entity.getSpeed() / 1024;
|
||||
boolean isKb = true;
|
||||
if (speed > 1024) {
|
||||
isKb = false;
|
||||
speed /= 1024;
|
||||
}
|
||||
Entry entry = new Entry(mPosition, speed, isKb);
|
||||
mPosition++;
|
||||
return entry;
|
||||
}
|
||||
|
||||
public List<NormalTo> getDownloadData() {
|
||||
List<NormalTo> list = new ArrayList<>();
|
||||
String[] titles = getContext().getResources().getStringArray(R.array.download_items);
|
||||
@@ -62,6 +82,7 @@ public class CommonModule extends AbsModule {
|
||||
public List<NormalTo> getMainData() {
|
||||
List<NormalTo> list = new ArrayList<>();
|
||||
String[] titles = getContext().getResources().getStringArray(R.array.main_items);
|
||||
String[] descs = getContext().getResources().getStringArray(R.array.main_items_desc);
|
||||
int[] icons = new int[] {
|
||||
R.drawable.ic_http,
|
||||
R.drawable.ic_http,
|
||||
@@ -75,6 +96,7 @@ public class CommonModule extends AbsModule {
|
||||
NormalTo to = new NormalTo();
|
||||
to.icon = icons[i];
|
||||
to.title = title;
|
||||
to.desc = descs[i];
|
||||
i++;
|
||||
list.add(to);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ import android.os.Parcelable;
|
||||
public class NormalTo implements Parcelable {
|
||||
public int icon;
|
||||
public String title;
|
||||
public String desc;
|
||||
|
||||
public NormalTo() {
|
||||
}
|
||||
|
||||
@Override public int describeContents() {
|
||||
return 0;
|
||||
@@ -32,17 +36,16 @@ public class NormalTo implements Parcelable {
|
||||
@Override public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(this.icon);
|
||||
dest.writeString(this.title);
|
||||
}
|
||||
|
||||
public NormalTo() {
|
||||
dest.writeString(this.desc);
|
||||
}
|
||||
|
||||
protected NormalTo(Parcel in) {
|
||||
this.icon = in.readInt();
|
||||
this.title = in.readString();
|
||||
this.desc = in.readString();
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<NormalTo> CREATOR = new Parcelable.Creator<NormalTo>() {
|
||||
public static final Creator<NormalTo> CREATOR = new Creator<NormalTo>() {
|
||||
@Override public NormalTo createFromParcel(Parcel source) {
|
||||
return new NormalTo(source);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
<vector android:height="24dp" android:viewportHeight="1024"
|
||||
android:viewportWidth="1024" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@color/icon_color" android:pathData="M512,442.64L148.24,78.88c-20.01,-20.01 -50.59,-19.53 -69.74,-0.38 -18.59,18.59 -18.98,50.38 0.38,69.74L442.64,512 78.88,875.76c-20.01,20.01 -19.53,50.59 -0.38,69.74 18.59,18.59 50.38,18.98 69.74,-0.38L512,581.36l363.76,363.76c20.01,20.01 50.59,19.53 69.74,0.38 18.59,-18.59 18.98,-50.38 -0.38,-69.74L581.36,512l363.76,-363.76c20.01,-20.01 19.53,-50.59 0.38,-69.74 -18.59,-18.59 -50.38,-18.98 -69.74,0.38L512,442.64z"/>
|
||||
<path android:fillColor="@color/icon_color" android:pathData="M801.59,333.13c0.04,1.45 0.09,2.45 0.09,3.62l0,534.45c0,52.39 -42.47,94.87 -94.87,94.87l-389.61,0c-52.39,0 -94.87,-42.47 -94.87,-94.87l0,-534.45c0,-1.17 0.05,-2.17 0.09,-3.62L164.39,333.13l0,555.45c0,74.79 60.63,135.42 135.42,135.42l424.37,0c74.79,0 135.42,-60.63 135.42,-135.42L859.61,333.13 801.59,333.13z"/>
|
||||
<path android:fillColor="@color/icon_color" android:pathData="M48.52,237.54l0,17.38c0,67.19 54.47,121.66 121.66,121.66l683.63,0c67.19,0 121.66,-54.47 121.66,-121.66l0,-17.38c0,-67.19 -54.47,-121.66 -121.66,-121.66l-683.63,0C102.99,115.87 48.52,170.34 48.52,237.54zM845.13,318.65l-666.25,0c-40,0 -72.42,-32.42 -72.42,-72.42l0,0c0,-40 32.42,-72.42 72.42,-72.42l666.25,0c40,0 72.42,32.42 72.42,72.42l0,0C917.54,286.22 885.12,318.65 845.13,318.65z"/>
|
||||
<path android:fillColor="@color/icon_color" android:pathData="M367.16,119.13l0,-52.15C367.16,45.99 384.18,28.97 405.18,28.97L618.82,28.97C639.82,28.97 656.84,45.99 656.84,66.98l0,52.15c0,5.4 4.38,9.77 9.77,9.77l9.42,0c5.4,0 9.77,-4.38 9.77,-9.77L685.8,62.28c0,-34.4 -27.88,-62.28 -62.28,-62.28L400.47,0C366.08,0 338.2,27.88 338.2,62.28l0,56.85c0,5.4 4.38,9.77 9.77,9.77l9.42,0C362.79,128.91 367.16,124.53 367.16,119.13z"/>
|
||||
<path android:fillColor="@color/icon_color" android:pathData="M345.58,876.27 L345.58,876.27c-8,0 -14.48,-6.48 -14.48,-14.48L331.09,457.81c0,-8 6.48,-14.48 14.48,-14.48l0,0c8,0 14.48,6.48 14.48,14.48L360.06,861.78C360.06,869.78 353.58,876.27 345.58,876.27z"/>
|
||||
<path android:fillColor="@color/icon_color" android:pathData="M511.28,876.27 L511.28,876.27c-8,0 -14.48,-6.48 -14.48,-14.48L496.79,457.81c0,-8 6.48,-14.48 14.48,-14.48l0,0c8,0 14.48,6.48 14.48,14.48L525.76,861.78C525.76,869.78 519.28,876.27 511.28,876.27z"/>
|
||||
<path android:fillColor="@color/icon_color" android:pathData="M677.11,753.91 L677.11,753.91c-8,0 -14.48,-6.48 -14.48,-14.48L662.63,457.81c0,-8 6.48,-14.48 14.48,-14.48l0,0c8,0 14.48,6.48 14.48,14.48l0,281.61C691.6,747.43 685.11,753.91 677.11,753.91z"/>
|
||||
<path android:fillColor="@color/icon_color" android:pathData="M677.11,876.27 L677.11,876.27c-8,0 -14.48,-6.48 -14.48,-14.48l0,-46.36c0,-8 6.48,-14.48 14.48,-14.48l0,0c8,0 14.48,6.48 14.48,14.48L691.6,861.78C691.6,869.78 685.11,876.27 677.11,876.27z"/>
|
||||
</vector>
|
||||
|
||||
7
app/src/main/res/drawable/selector_start_stop_bt.xml
Normal file
7
app/src/main/res/drawable/selector_start_stop_bt.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:drawable="@drawable/ic_start" android:state_selected="false"/>
|
||||
<item android:drawable="@drawable/ic_stop"/>
|
||||
|
||||
</selector>
|
||||
@@ -10,23 +10,39 @@
|
||||
|
||||
<android.support.v7.widget.AppCompatImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_width="@dimen/icon_size"
|
||||
android:layout_height="@dimen/icon_size"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="16dp"
|
||||
app:srcCompat="@drawable/ic_ftp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_toRightOf="@+id/image"
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:textColor="@color/colorAccent"
|
||||
android:textSize="@dimen/text_size_normal"
|
||||
/>
|
||||
android:layout_toRightOf="@+id/image"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/colorAccent"
|
||||
android:textSize="@dimen/text_size_normal"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_marginTop="4dp"
|
||||
android:id="@+id/desc"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/text_black"
|
||||
android:textSize="@dimen/text_size_smallest"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -7,4 +7,5 @@
|
||||
<color name="black">#2B2B2B</color>
|
||||
<color name="text_black">#2B2B2B</color>
|
||||
<color name="bg_grey">#efefef</color>
|
||||
<color name="bg_line">#597F96</color>
|
||||
</resources>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
<dimen name="item_h">48dp</dimen>
|
||||
<dimen name="item_h">60dp</dimen>
|
||||
|
||||
<dimen name="text_size_smallest">12sp</dimen>
|
||||
<dimen name="text_size_smaller">13sp</dimen>
|
||||
|
||||
@@ -10,6 +10,16 @@
|
||||
<item>FTP 文件夹下载</item>
|
||||
<item>FTP 文件上传</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="main_items_desc">
|
||||
<item>单文件下载、多文件队列下载、各组件中使用</item>
|
||||
<item>上传单个文件到服务器</item>
|
||||
<item>多文件组合为一个组(如:封面、字幕、电影)</item>
|
||||
<item>单文件下载、多文件队列下载</item>
|
||||
<item>下载服务器上的某个FTP文件夹</item>
|
||||
<item>上传单个文件到服务器</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="download_items">
|
||||
<item>单任务下载</item>
|
||||
<item>多任务下载</item>
|
||||
@@ -18,6 +28,9 @@
|
||||
<item>组件中使用</item>
|
||||
</string-array>
|
||||
|
||||
<string name="file_name">文件名: %1$s</string>
|
||||
<string name="file_path">保存路径: %1$s</string>
|
||||
|
||||
|
||||
<string-array name="test_apk_download_url">
|
||||
<item>http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk</item> <!--300M的文件-->
|
||||
|
||||
@@ -5,6 +5,7 @@ buildscript {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
google()
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
dependencies {
|
||||
// classpath 'com.android.tools.build:gradle:2.3.3'
|
||||
@@ -23,6 +24,7 @@ allprojects {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
google()
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
|
||||
tasks.withType(Javadoc) {
|
||||
@@ -41,7 +43,7 @@ task clean(type: Delete) {
|
||||
ext {
|
||||
userOrg = 'arialyy'
|
||||
groupId = 'com.arialyy.aria'
|
||||
publishVersion = '3.6.2_debug_5'
|
||||
publishVersion = '3.6.2_debug_6'
|
||||
// publishVersion = '1.0.4' //FTP插件
|
||||
repoName='maven'
|
||||
desc = 'android 下载框架'
|
||||
|
||||
Reference in New Issue
Block a user