diff --git a/app/src/main/kotlin/app/dapk/st/graph/AppModule.kt b/app/src/main/kotlin/app/dapk/st/graph/AppModule.kt index 8b013f4..c39313b 100644 --- a/app/src/main/kotlin/app/dapk/st/graph/AppModule.kt +++ b/app/src/main/kotlin/app/dapk/st/graph/AppModule.kt @@ -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 ) } diff --git a/domains/android/core/src/main/kotlin/app/dapk/st/core/DeviceMetaExtensions.kt b/domains/android/core/src/main/kotlin/app/dapk/st/core/DeviceMetaExtensions.kt index 3cc7e00..a2dc53e 100644 --- a/domains/android/core/src/main/kotlin/app/dapk/st/core/DeviceMetaExtensions.kt +++ b/domains/android/core/src/main/kotlin/app/dapk/st/core/DeviceMetaExtensions.kt @@ -6,6 +6,8 @@ fun 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() } diff --git a/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsItemFactory.kt b/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsItemFactory.kt index 015c5cf..a36e2f1 100644 --- a/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsItemFactory.kt +++ b/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsItemFactory.kt @@ -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), diff --git a/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsModule.kt b/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsModule.kt index 9240eb0..4e24052 100644 --- a/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsModule.kt +++ b/features/settings/src/main/kotlin/app/dapk/st/settings/SettingsModule.kt @@ -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, ) diff --git a/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt b/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt index 95ffa3c..ab631c4 100644 --- a/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt +++ b/features/settings/src/test/kotlin/app/dapk/st/settings/SettingsItemFactoryTest.kt @@ -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 {