public void postLike() {
    RequestParams params = new RequestParams();
    params.add("recipe", recipeBean.get_id());
    params.add("like", String.valueOf(isLike));

    String username = sp.getString(SharedPreferencesUtil.TAG_USER_NAME, "");
    String password = sp.getString(SharedPreferencesUtil.TAG_PASSWORD, "");

    KitchenRestClient.postWithLogin(
        "like",
        params,
        username,
        password,
        new JsonHttpResponseHandler() {
          @Override
          public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            Log.e("post like", response.toString());
            if (statusCode == 201) {
              try {
                likeBean = JsonTobean.getBean(LikeBean.class, response.toString());
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            // Toast.makeText(getApplicationContext(), "like it is wrong. Please try it.",
            // Toast.LENGTH_SHORT).show();
          }
        });
  }
  public void deleteLike() {
    String username = sp.getString(SharedPreferencesUtil.TAG_USER_NAME, "");
    String password = sp.getString(SharedPreferencesUtil.TAG_PASSWORD, "");

    String url = "deletelike/" + likeBean.get_id();
    KitchenRestClient.deleteWithLogin(
        url,
        username,
        password,
        new JsonHttpResponseHandler() {
          @Override
          public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            Log.e("delete like", response.toString());
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, String responseString, Throwable throwable) {
            super.onFailure(statusCode, headers, responseString, throwable);
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            super.onFailure(statusCode, headers, throwable, errorResponse);
          }
        });
  }
  public void getLikesFromRecipe() {
    String url = "getlikes/" + recipeBean.get_id();
    KitchenRestClient.get(
        url,
        null,
        new JsonHttpResponseHandler() {
          @Override
          public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            Log.e("getLikesFromRecipe", response.toString());
            if (statusCode == 200) {
              try {
                likeList = JsonTobean.getList(LikeBean[].class, response.toString());
                ObjectPersistence.writeObjectToFile(
                    RecipeDetailActivity.this,
                    likeList,
                    recipeBean.get_id() + DISH_LIKES_DATA_PATH);
                if (likeList != null && likeList.size() > 0) {
                  favor_num = likeList.size();
                  favor_num_tv.setText(favor_num + " Favor");
                  for (int i = 0; i < likeList.size(); i++) {
                    if ((likeList.get(i).getUser()).equals(userBean.get_id())) {
                      isLike = true;
                      recipe_favor_img.setImageResource(R.mipmap.favor_btn_highlight);
                      likeBean = likeList.get(i);
                    }
                  }
                }
              } catch (Exception e) {
                e.printStackTrace();
              }
            } else {
              getLocalLikesData();
              if (likeList != null && likeList.size() > 0) {
                favor_num = likeList.size();
                favor_num_tv.setText(favor_num + " Favor");
                for (int i = 0; i < likeList.size(); i++) {
                  if ((likeList.get(i).getUser()).equals(userBean.get_id())) {
                    isLike = true;
                    recipe_favor_img.setImageResource(R.mipmap.favor_btn_highlight);
                    likeBean = likeList.get(i);
                  } else {
                    isLike = false;
                    recipe_favor_img.setImageResource(R.mipmap.favor_btn_default);
                  }
                }
              } else {
                Toast.makeText(
                        RecipeDetailActivity.this,
                        "Network kitchendemo is wrong.",
                        Toast.LENGTH_SHORT)
                    .show();
              }
            }
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            getLocalLikesData();
            if (likeList != null && likeList.size() > 0) {
              favor_num = likeList.size();
              favor_num_tv.setText(favor_num + " Favor");
              for (int i = 0; i < likeList.size(); i++) {
                if ((likeList.get(i).getUser()).equals(userBean.get_id())) {
                  isLike = true;
                  recipe_favor_img.setImageResource(R.mipmap.favor_btn_highlight);
                  likeBean = likeList.get(i);
                } else {
                  isLike = false;
                  recipe_favor_img.setImageResource(R.mipmap.favor_btn_default);
                }
              }
            } else {
              Toast.makeText(
                      RecipeDetailActivity.this,
                      "Network kitchendemo is wrong.",
                      Toast.LENGTH_SHORT)
                  .show();
            }
          }
        });
  }