Alert validation time on tapping field checkmark, make validated field links green

This commit is contained in:
David Godfrey 2022-11-12 01:53:12 +00:00
parent c3009d6009
commit 35775a5b43
6 changed files with 95 additions and 1 deletions

View File

@ -49,6 +49,10 @@ extension ProfileFieldSection {
do {
let mastodonContent = MastodonContent(content: field.value.value, emojis: field.emojiMeta)
let metaContent = try MastodonMetaContent.convert(document: mastodonContent)
cell.valueMetaLabel.linkAttributes[.foregroundColor] = Asset.Colors.brand.color
if field.verifiedAt.value != nil {
cell.valueMetaLabel.linkAttributes[.foregroundColor] = Asset.Scene.Profile.About.bioAboutFieldValidatedLink.color
}
cell.valueMetaLabel.configure(content: metaContent)
} catch {
let content = PlaintextMetaContent(string: field.value.value)
@ -67,7 +71,10 @@ extension ProfileFieldSection {
cell.checkmark.isHidden = true
if let verifiedAt = field.verifiedAt.value {
cell.checkmark.isHidden = false
cell.checkmark.accessibilityLabel = "Ownership of this link was checked on \(verifiedAt)" // TODO: I18N / L10N
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .short
cell.checkmark.accessibilityLabel = "Ownership of this link was checked on \(formatter.string(from: verifiedAt))" // TODO: I18N / L10N
}
cell.delegate = configuration.profileFieldCollectionViewCellDelegate

View File

@ -14,6 +14,11 @@ import MastodonLocalization
protocol ProfileFieldCollectionViewCellDelegate: AnyObject {
func profileFieldCollectionViewCell(_ cell: ProfileFieldCollectionViewCell, metaLebel: MetaLabel, didSelectMeta meta: Meta)
func profileFieldCollectionViewCell(_ cell: ProfileFieldCollectionViewCell, didTapAction: ProfileFieldCollectionViewCellAction)
}
enum ProfileFieldCollectionViewCellAction {
case Checkmark
}
final class ProfileFieldCollectionViewCell: UICollectionViewCell {
@ -27,6 +32,7 @@ final class ProfileFieldCollectionViewCell: UICollectionViewCell {
let valueMetaLabel = MetaLabel(style: .profileFieldValue)
let checkmark = UIImageView(image: Asset.Editing.checkmark.image.withRenderingMode(.alwaysTemplate))
let tapGesture = UITapGestureRecognizer();
override func prepareForReuse() {
super.prepareForReuse()
@ -49,8 +55,14 @@ final class ProfileFieldCollectionViewCell: UICollectionViewCell {
extension ProfileFieldCollectionViewCell {
private func _init() {
// Setup colors
checkmark.tintColor = Asset.Scene.Profile.About.bioAboutFieldValidatedCheckmark.color;
// Setup gestures
tapGesture.addTarget(self, action: #selector(ProfileFieldCollectionViewCell.didTapCheckmark(_:)))
checkmark.addGestureRecognizer(tapGesture)
checkmark.isUserInteractionEnabled = true
// containerStackView: V - [ metaContainer | plainContainer ]
let containerStackView = UIStackView()
containerStackView.axis = .vertical
@ -87,6 +99,10 @@ extension ProfileFieldCollectionViewCell {
valueMetaLabel.linkDelegate = self
}
@objc public func didTapCheckmark(_: UITapGestureRecognizer) {
delegate?.profileFieldCollectionViewCell(self, didTapAction: .Checkmark)
}
}
// MARK: - MetaLabelDelegate

View File

@ -16,6 +16,7 @@ import MastodonCore
protocol ProfileAboutViewControllerDelegate: AnyObject {
func profileAboutViewController(_ viewController: ProfileAboutViewController, profileFieldCollectionViewCell: ProfileFieldCollectionViewCell, metaLabel: MetaLabel, didSelectMeta meta: Meta)
func profileAboutViewController(_ viewController: ProfileAboutViewController, didTapCheckmarkFor field: ProfileFieldItem.FieldValue)
}
final class ProfileAboutViewController: UIViewController {
@ -152,6 +153,21 @@ extension ProfileAboutViewController: ProfileFieldCollectionViewCellDelegate {
func profileFieldCollectionViewCell(_ cell: ProfileFieldCollectionViewCell, metaLebel: MetaLabel, didSelectMeta meta: Meta) {
delegate?.profileAboutViewController(self, profileFieldCollectionViewCell: cell, metaLabel: metaLebel, didSelectMeta: meta)
}
func profileFieldCollectionViewCell(_ cell: ProfileFieldCollectionViewCell, didTapAction action: ProfileFieldCollectionViewCellAction) {
guard let diffableDataSource = viewModel.diffableDataSource else { return }
guard let indexPath = collectionView.indexPath(for: cell) else { return }
guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return }
switch item {
case .field(let field):
delegate?.profileAboutViewController(self, didTapCheckmarkFor: field)
case .addEntry: fallthrough
case .editField: fallthrough
case .noResult:
break
}
}
}
// MARK: - ProfileFieldEditCollectionViewCellDelegate

View File

@ -854,6 +854,22 @@ extension ProfileViewController: ProfileAboutViewControllerDelegate {
) {
handleMetaPress(meta)
}
func profileAboutViewController(_ viewController: ProfileAboutViewController, didTapCheckmarkFor field: ProfileFieldItem.FieldValue) {
guard let verifiedAt = field.verifiedAt.value else {
return
}
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .short
let alert = UIAlertController(title: "Validated", message: "Ownership of this link was checked on \(formatter.string(from: verifiedAt))", preferredStyle: .alert) // TODO: I18N / L10N
alert.addAction(UIAlertAction(title: L10n.Common.Controls.Actions.ok, style: .default) { _ in
alert.dismiss(animated: true)
})
self.present(alert, animated: true)
}
}
// MARK: - MastodonMenuDelegate

View File

@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.371",
"green" : "0.565",
"red" : "0.290"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.603",
"green" : "0.742",
"red" : "0.476"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -166,6 +166,7 @@ public enum Asset {
public enum About {
public static let bioAboutFieldValidatedBackground = ColorAsset(name: "Scene/Profile/About/bio.about.field.validated.background")
public static let bioAboutFieldValidatedCheckmark = ColorAsset(name: "Scene/Profile/About/bio.about.field.validated.checkmark")
public static let bioAboutFieldValidatedLink = ColorAsset(name: "Scene/Profile/About/bio.about.field.validated.link")
}
public enum Banner {
public static let bioEditBackgroundGray = ColorAsset(name: "Scene/Profile/Banner/bio.edit.background.gray")