in AutofillFrameworkKotlin/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/model/FilledAutofillFieldCollection.kt [55:97]
fun applyToFields(autofillFieldMetadataCollection: AutofillFieldMetadataCollection,
datasetBuilder: Dataset.Builder): Boolean {
var setValueAtLeastOnce = false
for (hint in autofillFieldMetadataCollection.allAutofillHints) {
val autofillFields = autofillFieldMetadataCollection.getFieldsForHint(hint) ?: continue
for (autofillField in autofillFields) {
val autofillId = autofillField.autofillId
val autofillType = autofillField.autofillType
val savedAutofillValue = hintMap[hint]
when (autofillType) {
View.AUTOFILL_TYPE_LIST -> {
savedAutofillValue?.textValue?.let {
val index = autofillField.getAutofillOptionIndex(it)
if (index != -1) {
datasetBuilder.setValue(autofillId, AutofillValue.forList(index))
setValueAtLeastOnce = true
}
}
}
View.AUTOFILL_TYPE_DATE -> {
savedAutofillValue?.dateValue?.let { date ->
datasetBuilder.setValue(autofillId, AutofillValue.forDate(date))
setValueAtLeastOnce = true
}
}
View.AUTOFILL_TYPE_TEXT -> {
savedAutofillValue?.textValue?.let { text ->
datasetBuilder.setValue(autofillId, AutofillValue.forText(text))
setValueAtLeastOnce = true
}
}
View.AUTOFILL_TYPE_TOGGLE -> {
savedAutofillValue?.toggleValue?.let { toggle ->
datasetBuilder.setValue(autofillId, AutofillValue.forToggle(toggle))
setValueAtLeastOnce = true
}
}
else -> Log.w(TAG, "Invalid autofill type - " + autofillType)
}
}
}
return setValueAtLeastOnce
}