Browse Source

Reloading only if there's changesets is different.

pull/92/head
Abhishek 5 years ago
parent
commit
cfbf53cb77
  1. 7
      Clocker/Preferences/General/PreferencesViewController.swift
  2. 21
      Clocker/Preferences/General/SearchDataSource.swift

7
Clocker/Preferences/General/PreferencesViewController.swift

@ -556,9 +556,10 @@ extension PreferencesViewController {
}
private func reloadSearchResults() {
print("Reloading Search Results")
searchResultsDataSource.calculateArray()
availableTimezoneTableView.reloadData()
if searchResultsDataSource.calculateChangesets() {
print("Reloading Search Results")
availableTimezoneTableView.reloadData()
}
}
// Extracting this out for tests

21
Clocker/Preferences/General/SearchDataSource.swift

@ -34,7 +34,7 @@ class SearchDataSource: NSObject {
super.init()
self.searchField = searchField
setupTimezoneDatasource()
calculateArray()
_ = calculateChangesets()
}
func cleanupFilterArray() {
@ -78,15 +78,15 @@ class SearchDataSource: NSObject {
}
}
func calculateArray() {
finalArray = []
func calculateChangesets() -> Bool {
var changesets: [RowType] = []
func addTimezonesIfNeeded(_ data: [TimezoneMetadata]) {
if !data.isEmpty {
finalArray.append(.timezoneHeader)
changesets.append(.timezoneHeader)
}
data.forEach { _ in
finalArray.append(.timezone)
changesets.append(.timezone)
}
}
@ -94,13 +94,20 @@ class SearchDataSource: NSObject {
addTimezonesIfNeeded(timezoneArray)
} else {
if !filteredArray.isEmpty {
finalArray.append(.cityHeader)
changesets.append(.cityHeader)
}
filteredArray.forEach { _ in
finalArray.append(.city)
changesets.append(.city)
}
addTimezonesIfNeeded(timezoneFilteredArray)
}
if changesets != finalArray {
finalArray = changesets
return true
}
return false
}
}

Loading…
Cancel
Save