From 6538c1d13e9cc5bf5b45c14ccaa085c39c844532 Mon Sep 17 00:00:00 2001 From: Artem Chepurnyi Date: Sat, 14 Dec 2024 18:12:53 +0200 Subject: [PATCH] improvement: Hide Inline autofill suggestions option on unsupported platforms --- .../kotlin/com/artemchep/keyguard/platform/LePlatform.kt | 1 + .../component/SettingAutofillInlineSuggestions.kt | 8 ++++++++ .../kotlin/com/artemchep/keyguard/platform/LePlatform.kt | 1 + .../com/artemchep/keyguard/platform/LePlatformUtil.kt | 5 +++++ 4 files changed, 15 insertions(+) diff --git a/common/src/androidMain/kotlin/com/artemchep/keyguard/platform/LePlatform.kt b/common/src/androidMain/kotlin/com/artemchep/keyguard/platform/LePlatform.kt index 317b7575..51919e7f 100644 --- a/common/src/androidMain/kotlin/com/artemchep/keyguard/platform/LePlatform.kt +++ b/common/src/androidMain/kotlin/com/artemchep/keyguard/platform/LePlatform.kt @@ -7,6 +7,7 @@ private val platform by lazy { .matches(".+_cheets|cheets_.+".toRegex()) Platform.Mobile.Android( isChromebook = isChromebook, + sdk = Build.VERSION.SDK_INT, ) } diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/settings/component/SettingAutofillInlineSuggestions.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/settings/component/SettingAutofillInlineSuggestions.kt index 9cb328c2..a39604b5 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/settings/component/SettingAutofillInlineSuggestions.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/settings/component/SettingAutofillInlineSuggestions.kt @@ -11,6 +11,8 @@ import com.artemchep.keyguard.common.io.launchIn import com.artemchep.keyguard.common.usecase.GetAutofillInlineSuggestions import com.artemchep.keyguard.common.usecase.PutAutofillInlineSuggestions import com.artemchep.keyguard.common.usecase.WindowCoroutineScope +import com.artemchep.keyguard.platform.CurrentPlatform +import com.artemchep.keyguard.platform.hasAutofillInlineSuggestions import com.artemchep.keyguard.res.Res import com.artemchep.keyguard.res.* import com.artemchep.keyguard.ui.FlatItem @@ -32,6 +34,12 @@ fun settingAutofillInlineSuggestionsProvider( putAutofillInlineSuggestions: PutAutofillInlineSuggestions, windowCoroutineScope: WindowCoroutineScope, ): SettingComponent = getAutofillInlineSuggestions().map { inlineSuggestions -> + // Hide inline suggestions option if + // it is not supported by the platform. + if (!CurrentPlatform.hasAutofillInlineSuggestions()) { + return@map null + } + val onCheckedChange = { shouldInlineSuggestions: Boolean -> putAutofillInlineSuggestions(shouldInlineSuggestions) .launchIn(windowCoroutineScope) diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatform.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatform.kt index 87745ac0..9e89b4d8 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatform.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatform.kt @@ -6,6 +6,7 @@ sealed interface Platform { sealed interface Mobile : Platform { data class Android( val isChromebook: Boolean, + val sdk: Int, ) : Mobile } diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatformUtil.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatformUtil.kt index 72a60fb6..7fbf6e88 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatformUtil.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatformUtil.kt @@ -4,3 +4,8 @@ fun Platform.hasShareFeature(): Boolean = when (this) { is Platform.Mobile -> true is Platform.Desktop -> false } + +fun Platform.hasAutofillInlineSuggestions(): Boolean = when (this) { + is Platform.Mobile.Android -> sdk >= 30 // Android R + is Platform.Desktop -> false +}