Ejemplo n.º 1
0
 private void refuse(String txt, View v) {
   for (Invitation i : invitations) {
     if (i.getNomFoyer().equals(txt)) {
       repondre(i, "declined", v);
     }
   }
 }
Ejemplo n.º 2
0
 private void accept(String txt, View v) {
   for (Invitation i : invitations) {
     if (i.getNomFoyer().equals(txt)) {
       repondre(i, "accepted", v);
     }
   }
 }
Ejemplo n.º 3
0
  private void showInvitations() {

    GridLayout.Spec row;
    GridLayout.Spec column;
    GridLayout.LayoutParams params;

    for (Invitation i : invitations) {

      final TextView tempText = new TextView(getApplicationContext());
      tempText.setText(i.getNomFoyer());
      tempText.setTextSize(18);
      row = GridLayout.spec(mainLayout.getRowCount());
      column = GridLayout.spec(0);
      params = new GridLayout.LayoutParams(row, column);
      params.setGravity(Gravity.FILL_HORIZONTAL);
      tempText.setLayoutParams(params);
      mainLayout.addView(tempText);

      Button tempAcceptButton =
          new Button(getApplicationContext(), null, android.R.attr.buttonStyleSmall);
      tempAcceptButton.setText(R.string.show_invitations_accept);
      column = GridLayout.spec(1);
      params = new GridLayout.LayoutParams(row, column);
      tempAcceptButton.setLayoutParams(params);
      tempAcceptButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              accept(tempText.getText().toString(), mainLayout.getFocusedChild());
            }
          });
      mainLayout.addView(tempAcceptButton);

      Button tempRefuseButton =
          new Button(getApplicationContext(), null, android.R.attr.buttonStyleSmall);
      tempRefuseButton.setText(R.string.show_invitations_refuse);
      column = GridLayout.spec(2);
      params = new GridLayout.LayoutParams(row, column);
      tempRefuseButton.setLayoutParams(params);
      tempRefuseButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              refuse(tempText.getText().toString(), mainLayout.getFocusedChild());
            }
          });
      mainLayout.addView(tempRefuseButton);
    }
  }
Ejemplo n.º 4
0
  private void repondre(Invitation i, String newState, View v) {
    final View view = v;
    Map<String, String> params = new HashMap<>();
    params.put("action", Actions.REPONDRE_INVITATION.toString());
    params.put("id_google", id_google);
    params.put("id_invitation", i.getId());
    params.put("reponse", newState);
    Log.i(TAG, "Modifying the invitation...");
    mSyncNetworkResponses.addTransaction();
    ApiClient.post(
        getString(R.string.url_api),
        new RequestParams(params),
        new JsonHttpResponseHandler() {
          @Override
          public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
              boolean success = response.getBoolean("success");
              if (success) {
                Log.i(TAG, "The modification has been made");
                mSyncNetworkResponses.removeTransaction();
              } else {
                sendDialog(
                    "Une erreur s'est produite lors de la modification du statut.\n Veuillez réessayer.");
              }
            } catch (JSONException e) {
              Log.e(
                  TAG,
                  "ERROR while retriving data from JSONObject "
                      + "representing success of modifying the state of an invitation : \n"
                      + e.getMessage());
            }
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, String responseString, Throwable throwable) {
            Log.e(TAG, "statusCode : " + statusCode);
            Log.e(TAG, "\n response : " + responseString);
          }
        });
  }