Ejemplo n.º 1
0
  /**
   * Method called when a request is received from the server. Parse the JSON data and delivers it
   * to the properly activity according to the route request and the status code.
   *
   * @param route
   * @param statusCode
   * @param jObject
   * @param jArray
   */
  public synchronized void requestFinished(
      String route, int statusCode, JSONObject jObject, JSONArray jArray) {
    try {
      if (statusCode == HttpStatusCode.REQUEST_TIMEOUT) {
        throw new Exception();
      }

      if (route.matches("collections/" + Regex.INTEGER)) {
        // GET <URLbase>/collections/{idCollection}
        if (jObject != null) {
          // get language code
          String lang = LocalStorage.getInstance().getLocaleLanguage(activity);
          // collection
          Collection collection = new Collection(jObject, lang);

          if (activity instanceof ProductActivity) {
            ProductActivity productActivity = (ProductActivity) activity;
            productActivity.collectionReceived(collection);
          }
        }
      }

    } catch (Exception e) {
      if (!RESTClient.isOnline(activity)) {
        Toast.makeText(
                activity,
                activity.getResources().getString(R.string.toast_problem_internetconnection),
                Toast.LENGTH_SHORT)
            .show();
      } else {
        Toast.makeText(
                activity,
                activity.getResources().getString(R.string.toast_problem_request),
                Toast.LENGTH_SHORT)
            .show();
      }
      activity.finish();
    }
  }
Ejemplo n.º 2
0
 /**
  * Get collection
  *
  * @param idCollection
  */
 public void getCollection(int idCollection) {
   // GET <URLbase>/collections/{idCollection}
   client.getCollection(this, idCollection);
 }
Ejemplo n.º 3
0
 /**
  * Collections controller constructor
  *
  * @param activity
  */
 public CollectionsController(Activity activity) {
   this.activity = activity;
   client = RESTClient.getInstance();
 }