Example #1
0
 public void sendFeedbackApi() {
   if (DMUtils.isOnline()) {
     String rate = "";
     String ids = "";
     if (null != rates && rates.size() > 0) {
       for (int i = 0; i < rates.size(); i++) {
         if (i == rates.size() - 1) {
           rate = rate + rates.get(i);
         } else {
           rate = rate + rates.get(i) + "-";
         }
       }
     }
     if (null != dmFeedbacks && dmFeedbacks.size() > 0) {
       for (int i = 0; i < dmFeedbacks.size(); i++) {
         if (i == dmFeedbacks.size() - 1) {
           ids = ids + dmFeedbacks.get(i).getFeedbackId();
         } else {
           ids = ids + dmFeedbacks.get(i).getFeedbackId() + "-";
         }
       }
     }
     requestDidStart();
     String url = DMApiManager.METHOD_FEEDBACK_SEND + "fids=" + ids + "&rates=" + rate;
     DMApiManager dmApiManager = new DMApiManager(getActivity());
     dmApiManager.get(
         url,
         new JsonHttpResponseHandler() {
           @Override
           public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
             super.onSuccess(statusCode, headers, response);
             requestDidFinish();
             try {
               showToast(response.get(1).toString());
               getActivity().finish();
             } catch (Exception e) {
               e.printStackTrace();
             }
           }
         });
   } else {
     if (isAdded()) showToast(getResources().getString(R.string.api_error_no_network));
   }
 }
Example #2
0
  private void getFeedback() {

    if (DMUtils.isOnline()) {
      requestDidStart();
      String url =
          DMApiManager.METHOD_FEEDBACK
              + "lid="
              + DMUtils.getLanguageId(getActivity())
              + "&uid="
              + DMUtils.getUserId(getActivity());
      DMApiManager dmApiManager = new DMApiManager(getActivity());
      dmApiManager.get(
          url,
          new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
              super.onSuccess(statusCode, headers, response);
              requestDidFinish();
              try {
                ArrayList<DMFeedback> dmFeedbacks = new ArrayList<DMFeedback>();
                Gson gson = new Gson();
                for (int i = 0; i < response.length() - 1; i++) {
                  JSONObject responseJSon = response.getJSONObject(i);
                  DMFeedback dmFeedback = gson.fromJson(responseJSon.toString(), DMFeedback.class);
                  dmFeedbacks.add(dmFeedback);
                }
                initFeedback(dmFeedbacks);
              } catch (JSONException e) {
                e.printStackTrace();
              }
            }
          });
    } else {
      if (isAdded()) showToast(getResources().getString(R.string.api_error_no_network));
    }
  }