Created
April 2, 2019 23:06
-
-
Save marcelpinto/d7410b27325e0569020492ea564aac19 to your computer and use it in GitHub Desktop.
Gist for ViewData best practice blog - Good way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class MyViewData(val value: Int, val textId: Int, val labelId: Int) | |
class MyViewModel: ViewModel() { | |
private val _myViewData = MutableLiveData<MyViewData>() | |
val myViewData: LiveData<MyViewData> = _myViewData | |
fun updateViewData() { | |
val value = getDistance() | |
val distanceUnit = userPref.getDistanceUnit() | |
val label = when (distanceUnit) { | |
KM -> R.string.km_label | |
MILES -> R.string.miles_label | |
} | |
_myViewData.value = MyViewData(distance, R.string.my_view_distance, label) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment