VLCFileServerView.swift 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*****************************************************************************
  2. * VLCFileServerView.swift
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2018 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Author: Carola Nitz <caro # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. import Foundation
  13. @objc protocol VLCFileServerViewDelegate: NSObjectProtocol {
  14. func connectToServer()
  15. }
  16. class VLCFileServerView: UIView {
  17. @objc weak var delegate: VLCFileServerViewDelegate?
  18. lazy var connectButton: UIButton = {
  19. let connectButton = UIButton(type: .system)
  20. connectButton.setTitle(NSLocalizedString("BUTTON_CONNECT", comment: ""), for: .normal)
  21. connectButton.titleLabel?.font = UIFont.systemFont(ofSize: 17)
  22. connectButton.setTitleColor(PresentationTheme.current.colors.orangeUI, for: .normal)
  23. connectButton.translatesAutoresizingMaskIntoConstraints = false
  24. connectButton.addTarget(self, action: #selector(connectButtonDidPress), for: .touchUpInside)
  25. addSubview(connectButton)
  26. return connectButton
  27. }()
  28. lazy var textLabel: UILabel = {
  29. let textLabel = UILabel(frame: .zero)
  30. textLabel.text = NSLocalizedString("FILE_SERVER", comment: "")
  31. textLabel.font = PresentationTheme.current.font.tableHeaderFont
  32. textLabel.translatesAutoresizingMaskIntoConstraints = false
  33. addSubview(textLabel)
  34. return textLabel
  35. }()
  36. lazy var separator: UIView = {
  37. let separator = UIView(frame: .zero)
  38. separator.translatesAutoresizingMaskIntoConstraints = false
  39. addSubview(separator)
  40. return separator
  41. }()
  42. override init(frame: CGRect) {
  43. super.init(frame: frame)
  44. NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
  45. setupUI()
  46. updateTheme()
  47. }
  48. required init?(coder aDecoder: NSCoder) {
  49. fatalError("init(coder:) has not been implemented")
  50. }
  51. @objc func updateTheme() {
  52. backgroundColor = PresentationTheme.current.colors.background
  53. separator.backgroundColor = PresentationTheme.current.colors.separatorColor
  54. textLabel.textColor = PresentationTheme.current.colors.cellTextColor
  55. }
  56. func setupUI() {
  57. NSLayoutConstraint.activate([
  58. separator.leadingAnchor.constraint(equalTo: leadingAnchor),
  59. separator.trailingAnchor.constraint(equalTo: trailingAnchor),
  60. separator.topAnchor.constraint(equalTo: topAnchor),
  61. textLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 15),
  62. textLabel.trailingAnchor.constraint(lessThanOrEqualTo: connectButton.leadingAnchor),
  63. connectButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
  64. textLabel.topAnchor.constraint(equalTo: separator.bottomAnchor, constant: 15),
  65. textLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -9),
  66. connectButton.firstBaselineAnchor.constraint(equalTo: textLabel.firstBaselineAnchor),
  67. separator.heightAnchor.constraint(equalToConstant: 1)
  68. ])
  69. }
  70. @objc func connectButtonDidPress() {
  71. delegate?.connectToServer()
  72. }
  73. }