コード例 #1
0
  public void initData() {
    recipe_name_tv.setText(recipeBean.getName());
    recipe_description_tv.setText(recipeBean.getDescription());

    asynImageLoader = new AsynImageLoader();
    if (recipeBean.getPhoto() == null
        || "".equals(recipeBean.getPhoto().trim())
        || "null".equals(recipeBean.getPhoto().trim())) {
      recipe_picture_img.setImageResource(R.mipmap.default_recipe_picture);
    } else {
      asynImageLoader.showImageAsyn(
          recipe_picture_img,
          pictureBaseUrl + recipeBean.getPhoto(),
          R.mipmap.default_recipe_picture);
    }

    recipe_ingredient_tv.setText(recipeBean.getMeterials()[0].toString());
    recipe_step_tv.setText(recipeBean.getSteps()[0].toString());
    //        if(recipeBean.getRestaurant()==null || "".equals(recipeBean.getRestaurant().trim()) ||
    // "null".equals(recipeBean.getRestaurant().trim())){
    //            recipe_pay_rl.setVisibility(View.GONE);
    //        }else{
    //            recipe_pay_rl.setVisibility(View.VISIBLE);
    //        }

    //        recipe_price = recipeBean.getPrice();
    //        recipe_price_tv.setText("Price: " + String.valueOf(recipe_price));

    //        getLikesFromRecipe();
  }
コード例 #2
0
  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();
          }
        });
  }
コード例 #3
0
 private void getLocalLikesData() {
   List<LikeBean> localLikeList =
       (List<LikeBean>)
           ObjectPersistence.readObjectFromFile(
               RecipeDetailActivity.this, recipeBean.get_id() + DISH_LIKES_DATA_PATH);
   if (localLikeList != null) {
     likeList = localLikeList;
   }
 }
コード例 #4
0
  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();
            }
          }
        });
  }