Merge pull request #631 from DaveBoy/aria

修改任务组分页逻辑
pull/640/head
lyy 5 years ago committed by GitHub
commit 54cbdb7ee0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  2. 29
      PublicComponent/src/main/java/com/arialyy/aria/orm/DelegateFind.java

@ -417,15 +417,7 @@ public class DownloadReceiver extends AbsReceiver {
* @return 如果没有任务组列表则返回null * @return 如果没有任务组列表则返回null
*/ */
public List<DownloadGroupEntity> getGroupTaskList() { public List<DownloadGroupEntity> getGroupTaskList() {
List<DGEntityWrapper> wrappers = DbEntity.findRelationData(DGEntityWrapper.class); return getGroupTaskList(1,10);
if (wrappers == null || wrappers.isEmpty()) {
return null;
}
List<DownloadGroupEntity> entities = new ArrayList<>();
for (DGEntityWrapper wrapper : wrappers) {
entities.add(wrapper.groupEntity);
}
return entities;
} }
/** /**

@ -215,12 +215,15 @@ class DelegateFind extends AbsDelegate {
} else { } else {
sql = sb.toString(); sql = sb.toString();
} }
boolean paged=false;
if (page != -1 && num != -1) { if (page != -1 && num != -1) {
sql = sql.concat(String.format(" LIMIT %s,%s", (page - 1) * num, num)); paged=true;
sql = sql.concat(String.format(" Group by %s LIMIT %s,%s", pTableName.concat(".").concat(m.parentColumn()), (page - 1) * num, num));
} }
Cursor cursor = db.rawQuery(sql, null); Cursor cursor = db.rawQuery(sql, null);
List<T> data = List<T> data =
newInstanceEntity(wrapperClazz, parentClazz, childClazz, cursor, pColumn, cColumn); newInstanceEntity(wrapperClazz, parentClazz, childClazz, cursor, pColumn, cColumn,paged, db,m.entityColumn(),m.parentColumn());
closeCursor(cursor); closeCursor(cursor);
return data; return data;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
@ -243,7 +246,7 @@ class DelegateFind extends AbsDelegate {
Class<T> wrapperClazz, Class<P> parentClazz, Class<T> wrapperClazz, Class<P> parentClazz,
Class<C> childClazz, Class<C> childClazz,
Cursor cursor, Cursor cursor,
List<Field> pColumn, List<Field> cColumn) { List<Field> pColumn, List<Field> cColumn,boolean paged,SQLiteDatabase db,String entityColumn,String parentColumn) {
List<T> wrappers = new ArrayList<>(); List<T> wrappers = new ArrayList<>();
SparseArray<List<DbEntity>> childs = new SparseArray<>(); // 所有子表数据 SparseArray<List<DbEntity>> childs = new SparseArray<>(); // 所有子表数据
SparseArray<DbEntity> parents = new SparseArray<>(); // 所有父表数据 SparseArray<DbEntity> parents = new SparseArray<>(); // 所有父表数据
@ -255,8 +258,13 @@ class DelegateFind extends AbsDelegate {
childs.put(pRowId, new ArrayList<DbEntity>()); childs.put(pRowId, new ArrayList<DbEntity>());
parents.put(pRowId, createParent(pRowId, parentClazz, pColumn, cursor)); parents.put(pRowId, createParent(pRowId, parentClazz, pColumn, cursor));
} }
if(paged){
childs.get(pRowId).addAll(createChildren(db,childClazz,pColumn,entityColumn,parentColumn,parents.get(pRowId)));
}
else {
childs.get(pRowId).add(createChild(childClazz, cColumn, cursor)); childs.get(pRowId).add(createChild(childClazz, cColumn, cursor));
} }
}
List<Field> wFields = SqlUtil.getAllNotIgnoreField(wrapperClazz); List<Field> wFields = SqlUtil.getAllNotIgnoreField(wrapperClazz);
if (wFields == null || wFields.isEmpty()) { if (wFields == null || wFields.isEmpty()) {
@ -285,7 +293,22 @@ class DelegateFind extends AbsDelegate {
return wrappers; return wrappers;
} }
/**
* 创建子对象集合
*/
private <T extends DbEntity> List<T> createChildren(SQLiteDatabase db,Class<T> childClazz, List<Field> pColumn,
String entityColumn,String parentColumn,DbEntity parents)
throws IllegalAccessException {
for (Field field : pColumn) {
field.setAccessible(true);
if(field.getName().equals(parentColumn)){
Object o = field.get(parents);
return findData(db,childClazz,entityColumn+"='"+o+"'");
}
}
return new ArrayList<T>();
}
/** /**
* 创建子对象 * 创建子对象
*/ */

Loading…
Cancel
Save