2019-11-09 00:16:09 +01:00
|
|
|
//
|
|
|
|
// TimelineCustomizerViewController.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 11/8/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
class TimelineCustomizerViewController: UIViewController {
|
|
|
|
|
|
|
|
@IBOutlet weak var iconSizeSliderContainerView: UIView!
|
2019-11-09 03:11:17 +01:00
|
|
|
@IBOutlet weak var iconSizeSlider: TickMarkSlider!
|
2019-11-09 00:16:09 +01:00
|
|
|
@IBOutlet weak var numberOfLinesSliderContainerView: UIView!
|
2019-11-09 03:11:17 +01:00
|
|
|
@IBOutlet weak var numberOfLinesSlider: TickMarkSlider!
|
2019-11-09 00:16:09 +01:00
|
|
|
|
|
|
|
@IBOutlet weak var previewWidthConstraint: NSLayoutConstraint!
|
|
|
|
@IBOutlet weak var previewHeightConstraint: NSLayoutConstraint!
|
|
|
|
|
|
|
|
@IBOutlet weak var previewContainerView: UIView!
|
|
|
|
var previewController: TimelinePreviewTableViewController {
|
|
|
|
return children.first as! TimelinePreviewTableViewController
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
iconSizeSliderContainerView.layer.cornerRadius = 12
|
2019-11-09 03:11:17 +01:00
|
|
|
iconSizeSlider.value = Float(AppDefaults.timelineIconSize.rawValue)
|
|
|
|
iconSizeSlider.addTickMarks()
|
|
|
|
|
2019-11-09 00:16:09 +01:00
|
|
|
numberOfLinesSliderContainerView.layer.cornerRadius = 12
|
|
|
|
numberOfLinesSlider.value = Float(AppDefaults.timelineNumberOfLines)
|
2019-11-09 03:11:17 +01:00
|
|
|
numberOfLinesSlider.addTickMarks()
|
2019-11-09 00:16:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
updatePreviewBorder()
|
|
|
|
updatePreview()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
|
|
|
updatePreviewBorder()
|
|
|
|
updatePreview()
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func iconSizeChanged(_ sender: Any) {
|
2019-11-09 03:11:17 +01:00
|
|
|
guard let iconSize = MasterTimelineIconSize(rawValue: Int(iconSizeSlider.value.rounded())) else { return }
|
2019-11-09 00:16:09 +01:00
|
|
|
AppDefaults.timelineIconSize = iconSize
|
|
|
|
updatePreview()
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func numberOfLinesChanged(_ sender: Any) {
|
2019-11-09 03:11:17 +01:00
|
|
|
AppDefaults.timelineNumberOfLines = Int(numberOfLinesSlider.value.rounded())
|
2019-11-09 00:16:09 +01:00
|
|
|
updatePreview()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Private
|
|
|
|
|
|
|
|
private extension TimelineCustomizerViewController {
|
|
|
|
|
|
|
|
func updatePreview() {
|
|
|
|
let previewWidth: CGFloat = {
|
|
|
|
if traitCollection.userInterfaceIdiom == .phone {
|
|
|
|
return view.bounds.width
|
|
|
|
} else {
|
|
|
|
return view.bounds.width / 1.5
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
previewWidthConstraint.constant = previewWidth
|
|
|
|
previewHeightConstraint.constant = previewController.heightFor(width: previewWidth)
|
|
|
|
|
|
|
|
previewController.reload()
|
|
|
|
}
|
|
|
|
|
|
|
|
func updatePreviewBorder() {
|
|
|
|
if traitCollection.userInterfaceStyle == .dark {
|
|
|
|
previewContainerView.layer.borderColor = UIColor.black.cgColor
|
|
|
|
previewContainerView.layer.borderWidth = 1
|
|
|
|
} else {
|
|
|
|
previewContainerView.layer.borderWidth = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|