Signal-iOS/SignalUI/Views/NonContactTableViewCell.swift
Evan Hahn 370ff654e7
Change license to AGPL
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
2022-10-13 08:25:37 -05:00

104 lines
4.3 KiB
Swift

//
// Copyright 2019 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import Foundation
import SignalMessaging
@objc
public class NonContactTableViewCell: UITableViewCell {
private let iconView = UIImageView()
private let identifierLabel = UILabel()
private let headerLabel = UILabel()
private let accessoryLabel = UILabel()
@objc
public var accessoryMessage: String?
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
OWSTableItem.configureCell(self)
let stackView = UIStackView()
stackView.spacing = ContactCellView.avatarTextHSpacing
stackView.addArrangedSubview(iconView)
contentView.addSubview(stackView)
stackView.autoPinWidthToSuperviewMargins()
stackView.autoPinHeightToSuperview(withMargin: 7)
let avatarSize = CGFloat(AvatarBuilder.smallAvatarSizePoints)
iconView.autoSetDimensions(to: CGSize(square: avatarSize))
iconView.layer.cornerRadius = avatarSize * 0.5
iconView.clipsToBounds = true
let labelStack = UIStackView()
labelStack.axis = .vertical
stackView.addArrangedSubview(labelStack)
let topSpacer = UIView.vStretchingSpacer()
labelStack.addArrangedSubview(topSpacer)
headerLabel.font = OWSTableItem.primaryLabelFont
headerLabel.textColor = Theme.primaryTextColor
labelStack.addArrangedSubview(headerLabel)
identifierLabel.font = OWSTableItem.primaryLabelFont.ows_semibold
identifierLabel.textColor = Theme.primaryTextColor
labelStack.addArrangedSubview(identifierLabel)
let bottomSpacer = UIView.vStretchingSpacer()
labelStack.addArrangedSubview(bottomSpacer)
bottomSpacer.autoMatch(.height, to: .height, of: topSpacer)
accessoryLabel.font = OWSTableItem.accessoryLabelFont.ows_semibold
accessoryLabel.textColor = Theme.middleGrayColor
accessoryLabel.textAlignment = .right
accessoryLabel.isHidden = true
stackView.addArrangedSubview(accessoryLabel)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc
public func configureWithUsername(_ username: String, hideHeaderLabel: Bool) {
iconView.setTemplateImageName("username-search-48-black", tintColor: Theme.isDarkThemeEnabled ? .ows_gray15 : .ows_gray75)
headerLabel.text = OWSLocalizedString("NON_CONTACT_TABLE_CELL_NEW_MESSAGE",
comment: "A string prompting the user to send a new mesaage to a user")
headerLabel.isHidden = hideHeaderLabel
identifierLabel.text = CommonFormats.formatUsername(username)
}
@objc
public func configureWithPhoneNumber(_ phoneNumber: String, isRegistered: Bool, hideHeaderLabel: Bool) {
identifierLabel.text = PhoneNumber.bestEffortFormatPartialUserSpecifiedText(toLookLikeAPhoneNumber: phoneNumber)
if isRegistered {
let address = SignalServiceAddress(phoneNumber: phoneNumber)
let avatar = Self.avatarBuilder.avatarImageWithSneakyTransaction(forAddress: address,
diameterPoints: 48,
localUserDisplayMode: .asUser)
iconView.image = avatar
headerLabel.text = OWSLocalizedString("NON_CONTACT_TABLE_CELL_NEW_MESSAGE",
comment: "A string prompting the user to send a new mesaage to a user")
} else {
iconView.image = UIImage(named: "invite-SMS-\(Theme.isDarkThemeEnabled ? "dark-" : "")48")
headerLabel.text = OWSLocalizedString("NON_CONTACT_TABLE_CELL_SEND_SMS",
comment: "A string asking the user if they'd like to invite a number to signal via SMS.")
}
headerLabel.isHidden = hideHeaderLabel
if let accessoryMessage = accessoryMessage, !accessoryMessage.isEmpty {
accessoryLabel.text = accessoryMessage
accessoryLabel.isHidden = false
} else {
accessoryLabel.isHidden = true
}
}
}