Skip to content

Commit

Permalink
ListView with images working, todo: view for single dish
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejgaciarz committed Jul 16, 2018
1 parent 749d5fb commit 4cf3d94
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public List<Recipe> getRecipes(String JSON){
String recipeUri = currentRecipe.get("uri").toString();
String imageUri = currentRecipe.get("image").toString();

Recipe recipe = new Recipe(label, imageUri, recipeUri);
Recipe recipe = new Recipe(label, imageUri, recipeUri, i);

recipes.add(recipe);
}
Expand Down
15 changes: 10 additions & 5 deletions app/src/main/java/com/example/mgaciarz/myrecipes/ListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ public class ListAdapter extends BaseAdapter {

@Override
public int getCount() {
return 0;
return recipes.size();
}

@Override
public Object getItem(int position) {
return null;
return recipes.get(position);
}

@Override
public long getItemId(int position) {
return 0;
}

return recipes.get(position).getId();
}

public ListAdapter(Activity activity, List<Recipe> recipes) {
this.activity = activity;
Expand All @@ -61,7 +62,11 @@ public View getView(int position, View convertView, ViewGroup parent){
//load
dishName.setText(recipe.getLabel());
dishDesc.setText(recipe.getInstructionURL());
Picasso.get().load(recipe.getImageURL()).into(dishImage);

//strip URL from one pair of additional quites ("")
String strippedURL = recipe.getImageURL().replaceAll("^\"|\"$", "");

Picasso.get().load(strippedURL).into(dishImage);


return vi;
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/models/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ public class Recipe {

private String imageURL;

public Recipe(String label, String imageURL, String instructionURL) {
private long id;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public Recipe(String label, String imageURL, String instructionURL, long id) {
this.label = label;
this.imageURL = imageURL;
this.instructionURL = instructionURL;
this.id = id;

}

private String instructionURL;
Expand Down

0 comments on commit 4cf3d94

Please sign in to comment.