コード例 #1
0
 /* go through and add html content to tables
  */
 protected void upgradeV43() {
   SearchUtils.reindexAll(ctx);
   prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
   User user = new User();
   user.setUsername(SessionManager.getUsername(ctx));
   user.setApiKey(prefs.getString(UpgradeManagerTask.PREF_API_KEY, ""));
   DbHelper db = DbHelper.getInstance(ctx);
   long userId = db.addOrUpdateUser(user);
   db.updateV43(userId);
 }
コード例 #2
0
  @Override
  protected Payload doInBackground(Payload... params) {
    Payload payload = new Payload();
    payload.setResult(false);
    String csvPath =
        Storage.getStorageLocationRoot(ctx) + File.separator + SessionManager.ACCOUNTS_CSV_FILENAME;
    File csvAccounts = new File(csvPath);

    if (csvAccounts.exists()) {
      BufferedReader reader = null;
      try {
        String line;
        reader = new BufferedReader(new FileReader(csvAccounts));
        DbHelper db = DbHelper.getInstance(ctx);
        int usersAdded = 0;
        while ((line = reader.readLine()) != null) {
          String[] rowData = line.split(CSV_SEPARATOR);

          if (rowData.length < CSV_COLUMNS) {
            Log.d(TAG, "Bad csv line, ignoring: " + line);
            continue;
          }
          User csvUser = new User();
          csvUser.setUsername(rowData[CSV_USERNAME_COLUMN]);
          csvUser.setPasswordEncrypted(rowData[CSV_PASSWORD_COLUMN]);
          csvUser.setApiKey(rowData[CSV_APIKEY_COLUMN]);

          db.addOrUpdateUser(csvUser);
          usersAdded++;
        }

        if (usersAdded > 0) {
          payload.setResult(true);
          payload.setResultResponse(
              ctx.getString(R.string.info_startup_preloaded_accounts, usersAdded));
        }
        Log.d(TAG, usersAdded + " users added");
      } catch (IOException ex) {
        Mint.logException(ex);
        ex.printStackTrace();
        payload.setResult(true);
        payload.setResultResponse(ctx.getString(R.string.error_preloading_accounts));
      } finally {
        try {
          if (reader != null) reader.close();
          boolean deleted = csvAccounts.delete();
          Log.d(TAG, "CSV file " + (deleted ? "" : "not ") + "deleted");
        } catch (IOException e) {
          Mint.logException(e);
        }
      }
    }

    return payload;
  }