获取任务列表增加分页功能

v3.6.6
laoyuyu 6 years ago
parent 93b3d64d77
commit 9ff9e1e5dd
  1. 3
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  2. 47
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  3. 3
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  4. 51
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  5. 42
      Aria/src/main/java/com/arialyy/aria/orm/DbEntity.java
  6. 79
      Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java
  7. 16
      Aria/src/main/java/com/arialyy/aria/orm/DelegateWrapper.java
  8. 9
      Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
  9. 2
      Aria/src/main/java/com/arialyy/aria/util/DbDataHelper.java
  10. 2
      app/build.gradle
  11. 12
      app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  12. 8
      gradle.properties

@ -133,6 +133,9 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
+ ", groupHash='"
+ groupHash
+ '\''
+ ", fileName='"
+ getFileName()
+ '\''
+ ", md5Code='"
+ md5Code
+ '\''

@ -48,7 +48,9 @@ public class DownloadReceiver extends AbsReceiver {
* 设置最大下载速度单位kb
*
* @param maxSpeed 为0表示不限速
* @deprecated {@code Aria.get(Context).getDownloadConfig().setMaxSpeed(int)}
*/
@Deprecated
public DownloadReceiver setMaxSpeed(int maxSpeed) {
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setMaxSpeed(maxSpeed);
return this;
@ -311,19 +313,45 @@ public class DownloadReceiver extends AbsReceiver {
/**
* 获取所有普通下载任务
* 获取未完成的普通任务列表{@link #getAllNotCompletTask()}
* 获取未完成的普通任务列表{@link #getAllNotCompleteTask()}
* 获取已经完成的普通任务列表{@link #getAllCompleteTask()}
*/
public List<DownloadEntity> getTaskList() {
return DownloadEntity.findDatas(DownloadEntity.class, "isGroupChild=? and downloadPath!=''",
return DbEntity.findDatas(DownloadEntity.class, "isGroupChild=? and downloadPath!=''",
"false");
}
/**
* 分页获取所有普通下载任务如果页数大于总页数返回null
* 获取未完成的普通任务列表{@link #getAllNotCompleteTask()}
* 获取已经完成的普通任务列表{@link #getAllCompleteTask()}
*
* @param page 当前页不能小于1
* @param num 每页数量不能小于1
*/
public List<DownloadEntity> getTaskList(int page, int num) {
CheckUtil.checkPageParams(page, num);
return DbEntity.findDatas(DownloadEntity.class, page, num,
"isGroupChild=? and downloadPath!=''", "false");
}
/**
* 获取所有未完成的普通下载任务
*/
public List<DownloadEntity> getAllNotCompletTask() {
return DownloadEntity.findDatas(DownloadEntity.class,
public List<DownloadEntity> getAllNotCompleteTask() {
return DbEntity.findDatas(DownloadEntity.class,
"isGroupChild=? and downloadPath!='' and isComplete=?", "false", "false");
}
/**
* 分页获取所有未完成的普通下载任务如果页数大于总页数返回null
*
* @param page 当前页不能小于1
* @param num 每页数量不能小于1
*/
public List<DownloadEntity> getAllNotCompleteTask(int page, int num) {
CheckUtil.checkPageParams(page, num);
return DbEntity.findDatas(DownloadEntity.class, page, num,
"isGroupChild=? and downloadPath!='' and isComplete=?", "false", "false");
}
@ -331,7 +359,16 @@ public class DownloadReceiver extends AbsReceiver {
* 获取所有已经完成的普通任务
*/
public List<DownloadEntity> getAllCompleteTask() {
return DownloadEntity.findDatas(DownloadEntity.class,
return DbEntity.findDatas(DownloadEntity.class,
"isGroupChild=? and downloadPath!='' and isComplete=?", "false", "true");
}
/**
* 分页获取所有已经完成的普通任务如果页数大于总页数返回null
*/
public List<DownloadEntity> getAllCompleteTask(int page, int num) {
CheckUtil.checkPageParams(page, num);
return DbEntity.findDatas(DownloadEntity.class,
"isGroupChild=? and downloadPath!='' and isComplete=?", "false", "true");
}

@ -193,7 +193,10 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
public void save() {
if (!checkEntity()) {
ALog.e(TAG, "保存修改失败");
}else {
ALog.i(TAG, "保存成功");
}
}
/**

@ -15,9 +15,11 @@
*/
package com.arialyy.aria.core.upload;
import android.content.Context;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.command.normal.CancelAllCmd;
@ -44,7 +46,9 @@ public class UploadReceiver extends AbsReceiver {
* 设置最大上传速度单位kb
*
* @param maxSpeed 为0表示不限速
* @deprecated 请使用 {@code Aria.get(Context).getUploadConfig().setMaxSpeed(int)}
*/
@Deprecated
public UploadReceiver setMaxSpeed(int maxSpeed) {
AriaManager.getInstance(AriaManager.APP).getUploadConfig().setMaxSpeed(maxSpeed);
return this;
@ -94,27 +98,62 @@ public class UploadReceiver extends AbsReceiver {
/**
* 获取所有普通上传任务
* 获取未完成的普通任务列表{@link #getAllNotCompletTask()}
* 获取未完成的普通任务列表{@link #getAllNotCompleteTask()}
* 获取已经完成的普通任务列表{@link #getAllCompleteTask()}
*/
public List<UploadEntity> getTaskList() {
return DbEntity.findAllData(UploadEntity.class);
}
/**
* 分页获取所有普通上传任务如果页数大于总页数返回null
* 获取未完成的普通任务列表{@link #getAllNotCompleteTask()}
* 获取已经完成的普通任务列表{@link #getAllCompleteTask()}
*
* @param page 当前页不能小于1
* @param num 每页数量不能小于1
*/
public List<UploadEntity> getTaskList(int page, int num) {
CheckUtil.checkPageParams(page, num);
return DbEntity.findDatas(UploadEntity.class, page, num,
"isGroupChild=? and downloadPath!=''", "false");
}
/**
* 获取所有未完成的普通上传任务
*/
public List<UploadEntity> getAllNotCompletTask() {
return UploadEntity.findDatas(UploadEntity.class,
public List<UploadEntity> getAllNotCompleteTask() {
return DbEntity.findDatas(UploadEntity.class,
"isGroupChild=? and isComplete=?", "false", "false");
}
/**
* 获取所有已经完成的普通任务
* 分页获取所有未完成的普通上传任务如果页数大于总页数返回null
*
* @param page 当前页不能小于1
* @param num 每页数量不能小于1
*/
public List<UploadEntity> getAllNotCompleteTask(int page, int num) {
CheckUtil.checkPageParams(page, num);
return DbEntity.findDatas(UploadEntity.class, page, num,
"isGroupChild=? and downloadPath!='' and isComplete=?", "false", "false");
}
/**
* 获取所有已经完成的普通任务如果页数大于总页数返回null
*/
public List<UploadEntity> getAllCompleteTask() {
return UploadEntity.findDatas(UploadEntity.class,
"isGroupChild=? and isComplete=?", "false", "true");
return DbEntity.findDatas(UploadEntity.class, "isGroupChild=? and isComplete=?", "false",
"true");
}
/**
* 分页获取所有已经完成的普通任务如果页数大于总页数返回null
*/
public List<UploadEntity> getAllCompleteTask(int page, int num) {
CheckUtil.checkPageParams(page, num);
return DbEntity.findDatas(UploadEntity.class,
"isGroupChild=? and downloadPath!='' and isComplete=?", "false", "true");
}
/**

@ -77,8 +77,7 @@ public abstract class DbEntity {
* @return 没有数据返回null
*/
public static <T extends DbEntity> List<T> findAllData(Class<T> clazz) {
DelegateWrapper util = DelegateWrapper.getInstance();
return util.findAllData(clazz);
return DelegateWrapper.getInstance().findAllData(clazz);
}
/**
@ -98,8 +97,25 @@ public abstract class DbEntity {
* @return 没有数据返回null
*/
public static <T extends DbEntity> List<T> findDatas(Class<T> clazz, String... expression) {
DelegateWrapper util = DelegateWrapper.getInstance();
return util.findData(clazz, expression);
return DelegateWrapper.getInstance().findData(clazz, expression);
}
/**
* 分页查询数据
* <code>
* DownloadEntity.findFirst(DownloadEntity.class, 0, 10, "downloadUrl=?", downloadUrl);
* </code>
*
* @param page 需要查询的页数从1开始如果page小于1 num 小于1返回null
* @param num 每页返回的数量
* @return 没有数据返回null如果页数大于总页数返回null
*/
public static <T extends DbEntity> List<T> findDatas(Class<T> clazz, int page, int num,
String... expression) {
if (page < 1 || num < 1) {
return null;
}
return DelegateWrapper.getInstance().findData(clazz, page, num, expression);
}
/**
@ -111,8 +127,22 @@ public abstract class DbEntity {
* @return 没有数据返回null
*/
public static <T extends DbEntity> List<T> findDataByFuzzy(Class<T> clazz, String conditions) {
DelegateWrapper util = DelegateWrapper.getInstance();
return util.findDataByFuzzy(clazz, conditions);
return DelegateWrapper.getInstance().findDataByFuzzy(clazz, conditions);
}
/**
* 模糊查询一组数据
* <code>
* DownloadEntity.findDatas(DownloadEntity.class, "downloadUrl like http://");
* </code>
*
* @param page 需要查询的页数从1开始如果page小于1 num 小于1返回null
* @param num 每页返回的数量
* @return 没有数据返回null如果页数大于总页数返回null
*/
public static <T extends DbEntity> List<T> findDataByFuzzy(Class<T> clazz, int page, int num,
String conditions) {
return DelegateWrapper.getInstance().findDataByFuzzy(clazz, page, num, conditions);
}
/**

@ -29,6 +29,7 @@ import com.arialyy.aria.util.CommonUtil;
import java.lang.reflect.Field;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
@ -340,16 +341,38 @@ class DelegateFind extends AbsDelegate {
<T extends DbEntity> List<T> findData(SQLiteDatabase db, Class<T> clazz, String... expression) {
db = checkDb(db);
CheckUtil.checkSqlExpression(expression);
String sql =
"SELECT rowid, * FROM " + CommonUtil.getClassName(clazz) + " WHERE " + expression[0] + " ";
sql = sql.replace("?", "%s");
Object[] params = new String[expression.length - 1];
for (int i = 0, len = params.length; i < len; i++) {
params[i] = String.format("'%s'", encodeStr(expression[i + 1]));
String sql = String.format("SELECT rowid, * FROM %s WHERE %s", CommonUtil.getClassName(clazz),
expression[0]);
String[] params = new String[expression.length - 1];
System.arraycopy(expression, 1, params, 0, params.length);
print(FIND_DATA, sql);
Cursor cursor = db.rawQuery(sql, params);
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(clazz, cursor) : null;
closeCursor(cursor);
close(db);
return data;
}
sql = String.format(sql, params);
/**
* 获取分页数据
*/
<T extends DbEntity> List<T> findData(SQLiteDatabase db, Class<T> clazz, int page, int num,
String... expression) {
if (page < 1 || num < 1) {
return null;
}
db = checkDb(db);
CheckUtil.checkSqlExpression(expression);
String sql = String.format("SELECT rowid, * FROM %s WHERE %s LIMIT %s,%s",
CommonUtil.getClassName(clazz),
expression[0], (page - 1) * num, num);
String[] params = new String[expression.length - 1];
System.arraycopy(expression, 1, params, 0, params.length);
print(FIND_DATA, sql);
Cursor cursor = db.rawQuery(sql, null);
Cursor cursor = db.rawQuery(sql, params);
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(clazz, cursor) : null;
closeCursor(cursor);
close(db);
@ -359,16 +382,42 @@ class DelegateFind extends AbsDelegate {
/**
* 模糊查寻数据
*/
<T extends DbEntity> List<T> findDataByFuzzy(SQLiteDatabase db, Class<T> clazz, String conditions) {
<T extends DbEntity> List<T> findDataByFuzzy(SQLiteDatabase db, Class<T> clazz,
String conditions) {
db = checkDb(db);
if (TextUtils.isEmpty(conditions)) {
throw new IllegalArgumentException("sql语句表达式不能为null或\"\"");
}
if (!conditions.toUpperCase().contains("LIKE")) {
throw new IllegalArgumentException("sql语句表达式未包含LIEK");
}
String sql = String.format("SELECT rowid, * FROM %s, WHERE %s", CommonUtil.getClassName(clazz),
conditions);
print(FIND_DATA, sql);
Cursor cursor = db.rawQuery(sql, null);
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(clazz, cursor) : null;
closeCursor(cursor);
close(db);
return data;
}
/**
* 分页模糊搜索数据
*/
<T extends DbEntity> List<T> findDataByFuzzy(SQLiteDatabase db, Class<T> clazz,
int page, int num, String conditions) {
if (page < 1 || num < 1) {
return null;
}
db = checkDb(db);
if(TextUtils.isEmpty(conditions)){
if (TextUtils.isEmpty(conditions)) {
throw new IllegalArgumentException("sql语句表达式不能为null或\"\"");
}
if(!conditions.toUpperCase().contains("LIKE")){
if (!conditions.toUpperCase().contains("LIKE")) {
throw new IllegalArgumentException("sql语句表达式未包含LIEK");
}
String sql =
"SELECT rowid, * FROM " + CommonUtil.getClassName(clazz) + " WHERE "+conditions;
String sql = String.format("SELECT rowid, * FROM %s WHERE %s LIMIT %s,%s",
CommonUtil.getClassName(clazz), conditions, (page - 1) * num, num);
print(FIND_DATA, sql);
Cursor cursor = db.rawQuery(sql, null);
List<T> data = cursor.getCount() > 0 ? newInstanceEntity(clazz, cursor) : null;
@ -376,6 +425,7 @@ class DelegateFind extends AbsDelegate {
close(db);
return data;
}
/**
* 查找表的所有数据
*/
@ -394,7 +444,8 @@ class DelegateFind extends AbsDelegate {
/**
* 根据数据游标创建一个具体的对象
*/
private synchronized <T extends DbEntity> List<T> newInstanceEntity(Class<T> clazz, Cursor cursor) {
private synchronized <T extends DbEntity> List<T> newInstanceEntity(Class<T> clazz,
Cursor cursor) {
List<Field> fields = CommonUtil.getAllFields(clazz);
List<T> entitys = new ArrayList<>();
if (fields != null && fields.size() > 0) {

@ -124,6 +124,13 @@ public class DelegateWrapper {
return mDManager.getDelegate(DelegateFind.class).findData(mDb, clazz, expression);
}
/**
* 获取分页数据
*/
<T extends DbEntity> List<T> findData(Class<T> clazz, int page, int num, String... expression) {
return mDManager.getDelegate(DelegateFind.class).findData(mDb, clazz, page, num, expression);
}
/**
* 模糊查寻数据
*/
@ -131,6 +138,15 @@ public class DelegateWrapper {
return mDManager.getDelegate(DelegateFind.class).findDataByFuzzy(mDb, clazz, conditions);
}
/**
* 模糊查寻数据
*/
<T extends DbEntity> List<T> findDataByFuzzy(Class<T> clazz, int page, int num,
String conditions) {
return mDManager.getDelegate(DelegateFind.class)
.findDataByFuzzy(mDb, clazz, page, num, conditions);
}
/**
* 通过rowId判断数据是否存在
*/

@ -41,6 +41,15 @@ public class CheckUtil {
if (obj == null) throw new IllegalArgumentException("不能传入空对象");
}
/**
* 检查分页数据需要查询的页数从1开始如果page小于1 num 小于1则抛出{@link NullPointerException}
* @param page 从1 开始
* @param num 每页数量
*/
public static void checkPageParams(int page, int num){
if (page < 1 || num < 1) throw new NullPointerException("page和num不能小于1");
}
/**
* 检查sql的expression是否合法
*/

@ -48,7 +48,7 @@ public class DbDataHelper {
/**
* 获取组合任务实体 如果数据库不存在该实体则新创建一个新的任务组实体
*
* @param groupHash 组合任务名称
* @param groupHash 组合任务Hash
* @param urls 子任务url列表
*/
public static DownloadGroupEntity getHttpDGEntity(String groupHash, List<String> urls) {

@ -51,7 +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'
api 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation project(':AppFrame')
}
repositories {

@ -30,6 +30,7 @@ import android.widget.Toast;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.IEntity;
@ -44,6 +45,7 @@ import com.arialyy.simple.databinding.ActivitySingleBinding;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@ -123,7 +125,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) {
@ -288,7 +290,9 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
startD();
//startD();
List<DownloadEntity> list = Aria.download(this).getAllNotCompleteTask(5, 2);
ALog.d("Tag", list.size() + "");
break;
case R.id.stop:
Aria.download(this).load(DOWNLOAD_URL).stop();
@ -320,7 +324,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//if (file.exists()){
// file.delete();
//}
Aria.download(SingleTaskActivity.this).load(DOWNLOAD_URL).resetState().save();
//Aria.download(SingleTaskActivity.this).load(DOWNLOAD_URL).resetState().save();
Map<String, String> params = new HashMap<>();
params.put("key", "value");
params.put("filename", "CentOS-7-x86_64-Minimal-1804.iso");
@ -339,7 +343,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
// + "\"id\":\"你的样子\"\n< > "
// + "}")
//.resetState()
.start();
.save();
//.add();
}

@ -16,12 +16,12 @@
#org.gradle.daemon=true
#org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
# gradle proxy https://chaosleong.github.io/2017/02/10/Configuring-Gradle-Proxy/
systemProp.socksProxyHost=127.0.0.1
systemProp.socksProxyPort=1080
systemprop.socksProxyVersion=5
#systemProp.socksProxyHost=127.0.0.1
#systemProp.socksProxyPort=1080
#systemprop.socksProxyVersion=5
#Pandroid.debug.obsoleteApi=true
# androidx ǨÒÆhttps://developer.android.com/studio/preview/features/?hl=zh-cn#androidx_migration
# androidx Ǩ<EFBFBD><EFBFBD>https://developer.android.com/studio/preview/features/?hl=zh-cn#androidx_migration
#android.useAndroidX=true
#android.enableJetifier=true
Loading…
Cancel
Save