using AACs Viewmodel, Is it ok to pass an Applicat...
# android-architecture
r
using AACs Viewmodel, Is it ok to pass an Application Context within the viewmodel. I need to access a color from resources.
m
d
Exposing IDs is a safer approach. That said it still smells to me.
a
By the way, if you need formatted strings and would like to expose something like
Copy code
data class StringResource(val resId: Int, vararg formatArgs: Any?)
Is there any easy way to get the formatting strings lint check that is applied to
Context.getString
work on
StringResource
constructor calls?
b
@arekolek You need to use
@StringRes
annotation for that
a
I should have been more specific, I meant the
StringFormatMatches
check
j
Personally I prefer to expose non Android version of the state (a.k.a. Business Logic state) from my ViewModel and then my Fragment would observe and transform it with Android concerns (ex: string resources).
r
Yea but try to reframe from bringing framework specific stuff to your viewmodel. It will be stressful during tests
d
Refrain*☝️