I have this model
data class HourlyModel(
val time: String,
@DrawableRes val image: Int,
val temp: Double
)
I realized that the server will provide me with weather codes which translate to the icon that will be displayed. I think if I pull the @DrawableRes into an enum, it maybe better because I have a model for Today's Weather and WeeklyWeather forecasts.
All 3 models will be using the same weather codes. I am new to Kotlin but I think if I have an enum class, I should be able to somehow use this within each model
enum class WeatherTypes (
val weatherCode: Int,
@DrawableRes val drawable: Int
) {
SUNNY(0, R.drawable.sunny_t),
RAIN(1,R.drawable.rain_t);
companion object {
fun weatherToImage(weatherCode: Int) = when(weatherCode) {
0 -> SUNNY
1 -> RAIN
else -> SUNNY
}
}
}
Can someone help me out and tell me what I should do to my model to use this enum class to replace the @DrawableRes? if I can't then what is the best option for me?