mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-16 20:10:04 +03:00
avoiding unneeded cast by providing more types
This commit is contained in:
parent
6c21ed8eab
commit
90d00b96b7
2 changed files with 8 additions and 8 deletions
|
@ -36,9 +36,8 @@ class DebugFeaturesSettingsActivity : VectorBaseActivity<FragmentGenericRecycler
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
controller.listener = object : EnumFeatureItem.Listener {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : Enum<T>> onOptionSelected(option: Any?, feature: Feature.EnumFeature<T>) {
|
||||
debugFeatures.overrideEnum(option as? T, feature.type)
|
||||
override fun <T : Enum<T>> onOptionSelected(option: T?, feature: Feature.EnumFeature<T>) {
|
||||
debugFeatures.overrideEnum(option, feature.type)
|
||||
}
|
||||
}
|
||||
views.genericRecyclerView.configureWith(controller)
|
||||
|
|
|
@ -53,10 +53,7 @@ abstract class EnumFeatureItem : VectorEpoxyModel<EnumFeatureItem.Holder>() {
|
|||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
when (position) {
|
||||
0 -> listener?.onOptionSelected(option = null, feature)
|
||||
else -> {
|
||||
val option: Any = feature.options[position - 1]
|
||||
listener?.onOptionSelected(option, feature)
|
||||
}
|
||||
else -> feature.onOptionSelected(position - 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,12 +64,16 @@ abstract class EnumFeatureItem : VectorEpoxyModel<EnumFeatureItem.Holder>() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun <T : Enum<T>> Feature.EnumFeature<T>.onOptionSelected(selection: Int) {
|
||||
listener?.onOptionSelected(options[selection], this)
|
||||
}
|
||||
|
||||
class Holder : VectorEpoxyHolder() {
|
||||
val label by bind<TextView>(im.vector.app.R.id.feature_label)
|
||||
val optionsSpinner by bind<Spinner>(im.vector.app.R.id.feature_options)
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
fun <T : Enum<T>> onOptionSelected(option: Any?, feature: Feature.EnumFeature<T>)
|
||||
fun <T : Enum<T>> onOptionSelected(option: T?, feature: Feature.EnumFeature<T>)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue