improvement: Hide Inline autofill suggestions option on unsupported platforms

This commit is contained in:
Artem Chepurnyi 2024-12-14 18:12:53 +02:00
parent 9fa53ea157
commit 6538c1d13e
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
4 changed files with 15 additions and 0 deletions

View File

@ -7,6 +7,7 @@ private val platform by lazy {
.matches(".+_cheets|cheets_.+".toRegex())
Platform.Mobile.Android(
isChromebook = isChromebook,
sdk = Build.VERSION.SDK_INT,
)
}

View File

@ -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)

View File

@ -6,6 +6,7 @@ sealed interface Platform {
sealed interface Mobile : Platform {
data class Android(
val isChromebook: Boolean,
val sdk: Int,
) : Mobile
}

View File

@ -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
}