Пример #1
0
  private void callAPI() {
    Log.d(TAG, "----- callAPI ----- ");

    progressDialog.setIndeterminate(true);
    progressDialog.setMessage("Authenticating...");
    progressDialog.show();

    SharedPreferences prefs = this.getSharedPreferences("CopyistPreferences", Context.MODE_PRIVATE);
    String token = prefs.getString("token", null);

    String uri = String.format("https://copyist.io/api/v1/musician/ensembles?token=%1$s", token);

    StringRequest stringRequest =
        new StringRequest(
            Request.Method.GET,
            uri,
            new Response.Listener<String>() {

              @Override
              public void onResponse(String response) {
                Log.d(TAG, response.toString());

                try {
                  JSONObject responseObject = new JSONObject(response);

                  JSONArray ensemblesArray = responseObject.getJSONArray("ensembles");

                  SharedPreferences.Editor editor =
                      getSharedPreferences("CopyistPreferences", MODE_PRIVATE).edit();
                  editor.putString("ensembles", ensemblesArray.toString());
                  editor.commit();

                  loadListView();

                } catch (Exception e) {
                  e.printStackTrace();
                  Toast.makeText(
                          getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG)
                      .show();
                } finally {
                  progressDialog.dismiss();
                }
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error: " + error.getMessage());
                Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT)
                    .show();
              }
            });

    progressDialog.dismiss();

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(stringRequest);
  }
Пример #2
0
  private void callDeleteEnsembleAPI(int ensembleId) {
    Log.d(TAG, "----- callDeleteEnsembleAPI ----- ");

    progressDialog.setIndeterminate(true);
    progressDialog.setMessage("Authenticating...");
    progressDialog.show();

    SharedPreferences prefs = this.getSharedPreferences("CopyistPreferences", Context.MODE_PRIVATE);
    String token = prefs.getString("token", null);

    String uri =
        String.format(
            "https://copyist.io/api/v1/composer/ensembles/delete?token=%1$s&id=%2$s",
            token, ensembleId);

    StringRequest stringRequest =
        new StringRequest(
            Request.Method.POST,
            uri,
            new Response.Listener<String>() {

              @Override
              public void onResponse(String response) {
                Log.d(TAG, response.toString());
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error: " + error.getMessage());
                Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT)
                    .show();
              }
            });

    progressDialog.dismiss();

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(stringRequest);
  }