mirror of
https://github.com/bitwarden/android.git
synced 2026-06-07 06:49:07 -05:00
BIT-1486: Use inline autofill based on user's setting (#702)
This commit is contained in:
committed by
Álison Fernandes
parent
99f5325580
commit
4510695f76
@@ -13,6 +13,7 @@ import com.x8bit.bitwarden.data.autofill.processor.AutofillProcessorImpl
|
||||
import com.x8bit.bitwarden.data.autofill.provider.AutofillCipherProvider
|
||||
import com.x8bit.bitwarden.data.autofill.provider.AutofillCipherProviderImpl
|
||||
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
@@ -34,7 +35,12 @@ object AutofillModule {
|
||||
): AutofillManager = context.getSystemService(AutofillManager::class.java)
|
||||
|
||||
@Provides
|
||||
fun providesAutofillParser(): AutofillParser = AutofillParserImpl()
|
||||
fun providesAutofillParser(
|
||||
settingsRepository: SettingsRepository,
|
||||
): AutofillParser =
|
||||
AutofillParserImpl(
|
||||
settingsRepository = settingsRepository,
|
||||
)
|
||||
|
||||
@Provides
|
||||
fun providesAutofillCipherProvider(): AutofillCipherProvider = AutofillCipherProviderImpl()
|
||||
|
||||
@@ -12,12 +12,15 @@ import com.x8bit.bitwarden.data.autofill.util.buildUriOrNull
|
||||
import com.x8bit.bitwarden.data.autofill.util.getInlinePresentationSpecs
|
||||
import com.x8bit.bitwarden.data.autofill.util.getMaxInlineSuggestionsCount
|
||||
import com.x8bit.bitwarden.data.autofill.util.toAutofillView
|
||||
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
|
||||
|
||||
/**
|
||||
* The default [AutofillParser] implementation for the app. This is a tool for parsing autofill data
|
||||
* from the OS into domain models.
|
||||
*/
|
||||
class AutofillParserImpl : AutofillParser {
|
||||
class AutofillParserImpl(
|
||||
private val settingsRepository: SettingsRepository,
|
||||
) : AutofillParser {
|
||||
override fun parse(
|
||||
autofillAppInfo: AutofillAppInfo,
|
||||
fillRequest: FillRequest,
|
||||
@@ -79,12 +82,15 @@ class AutofillParserImpl : AutofillParser {
|
||||
.map { it.ignoreAutofillIds }
|
||||
.flatten()
|
||||
|
||||
// Get inline information if available
|
||||
val isInlineAutofillEnabled = settingsRepository.isInlineAutofillEnabled
|
||||
val maxInlineSuggestionsCount = fillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = isInlineAutofillEnabled,
|
||||
)
|
||||
|
||||
val inlinePresentationSpecs = fillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = isInlineAutofillEnabled,
|
||||
)
|
||||
|
||||
return AutofillRequest.Fillable(
|
||||
|
||||
@@ -12,8 +12,9 @@ import com.x8bit.bitwarden.data.autofill.model.AutofillAppInfo
|
||||
@SuppressLint("NewApi")
|
||||
fun FillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo: AutofillAppInfo,
|
||||
isInlineAutofillEnabled: Boolean,
|
||||
): List<InlinePresentationSpec> =
|
||||
if (autofillAppInfo.sdkInt >= Build.VERSION_CODES.R) {
|
||||
if (isInlineAutofillEnabled && autofillAppInfo.sdkInt >= Build.VERSION_CODES.R) {
|
||||
inlineSuggestionsRequest?.inlinePresentationSpecs ?: emptyList()
|
||||
} else {
|
||||
emptyList()
|
||||
@@ -26,8 +27,9 @@ fun FillRequest.getInlinePresentationSpecs(
|
||||
@SuppressLint("NewApi")
|
||||
fun FillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo: AutofillAppInfo,
|
||||
isInlineAutofillEnabled: Boolean,
|
||||
): Int =
|
||||
if (autofillAppInfo.sdkInt >= Build.VERSION_CODES.R) {
|
||||
if (isInlineAutofillEnabled && autofillAppInfo.sdkInt >= Build.VERSION_CODES.R) {
|
||||
inlineSuggestionsRequest?.maxSuggestionCount ?: 0
|
||||
} else {
|
||||
0
|
||||
|
||||
Reference in New Issue
Block a user