79 lines
2.8 KiB
Swift
79 lines
2.8 KiB
Swift
//
|
|
// AlertsNoLocationTableViewCell.swift
|
|
// Earthquake Network
|
|
//
|
|
// Created by Busi Andrea on 06/10/2020.
|
|
// Copyright © 2020 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import CoreLocation
|
|
|
|
@objc
|
|
class AlertsNoLocationTableViewCell: EQNBaseContainerTableViewCell {
|
|
|
|
override var isHeaderVisible: Bool { false }
|
|
|
|
// MARK: - UI
|
|
|
|
private lazy var messageLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
label.numberOfLines = 0
|
|
label.textColor = AppTheme.Colors.red
|
|
label.font = .preferredFont(forTextStyle: .body)
|
|
return label
|
|
}()
|
|
|
|
private lazy var actionButton: UIButton = {
|
|
let button = EQNRoundedButton.make(title: NSLocalizedString("permission_location_no_background_solve", comment: ""), target: self, action: #selector(solveTapped(_:)))
|
|
return button
|
|
}()
|
|
|
|
// MARK: - Internal
|
|
|
|
override func setupUI() {
|
|
super.setupUI()
|
|
|
|
containerView.addSubview(messageLabel)
|
|
containerView.addSubview(actionButton)
|
|
|
|
messageLabel.topAnchor.constraint(equalTo: topView.bottomAnchor, constant: .cardVerticalSpacing).isActive = true
|
|
messageLabel.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: .cardPadding).isActive = true
|
|
messageLabel.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: .cardPadding.negative).isActive = true
|
|
|
|
actionButton.heightAnchor.constraint(greaterThanOrEqualToConstant: 40.0).isActive = true
|
|
actionButton.topAnchor.constraint(equalTo: messageLabel.bottomAnchor, constant: .cardPadding).isActive = true
|
|
actionButton.leadingAnchor.constraint(equalTo: messageLabel.leadingAnchor).isActive = true
|
|
actionButton.trailingAnchor.constraint(equalTo: messageLabel.trailingAnchor).isActive = true
|
|
actionButton.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: .cardPadding.negative).isActive = true
|
|
}
|
|
|
|
override func updateUI() {
|
|
super.updateUI()
|
|
|
|
actionButton.backgroundColor = AppTheme.Colors.lightGray
|
|
}
|
|
|
|
// MARK: - Public
|
|
|
|
@objc
|
|
func update(with status: CLAuthorizationStatus) {
|
|
messageLabel.text = switch status {
|
|
case .authorizedAlways: ""
|
|
case .authorizedWhenInUse: NSLocalizedString("permission_location_no_background", comment: "")
|
|
default: NSLocalizedString("permission_location_no", comment: "")
|
|
}
|
|
}
|
|
|
|
// MARK: - Actions
|
|
|
|
@objc private func solveTapped(_ sender: UIButton) {
|
|
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
|
|
return
|
|
}
|
|
|
|
UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)
|
|
}
|
|
}
|