Exemplo n.º 1
0
  @Override
  protected JSONObject doInBackground(String... params) {
    String jsonString = params[0];

    // get url
    int localCatalogIndex = PrefUtils.getLocalCatalogIndex(activity);
    String paiaUrl =
        Constants.getPaiaUrl(localCatalogIndex)
            + "/core/"
            + PaiaHelper.getInstance().getUsername()
            + "/request?access_token="
            + PaiaHelper.getInstance().getAccessToken();

    JSONObject paiaResponse = new JSONObject();

    try {
      this.setPostParameters(jsonString);
      paiaResponse = this.performRequest(paiaUrl);
    } catch (Exception e) {
      e.printStackTrace();

      this.raiseFailure();
    }

    return paiaResponse;
  }
Exemplo n.º 2
0
  private void cleanStoredCredentials() {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
    SharedPreferences.Editor editor = sharedPref.edit();

    editor.putString("store_login_username", null);
    editor.putString("store_login_password", null);

    editor.commit();

    // and remove stored login information
    PaiaHelper.getInstance().reset();

    BaseActivity instance = BaseActivity.instance;
    if (instance != null) {
      instance.selectSearch();
    }
  }
Exemplo n.º 3
0
  /**
   * This is where the bulk of our work is done. This function is called in a background thread and
   * should generate a new set of data to be published by the loader.
   */
  @Override
  public List<FeeEntry> loadInBackground() {
    List<FeeEntry> response = new ArrayList<FeeEntry>();

    // get url
    SharedPreferences settings = this.fragment.getActivity().getPreferences(0);
    int spinnerValue = settings.getInt("local_catalog", Constants.LOCAL_CATALOG_DEFAULT);

    String paiaUrl =
        Constants.getPaiaUrl(spinnerValue)
            + "/core/"
            + PaiaHelper.getUsername()
            + "/fees?access_token="
            + PaiaHelper.getAccessToken();
    URLConnectionHelper urlConnectionHelper = new URLConnectionHelper(paiaUrl);

    try {
      // open connection
      urlConnectionHelper.configure();
      urlConnectionHelper.connect(null);

      InputStream inputStream = urlConnectionHelper.getStream();

      String httpResponse = urlConnectionHelper.readStream(inputStream);
      Log.v("PAIA", httpResponse);

      JSONObject paiaResponse;
      try {
        paiaResponse = new JSONObject(httpResponse);
      } catch (JSONException e) {
        return response;
      }

      String sum = paiaResponse.getString("amount");

      JSONArray feeArray = paiaResponse.getJSONArray("fee");
      int feeArrayLength = feeArray.length();
      for (int i = 0; i < feeArrayLength; i++) {
        JSONObject fee = (JSONObject) feeArray.get(i);

        String feeDateString = fee.getString("date");
        SimpleDateFormat simpleDateFormat;

        if (feeDateString.substring(2, 3).equals("-")
            && feeDateString.substring(5, 6).equals("-")) {
          simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.GERMANY);
        } else {
          simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.GERMANY);
        }

        Date feeDate = simpleDateFormat.parse(fee.getString("date"));

        response.add(new FeeEntry(fee.getString("amount"), fee.getString("about"), feeDate, sum));
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

      this.raiseFailure();
    } finally {
      urlConnectionHelper.disconnect();
    }

    return response;
  }