|
7 | 7 | import com.biermacht.brews.frontend.MainActivity;
|
8 | 8 | import com.biermacht.brews.ingredient.Ingredient;
|
9 | 9 | import com.biermacht.brews.recipe.MashProfile;
|
| 10 | +import com.biermacht.brews.recipe.MashStep; |
10 | 11 | import com.biermacht.brews.recipe.Recipe;
|
11 | 12 | import com.biermacht.brews.utils.Constants;
|
12 | 13 | import com.biermacht.brews.utils.comparators.RecipeComparator;
|
@@ -68,6 +69,14 @@ public boolean updateIngredient(Ingredient i, long dbid) {
|
68 | 69 |
|
69 | 70 | // Deletes the given recipe if it exists in the database.
|
70 | 71 | public boolean deleteRecipe(Recipe r) {
|
| 72 | + // Delete all ingredients for this recipe. |
| 73 | + for (Ingredient i : r.getIngredientList()) { |
| 74 | + this.deleteIngredientWithId(i.getId(), i.getDatabaseId()); |
| 75 | + } |
| 76 | + |
| 77 | + // Delete the MashProfile. |
| 78 | + this.deleteMashProfileFromDatabase(r.getMashProfile(), Constants.DATABASE_DEFAULT); |
| 79 | + |
71 | 80 | return this.databaseInterface.deleteRecipeIfExists(r.getId());
|
72 | 81 | }
|
73 | 82 |
|
@@ -155,7 +164,10 @@ public ArrayList<MashProfile> getMashProfiles(long dbid) {
|
155 | 164 | }
|
156 | 165 |
|
157 | 166 | // Deletes the given mash profile
|
158 |
| - public boolean deleteMashProfileFromDatabase(long id, long dbid) { |
159 |
| - return this.databaseInterface.deleteMashProfile(id, dbid); |
| 167 | + public boolean deleteMashProfileFromDatabase(MashProfile p, long dbid) { |
| 168 | + for (MashStep s : p.getMashStepList()) { |
| 169 | + this.databaseInterface.deleteMashStep(s.getId()); |
| 170 | + } |
| 171 | + return this.databaseInterface.deleteMashProfile(p.getId(), dbid); |
160 | 172 | }
|
161 | 173 | }
|
0 commit comments