@Override
 public void onSuccess(ResponseInfo<File> responseInfo) {
   if (downloadInfo.getFileLength() != downloadInfo.getProgress()) { // 不一致 返回
     return;
   }
   if (downloadInfo.getAutoRenameTmp()) { // 成功后改名
     File tarFile = new File(downloadInfo.getFileTmpPath());
     if (tarFile.exists()) {
       File newFile = new File(downloadInfo.getFileSavePath());
       tarFile.renameTo(newFile);
     }
   }
   LogUtils.d(downloadInfo.getPkg() + " onSuccess");
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null) {
     downloadInfo.setState(handler.getState());
   }
   try {
     db.saveOrUpdate(downloadInfo);
   } catch (DbException e) {
     LogUtils.e(e.getMessage(), e);
   }
   if (baseCallBack != null) {
     baseCallBack.onSuccess(responseInfo);
   }
 }
 @Override
 public void onFailure(HttpException error, String msg) {
   LogUtils.d(downloadInfo.getPkg() + " onFailure");
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null) {
     downloadInfo.setState(handler.getState());
   }
   try {
     db.saveOrUpdate(downloadInfo);
   } catch (DbException e) {
     LogUtils.e(e.getMessage(), e);
   }
   if (baseCallBack != null) {
     baseCallBack.onFailure(error, msg);
   }
 }
 /* package */
 public DownloadManager(Context appContext) {
   LogUtils.allowD = true;
   ColumnConverterFactory.registerColumnConverter(
       HttpHandler.State.class, new HttpHandlerStateConverter());
   mContext = appContext;
   db = DbUtils.create(mContext);
   try {
     downloadInfoList = db.findAll(Selector.from(DownloadInfo.class));
   } catch (DbException e) {
     LogUtils.e(e.getMessage(), e);
   }
   if (downloadInfoList == null) {
     downloadInfoList = new ArrayList<DownloadInfo>();
   }
 }
 @Override
 public void onCancelled() {
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null) {
     downloadInfo.setState(handler.getState());
   }
   try {
     db.saveOrUpdate(downloadInfo);
   } catch (DbException e) {
     LogUtils.e(e.getMessage(), e);
   }
   if (baseCallBack != null) {
     baseCallBack.onCancelled();
   }
 }
 @Override
 public void onLoading(long total, long current, boolean isUploading) {
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null) {
     downloadInfo.setState(handler.getState());
   }
   downloadInfo.setFileLength(total);
   downloadInfo.setProgress(current);
   try {
     db.saveOrUpdate(downloadInfo);
   } catch (DbException e) {
     LogUtils.e(e.getMessage(), e);
   }
   if (baseCallBack != null) {
     baseCallBack.onLoading(total, current, isUploading);
   }
 }
Exemplo n.º 6
0
  private static void addColumns2Map(
      Class<?> entityType, String primaryKeyFieldName, HashMap<String, Column> columnMap) {
    if (Object.class.equals(entityType)) return;
    try {
      Field[] fields = entityType.getDeclaredFields();
      for (Field field : fields) {
        if (ColumnUtils.isTransient(field) || Modifier.isStatic(field.getModifiers())) {
          continue;
        }
        if (ColumnConverterFactory.isSupportColumnConverter(field.getType())) {
          if (!field.getName().equals(primaryKeyFieldName)) {
            Column column = new Column(entityType, field);
            if (!columnMap.containsKey(column.getColumnName())) {
              columnMap.put(column.getColumnName(), column);
            }
          }
        } else if (ColumnUtils.isForeign(field)) {
          Foreign column = new Foreign(entityType, field);
          if (!columnMap.containsKey(column.getColumnName())) {
            columnMap.put(column.getColumnName(), column);
          }
        } else if (ColumnUtils.isFinder(field)) {
          Finder column = new Finder(entityType, field);
          if (!columnMap.containsKey(column.getColumnName())) {
            columnMap.put(column.getColumnName(), column);
          }
        }
      }

      if (!Object.class.equals(entityType.getSuperclass())) {
        addColumns2Map(entityType.getSuperclass(), primaryKeyFieldName, columnMap);
      }
    } catch (Throwable e) {
      LogUtils.e(e.getMessage(), e);
    }
  }