code4romania / mon-vot-android-kotlin

Android election monitoring app - a mobile app through which commissioned observers can easily report back to their respective NGOs throughout the election day
https://votemonitor.org
Mozilla Public License 2.0
7 stars 29 forks source link

Error messages #88

Open AlexandraDaraban opened 5 years ago

AlexandraDaraban commented 5 years ago
sergiuciuperca commented 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.

AlexandraDaraban commented 5 years ago

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 😄