Jorge Domínguez
05/17/2022, 7:59 PMfun SomeEnum.getImageRes(
param: SomeOtherEnum
): Int {
return when (param) {
SomeOtherEnum.OtherEnumA -> {
when (this) {
SomeEnum.EnumA -> R.drawable.res1_a
SomeEnum.EnumB -> R.drawable.res1_b
}
}
SomeOtherEnum.OtherEnumB -> {
when (this) {
SomeEnum.EnumA -> R.drawable.res2_a
SomeEnum.EnumB -> R.drawable.res2_b
}
}
}
}
Joffrey
05/17/2022, 8:01 PMJoffrey
05/17/2022, 8:02 PMPaul Griffith
05/17/2022, 8:03 PMJorge Domínguez
05/17/2022, 8:16 PMfun PlatformType.getEnrollmentImageRes(
enrollmentType: EnrollmentType
): Int {
return when (enrollmentType) {
EnrollmentType.SDK -> {
when (this) {
PlatformType.GOOGLE_FIT -> R.drawable.google_fit_enrollment
PlatformType.FITBIT -> R.drawable.fitbit_enrollment
}
}
EnrollmentType.SIGN_UP -> {
when (this) {
PlatformType.GOOGLE_FIT -> R.drawable.google_fit_connection
PlatformType.FITBIT -> R.drawable.fitbit_connection
}
}
}
}
Jorge Domínguez
05/17/2022, 8:16 PMenum class PlatformType {
GOOGLE_FIT {
val enrollmentImageRes = mapOf(
EnrollmentType.SDK to R.drawable.google_fit_enrollment,
EnrollmentType.SIGN_UP to R.drawable.google_fit_connection
)
},
FITBIT {
val enrollmentImageRes = mapOf(
EnrollmentType.SDK to R.drawable.fitbit_enrollment,
EnrollmentType.SIGN_UP to R.drawable.fitbit_connection
)
}
}
Joffrey
05/17/2022, 9:59 PMPlatformType
, not only on specific values like PlatformType.GOOGLE_FIT
):
enum class PlatformType(val enrollmentImageRes: Map<EnrollmentType, Int>) {
GOOGLE_FIT(
mapOf(
EnrollmentType.SDK to R.drawable.google_fit_enrollment,
EnrollmentType.SIGN_UP to R.drawable.google_fit_connection
)
),
FITBIT(
mapOf(
EnrollmentType.SDK to R.drawable.fitbit_enrollment,
EnrollmentType.SIGN_UP to R.drawable.fitbit_connection
)
)
}
Also given how your types maybe you could do the opposite and define those maps in the EnrollmentType
enum instead, with PlatformType
as key (if the PlatformType
enum is used in other contexts than the enrollment-related things).Jorge Domínguez
05/17/2022, 10:17 PMEnrollmentType
wouldn't be as semantically correct, because those resources are representations of each PlatformType
. What do you think about this?
enum class PlatformType {
GOOGLE_FIT {
override val resMap = mapOf(
EnrollmentType.SDK to R.drawable.google_fit_enrollment,
EnrollmentType.SIGN_UP to R.drawable.google_fit_connection
)
},
FITBIT {
override val resMap = mapOf(
EnrollmentType.SDK to R.drawable.fitbit_enrollment,
EnrollmentType.SIGN_UP to R.drawable.fitbit_connection
)
};
abstract val resMap: Map<EnrollmentType, Int>
}
Jorge Domínguez
05/17/2022, 10:18 PMPlatformType
Joffrey
05/17/2022, 10:29 PMJorge Domínguez
05/17/2022, 10:48 PMJoffrey
05/18/2022, 3:00 PMinit
block to the enum class, but still use the constructor I think. Of course it may depend on the use-case at hand