|
@@ -13,58 +13,60 @@
|
|
|
import UIKit
|
|
|
|
|
|
class VLCSettingsTableViewCell: UITableViewCell {
|
|
|
-
|
|
|
- override func prepareForReuse() {
|
|
|
- super.prepareForReuse()
|
|
|
- setupCell()
|
|
|
- }
|
|
|
|
|
|
- fileprivate func setupCell() {
|
|
|
+ @objc fileprivate func themeDidChange() {
|
|
|
backgroundColor = PresentationTheme.current.colors.background
|
|
|
textLabel?.textColor = PresentationTheme.current.colors.cellTextColor
|
|
|
detailTextLabel?.textColor = PresentationTheme.current.colors.cellDetailTextColor
|
|
|
}
|
|
|
-
|
|
|
- @objc static func cell(identifier: String, target: IASKAppSettingsViewController) -> VLCSettingsTableViewCell? {
|
|
|
- let cell = VLCSettingsTableViewCell(style: .subtitle, reuseIdentifier: identifier)
|
|
|
- cell.setupCell()
|
|
|
+
|
|
|
+ @objc init(reuseIdentifier: String, target: IASKAppSettingsViewController) {
|
|
|
+ super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .VLCThemeDidChangeNotification, object: nil)
|
|
|
+ themeDidChange()
|
|
|
|
|
|
- switch identifier {
|
|
|
+ switch reuseIdentifier {
|
|
|
case kIASKPSToggleSwitchSpecifier:
|
|
|
let toggle = IASKSwitch(frame: .zero)
|
|
|
toggle.addTarget(target, action: #selector(target.toggledValue(_:)), for: .valueChanged)
|
|
|
- cell.accessoryView = toggle
|
|
|
- cell.selectionStyle = .none
|
|
|
+ accessoryView = toggle
|
|
|
+ selectionStyle = .none
|
|
|
case kIASKOpenURLSpecifier, kIASKPSMultiValueSpecifier:
|
|
|
- cell.accessoryType = .disclosureIndicator
|
|
|
- cell.selectionStyle = .default
|
|
|
+ accessoryType = .disclosureIndicator
|
|
|
+ selectionStyle = .default
|
|
|
default:
|
|
|
- assertionFailure("\(identifier) has not been defined for VLCSettingsTableViewCell")
|
|
|
+ assertionFailure("\(reuseIdentifier) has not been defined for VLCSettingsTableViewCell")
|
|
|
}
|
|
|
-
|
|
|
- return cell
|
|
|
}
|
|
|
-
|
|
|
- @objc func configure(specifier: IASKSpecifier, value: Any?) {
|
|
|
+
|
|
|
+ @available(*, unavailable, message: "use init(reuseIdentifier: String)")
|
|
|
+ required init?(coder aDecoder: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func configure(specifier: IASKSpecifier, settingsValue: Any?) {
|
|
|
textLabel?.text = specifier.title()
|
|
|
-
|
|
|
+ detailTextLabel?.text = specifier.subtitle()
|
|
|
+
|
|
|
switch specifier.type() {
|
|
|
case kIASKPSToggleSwitchSpecifier:
|
|
|
- configureToggle(specifier, value)
|
|
|
+ configureToggle(specifier, settingsValue)
|
|
|
case kIASKPSMultiValueSpecifier:
|
|
|
- configureMultiValue(specifier, value)
|
|
|
+ configureMultiValue(specifier, settingsValue)
|
|
|
case kIASKOpenURLSpecifier:
|
|
|
- configureOpenURL(specifier)
|
|
|
+ break
|
|
|
default:
|
|
|
assertionFailure("\(specifier.type()) has not been defined for VLCSettingsTableViewCell")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fileprivate func configureToggle(_ specifier: IASKSpecifier, _ value: Any?) {
|
|
|
- detailTextLabel?.text = specifier.subtitle()
|
|
|
-
|
|
|
- var state: Bool
|
|
|
- if let currentValue = value as? Bool {
|
|
|
+ fileprivate func configureToggle(_ specifier: IASKSpecifier, _ settingsValue: Any?) {
|
|
|
+ assert(specifier.type() == kIASKPSToggleSwitchSpecifier, "configureToggle should only be called for kIASKPSToggleSwitchSpecifier")
|
|
|
+ assert(settingsValue is Bool?, "settingsValue should be Bool?")
|
|
|
+ assert(accessoryView is IASKSwitch, "the accessory should be a switch")
|
|
|
+
|
|
|
+ var state = specifier.defaultBoolValue()
|
|
|
+ if let currentValue = settingsValue as? Bool {
|
|
|
switch currentValue {
|
|
|
case specifier.trueValue() as? Bool:
|
|
|
state = true
|
|
@@ -73,8 +75,6 @@ class VLCSettingsTableViewCell: UITableViewCell {
|
|
|
default:
|
|
|
state = currentValue
|
|
|
}
|
|
|
- } else {
|
|
|
- state = specifier.defaultBoolValue()
|
|
|
}
|
|
|
|
|
|
if let toggle = accessoryView as? IASKSwitch {
|
|
@@ -84,14 +84,8 @@ class VLCSettingsTableViewCell: UITableViewCell {
|
|
|
}
|
|
|
|
|
|
fileprivate func configureMultiValue(_ specifier: IASKSpecifier, _ value: Any?) {
|
|
|
- if let currentValue = value {
|
|
|
- detailTextLabel?.text = specifier.title(forCurrentValue: currentValue)
|
|
|
- } else {
|
|
|
- detailTextLabel?.text = specifier.title(forCurrentValue: specifier.defaultValue())
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- fileprivate func configureOpenURL(_ specifier: IASKSpecifier) {
|
|
|
- detailTextLabel?.text = specifier.subtitle()
|
|
|
+ assert(specifier.type() == kIASKPSMultiValueSpecifier, "configureMultiValue should only be called for kIASKPSMultiValueSpecifier")
|
|
|
+
|
|
|
+ detailTextLabel?.text = specifier.title(forCurrentValue: value ?? specifier.defaultValue())
|
|
|
}
|
|
|
}
|