mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 11:26:01 +03:00
extracting the debug feature state creation to its own factory
This commit is contained in:
parent
2d74eb060c
commit
440de9741b
2 changed files with 48 additions and 23 deletions
|
@ -22,7 +22,6 @@ import dagger.hilt.android.AndroidEntryPoint
|
|||
import im.vector.app.core.extensions.cleanup
|
||||
import im.vector.app.core.extensions.configureWith
|
||||
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.ThemeUtils
|
||||
import javax.inject.Inject
|
||||
|
@ -31,7 +30,7 @@ import javax.inject.Inject
|
|||
class DebugFeaturesSettingsActivity : AppCompatActivity() {
|
||||
|
||||
@Inject lateinit var debugFeatures: DebugVectorFeatures
|
||||
@Inject lateinit var defaultFeatures: DefaultVectorFeatures
|
||||
@Inject lateinit var debugFeaturesStateFactory: DebugFeaturesStateFactory
|
||||
|
||||
private lateinit var views: FragmentGenericRecyclerBinding
|
||||
|
||||
|
@ -48,27 +47,7 @@ class DebugFeaturesSettingsActivity : AppCompatActivity() {
|
|||
}
|
||||
})
|
||||
views.genericRecyclerView.configureWith(controller)
|
||||
controller.setData(createState())
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
controller.setData(debugFeaturesStateFactory.create())
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue