-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add methods for retrieving, adding, and deleting recipe ingredients
- Loading branch information
Cody Weaver
authored and
Cody Weaver
committed
Jan 23, 2024
1 parent
814f2a2
commit 9ff701f
Showing
16 changed files
with
226 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/android/pocketalchemy/editrecipe/EditRecipeUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.android.pocketalchemy.editrecipe | ||
|
||
import com.android.pocketalchemy.model.Recipe | ||
import com.android.pocketalchemy.model.RecipeIngredient | ||
|
||
/** | ||
* Wrapper class for holding state of EditRecipeScreen | ||
*/ | ||
data class EditRecipeUiState( | ||
var recipe: Recipe, | ||
val ingredients: List<RecipeIngredient> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/android/pocketalchemy/model/RecipeIngredient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.android.pocketalchemy.model | ||
|
||
import com.google.errorprone.annotations.Keep | ||
import com.google.firebase.firestore.DocumentId | ||
import com.google.firebase.firestore.IgnoreExtraProperties | ||
|
||
/** | ||
* A lightweight representation of a | ||
* an ingredient in a recipe. | ||
* @param ingredientId | ||
* @param description | ||
* @param gramWeight | ||
*/ | ||
@Keep | ||
@IgnoreExtraProperties | ||
data class RecipeIngredient( | ||
@DocumentId val id: String? = null, | ||
val recipeId: String = "", | ||
val ingredientId: String = "", | ||
val description: String = "", | ||
val gramWeight: Float = 0f | ||
) { | ||
/** | ||
* Shortened recipe description for recipe view | ||
*/ | ||
val name: String | ||
get() { | ||
val splitDescription = description.split(", ") | ||
val nameWords = mutableListOf<String>() | ||
for (i in 0..<4) { | ||
nameWords.add(splitDescription[i]) | ||
} | ||
if (splitDescription.size > 4) { | ||
nameWords.add("...") | ||
} | ||
return nameWords.joinToString(" ") | ||
} | ||
|
||
companion object { | ||
/** Field Names */ | ||
const val RECIPE_ID_KEY = "recipeId" | ||
const val INGREDIENT_ID_KEY = "ingredientId" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.