Implement displaying ingredient sections

This commit is contained in:
Kirill Kamakin
2022-12-04 19:25:36 +01:00
parent e2e76ea842
commit a18984bda0
8 changed files with 61 additions and 5 deletions

View File

@@ -18,6 +18,7 @@ data class RecipeIngredientInfo(
val quantity: Double?, val quantity: Double?,
val unit: String?, val unit: String?,
val food: String?, val food: String?,
val title: String?,
) )
data class RecipeInstructionInfo( data class RecipeInstructionInfo(

View File

@@ -52,6 +52,7 @@ fun RecipeIngredientInfo.toRecipeIngredientEntity(remoteId: String) = RecipeIngr
unit = unit, unit = unit,
food = food, food = food,
quantity = quantity, quantity = quantity,
title = title,
) )
fun RecipeInstructionInfo.toRecipeInstructionEntity(remoteId: String) = RecipeInstructionEntity( fun RecipeInstructionInfo.toRecipeInstructionEntity(remoteId: String) = RecipeInstructionEntity(
@@ -129,6 +130,7 @@ fun GetRecipeIngredientResponseV0.toRecipeIngredientInfo() = RecipeIngredientInf
unit = null, unit = null,
food = null, food = null,
quantity = 1.0, quantity = 1.0,
title = null,
) )
fun GetRecipeInstructionResponseV0.toRecipeInstructionInfo() = RecipeInstructionInfo( fun GetRecipeInstructionResponseV0.toRecipeInstructionInfo() = RecipeInstructionInfo(
@@ -153,6 +155,7 @@ fun GetRecipeIngredientResponseV1.toRecipeIngredientInfo() = RecipeIngredientInf
unit = unit?.name, unit = unit?.name,
food = food?.name, food = food?.name,
quantity = quantity, quantity = quantity,
title = title,
) )
fun GetRecipeInstructionResponseV1.toRecipeInstructionInfo() = RecipeInstructionInfo( fun GetRecipeInstructionResponseV1.toRecipeInstructionInfo() = RecipeInstructionInfo(

View File

@@ -3,6 +3,7 @@ package gq.kirmanak.mealient.ui.recipes.info
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import androidx.core.view.isGone
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@@ -54,6 +55,8 @@ class RecipeIngredientsAdapter private constructor(
fun bind(item: RecipeIngredientEntity) { fun bind(item: RecipeIngredientEntity) {
logger.v { "bind() called with: item = $item" } logger.v { "bind() called with: item = $item" }
binding.sectionGroup.isGone = item.title.isNullOrBlank()
binding.title.text = item.title.orEmpty()
binding.checkBox.text = if (disableAmounts) { binding.checkBox.text = if (disableAmounts) {
item.note item.note
} else { } else {

View File

@@ -5,12 +5,41 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<androidx.constraintlayout.widget.Group
android:id="@+id/section_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="title, title_divider"
tools:visibility="visible" />
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/margin_small"
android:textAppearance="?textAppearanceHeadline6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Meat a very long and weird title that someone might have for some reason" />
<View
android:id="@+id/title_divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:alpha="0.3"
android:background="?colorOnSurface"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title" />
<CheckBox <CheckBox
android:id="@+id/checkBox" android:id="@+id/checkBox"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toBottomOf="@id/title_divider"
tools:text="900 g braising steak/stew meat, cubed into 2.5cm pieces" /> tools:text="900 g braising steak/stew meat, cubed into 2.5cm pieces" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -100,6 +100,7 @@ object RecipeImplTestData {
quantity = 1.0, quantity = 1.0,
unit = null, unit = null,
food = null, food = null,
title = null,
) )
val BREAD_INGREDIENT = RecipeIngredientInfo( val BREAD_INGREDIENT = RecipeIngredientInfo(
@@ -107,6 +108,7 @@ object RecipeImplTestData {
quantity = 1.0, quantity = 1.0,
unit = null, unit = null,
food = null, food = null,
title = null,
) )
private val MILK_INGREDIENT = RecipeIngredientInfo( private val MILK_INGREDIENT = RecipeIngredientInfo(
@@ -114,6 +116,7 @@ object RecipeImplTestData {
quantity = 1.0, quantity = 1.0,
unit = null, unit = null,
food = null, food = null,
title = null,
) )
val MIX_INSTRUCTION = RecipeInstructionInfo( val MIX_INSTRUCTION = RecipeInstructionInfo(
@@ -168,6 +171,7 @@ object RecipeImplTestData {
quantity = 1.0, quantity = 1.0,
unit = null, unit = null,
food = null, food = null,
title = null,
) )
val CAKE_BREAD_RECIPE_INGREDIENT_ENTITY = RecipeIngredientEntity( val CAKE_BREAD_RECIPE_INGREDIENT_ENTITY = RecipeIngredientEntity(
@@ -176,6 +180,7 @@ object RecipeImplTestData {
quantity = 1.0, quantity = 1.0,
unit = null, unit = null,
food = null, food = null,
title = null,
) )
val FULL_CAKE_INFO_ENTITY = FullRecipeEntity( val FULL_CAKE_INFO_ENTITY = FullRecipeEntity(
@@ -203,6 +208,7 @@ object RecipeImplTestData {
quantity = 1.0, quantity = 1.0,
unit = null, unit = null,
food = null, food = null,
title = null,
) )
private val PORRIDGE_SUGAR_RECIPE_INGREDIENT_ENTITY = RecipeIngredientEntity( private val PORRIDGE_SUGAR_RECIPE_INGREDIENT_ENTITY = RecipeIngredientEntity(
@@ -211,6 +217,7 @@ object RecipeImplTestData {
quantity = 1.0, quantity = 1.0,
unit = null, unit = null,
food = null, food = null,
title = null,
) )
private val PORRIDGE_MIX_RECIPE_INSTRUCTION_ENTITY = RecipeInstructionEntity( private val PORRIDGE_MIX_RECIPE_INSTRUCTION_ENTITY = RecipeInstructionEntity(
@@ -306,6 +313,7 @@ object RecipeImplTestData {
quantity = 1.0, quantity = 1.0,
unit = null, unit = null,
food = null, food = null,
title = null,
) )
val SUGAR_RECIPE_INGREDIENT_RESPONSE_V1 = GetRecipeIngredientResponseV1( val SUGAR_RECIPE_INGREDIENT_RESPONSE_V1 = GetRecipeIngredientResponseV1(
@@ -313,6 +321,7 @@ object RecipeImplTestData {
quantity = 1.0, quantity = 1.0,
unit = null, unit = null,
food = null, food = null,
title = null,
) )
val MILK_RECIPE_INGREDIENT_INFO = RecipeIngredientInfo( val MILK_RECIPE_INGREDIENT_INFO = RecipeIngredientInfo(
@@ -320,6 +329,7 @@ object RecipeImplTestData {
quantity = 1.0, quantity = 1.0,
unit = null, unit = null,
food = null, food = null,
title = null,
) )
val MIX_RECIPE_INSTRUCTION_RESPONSE_V0 = GetRecipeInstructionResponseV0("Mix the ingredients") val MIX_RECIPE_INSTRUCTION_RESPONSE_V0 = GetRecipeInstructionResponseV0("Mix the ingredients")

View File

@@ -2,7 +2,7 @@
"formatVersion": 1, "formatVersion": 1,
"database": { "database": {
"version": 7, "version": 7,
"identityHash": "2383ca8fe2fbd04ddaec6d7680de62ad", "identityHash": "d2679aea13d3c18e58c537164f70e249",
"entities": [ "entities": [
{ {
"tableName": "recipe_summaries", "tableName": "recipe_summaries",
@@ -95,7 +95,7 @@
}, },
{ {
"tableName": "recipe_ingredient", "tableName": "recipe_ingredient",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`local_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `recipe_id` TEXT NOT NULL, `note` TEXT NOT NULL, `food` TEXT, `unit` TEXT, `quantity` REAL)", "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`local_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `recipe_id` TEXT NOT NULL, `note` TEXT NOT NULL, `food` TEXT, `unit` TEXT, `quantity` REAL, `title` TEXT)",
"fields": [ "fields": [
{ {
"fieldPath": "localId", "fieldPath": "localId",
@@ -132,6 +132,12 @@
"columnName": "quantity", "columnName": "quantity",
"affinity": "REAL", "affinity": "REAL",
"notNull": false "notNull": false
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": false
} }
], ],
"primaryKey": { "primaryKey": {
@@ -179,7 +185,7 @@
"views": [], "views": [],
"setupQueries": [ "setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '2383ca8fe2fbd04ddaec6d7680de62ad')" "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'd2679aea13d3c18e58c537164f70e249')"
] ]
} }
} }

View File

@@ -12,6 +12,7 @@ data class RecipeIngredientEntity(
@ColumnInfo(name = "food") val food: String?, @ColumnInfo(name = "food") val food: String?,
@ColumnInfo(name = "unit") val unit: String?, @ColumnInfo(name = "unit") val unit: String?,
@ColumnInfo(name = "quantity") val quantity: Double?, @ColumnInfo(name = "quantity") val quantity: Double?,
@ColumnInfo(name = "title") val title: String?,
) { ) {
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
@@ -24,6 +25,7 @@ data class RecipeIngredientEntity(
if (food != other.food) return false if (food != other.food) return false
if (unit != other.unit) return false if (unit != other.unit) return false
if (quantity != other.quantity) return false if (quantity != other.quantity) return false
if (title != other.title) return false
return true return true
} }
@@ -33,7 +35,8 @@ data class RecipeIngredientEntity(
result = 31 * result + note.hashCode() result = 31 * result + note.hashCode()
result = 31 * result + (food?.hashCode() ?: 0) result = 31 * result + (food?.hashCode() ?: 0)
result = 31 * result + (unit?.hashCode() ?: 0) result = 31 * result + (unit?.hashCode() ?: 0)
result = 31 * result + quantity.hashCode() result = 31 * result + (quantity?.hashCode() ?: 0)
result = 31 * result + (title?.hashCode() ?: 0)
return result return result
} }
} }

View File

@@ -24,6 +24,7 @@ data class GetRecipeIngredientResponseV1(
@SerialName("unit") val unit: GetRecipeIngredientUnitResponseV1?, @SerialName("unit") val unit: GetRecipeIngredientUnitResponseV1?,
@SerialName("food") val food: GetRecipeIngredientFoodResponseV1?, @SerialName("food") val food: GetRecipeIngredientFoodResponseV1?,
@SerialName("quantity") val quantity: Double?, @SerialName("quantity") val quantity: Double?,
@SerialName("title") val title: String?,
) )
@Serializable @Serializable