Exemplo n.º 1
0
  /**
   * 5.search all results <url,bean>
   *
   * @return
   */
  public HashMap<String, ArrayList<DownloadBean>> getAllTasks() {
    HashMap<String, ArrayList<DownloadBean>> map = new HashMap<String, ArrayList<DownloadBean>>();
    SQLiteDatabase database = dbHelper.getReadableDatabase();
    String sql =
        "select url, file_name, "
            + "total_size, start_pos, end_pos, "
            + "compelete_size, thread_id, file_version, "
            + "file_version_code, package_name, "
            + "icon_url, soft_id, download_id, version_code "
            + "from download_info";
    Cursor cursor = null;
    try {
      cursor = database.rawQuery(sql, null);
      while (cursor.moveToNext()) {
        DownloadBean info = new DownloadBean();
        info.url = cursor.getString(0);
        info.fileName = cursor.getString(1);
        info.fileSize = cursor.getLong(2);
        info.startPosition = cursor.getLong(3);
        info.endPosition = cursor.getLong(4);
        info.currentPosition = cursor.getLong(5);
        info.threadId = cursor.getInt(6);
        info.fileVersion = cursor.getString(7);
        info.fileVersionCode = cursor.getInt(8);
        info.packageName = cursor.getString(9);
        info.iconUrl = cursor.getString(10);
        info.fileId = cursor.getString(11);
        info.downloadId = cursor.getString(12);
        info.versionCode = cursor.getInt(13);

        // update the list, contains by Map
        String mapKey = info.url + "_" + info.downloadId;
        if (map.containsKey(mapKey)) {
          map.get(mapKey).add(info);
        } else { // not exist in the map, create a new one
          ArrayList<DownloadBean> list = new ArrayList<DownloadBean>();
          list.add(info);
          map.put(mapKey, list);
        }
      }
    } catch (Exception e) {
      Log.e(TAG, "getAllTasks Error:" + e);
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
    return map;
  }
Exemplo n.º 2
0
 /**
  * 4.searching by url
  *
  * @param urlstr
  * @return
  */
 public ArrayList<DownloadBean> getDownloadTaskByUrl(String urlstr, String downloadId) {
   ArrayList<DownloadBean> list = new ArrayList<DownloadBean>();
   SQLiteDatabase database = dbHelper.getReadableDatabase();
   String sql =
       "select url, file_name, total_size, "
           + "start_pos, end_pos, compelete_size, "
           + "thread_id, file_version, file_version_code, "
           + "package_name, icon_url, soft_id, download_id, version_code "
           + "from download_info "
           + "where url=? and download_id=?";
   Cursor cursor = null;
   try {
     cursor = database.rawQuery(sql, new String[] {urlstr, downloadId});
     while (cursor.moveToNext()) {
       DownloadBean info = new DownloadBean();
       info.url = cursor.getString(0);
       info.fileName = cursor.getString(1);
       info.fileSize = cursor.getLong(2);
       info.startPosition = cursor.getLong(3);
       info.endPosition = cursor.getLong(4);
       info.currentPosition = cursor.getLong(5);
       info.threadId = cursor.getInt(6);
       info.fileVersion = cursor.getString(7);
       info.fileVersionCode = cursor.getInt(8);
       info.packageName = cursor.getString(9);
       info.iconUrl = cursor.getString(10);
       info.fileId = cursor.getString(11);
       info.downloadId = cursor.getString(12);
       info.versionCode = cursor.getInt(13);
       list.add(info);
     }
   } catch (Exception e) {
     Log.e(TAG, "getDownloadTaskByUrl Error:" + e);
     e.printStackTrace();
   } finally {
     if (cursor != null) {
       cursor.close();
     }
   }
   return list;
 }