But this won’t be type-safe if you just add a vararg at the end and you lose the lint check you get when doing this directly with context.getString(...).
Or do you mean adding a function for each string resource that takes some argument(s)? Wouldn’t this make the mapper not generic any more and you’ll have to maintain / test it often?
I’ve given up messing with string / any other resources in ViewModel (AndroidViewModel sucks) directly 😅 and instead just expose streams of states for Fragment / Activity to render which includes mapping the states to the correct string / color resources etc. This way you don’t need to mock your string mapper in your ViewModelTest and your UI tests will cover your string resource loading anyway.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Add another function to the interface which takes the params you'll need.
Expand as you need things!
But this won’t be type-safe if you just add a vararg at the end and you lose the lint check you get when doing this directly with context.getString(...).
Or do you mean adding a function for each string resource that takes some argument(s)? Wouldn’t this make the mapper not generic any more and you’ll have to maintain / test it often?
I’ve given up messing with string / any other resources in ViewModel (AndroidViewModel sucks) directly 😅 and instead just expose streams of states for Fragment / Activity to render which includes mapping the states to the correct string / color resources etc. This way you don’t need to mock your string mapper in your ViewModelTest and your UI tests will cover your string resource loading anyway.