mirror of
https://github.com/ouchadam/small-talk.git
synced 2024-12-22 16:01:17 +01:00
only showing material you option for android 12+ devices
This commit is contained in:
parent
e773bc35c4
commit
c8eaeff48f
@ -69,6 +69,7 @@ import java.time.Clock
|
||||
internal class AppModule(context: Application, logger: MatrixLogger) {
|
||||
|
||||
private val buildMeta = BuildMeta(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
|
||||
private val deviceMeta = DeviceMeta(Build.VERSION.SDK_INT)
|
||||
private val trackingModule by unsafeLazy {
|
||||
TrackingModule(
|
||||
isCrashTrackingEnabled = !BuildConfig.DEBUG
|
||||
@ -135,6 +136,7 @@ internal class AppModule(context: Application, logger: MatrixLogger) {
|
||||
imageLoaderModule,
|
||||
context,
|
||||
buildMeta,
|
||||
deviceMeta,
|
||||
coroutineDispatchers,
|
||||
clock,
|
||||
)
|
||||
@ -149,6 +151,7 @@ internal class FeatureModules internal constructor(
|
||||
imageLoaderModule: ImageLoaderModule,
|
||||
context: Context,
|
||||
buildMeta: BuildMeta,
|
||||
deviceMeta: DeviceMeta,
|
||||
coroutineDispatchers: CoroutineDispatchers,
|
||||
clock: Clock,
|
||||
) {
|
||||
@ -190,6 +193,7 @@ internal class FeatureModules internal constructor(
|
||||
matrixModules.sync,
|
||||
context.contentResolver,
|
||||
buildMeta,
|
||||
deviceMeta,
|
||||
coroutineDispatchers,
|
||||
coreAndroidModule.themeStore(),
|
||||
)
|
||||
@ -203,7 +207,7 @@ internal class FeatureModules internal constructor(
|
||||
context,
|
||||
intentFactory = coreAndroidModule.intentFactory(),
|
||||
dispatchers = coroutineDispatchers,
|
||||
deviceMeta = DeviceMeta(Build.VERSION.SDK_INT)
|
||||
deviceMeta = deviceMeta
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,8 @@ fun <T> DeviceMeta.isAtLeastO(block: () -> T, fallback: () -> T = { throw Illega
|
||||
return if (this.apiVersion >= Build.VERSION_CODES.O) block() else fallback()
|
||||
}
|
||||
|
||||
fun DeviceMeta.isAtLeastS() = this.apiVersion >= Build.VERSION_CODES.S
|
||||
|
||||
fun DeviceMeta.onAtLeastO(block: () -> Unit) {
|
||||
if (this.apiVersion >= Build.VERSION_CODES.O) block()
|
||||
}
|
||||
|
@ -1,26 +1,42 @@
|
||||
package app.dapk.st.settings
|
||||
|
||||
import app.dapk.st.core.BuildMeta
|
||||
import app.dapk.st.core.ThemeStore
|
||||
import app.dapk.st.core.*
|
||||
import app.dapk.st.push.PushTokenRegistrars
|
||||
|
||||
internal class SettingsItemFactory(
|
||||
private val buildMeta: BuildMeta,
|
||||
private val deviceMeta: DeviceMeta,
|
||||
private val pushTokenRegistrars: PushTokenRegistrars,
|
||||
private val themeStore: ThemeStore,
|
||||
) {
|
||||
|
||||
suspend fun root() = listOf(
|
||||
suspend fun root() = general() + theme() + data() + account() + about()
|
||||
|
||||
private suspend fun general() = listOf(
|
||||
SettingItem.Header("General"),
|
||||
SettingItem.Text(SettingItem.Id.Encryption, "Encryption"),
|
||||
SettingItem.Text(SettingItem.Id.EventLog, "Event log"),
|
||||
SettingItem.Text(SettingItem.Id.PushProvider, "Push provider", pushTokenRegistrars.currentSelection().id),
|
||||
SettingItem.Text(SettingItem.Id.PushProvider, "Push provider", pushTokenRegistrars.currentSelection().id)
|
||||
)
|
||||
|
||||
private fun theme() = listOfNotNull(
|
||||
SettingItem.Header("Theme"),
|
||||
SettingItem.Toggle(SettingItem.Id.ToggleDynamicTheme, "Enable Material You", state = themeStore.isMaterialYouEnabled()),
|
||||
SettingItem.Toggle(SettingItem.Id.ToggleDynamicTheme, "Enable Material You", state = themeStore.isMaterialYouEnabled()).takeIf {
|
||||
deviceMeta.isAtLeastS()
|
||||
},
|
||||
).takeIf { it.size > 1 } ?: emptyList()
|
||||
|
||||
private fun data() = listOf(
|
||||
SettingItem.Header("Data"),
|
||||
SettingItem.Text(SettingItem.Id.ClearCache, "Clear cache"),
|
||||
)
|
||||
|
||||
private fun account() = listOf(
|
||||
SettingItem.Header("Account"),
|
||||
SettingItem.Text(SettingItem.Id.SignOut, "Sign out"),
|
||||
)
|
||||
|
||||
private fun about() = listOf(
|
||||
SettingItem.Header("About"),
|
||||
SettingItem.Text(SettingItem.Id.PrivacyPolicy, "Privacy policy"),
|
||||
SettingItem.Text(SettingItem.Id.Ignored, "Version", buildMeta.versionName),
|
||||
|
@ -1,10 +1,7 @@
|
||||
package app.dapk.st.settings
|
||||
|
||||
import android.content.ContentResolver
|
||||
import app.dapk.st.core.BuildMeta
|
||||
import app.dapk.st.core.CoroutineDispatchers
|
||||
import app.dapk.st.core.ProvidableModule
|
||||
import app.dapk.st.core.ThemeStore
|
||||
import app.dapk.st.core.*
|
||||
import app.dapk.st.domain.StoreModule
|
||||
import app.dapk.st.matrix.crypto.CryptoService
|
||||
import app.dapk.st.matrix.sync.SyncService
|
||||
@ -18,6 +15,7 @@ class SettingsModule(
|
||||
private val syncService: SyncService,
|
||||
private val contentResolver: ContentResolver,
|
||||
private val buildMeta: BuildMeta,
|
||||
private val deviceMeta: DeviceMeta,
|
||||
private val coroutineDispatchers: CoroutineDispatchers,
|
||||
private val themeStore: ThemeStore,
|
||||
) : ProvidableModule {
|
||||
@ -29,7 +27,7 @@ class SettingsModule(
|
||||
cryptoService,
|
||||
syncService,
|
||||
UriFilenameResolver(contentResolver, coroutineDispatchers),
|
||||
SettingsItemFactory(buildMeta, pushModule.pushTokenRegistrars(), themeStore),
|
||||
SettingsItemFactory(buildMeta, deviceMeta, pushModule.pushTokenRegistrars(), themeStore),
|
||||
pushModule.pushTokenRegistrars(),
|
||||
themeStore,
|
||||
)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package app.dapk.st.settings
|
||||
|
||||
import app.dapk.st.core.BuildMeta
|
||||
import app.dapk.st.core.DeviceMeta
|
||||
import app.dapk.st.push.PushTokenRegistrars
|
||||
import app.dapk.st.push.Registrar
|
||||
import internalfixture.aSettingHeaderItem
|
||||
@ -18,10 +19,11 @@ private const val ENABLED_MATERIAL_YOU = true
|
||||
class SettingsItemFactoryTest {
|
||||
|
||||
private val buildMeta = BuildMeta(versionName = "a-version-name", versionCode = 100)
|
||||
private val deviceMeta = DeviceMeta(apiVersion = 31)
|
||||
private val fakePushTokenRegistrars = FakePushRegistrars()
|
||||
private val fakeThemeStore = FakeThemeStore()
|
||||
|
||||
private val settingsItemFactory = SettingsItemFactory(buildMeta, fakePushTokenRegistrars.instance, fakeThemeStore.instance)
|
||||
private val settingsItemFactory = SettingsItemFactory(buildMeta, deviceMeta, fakePushTokenRegistrars.instance, fakeThemeStore.instance)
|
||||
|
||||
@Test
|
||||
fun `when creating root items, then is expected`() = runTest {
|
||||
|
Loading…
Reference in New Issue
Block a user