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

5
Clocker/Panel/ParentPanelController.swift

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

13
Clocker/Panel/UI/TimezoneDataSource.swift

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

12
Clocker/Preferences/General/PreferencesDataSource.swift

@ -22,12 +22,14 @@ protocol PreferenceSelectionUpdates: AnyObject {
class PreferencesDataSource: NSObject { class PreferencesDataSource: NSObject {
private weak var updateDelegate: PreferenceSelectionUpdates? private weak var updateDelegate: PreferenceSelectionUpdates?
private let store: DataStore
var selectedTimezones: [Data] { var selectedTimezones: [Data] {
return DataStore.shared().timezones() return store.timezones()
} }
init(callbackDelegate delegate: PreferenceSelectionUpdates) { init(with store: DataStore, callbackDelegate delegate: PreferenceSelectionUpdates) {
updateDelegate = delegate self.store = store
self.updateDelegate = delegate
super.init() super.init()
} }
} }
@ -75,7 +77,7 @@ extension PreferencesDataSource: NSTableViewDelegate {
newOrder.insert(currentObject, at: destination) newOrder.insert(currentObject, at: destination)
DataStore.shared().setTimezones(newOrder) store.setTimezones(newOrder)
tableView.reloadData() tableView.reloadData()
@ -185,7 +187,7 @@ extension PreferencesDataSource: NSTableViewDataSource {
let encodedObject = NSKeyedArchiver.archivedData(withRootObject: timezone) let encodedObject = NSKeyedArchiver.archivedData(withRootObject: timezone)
var newDefaults = selectedTimezones var newDefaults = selectedTimezones
newDefaults[index] = encodedObject newDefaults[index] = encodedObject
DataStore.shared().setTimezones(newDefaults) store.setTimezones(newDefaults)
} }
private func updateMenubarTitles() { 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" searchField.placeholderString = "Enter city, state, country or timezone name"
selectionsDataSource = PreferencesDataSource(callbackDelegate: self) selectionsDataSource = PreferencesDataSource(with: DataStore.shared(), callbackDelegate: self)
timezoneTableView.dataSource = selectionsDataSource timezoneTableView.dataSource = selectionsDataSource
timezoneTableView.delegate = selectionsDataSource timezoneTableView.delegate = selectionsDataSource

Loading…
Cancel
Save