Skip to content

Commit

Permalink
Replacing allergens should keep their "enabled" statuses (#4325)
Browse files Browse the repository at this point in the history
* When the serving size value is incorrect (eg: "serving" with barcode 5900951251849), the app shouldn't crash
#4270

* When the taxonomies are refreshed, all allergens are replaced.
BUT an allergen may have its "enabled" column at true, which means it's also an alert.
Here, I copy the "enabled" value to be sure to not loose the previous state
  • Loading branch information
g123k committed Oct 24, 2021
1 parent 73a55a9 commit afd8056
Showing 1 changed file with 11 additions and 0 deletions.
Expand Up @@ -336,7 +336,18 @@ class ProductRepository @Inject constructor(
fun saveAllergens(allergens: List<Allergen>) {
daoSession.database.beginTransaction()
try {

allergens.forEach { allergen ->
// If the allergen is already in the database, ensure the "enabled" field is used,
// instead of replaced
val dbAllergen = daoSession.allergenDao.queryBuilder()
.where(AllergenDao.Properties.Tag.eq(allergen.tag))
.unique()

if (dbAllergen != null) {
allergen.enabled = dbAllergen.enabled
}

daoSession.allergenDao.insertOrReplace(allergen)
allergen.names.forEach { daoSession.allergenNameDao.insertOrReplace(it) }
}
Expand Down

0 comments on commit afd8056

Please sign in to comment.