Skip to content

Commit aa9c58b

Browse files
authored
Update "Categories" picker to indicate multiple selection (#24952)
* Add localization * Update accessoryView * Update release notes
1 parent ebf2fc2 commit aa9c58b

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [*] Add "File Size" to Site Media Details [#24947]
99
* [*] Add "Email to Subscribers" row to "Publishing" sheet [#24946]
1010
* [*] Add permalink preview in the slug editor and make other improvements [#24949]
11+
* [*] Update "Categories" picker to indicate multiple selection [#24952]
1112

1213
26.4
1314
-----

WordPress/Classes/ViewRelated/Post/Categories/PostCategoriesViewController.swift

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ import WordPressUI
7878
switch selectionMode {
7979
case .post:
8080
navigationItem.rightBarButtonItem = rightBarButtonItem
81-
title = NSLocalizedString("Post Categories", comment: "Title for selecting categories for a post")
81+
title = Strings.postCategoriesTitle
8282
case .parent:
8383
navigationItem.rightBarButtonItem = rightBarButtonItem
84-
title = NSLocalizedString("Parent Category", comment: "Title for selecting parent category of a category")
84+
title = Strings.parentCategoryTitle
8585
case .blogDefault:
86-
title = NSLocalizedString("Default Category", comment: "Title for selecting a default category for a post")
86+
title = Strings.defaultCategoryTitle
8787
}
8888
}
8989

@@ -170,7 +170,7 @@ import WordPressUI
170170
private func configureNoCategoryRow(cell: WPTableViewCell) {
171171
WPStyleGuide.configureTableViewDestructiveActionCell(cell)
172172
cell.textLabel?.textAlignment = .natural
173-
cell.textLabel?.text = NSLocalizedString("No Category", comment: "Text shown (to select no-category) in the parent-category-selection screen when creating a new category.")
173+
cell.textLabel?.text = Strings.noCategoryText
174174
if selectedCategories.isEmpty {
175175
cell.accessoryType = selectedCategories.isEmpty ? .checkmark : .none
176176
} else {
@@ -184,11 +184,14 @@ import WordPressUI
184184
cell.indentationWidth = Constants.categoryCellIndentation
185185
cell.textLabel?.text = category.categoryName.stringByDecodingXMLCharacters()
186186
WPStyleGuide.configureTableViewCell(cell)
187-
if selectedCategories.contains(category) {
188-
cell.accessoryType = .checkmark
189-
} else {
190-
cell.accessoryType = .none
191-
}
187+
cell.accessoryView = makeAccessoryView(isSelected: selectedCategories.contains(category))
188+
}
189+
190+
private func makeAccessoryView(isSelected: Bool) -> UIView {
191+
let image = UIImage(systemName: isSelected ? "checkmark.circle.fill" : "circle")
192+
let view = UIImageView(image: image)
193+
view.tintColor = isSelected ? UIAppColor.primary : .opaqueSeparator
194+
return view
192195
}
193196

194197
//tableView
@@ -255,10 +258,10 @@ import WordPressUI
255258
if selectedCategories.contains(category),
256259
let index = selectedCategories.firstIndex(of: category) {
257260
selectedCategories.remove(at: index)
258-
tableView.cellForRow(at: indexPath)?.accessoryType = .none
261+
tableView.cellForRow(at: indexPath)?.accessoryView = makeAccessoryView(isSelected: false)
259262
} else {
260263
selectedCategories.append(category)
261-
tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
264+
tableView.cellForRow(at: indexPath)?.accessoryView = makeAccessoryView(isSelected: true)
262265
}
263266

264267
delegate?.postCategoriesViewController?(self, didUpdateSelectedCategories: NSSet(array: selectedCategories))
@@ -284,4 +287,30 @@ private extension PostCategoriesViewController {
284287
static let categoryCellIdentifier = "CategoryCellIdentifier"
285288
static let categoryCellIndentation = CGFloat(16.0)
286289
}
290+
291+
enum Strings {
292+
static let postCategoriesTitle = NSLocalizedString(
293+
"postCategories.title",
294+
value: "Categories",
295+
comment: "Title for selecting categories for a post or a page"
296+
)
297+
298+
static let parentCategoryTitle = NSLocalizedString(
299+
"parentCategory.title",
300+
value: "Parent Category",
301+
comment: "Title for selecting parent category of a category"
302+
)
303+
304+
static let defaultCategoryTitle = NSLocalizedString(
305+
"defaultCategory.title",
306+
value: "Default Category",
307+
comment: "Title for selecting a default category for a post"
308+
)
309+
310+
static let noCategoryText = NSLocalizedString(
311+
"parentCategory.noCategory",
312+
value: "No Category",
313+
comment: "Text shown (to select no-category) in the parent-category-selection screen when creating a new category."
314+
)
315+
}
287316
}

0 commit comments

Comments
 (0)