Tusker/Tusker/Screens/Preferences/AdvancedTableViewController...

57 lines
1.7 KiB
Swift

//
// AdvancedTableViewController.swift
// Tusker
//
// Created by Shadowfacts on 1/12/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import UIKit
import Pachyderm
class AdvancedTableViewController: UITableViewController {
@IBOutlet weak var postContentTypeLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
postContentTypeLabel.text = Preferences.shared.statusContentType.displayName
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard indexPath.section == 1 && indexPath.row == 0 else {
return
}
tableView.deselectRow(at: indexPath, animated: true)
let alertController = UIAlertController(title: "Post Content Type", message: nil, preferredStyle: .actionSheet)
for contentType in StatusContentType.allCases {
let action = UIAlertAction(title: contentType.displayName, style: .default) { (_) in
Preferences.shared.statusContentType = contentType
self.postContentTypeLabel.text = contentType.displayName
}
if contentType == Preferences.shared.statusContentType {
action.setValue(true, forKey: "checked")
}
alertController.addAction(action)
}
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alertController, animated: true)
}
}
extension StatusContentType {
var displayName: String {
switch self {
case .plain:
return "Plain"
case .markdown:
return "Markdown"
case .html:
return "HTML"
}
}
}