mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-21 05:43:37 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
84
iphone/Maps/UI/Downloader/SearchMapsDataSource.swift
Normal file
84
iphone/Maps/UI/Downloader/SearchMapsDataSource.swift
Normal file
@@ -0,0 +1,84 @@
|
||||
class SearchMapsDataSource {
|
||||
typealias SearchCallback = (Bool) -> Void
|
||||
|
||||
fileprivate var searchResults: [MapSearchResult] = []
|
||||
fileprivate var searchId = 0
|
||||
fileprivate var onUpdate: SearchCallback?
|
||||
}
|
||||
|
||||
extension SearchMapsDataSource: IDownloaderDataSource {
|
||||
var isEmpty: Bool {
|
||||
searchResults.isEmpty
|
||||
}
|
||||
|
||||
var title: String {
|
||||
""
|
||||
}
|
||||
|
||||
var isRoot: Bool {
|
||||
true
|
||||
}
|
||||
|
||||
var isSearching: Bool {
|
||||
true
|
||||
}
|
||||
|
||||
func numberOfSections() -> Int {
|
||||
1
|
||||
}
|
||||
|
||||
func getParentCountryId() -> String {
|
||||
return Storage.shared().getRootId()
|
||||
}
|
||||
|
||||
func parentAttributes() -> MapNodeAttributes {
|
||||
return Storage.shared().attributesForRoot()
|
||||
}
|
||||
|
||||
func numberOfItems(in section: Int) -> Int {
|
||||
searchResults.count
|
||||
}
|
||||
|
||||
func item(at indexPath: IndexPath) -> MapNodeAttributes {
|
||||
Storage.shared().attributes(forCountry: searchResults[indexPath.item].countryId)
|
||||
}
|
||||
|
||||
func matchedName(at indexPath: IndexPath) -> String? {
|
||||
searchResults[indexPath.item].matchedName
|
||||
}
|
||||
|
||||
func title(for section: Int) -> String {
|
||||
L("downloader_search_results")
|
||||
}
|
||||
|
||||
func indexTitles() -> [String]? {
|
||||
nil
|
||||
}
|
||||
|
||||
func dataSourceFor(_ childId: String) -> IDownloaderDataSource {
|
||||
AvailableMapsDataSource(childId)
|
||||
}
|
||||
|
||||
func reload(_ completion: () -> Void) {
|
||||
completion()
|
||||
}
|
||||
|
||||
func search(_ query: String, locale: String, update: @escaping SearchCallback) {
|
||||
searchId += 1
|
||||
onUpdate = update
|
||||
FrameworkHelper.search(inDownloader: query, inputLocale: locale) { [weak self, searchId] (results, finished) in
|
||||
if searchId != self?.searchId {
|
||||
return
|
||||
}
|
||||
self?.searchResults = results
|
||||
if results.count > 0 || finished {
|
||||
self?.onUpdate?(finished)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func cancelSearch() {
|
||||
searchResults = []
|
||||
onUpdate = nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user