Fix displaying recipe ingredient note twice (#197)

* Update README.md

* Bump version to 35

* Cleanup dependencies

* Bump versions of dependencies

* Save isFood/disableAmount flags to db

* Fix displaying ingredient note twice

* Remove whitespace after note is extracted
This commit is contained in:
Kirill Kamakin
2024-01-14 11:44:21 +01:00
committed by GitHub
parent c8f1f477cc
commit 7c02a8341d
17 changed files with 100 additions and 119 deletions

View File

@@ -1,36 +0,0 @@
package gq.kirmanak.mealient.ui
import android.os.Bundle
import android.view.View
import androidx.annotation.IdRes
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowInsetsControllerCompat
import androidx.viewbinding.ViewBinding
import by.kirich1409.viewbindingdelegate.viewBinding
import gq.kirmanak.mealient.extensions.isDarkThemeOn
import gq.kirmanak.mealient.logging.Logger
import javax.inject.Inject
abstract class BaseActivity<T : ViewBinding>(
binder: (View) -> T,
@IdRes containerId: Int,
@LayoutRes layoutRes: Int,
) : AppCompatActivity(layoutRes) {
protected val binding by viewBinding(binder, containerId)
@Inject
lateinit var logger: Logger
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
logger.v { "onCreate() called with: savedInstanceState = $savedInstanceState" }
setContentView(binding.root)
with(WindowInsetsControllerCompat(window, window.decorView)) {
val isAppearanceLightBars = !isDarkThemeOn()
isAppearanceLightNavigationBars = isAppearanceLightBars
isAppearanceLightStatusBars = isAppearanceLightBars
}
}
}

View File

@@ -86,13 +86,14 @@ private fun IngredientListItem(
onCheckedChange = { isChecked = it },
)
val (text, note) = item.textAndNote
Column {
Text(
text = item.display,
text = text,
style = MaterialTheme.typography.bodyLarge,
)
if (item.note.isNotBlank()) {
if (note.isNotBlank()) {
Text(
text = item.note,
style = MaterialTheme.typography.bodyMedium,
@@ -100,4 +101,21 @@ private fun IngredientListItem(
}
}
}
}
}
private val RecipeIngredientEntity.textAndNote: Pair<String, String>
get() = when {
disableAmount -> note to ""
note.isBlank() -> display to ""
else -> {
val text = if (display.endsWith(note)) {
display.dropLast(note.length).trimEnd()
} else {
display
}
text to note
}
}

View File

@@ -12,9 +12,11 @@ internal val INGREDIENT_TWO = RecipeIngredientEntity(
note = "Recipe ingredient note",
food = "Recipe ingredient food",
unit = "Recipe ingredient unit",
display = "Recipe ingredient display that is very long and should be wrapped",
quantity = 1.0,
display = "Recipe ingredient display that is very long and should be wrapped",
title = null,
isFood = false,
disableAmount = true,
)
internal val SUMMARY_ENTITY = RecipeSummaryEntity(
@@ -34,9 +36,11 @@ internal val INGREDIENT_ONE = RecipeIngredientEntity(
note = "Recipe ingredient note",
food = "Recipe ingredient food",
unit = "Recipe ingredient unit",
display = "Recipe ingredient display that is very long and should be wrapped",
quantity = 1.0,
display = "Recipe ingredient display that is very long and should be wrapped",
title = "Recipe ingredient section title",
isFood = false,
disableAmount = true,
)
internal val INSTRUCTION_ONE = RecipeInstructionEntity(