openfoodfacts / smooth-app

🤳🥫 The new Open Food Facts mobile application for Android and iOS, crafted with Flutter and Dart
https://world.openfoodfacts.org/open-food-facts-mobile-app?utm_source=off&utf_medium=web&utm_campaign=github-repo
Apache License 2.0
843 stars 281 forks source link

Load possible attributes that can have preferences from the API and cache them #30

Closed stephanegigandet closed 3 years ago

stephanegigandet commented 3 years ago

Smoothie currently shows preferences that are hardcoded (Vegan, Vegetarian, Gluten Free etc.).

They should be loaded from the API instead:

List of all attributes: https://world.openfoodfacts.org/api/v2/attribute_groups?lc=fr (lc indicates the language for the preferences names, descriptions, warnings etc.)

Possible values for each attribute, with translations: https://world.openfoodfacts.org/api/v2/preferences?lc=fr

In order to be able to set / change preferences even if there is no network, the app should cache the possible preferences.*

monsieurtanuki commented 3 years ago

Sounds interesting.

Some remarks:

  1. we should start with at least a limited set of hardcoded preferences, to be expanded with what we retrieve from the website
  2. what should trigger a refresh of the preference list from the website? In first approach, we could consider that we only refresh the list at app init time. And later think about the iterative refresh process.
monsieurtanuki commented 3 years ago

The main impact will be in user_preferences.dart.

Regarding the importance level, we just retrieve the translations, right, not the list? We would need the colors.

monsieurtanuki commented 3 years ago
stephanegigandet commented 3 years ago
  1. we should start with at least a limited set of hardcoded preferences, to be expanded with what we retrieve from the website

We could do that, for instance we could store the current JSON file. One issue is that it is language specific. I guess we could just display English until we load the language of the user.

  1. what should trigger a refresh of the preference list from the website? In first approach, we could consider that we only refresh the list at app init time. And later think about the iterative refresh process.

We can try to refresh the list whenever the user tries to update the preferences.

Regarding the importance level, we just retrieve the translations, right, not the list? We would need the colors.

The server will not set colors, that's more a choice of the client. We could also retrieve the list of names, and not just the translations. That's how the Javascript interface does it on the web site.

https://world.openfoodfacts.org/api/v2/attribute_groups?lc=en is a list - should we keep the same order? should "super-types" like nutritional_quality or ingredients_analysis be displayed, in different colors?

Yes and yes, see #32 for how we should display it.

stephanegigandet commented 3 years ago

@monsieurtanuki : I started something here: https://github.com/openfoodfacts/smooth-app/pull/38 I'm starting Flutter so it may not be the best way to do things, I don't know. Feedback welcome!

monsieurtanuki commented 3 years ago

What I meant about "colors":

monsieurtanuki commented 3 years ago

Regarding food preference group ("allergens", ...): the display is dealt with by #31.

monsieurtanuki commented 3 years ago

I should be able to create a PR tomorrow.

monsieurtanuki commented 3 years ago

The "let's find an up-to-date or a translated version on the server" part of this issue is now in #41.