NetNewsWire/iOS/Settings/TimelineCustomizerViewController.swift

91 lines
2.6 KiB
Swift
Raw Normal View History

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
import Images
2024-05-07 07:11:28 +02:00
import UIKitExtras
2019-11-09 00:16:09 +01:00
2024-05-07 07:11:28 +02:00
final class TimelineCustomizerViewController: UIViewController {
2019-11-09 00:16:09 +01:00
@IBOutlet weak var iconSizeSliderContainerView: UIView!
@IBOutlet weak var iconSizeSlider: TickMarkSlider!
2019-11-09 00:16:09 +01:00
@IBOutlet weak var numberOfLinesSliderContainerView: UIView!
@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 = 10
iconSizeSlider.value = Float(AppDefaults.shared.timelineIconSize.rawValue)
2024-05-07 07:11:28 +02:00
iconSizeSlider.addTickMarks(color: AppAssets.tickMarkColor)
numberOfLinesSliderContainerView.layer.cornerRadius = 10
numberOfLinesSlider.value = Float(AppDefaults.shared.timelineNumberOfLines)
2024-05-07 07:11:28 +02:00
numberOfLinesSlider.addTickMarks(color: AppAssets.tickMarkColor)
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) {
guard let iconSize = IconSize(rawValue: Int(iconSizeSlider.value.rounded())) else { return }
AppDefaults.shared.timelineIconSize = iconSize
2019-11-09 00:16:09 +01:00
updatePreview()
}
@IBAction func numberOfLinesChanged(_ sender: Any) {
AppDefaults.shared.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
}
}
}