Browse Source

DI Pref and Time Data Source.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
f38c733d38
  1. 3
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  2. 5
      Clocker/Panel/ParentPanelController.swift
  3. 13
      Clocker/Panel/UI/TimezoneDataSource.swift
  4. 12
      Clocker/Preferences/General/PreferencesDataSource.swift
  5. 2
      Clocker/Preferences/General/PreferencesViewController.swift

3
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -6,7 +6,7 @@ import CoreLoggerKit
import CoreModelKit
class TimezoneDataOperations: NSObject {
private var dataObject: TimezoneData!
private var dataObject: TimezoneData
private lazy var nsCalendar = Calendar.autoupdatingCurrent
private static var gregorianCalendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)
private static var swiftyCalendar = Calendar(identifier: .gregorian)
@ -14,6 +14,7 @@ class TimezoneDataOperations: NSObject {
init(with timezone: TimezoneData) {
dataObject = timezone
super.init()
}
}

5
Clocker/Panel/ParentPanelController.swift

@ -509,12 +509,13 @@ class ParentPanelController: NSWindowController {
updatePanelColor()
let defaults = DataStore.shared().timezones()
let store = DataStore.shared()
let defaults = store.timezones()
let convertedTimezones = defaults.map { data -> TimezoneData in
TimezoneData.customObject(from: data)!
}
datasource = TimezoneDataSource(items: convertedTimezones)
datasource = TimezoneDataSource(items: convertedTimezones, store: store)
mainTableView.dataSource = datasource
mainTableView.delegate = datasource
mainTableView.panelDelegate = datasource

13
Clocker/Panel/UI/TimezoneDataSource.swift

@ -6,10 +6,13 @@ import CoreModelKit
class TimezoneDataSource: NSObject {
var timezones: [TimezoneData] = []
var sliderValue: Int = 0
var dataStore: DataStore
init(items: [TimezoneData]) {
init(items: [TimezoneData], store: DataStore) {
sliderValue = 0
timezones = Array(items)
dataStore = store
super.init()
}
}
@ -85,12 +88,12 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate {
return 100
}
if let userFontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber,
if let userFontSize = dataStore.retrieve(key: CLUserFontSizePreference) as? NSNumber,
timezones.count > row,
let relativeDisplay = DataStore.shared().retrieve(key: CLRelativeDateKey) as? NSNumber
let relativeDisplay = dataStore.retrieve(key: CLRelativeDateKey) as? NSNumber
{
let model = timezones[row]
let shouldShowSunrise = DataStore.shared().shouldDisplay(.sunrise)
let shouldShowSunrise = dataStore.shouldDisplay(.sunrise)
var rowHeight: Int = userFontSize == 4 ? 60 : 65
@ -140,7 +143,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate {
tableView.removeRows(at: indexSet, withAnimation: NSTableView.AnimationOptions())
if DataStore.shared().shouldDisplay(ViewType.showAppInForeground) {
if self.dataStore.shouldDisplay(ViewType.showAppInForeground) {
windowController.deleteTimezone(at: row)
} else {
guard let panelController = PanelController.panel() else { return }

12
Clocker/Preferences/General/PreferencesDataSource.swift

@ -22,12 +22,14 @@ protocol PreferenceSelectionUpdates: AnyObject {
class PreferencesDataSource: NSObject {
private weak var updateDelegate: PreferenceSelectionUpdates?
private let store: DataStore
var selectedTimezones: [Data] {
return DataStore.shared().timezones()
return store.timezones()
}
init(callbackDelegate delegate: PreferenceSelectionUpdates) {
updateDelegate = delegate
init(with store: DataStore, callbackDelegate delegate: PreferenceSelectionUpdates) {
self.store = store
self.updateDelegate = delegate
super.init()
}
}
@ -75,7 +77,7 @@ extension PreferencesDataSource: NSTableViewDelegate {
newOrder.insert(currentObject, at: destination)
DataStore.shared().setTimezones(newOrder)
store.setTimezones(newOrder)
tableView.reloadData()
@ -185,7 +187,7 @@ extension PreferencesDataSource: NSTableViewDataSource {
let encodedObject = NSKeyedArchiver.archivedData(withRootObject: timezone)
var newDefaults = selectedTimezones
newDefaults[index] = encodedObject
DataStore.shared().setTimezones(newDefaults)
store.setTimezones(newDefaults)
}
private func updateMenubarTitles() {

2
Clocker/Preferences/General/PreferencesViewController.swift

@ -116,7 +116,7 @@ class PreferencesViewController: ParentViewController {
searchField.placeholderString = "Enter city, state, country or timezone name"
selectionsDataSource = PreferencesDataSource(callbackDelegate: self)
selectionsDataSource = PreferencesDataSource(with: DataStore.shared(), callbackDelegate: self)
timezoneTableView.dataSource = selectionsDataSource
timezoneTableView.delegate = selectionsDataSource

Loading…
Cancel
Save