Skip to content

Commit

Permalink
Merge branch 'remember-preferred-scale'
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmichel committed Dec 26, 2016
2 parents 82c38c6 + 7b0796e commit 54e8f55
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Juice/Classes/PreferencesStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import Foundation
import RxSwift

final class PreferencesStorage {
private enum Constants {
static let PreferredScaleKey = "PreferredScaleKey"
}

static let shared = PreferencesStorage()

private let scanQueue = OperationQueue()
Expand All @@ -26,6 +30,7 @@ final class PreferencesStorage {

func set(chargeDisplayScale: ChargeScaleDisplay) {
self.chargeDisplayScale.value = chargeDisplayScale
setPreferredScale(scale: chargeDisplayScale)
}

func scanApplicationSupportForFiles() {
Expand All @@ -41,9 +46,20 @@ final class PreferencesStorage {
localScales.append(contentsOf: FileBackedChargeScaleDisplay.makeApplicationDefaults())

self?.scales.value = localScales

let preferredScaleTitle = UserDefaults.standard.string(forKey: Constants.PreferredScaleKey)

if let title = preferredScaleTitle,
let scale = localScales.filter({ $0.title == title }).first {
self?.chargeDisplayScale.value = scale
}
} catch (let error) {
print("Error scanning application support directory: \(error)")
}
}
}

private func setPreferredScale(scale: ChargeScaleDisplay) {
UserDefaults.standard.set(scale.title, forKey: Constants.PreferredScaleKey)
}
}

0 comments on commit 54e8f55

Please sign in to comment.