コード例 #1
0
  public static void StartDownloadingImages(
      Context context, long highestItemIdBeforeSync, boolean favIconsExclusive) {
    DatabaseConnection dbConn = new DatabaseConnection(context);
    try {
      Intent service = new Intent(context, DownloadImagesService.class);
      service.putExtra(DownloadImagesService.LAST_ITEM_ID, highestItemIdBeforeSync);

      if (favIconsExclusive)
        service.putExtra(DownloadImagesService.DOWNLOAD_FAVICONS_EXCLUSIVE, true);

      context.startService(service);
    } finally {
      dbConn.closeDatabase();
    }
  }
コード例 #2
0
  @Override
  protected Exception doInBackground(Object... params) {
    DatabaseConnection dbConn = new DatabaseConnection(context);
    try {
      // String authKey = AuthenticationManager.getGoogleAuthKey(username, password);
      // SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
      // int maxItemsInDatabase =
      // Integer.parseInt(mPrefs.getString(SettingsActivity.SP_MAX_ITEMS_SYNC, "200"));

      long lastModified = dbConn.getLastModified();
      // dbConn.clearDatabaseOverSize();

      // List<RssFile> files;
      long offset = dbConn.getLowestItemId(false);

      int requestCount;
      int maxSyncSize = Integer.parseInt(OwnCloudReaderMethods.maxSizePerSync);

      highestItemIdBeforeSync = dbConn.getHighestItemId();

      SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);

      if (lastModified == 0) // Only on first sync
      {
        int maxItemsInDatabase = Constants.maxItemsCount;

        int totalCount = 0;
        do {
          requestCount =
              api.GetItems(TAGS.ALL, context, String.valueOf(offset), false, "0", "3", api);
          if (requestCount > 0) offset = dbConn.getLowestItemId(false);
          totalCount += requestCount;
        } while (requestCount == maxSyncSize);

        mPrefs.edit().putInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, totalCount).commit();

        do {
          offset = dbConn.getLowestItemId(true);
          requestCount =
              api.GetItems(TAGS.ALL_STARRED, context, String.valueOf(offset), true, "0", "2", api);
          // if(requestCount > 0)
          //	offset = dbConn.getLowestItemId(true);
          totalCount += requestCount;
        } while (requestCount == maxSyncSize && totalCount < maxItemsInDatabase);
      } else {
        int[] result = api.GetUpdatedItems(TAGS.ALL, context, lastModified + 1, api);
        mPrefs.edit().putInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, result[1]).commit();

        // OwnCloudReaderMethods.GetUpdatedItems(TAGS.ALL, context, lastModified, api);
      }
    } catch (Exception ex) {
      return ex;
    } finally {
      dbConn.closeDatabase();
    }
    return null;
  }