mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2025-01-06 14:27:14 +01:00
62cc9105a9
* Fix image-editing (#1244)
Probably introduced in 76304e5
and we just missed that :)
* Removed unused property (#1244)
* Don't allow tapping on followers/followees when editing my profile
* Remove obsolete code
relationship-update on viewDidAppear is not needed anylonger as we use update user/relationship using notifications like in the good ol days
* Make relationship optional and use switch-pattern-matching for button-configuration
* Don't change relationship when relationship is updating
* [WIP] don't toggle, but just set booleans.
72 lines
2.7 KiB
Swift
72 lines
2.7 KiB
Swift
//
|
|
// ProfileRelationshipActionButton.swift
|
|
// Mastodon
|
|
//
|
|
// Created by MainasuK Cirno on 2021-3-30.
|
|
//
|
|
|
|
import UIKit
|
|
import MastodonAsset
|
|
import MastodonSDK
|
|
import MastodonLocalization
|
|
|
|
public final class ProfileRelationshipActionButton: UIButton {
|
|
public func configure(relationship: Mastodon.Entity.Relationship?, between account: Mastodon.Entity.Account, and me: Mastodon.Entity.Account, isEditing: Bool = false, isUpdating: Bool = false) {
|
|
|
|
let isMyself = (account == me)
|
|
|
|
var configuration = UIButton.Configuration.filled()
|
|
|
|
configuration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 4, bottom: 0, trailing: 4)
|
|
configuration.baseBackgroundColor = Asset.Scene.Profile.RelationshipButton.background.color
|
|
configuration.activityIndicatorColorTransformer = UIConfigurationColorTransformer({ _ in return Asset.Colors.Label.primaryReverse.color })
|
|
configuration.background.cornerRadius = 10
|
|
|
|
let title: String
|
|
|
|
switch (isMyself, isUpdating, relationship) {
|
|
case (true, _, _):
|
|
if isEditing {
|
|
title = L10n.Common.Controls.Actions.save
|
|
} else {
|
|
title = L10n.Common.Controls.Friendship.editInfo
|
|
}
|
|
configuration.showsActivityIndicator = false
|
|
case (_, true, _):
|
|
title = ""
|
|
configuration.showsActivityIndicator = true
|
|
case (false, false, .some(let relationship)):
|
|
configuration.showsActivityIndicator = false
|
|
|
|
if relationship.blocking {
|
|
title = L10n.Common.Controls.Friendship.blocked
|
|
} else if relationship.domainBlocking {
|
|
title = L10n.Common.Controls.Friendship.domainBlocked
|
|
} else if relationship.requested {
|
|
title = L10n.Common.Controls.Friendship.pending
|
|
} else if relationship.muting {
|
|
title = L10n.Common.Controls.Friendship.muted
|
|
} else if relationship.following {
|
|
title = L10n.Common.Controls.Friendship.following
|
|
} else if account.locked {
|
|
title = L10n.Common.Controls.Friendship.request
|
|
} else {
|
|
title = L10n.Common.Controls.Friendship.follow
|
|
}
|
|
case (_, _, nil):
|
|
title = ""
|
|
configuration.showsActivityIndicator = false
|
|
}
|
|
|
|
configuration.attributedTitle = AttributedString(
|
|
title,
|
|
attributes: AttributeContainer([
|
|
.font: UIFont.systemFont(ofSize: 17, weight: .semibold),
|
|
.foregroundColor: Asset.Colors.Label.primaryReverse.color
|
|
])
|
|
)
|
|
|
|
self.configuration = configuration
|
|
}
|
|
}
|