Browse Source

Reloading only if there's changesets is different.

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

3
Clocker/Preferences/General/PreferencesViewController.swift

@ -556,10 +556,11 @@ extension PreferencesViewController {
} }
private func reloadSearchResults() { private func reloadSearchResults() {
if searchResultsDataSource.calculateChangesets() {
print("Reloading Search Results") print("Reloading Search Results")
searchResultsDataSource.calculateArray()
availableTimezoneTableView.reloadData() availableTimezoneTableView.reloadData()
} }
}
// Extracting this out for tests // Extracting this out for tests
private func decode(from data: Data) -> SearchResult? { private func decode(from data: Data) -> SearchResult? {

21
Clocker/Preferences/General/SearchDataSource.swift

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

Loading…
Cancel
Save