mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 21:13:35 +00:00
[carplay] Fix list selection highlight
Need to create the templates with sections from the start, or the second item will be highlighted Fixes bug #1913 Signed-off-by: eisa01 <eisa01@gmail.com>
This commit is contained in:
@@ -13,7 +13,7 @@ final class ListTemplateBuilder {
|
|||||||
case search
|
case search
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - CPListTemplate bilder
|
// MARK: - CPListTemplate builder
|
||||||
class func buildListTemplate(for type: ListTemplateType) -> CPListTemplate {
|
class func buildListTemplate(for type: ListTemplateType) -> CPListTemplate {
|
||||||
var title = ""
|
var title = ""
|
||||||
var trailingNavigationBarButtons = [CPBarButton]()
|
var trailingNavigationBarButtons = [CPBarButton]()
|
||||||
@@ -40,26 +40,27 @@ final class ListTemplateBuilder {
|
|||||||
case .bookmarks(let category):
|
case .bookmarks(let category):
|
||||||
title = category.title
|
title = category.title
|
||||||
}
|
}
|
||||||
let template = CPListTemplate(title: title, sections: [])
|
|
||||||
|
let sections = buildSectionsForType(type)
|
||||||
|
let template = CPListTemplate(title: title, sections: sections)
|
||||||
template.trailingNavigationBarButtons = trailingNavigationBarButtons
|
template.trailingNavigationBarButtons = trailingNavigationBarButtons
|
||||||
obtainResources(for: type, template: template)
|
|
||||||
return template
|
return template
|
||||||
}
|
}
|
||||||
|
|
||||||
private class func obtainResources(for type: ListTemplateType, template: CPListTemplate) {
|
private class func buildSectionsForType(_ type: ListTemplateType) -> [CPListSection] {
|
||||||
switch type {
|
switch type {
|
||||||
case .history:
|
case .history:
|
||||||
obtainHistory(template: template)
|
return buildHistorySections()
|
||||||
case .bookmarks(let category):
|
case .bookmarks(let category):
|
||||||
obtainBookmarks(template: template, categoryId: category.categoryId)
|
return buildBookmarksSections(categoryId: category.categoryId)
|
||||||
case .bookmarkLists:
|
case .bookmarkLists:
|
||||||
obtainCategories(template: template)
|
return buildBookmarkListsSections()
|
||||||
case .searchResults(let results):
|
case .searchResults(let results):
|
||||||
convertSearchResults(results, template: template)
|
return buildSearchResultsSections(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class func obtainHistory(template: CPListTemplate) {
|
private class func buildHistorySections() -> [CPListSection] {
|
||||||
let searchQueries = FrameworkHelper.obtainLastSearchQueries()
|
let searchQueries = FrameworkHelper.obtainLastSearchQueries()
|
||||||
let items = searchQueries.map({ (text) -> CPListItem in
|
let items = searchQueries.map({ (text) -> CPListItem in
|
||||||
let item = CPListItem(text: text, detailText: nil, image: UIImage(named: "recent"))
|
let item = CPListItem(text: text, detailText: nil, image: UIImage(named: "recent"))
|
||||||
@@ -67,11 +68,10 @@ final class ListTemplateBuilder {
|
|||||||
metadata: nil)
|
metadata: nil)
|
||||||
return item
|
return item
|
||||||
})
|
})
|
||||||
let section = CPListSection(items: items)
|
return [CPListSection(items: items)]
|
||||||
template.updateSections([section])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class func obtainCategories(template: CPListTemplate) {
|
private class func buildBookmarkListsSections() -> [CPListSection] {
|
||||||
let bookmarkManager = BookmarksManager.shared()
|
let bookmarkManager = BookmarksManager.shared()
|
||||||
let categories = bookmarkManager.sortedUserCategories()
|
let categories = bookmarkManager.sortedUserCategories()
|
||||||
let items: [CPListItem] = categories.compactMap({ category in
|
let items: [CPListItem] = categories.compactMap({ category in
|
||||||
@@ -82,11 +82,10 @@ final class ListTemplateBuilder {
|
|||||||
metadata: CategoryInfo(category: category))
|
metadata: CategoryInfo(category: category))
|
||||||
return item
|
return item
|
||||||
})
|
})
|
||||||
let section = CPListSection(items: items)
|
return [CPListSection(items: items)]
|
||||||
template.updateSections([section])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class func obtainBookmarks(template: CPListTemplate, categoryId: MWMMarkGroupID) {
|
private class func buildBookmarksSections(categoryId: MWMMarkGroupID) -> [CPListSection] {
|
||||||
let bookmarkManager = BookmarksManager.shared()
|
let bookmarkManager = BookmarksManager.shared()
|
||||||
let bookmarks = bookmarkManager.bookmarks(forCategory: categoryId)
|
let bookmarks = bookmarkManager.bookmarks(forCategory: categoryId)
|
||||||
var items = bookmarks.map({ (bookmark) -> CPListItem in
|
var items = bookmarks.map({ (bookmark) -> CPListItem in
|
||||||
@@ -103,11 +102,10 @@ final class ListTemplateBuilder {
|
|||||||
cropWarning.isEnabled = false
|
cropWarning.isEnabled = false
|
||||||
items.append(cropWarning)
|
items.append(cropWarning)
|
||||||
}
|
}
|
||||||
let section = CPListSection(items: items)
|
return [CPListSection(items: items)]
|
||||||
template.updateSections([section])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class func convertSearchResults(_ results: [MWMCarPlaySearchResultObject], template: CPListTemplate) {
|
private class func buildSearchResultsSections(_ results: [MWMCarPlaySearchResultObject]) -> [CPListSection] {
|
||||||
var items = [CPListItem]()
|
var items = [CPListItem]()
|
||||||
for object in results {
|
for object in results {
|
||||||
let item = CPListItem(text: object.title, detailText: object.address)
|
let item = CPListItem(text: object.title, detailText: object.address)
|
||||||
@@ -115,10 +113,10 @@ final class ListTemplateBuilder {
|
|||||||
metadata: SearchResultInfo(originalRow: object.originalRow))
|
metadata: SearchResultInfo(originalRow: object.originalRow))
|
||||||
items.append(item)
|
items.append(item)
|
||||||
}
|
}
|
||||||
let section = CPListSection(items: items)
|
return [CPListSection(items: items)]
|
||||||
template.updateSections([section])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - CPBarButton builder
|
// MARK: - CPBarButton builder
|
||||||
private class func buildBarButton(type: BarButtonType, action: ((CPBarButton) -> Void)?) -> CPBarButton {
|
private class func buildBarButton(type: BarButtonType, action: ((CPBarButton) -> Void)?) -> CPBarButton {
|
||||||
switch type {
|
switch type {
|
||||||
|
|||||||
Reference in New Issue
Block a user