if (!other.empty()) {
[model addSectionWithIdentifier:SectionIdentifierOther];
[model setHeader:[self otherSectionHeader]
forSectionWithIdentifier:SectionIdentifierOther];
std::vector<autofill::EntityLabel> labels = autofill::GetLabelsForEntities(
other, /*attribute_types_to_ignore=*/{},
/*only_disambiguating_types=*/true, /*obfuscate_sensitive_types=*/true,
locale);
for (size_t i = 0; i < other.size(); ++i) {
[model addItem:[self itemForEntityInstance:*other[i]
withLabel:labels[i]
type:ItemTypeOther]
toSectionWithIdentifier:SectionIdentifierOther];
}
}At this point it might be worth considering adding a helper method to construct these sections. You could take a `std::vector<const autofill::EntityInstance*>`, item type, and a section identifier as parameters.
- (TableViewHeaderFooterItem*)identityDocsSectionHeader {
TableViewTextHeaderFooterItem* header = [[TableViewTextHeaderFooterItem alloc]
initWithType:ItemTypeIdentityDocHeader];
header.text = l10n_util::GetNSString(IDS_AUTOFILL_IDENTITY_DOCS_TITLE);
return header;
}
- (TableViewHeaderFooterItem*)travelSectionHeader {
TableViewTextHeaderFooterItem* header =
[[TableViewTextHeaderFooterItem alloc] initWithType:ItemTypeTravelHeader];
header.text = l10n_util::GetNSString(IDS_AUTOFILL_TRAVEL_TITLE);
return header;
}
- (TableViewHeaderFooterItem*)otherSectionHeader {
TableViewTextHeaderFooterItem* header =
[[TableViewTextHeaderFooterItem alloc] initWithType:ItemTypeOtherHeader];
header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_AI_OTHER_TITLE);
return header;
}Similarly, and especially if you take my suggestion above, you could make these into a single method that generates the header item based on the item type.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
if (!other.empty()) {
[model addSectionWithIdentifier:SectionIdentifierOther];
[model setHeader:[self otherSectionHeader]
forSectionWithIdentifier:SectionIdentifierOther];
std::vector<autofill::EntityLabel> labels = autofill::GetLabelsForEntities(
other, /*attribute_types_to_ignore=*/{},
/*only_disambiguating_types=*/true, /*obfuscate_sensitive_types=*/true,
locale);
for (size_t i = 0; i < other.size(); ++i) {
[model addItem:[self itemForEntityInstance:*other[i]
withLabel:labels[i]
type:ItemTypeOther]
toSectionWithIdentifier:SectionIdentifierOther];
}
}At this point it might be worth considering adding a helper method to construct these sections. You could take a `std::vector<const autofill::EntityInstance*>`, item type, and a section identifier as parameters.
Done.
- (TableViewHeaderFooterItem*)identityDocsSectionHeader {
TableViewTextHeaderFooterItem* header = [[TableViewTextHeaderFooterItem alloc]
initWithType:ItemTypeIdentityDocHeader];
header.text = l10n_util::GetNSString(IDS_AUTOFILL_IDENTITY_DOCS_TITLE);
return header;
}
- (TableViewHeaderFooterItem*)travelSectionHeader {
TableViewTextHeaderFooterItem* header =
[[TableViewTextHeaderFooterItem alloc] initWithType:ItemTypeTravelHeader];
header.text = l10n_util::GetNSString(IDS_AUTOFILL_TRAVEL_TITLE);
return header;
}
- (TableViewHeaderFooterItem*)otherSectionHeader {
TableViewTextHeaderFooterItem* header =
[[TableViewTextHeaderFooterItem alloc] initWithType:ItemTypeOtherHeader];
header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_AI_OTHER_TITLE);
return header;
}Similarly, and especially if you take my suggestion above, you could make these into a single method that generates the header item based on the item type.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
ItemType itemType;
TableViewTextHeaderFooterItem* header;
switch (sectionIdentifier) {
case SectionIdentifierIdentityDocs:
itemType = ItemTypeIdentityDoc;
header = [[TableViewTextHeaderFooterItem alloc]
initWithType:ItemTypeIdentityDocHeader];
header.text = l10n_util::GetNSString(IDS_AUTOFILL_IDENTITY_DOCS_TITLE);
break;
case SectionIdentifierTravel:
itemType = ItemTypeTravel;
header = [[TableViewTextHeaderFooterItem alloc]
initWithType:ItemTypeTravelHeader];
header.text = l10n_util::GetNSString(IDS_AUTOFILL_TRAVEL_TITLE);
break;
case SectionIdentifierOther:
default:
itemType = ItemTypeOther;
header = [[TableViewTextHeaderFooterItem alloc]
initWithType:ItemTypeOtherHeader];
header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_AI_OTHER_TITLE);
break;
}Optional nit: This function is a bit long and I think this code would be clearer with a few utility functions (I haven't compiled those, I'm just writing them here, so don't necessarily use them as is):
1.
```
ItemType ItemTypeFromSectionIdentifier(SectionIdentifier sectionIdentifier) {
switch (sectionIdentifier) {
case SectionIdentifierIdentityDocs:
return ItemTypeIdentityDoc;
case SectionIdentifierTravel:
return ItemTypeTravel;
case SectionIdentifierOther:
default:
return ItemTypeOther;
}
}
```
2.
```
ItemType HeaderTypeForItemType(ItemType itemType) {
switch (itemType) {
case ItemTypeIdentityDoc:
return ItemTypeIdentityDocHeader;
case ItemTypeTravel:
return ItemTypeTravelHeader;
case ItemTypeOther:
default:
return ItemTypeOtherHeader;
}
}
```
3.
```
NSString* HeaderTextForItemType(ItemType itemType) {
switch (itemType) {
case ItemTypeIdentityDoc:
return l10n_util::GetNSString(IDS_AUTOFILL_IDENTITY_DOCS_TITLE);
case ItemTypeTravel:
return l10n_util::GetNSString(IDS_AUTOFILL_TRAVEL_TITLE);
case ItemTypeOther:
default:
return l10n_util::GetNSString(IDS_IOS_AUTOFILL_AI_OTHER_TITLE);
}
}
```
And then the code here becomes:
```
ItemType itemType = ItemTypeFromSectionIdentifier(sectionIdentifier);
TableViewTextHeaderFooterItem* header = [[TableViewTextHeaderFooterItem alloc]
initWithType:HeaderTypeForItemType(itemType)];
header.text = HeaderTextForItemType(itemType);
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
ItemType itemType;
TableViewTextHeaderFooterItem* header;
switch (sectionIdentifier) {
case SectionIdentifierIdentityDocs:
itemType = ItemTypeIdentityDoc;
header = [[TableViewTextHeaderFooterItem alloc]
initWithType:ItemTypeIdentityDocHeader];
header.text = l10n_util::GetNSString(IDS_AUTOFILL_IDENTITY_DOCS_TITLE);
break;
case SectionIdentifierTravel:
itemType = ItemTypeTravel;
header = [[TableViewTextHeaderFooterItem alloc]
initWithType:ItemTypeTravelHeader];
header.text = l10n_util::GetNSString(IDS_AUTOFILL_TRAVEL_TITLE);
break;
case SectionIdentifierOther:
default:
itemType = ItemTypeOther;
header = [[TableViewTextHeaderFooterItem alloc]
initWithType:ItemTypeOtherHeader];
header.text = l10n_util::GetNSString(IDS_IOS_AUTOFILL_AI_OTHER_TITLE);
break;
}| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |