extracting the debug feature state creation to its own factory

This commit is contained in:
Adam Brown 2021-12-06 12:18:55 +00:00
parent 2d74eb060c
commit 440de9741b
2 changed files with 48 additions and 23 deletions

View File

@ -22,7 +22,6 @@ import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith import im.vector.app.core.extensions.configureWith
import im.vector.app.databinding.FragmentGenericRecyclerBinding import im.vector.app.databinding.FragmentGenericRecyclerBinding
import im.vector.app.features.DefaultVectorFeatures
import im.vector.app.features.themes.ActivityOtherThemes import im.vector.app.features.themes.ActivityOtherThemes
import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.themes.ThemeUtils
import javax.inject.Inject import javax.inject.Inject
@ -31,7 +30,7 @@ import javax.inject.Inject
class DebugFeaturesSettingsActivity : AppCompatActivity() { class DebugFeaturesSettingsActivity : AppCompatActivity() {
@Inject lateinit var debugFeatures: DebugVectorFeatures @Inject lateinit var debugFeatures: DebugVectorFeatures
@Inject lateinit var defaultFeatures: DefaultVectorFeatures @Inject lateinit var debugFeaturesStateFactory: DebugFeaturesStateFactory
private lateinit var views: FragmentGenericRecyclerBinding private lateinit var views: FragmentGenericRecyclerBinding
@ -48,27 +47,7 @@ class DebugFeaturesSettingsActivity : AppCompatActivity() {
} }
}) })
views.genericRecyclerView.configureWith(controller) views.genericRecyclerView.configureWith(controller)
controller.setData(createState()) controller.setData(debugFeaturesStateFactory.create())
}
private fun createState(): FeaturesState {
return FeaturesState(listOf(
createEnumFeature(
label = "Login version",
selection = debugFeatures.loginVersion(),
default = defaultFeatures.loginVersion()
)
))
}
private inline fun <reified T : Enum<T>> createEnumFeature(label: String, selection: T, default: T): Feature {
return Feature.EnumFeature(
label = label,
selection = selection.takeIf { debugFeatures.hasEnumOverride(T::class) },
default = default,
options = enumValues<T>().toList(),
type = T::class
)
} }
override fun onDestroy() { override fun onDestroy() {

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.debug.features
import im.vector.app.features.DefaultVectorFeatures
import javax.inject.Inject
class DebugFeaturesStateFactory @Inject constructor(
private val debugFeatures: DebugVectorFeatures,
private val defaultFeatures: DefaultVectorFeatures
) {
fun create(): FeaturesState {
return FeaturesState(listOf(
createEnumFeature(
label = "Login version",
selection = debugFeatures.loginVersion(),
default = defaultFeatures.loginVersion()
)
))
}
private inline fun <reified T : Enum<T>> createEnumFeature(label: String, selection: T, default: T): Feature {
return Feature.EnumFeature(
label = label,
selection = selection.takeIf { debugFeatures.hasEnumOverride(T::class) },
default = default,
options = enumValues<T>().toList(),
type = T::class
)
}
}