From 93b3d64d7707903788238194619124fc16a13e60 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Mon, 25 Mar 2019 08:44:09 +0800 Subject: [PATCH] demog --- .../aria/core/command/normal/StartCmd.java | 3 +- .../aria/core/download/BaseGroupTarget.java | 2 +- .../aria/core/download/BaseNormalTarget.java | 5 +-- .../aria/core/download/DownloadReceiver.java | 6 ++++ .../aria/core/upload/BaseNormalTarget.java | 6 ++-- app/build.gradle | 1 + .../java/com/arialyy/simple/MainActivity.java | 12 ++++--- .../core/download/SingleTaskActivity.java | 2 +- .../multi_download/DownloadAdapter.java | 2 ++ .../multi_download/MultiDownloadActivity.java | 4 +++ .../arialyy/simple/modlue/CommonModule.java | 22 ++++++++++++ .../java/com/arialyy/simple/to/NormalTo.java | 11 +++--- app/src/main/res/drawable/ic_del.xml | 8 ++++- .../res/drawable/selector_start_stop_bt.xml | 7 ++++ app/src/main/res/layout/item_main.xml | 36 +++++++++++++------ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/dimens.xml | 2 +- app/src/main/res/values/strings.xml | 13 +++++++ build.gradle | 4 ++- 19 files changed, 119 insertions(+), 28 deletions(-) create mode 100644 app/src/main/res/drawable/selector_start_stop_bt.xml diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java index 041484b4..72e46b7b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java @@ -87,7 +87,8 @@ class StartCmd extends AbsNormalCmd { } } 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())); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java index ad5fb332..1cc0bf60 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java @@ -71,7 +71,7 @@ abstract class BaseGroupTarget } @Override public boolean taskExists() { - return DownloadGroupTaskQueue.getInstance().getTask(mEntity.getGroupHash()) != null; + return DbEntity.checkDataExist(DownloadGroupEntity.class, "groupHash=?", mGroupHash); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java index 0b9c8a92..49357622 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java @@ -82,7 +82,7 @@ abstract class 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 } 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()); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index 80f9bae3..04cea0ce 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -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); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java index d433a694..f29668e2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java @@ -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 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 * @return {@code true}存在 */ @Override public boolean taskExists() { - return UploadTaskQueue.getInstance().getTask(mEntity.getFilePath()) != null; + return DbEntity.checkDataExist(UploadEntity.class, "key=?", mEntity.getFilePath()); } /** diff --git a/app/build.gradle b/app/build.gradle index e27fbfda..03bf545c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { diff --git a/app/src/main/java/com/arialyy/simple/MainActivity.java b/app/src/main/java/com/arialyy/simple/MainActivity.java index 7c5743c3..703cf4aa 100644 --- a/app/src/main/java/com/arialyy/simple/MainActivity.java +++ b/app/src/main/java/com/arialyy/simple/MainActivity.java @@ -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 { final List 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 { } @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); } } diff --git a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java index 99e9183a..819cd929 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java @@ -123,7 +123,7 @@ public class SingleTaskActivity extends BaseActivity { private void setBtState(boolean state) { //mStart.setEnabled(state); //mStop.setEnabled(!state); - } + }DelegateUpdate @Override public boolean onCreateOptionsMenu(Menu menu) { diff --git a/app/src/main/java/com/arialyy/simple/core/download/multi_download/DownloadAdapter.java b/app/src/main/java/com/arialyy/simple/core/download/multi_download/DownloadAdapter.java index 3753286b..18a34edd 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/multi_download/DownloadAdapter.java +++ b/app/src/main/java/com/arialyy/simple/core/download/multi_download/DownloadAdapter.java @@ -168,6 +168,8 @@ public class DownloadAdapter extends AbsRVAdapter 1024) { + isKb = false; + speed /= 1024; + } + Entry entry = new Entry(mPosition, speed, isKb); + mPosition++; + return entry; + } + public List getDownloadData() { List list = new ArrayList<>(); String[] titles = getContext().getResources().getStringArray(R.array.download_items); @@ -62,6 +82,7 @@ public class CommonModule extends AbsModule { public List getMainData() { List 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); } diff --git a/app/src/main/java/com/arialyy/simple/to/NormalTo.java b/app/src/main/java/com/arialyy/simple/to/NormalTo.java index 9ec63fa3..98b1a30e 100644 --- a/app/src/main/java/com/arialyy/simple/to/NormalTo.java +++ b/app/src/main/java/com/arialyy/simple/to/NormalTo.java @@ -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 CREATOR = new Parcelable.Creator() { + public static final Creator CREATOR = new Creator() { @Override public NormalTo createFromParcel(Parcel source) { return new NormalTo(source); } diff --git a/app/src/main/res/drawable/ic_del.xml b/app/src/main/res/drawable/ic_del.xml index 41990767..31f4b0f7 100644 --- a/app/src/main/res/drawable/ic_del.xml +++ b/app/src/main/res/drawable/ic_del.xml @@ -1,4 +1,10 @@ - + + + + + + + diff --git a/app/src/main/res/drawable/selector_start_stop_bt.xml b/app/src/main/res/drawable/selector_start_stop_bt.xml new file mode 100644 index 00000000..507a66a8 --- /dev/null +++ b/app/src/main/res/drawable/selector_start_stop_bt.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_main.xml b/app/src/main/res/layout/item_main.xml index b929be23..f00000b9 100644 --- a/app/src/main/res/layout/item_main.xml +++ b/app/src/main/res/layout/item_main.xml @@ -10,23 +10,39 @@ - + android:layout_toRightOf="@+id/image" + android:orientation="vertical" + > + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index c6c8fc7a..81a1426f 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,4 +7,5 @@ #2B2B2B #2B2B2B #efefef + #597F96 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 4d58ba0b..b6ff7002 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -3,7 +3,7 @@ 16dp 16dp 16dp - 48dp + 60dp 12sp 13sp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 53285533..58039153 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,6 +10,16 @@ FTP 文件夹下载 FTP 文件上传 + + + 单文件下载、多文件队列下载、各组件中使用 + 上传单个文件到服务器 + 多文件组合为一个组(如:封面、字幕、电影) + 单文件下载、多文件队列下载 + 下载服务器上的某个FTP文件夹 + 上传单个文件到服务器 + + 单任务下载 多任务下载 @@ -18,6 +28,9 @@ 组件中使用 + 文件名: %1$s + 保存路径: %1$s + http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk diff --git a/build.gradle b/build.gradle index b781f287..e2e8873c 100644 --- a/build.gradle +++ b/build.gradle @@ -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 下载框架'