only showing material you option for android 12+ devices

This commit is contained in:
Adam Brown 2022-09-11 21:53:00 +01:00
parent 7554eac7af
commit 831036fd43
5 changed files with 34 additions and 12 deletions

View File

@ -69,6 +69,7 @@ import java.time.Clock
internal class AppModule(context: Application, logger: MatrixLogger) { internal class AppModule(context: Application, logger: MatrixLogger) {
private val buildMeta = BuildMeta(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE) private val buildMeta = BuildMeta(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
private val deviceMeta = DeviceMeta(Build.VERSION.SDK_INT)
private val trackingModule by unsafeLazy { private val trackingModule by unsafeLazy {
TrackingModule( TrackingModule(
isCrashTrackingEnabled = !BuildConfig.DEBUG isCrashTrackingEnabled = !BuildConfig.DEBUG
@ -135,6 +136,7 @@ internal class AppModule(context: Application, logger: MatrixLogger) {
imageLoaderModule, imageLoaderModule,
context, context,
buildMeta, buildMeta,
deviceMeta,
coroutineDispatchers, coroutineDispatchers,
clock, clock,
) )
@ -149,6 +151,7 @@ internal class FeatureModules internal constructor(
imageLoaderModule: ImageLoaderModule, imageLoaderModule: ImageLoaderModule,
context: Context, context: Context,
buildMeta: BuildMeta, buildMeta: BuildMeta,
deviceMeta: DeviceMeta,
coroutineDispatchers: CoroutineDispatchers, coroutineDispatchers: CoroutineDispatchers,
clock: Clock, clock: Clock,
) { ) {
@ -190,6 +193,7 @@ internal class FeatureModules internal constructor(
matrixModules.sync, matrixModules.sync,
context.contentResolver, context.contentResolver,
buildMeta, buildMeta,
deviceMeta,
coroutineDispatchers, coroutineDispatchers,
coreAndroidModule.themeStore(), coreAndroidModule.themeStore(),
) )
@ -202,7 +206,7 @@ internal class FeatureModules internal constructor(
context, context,
intentFactory = coreAndroidModule.intentFactory(), intentFactory = coreAndroidModule.intentFactory(),
dispatchers = coroutineDispatchers, dispatchers = coroutineDispatchers,
deviceMeta = DeviceMeta(Build.VERSION.SDK_INT) deviceMeta = deviceMeta
) )
} }

View File

@ -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() 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) { fun DeviceMeta.onAtLeastO(block: () -> Unit) {
if (this.apiVersion >= Build.VERSION_CODES.O) block() if (this.apiVersion >= Build.VERSION_CODES.O) block()
} }

View File

@ -1,26 +1,42 @@
package app.dapk.st.settings package app.dapk.st.settings
import app.dapk.st.core.BuildMeta import app.dapk.st.core.*
import app.dapk.st.core.ThemeStore
import app.dapk.st.push.PushTokenRegistrars import app.dapk.st.push.PushTokenRegistrars
internal class SettingsItemFactory( internal class SettingsItemFactory(
private val buildMeta: BuildMeta, private val buildMeta: BuildMeta,
private val deviceMeta: DeviceMeta,
private val pushTokenRegistrars: PushTokenRegistrars, private val pushTokenRegistrars: PushTokenRegistrars,
private val themeStore: ThemeStore, 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.Header("General"),
SettingItem.Text(SettingItem.Id.Encryption, "Encryption"), SettingItem.Text(SettingItem.Id.Encryption, "Encryption"),
SettingItem.Text(SettingItem.Id.EventLog, "Event log"), 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.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.Header("Data"),
SettingItem.Text(SettingItem.Id.ClearCache, "Clear cache"), SettingItem.Text(SettingItem.Id.ClearCache, "Clear cache"),
)
private fun account() = listOf(
SettingItem.Header("Account"), SettingItem.Header("Account"),
SettingItem.Text(SettingItem.Id.SignOut, "Sign out"), SettingItem.Text(SettingItem.Id.SignOut, "Sign out"),
)
private fun about() = listOf(
SettingItem.Header("About"), SettingItem.Header("About"),
SettingItem.Text(SettingItem.Id.PrivacyPolicy, "Privacy policy"), SettingItem.Text(SettingItem.Id.PrivacyPolicy, "Privacy policy"),
SettingItem.Text(SettingItem.Id.Ignored, "Version", buildMeta.versionName), SettingItem.Text(SettingItem.Id.Ignored, "Version", buildMeta.versionName),

View File

@ -1,10 +1,7 @@
package app.dapk.st.settings package app.dapk.st.settings
import android.content.ContentResolver import android.content.ContentResolver
import app.dapk.st.core.BuildMeta import app.dapk.st.core.*
import app.dapk.st.core.CoroutineDispatchers
import app.dapk.st.core.ProvidableModule
import app.dapk.st.core.ThemeStore
import app.dapk.st.domain.StoreModule import app.dapk.st.domain.StoreModule
import app.dapk.st.matrix.crypto.CryptoService import app.dapk.st.matrix.crypto.CryptoService
import app.dapk.st.matrix.sync.SyncService import app.dapk.st.matrix.sync.SyncService
@ -18,6 +15,7 @@ class SettingsModule(
private val syncService: SyncService, private val syncService: SyncService,
private val contentResolver: ContentResolver, private val contentResolver: ContentResolver,
private val buildMeta: BuildMeta, private val buildMeta: BuildMeta,
private val deviceMeta: DeviceMeta,
private val coroutineDispatchers: CoroutineDispatchers, private val coroutineDispatchers: CoroutineDispatchers,
private val themeStore: ThemeStore, private val themeStore: ThemeStore,
) : ProvidableModule { ) : ProvidableModule {
@ -29,7 +27,7 @@ class SettingsModule(
cryptoService, cryptoService,
syncService, syncService,
UriFilenameResolver(contentResolver, coroutineDispatchers), UriFilenameResolver(contentResolver, coroutineDispatchers),
SettingsItemFactory(buildMeta, pushModule.pushTokenRegistrars(), themeStore), SettingsItemFactory(buildMeta, deviceMeta, pushModule.pushTokenRegistrars(), themeStore),
pushModule.pushTokenRegistrars(), pushModule.pushTokenRegistrars(),
themeStore, themeStore,
) )

View File

@ -1,6 +1,7 @@
package app.dapk.st.settings package app.dapk.st.settings
import app.dapk.st.core.BuildMeta import app.dapk.st.core.BuildMeta
import app.dapk.st.core.DeviceMeta
import app.dapk.st.push.PushTokenRegistrars import app.dapk.st.push.PushTokenRegistrars
import app.dapk.st.push.Registrar import app.dapk.st.push.Registrar
import internalfixture.aSettingHeaderItem import internalfixture.aSettingHeaderItem
@ -18,10 +19,11 @@ private const val ENABLED_MATERIAL_YOU = true
class SettingsItemFactoryTest { class SettingsItemFactoryTest {
private val buildMeta = BuildMeta(versionName = "a-version-name", versionCode = 100) private val buildMeta = BuildMeta(versionName = "a-version-name", versionCode = 100)
private val deviceMeta = DeviceMeta(apiVersion = 31)
private val fakePushTokenRegistrars = FakePushRegistrars() private val fakePushTokenRegistrars = FakePushRegistrars()
private val fakeThemeStore = FakeThemeStore() private val fakeThemeStore = FakeThemeStore()
private val settingsItemFactory = SettingsItemFactory(buildMeta, fakePushTokenRegistrars.instance, fakeThemeStore.instance) private val settingsItemFactory = SettingsItemFactory(buildMeta, deviceMeta, fakePushTokenRegistrars.instance, fakeThemeStore.instance)
@Test @Test
fun `when creating root items, then is expected`() = runTest { fun `when creating root items, then is expected`() = runTest {