Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resolving strings in ViewModel #132

Closed
karczews opened this issue Aug 1, 2018 · 3 comments
Closed

Fix resolving strings in ViewModel #132

karczews opened this issue Aug 1, 2018 · 3 comments

Comments

@karczews
Copy link

karczews commented Aug 1, 2018

ViewModel should not be resolving strings from resources as shown in
https://github.com/googlesamples/android-sunflower/blob/4c8d9045d9662e5c659c9ee3dafc66d993e28968/app/src/main/java/com/google/samples/apps/sunflower/viewmodels/PlantAndGardenPlantingsViewModel.kt

If user changes locale on device, activity/fragment will be recreated but ViewModel will be retained with data, that might be invalid for new configuration/locale. Because this is sample referenced by official google documentation, it should not be showcasing invalid ViewModel usage.

The Sunflower demo app demonstrates best practices with architecture components.
https://developer.android.com/topic/libraries/architecture/

ref. https://issuetracker.google.com/u/1/issues/111961971

@andhie
Copy link
Contributor

andhie commented Aug 1, 2018

its true it improper to do this. in fact should not pass in a Context inside a ViewModel but a AndroidViewModel. it would be even better if its android framework free to be easily testable.

Usually my approach would be writing it in XML databinding
android:text="@{@string/watering_next_prefix(viewModel.waterDateString)}"

@XinyueZ
Copy link
Contributor

XinyueZ commented Aug 1, 2018

Hey @andhie @karczews , see #135

@tiembo
Copy link
Contributor

tiembo commented Aug 8, 2018

Quick follow up - we're discussing this internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants