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:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user