Change license to AGPL
This commit:
- Updates the `LICENSE` file
- Start every file with something like:
// Copyright YEAR_FIRST_PUBLISHED Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
---
First, I removed existing license headers with this Ruby 3.1.2 script:
require 'set'
EXTENSIONS_TO_CHECK = Set['.h', '.hpp', '.cpp', '.m', '.mm', '.pch', '.swift']
same = 0
different = 0
all_files = `git ls-files`.lines.map { |line| line.strip }
all_files.each do |relative_path|
if relative_path == 'Pods'
next
end
unless EXTENSIONS_TO_CHECK.include? File.extname(relative_path)
next
end
path = File.expand_path(relative_path)
contents = File.read(path)
new_contents = contents.sub(/\/\/\n\/\/ Copyright .*\n\/\/\n\n/, '')
if contents == new_contents
same += 1
else
different += 1
end
File.write(path, new_contents)
end
puts "updated #{different} file(s), left #{same} untouched"
I'm sure this script could be improved, but it worked well enough.
Then, I created `Scripts/lint/lint-license-headers` and ran it to auto-
fix a lot of files. This changed the mode of some files, but I think
that's actually desirable. For example,
`SignalServiceKit/src/Util/AppContext.m` previously had a mode of
`0755/-rwxr-xr-x`, and it's now `0644/-rw-r--r--`.
Then I fixed some stragglers and updated the precommit script.
See [a similar change in the Desktop app][0].
[0]: 8bfaf598af
118 lines
4.3 KiB
Swift
118 lines
4.3 KiB
Swift
//
|
|
// Copyright 2018 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import Foundation
|
|
|
|
@objc
|
|
public protocol DisappearingTimerConfigurationViewDelegate: AnyObject {
|
|
func disappearingTimerConfigurationViewWasTapped(_ disappearingTimerView: DisappearingTimerConfigurationView)
|
|
}
|
|
|
|
// DisappearingTimerConfigurationView shows a timer icon and a short label showing the duration
|
|
// of disappearing messages for a thread.
|
|
//
|
|
// If you assign a delegate, it behaves like a button.
|
|
@objc
|
|
public class DisappearingTimerConfigurationView: UIView {
|
|
|
|
@objc
|
|
public weak var delegate: DisappearingTimerConfigurationViewDelegate? {
|
|
didSet {
|
|
// gesture recognizer is only enabled when a delegate is assigned.
|
|
// This lets us use this view as either an interactive button
|
|
// or as a non-interactive status indicator
|
|
pressGesture.isEnabled = delegate != nil
|
|
}
|
|
}
|
|
|
|
private let imageView: UIImageView
|
|
private let label: UILabel
|
|
private var pressGesture: UILongPressGestureRecognizer!
|
|
|
|
public required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
@objc
|
|
public init(durationSeconds: UInt32) {
|
|
self.imageView = UIImageView(image: Theme.iconImage(.settingsTimer))
|
|
imageView.contentMode = .scaleAspectFit
|
|
|
|
self.label = UILabel()
|
|
label.text = NSString.formatDurationSeconds(durationSeconds, useShortFormat: true)
|
|
label.font = UIFont.systemFont(ofSize: 10)
|
|
label.textAlignment = .center
|
|
label.minimumScaleFactor = 0.5
|
|
|
|
super.init(frame: CGRect.zero)
|
|
|
|
applyTintColor(self.tintColor)
|
|
|
|
// Gesture, simulating button touch up inside
|
|
let gesture = UILongPressGestureRecognizer(target: self, action: #selector(pressHandler))
|
|
gesture.minimumPressDuration = 0
|
|
self.pressGesture = gesture
|
|
self.addGestureRecognizer(pressGesture)
|
|
|
|
// disable gesture recognizer until a delegate is assigned
|
|
// this lets us use the UI as either an interactive button
|
|
// or as a non-interactive status indicator
|
|
pressGesture.isEnabled = false
|
|
|
|
// Accessibility
|
|
self.accessibilityLabel = OWSLocalizedString("DISAPPEARING_MESSAGES_LABEL", comment: "Accessibility label for disappearing messages")
|
|
let hintFormatString = OWSLocalizedString("DISAPPEARING_MESSAGES_HINT", comment: "Accessibility hint that contains current timeout information")
|
|
let durationString = String.formatDurationLossless(durationSeconds: durationSeconds)
|
|
self.accessibilityHint = String(format: hintFormatString, durationString)
|
|
|
|
// Layout
|
|
self.addSubview(imageView)
|
|
self.addSubview(label)
|
|
|
|
let kHorizontalPadding: CGFloat = 4
|
|
let kVerticalPadding: CGFloat = 6
|
|
imageView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: kVerticalPadding, left: kHorizontalPadding, bottom: 0, right: kHorizontalPadding), excludingEdge: .bottom)
|
|
label.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 0, left: kHorizontalPadding, bottom: kVerticalPadding, right: kHorizontalPadding), excludingEdge: .top)
|
|
label.autoPinEdge(.top, to: .bottom, of: imageView)
|
|
}
|
|
|
|
@objc
|
|
func pressHandler(_ gestureRecognizer: UILongPressGestureRecognizer) {
|
|
Logger.verbose("")
|
|
|
|
// handle touch down and touch up events separately
|
|
if gestureRecognizer.state == .began {
|
|
applyTintColor(UIColor.gray)
|
|
} else if gestureRecognizer.state == .ended {
|
|
applyTintColor(self.tintColor)
|
|
|
|
let location = gestureRecognizer.location(in: self)
|
|
let isTouchUpInside = self.bounds.contains(location)
|
|
|
|
if isTouchUpInside {
|
|
// Similar to a UIButton's touch-up-inside
|
|
self.delegate?.disappearingTimerConfigurationViewWasTapped(self)
|
|
} else {
|
|
// Similar to a UIButton's touch-up-outside
|
|
|
|
// cancel gesture
|
|
gestureRecognizer.isEnabled = false
|
|
gestureRecognizer.isEnabled = true
|
|
}
|
|
}
|
|
}
|
|
|
|
override public var tintColor: UIColor! {
|
|
didSet {
|
|
applyTintColor(tintColor)
|
|
}
|
|
}
|
|
|
|
private func applyTintColor(_ color: UIColor) {
|
|
imageView.tintColor = color
|
|
label.textColor = color
|
|
}
|
|
}
|