Open AlexandraDaraban opened 5 years ago
I've seen that resources for toast messages are used in ViewModels. I think is not recommended to do so, as explained here: https://medium.com/androiddevelopers/locale-changes-and-the-androidviewmodel-antipattern-84eb677660d9
I would make a sealed class ToastMessage
sealed class ToastMessage {
object SimpleMessage: ToastMessage()
}
and expose a LiveData<ToastMessage>
from ViewModel. Then in activity/fragment just make a when statement and get the required resources.
The same can be made for error messages.
The reason the strings are accessed in the ViewModels instead of exposing the resource ids is because there is a specific error that receives arguments in BranchViewModel
. But if you can work around this issue you can go ahead 😄
strings.xml
Toast
withSnackbar