mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 15:09:31 +02:00
MESSENGER-5226 us12 federation in timeline header
This commit is contained in:
@@ -54,6 +54,8 @@
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *badgeImageViewLeadingToPictureViewConstraint;
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *badgeImageViewCenterYToDisplayNameConstraint;
|
||||
|
||||
// bwi: #5226 us12 add federation icon to navigationViewTitle
|
||||
@property(nonatomic) UIImageView *pillImageView;
|
||||
/**
|
||||
The room preview data may be used when mxRoom instance is not available
|
||||
*/
|
||||
|
||||
@@ -50,6 +50,20 @@
|
||||
self.dotView.layer.masksToBounds = YES;
|
||||
self.dotView.layer.cornerRadius = CGRectGetMidX(self.dotView.bounds);
|
||||
}
|
||||
|
||||
// bwi: #5226 us12 add federation icon to navigationViewTitle
|
||||
if (BWIBuildSettings.shared.isFederationEnabled)
|
||||
{
|
||||
// add imageview for the pill if it doesn't exist
|
||||
if (self.pillImageView == nil)
|
||||
{
|
||||
UIImageView *imageView = [FederationIconHelper.shared getFederatedIconImageViewWithAvatarFrame:self.pictureView.frame];
|
||||
self.pillImageView = imageView;
|
||||
self.pillImageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
[self addSubview:imageView];
|
||||
}
|
||||
self.pillImageView.image = FederationIconHelper.shared.federationBadgeImage;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
@@ -57,7 +71,13 @@
|
||||
[super layoutSubviews];
|
||||
|
||||
self.pictureView.layer.cornerRadius = self.pictureView.bounds.size.width / 2.;
|
||||
|
||||
|
||||
// bwi: #5226 us12 add federation icon to navigationViewTitle
|
||||
if (self.pillImageView)
|
||||
{
|
||||
self.pillImageView.image = FederationIconHelper.shared.federationBadgeImage;
|
||||
}
|
||||
|
||||
if (self.superview)
|
||||
{
|
||||
// Force the title view layout by adding 2 new constraints on the UINavigationBarContentView instance.
|
||||
@@ -122,6 +142,41 @@
|
||||
}
|
||||
|
||||
self.displayNameTextField.text = self.mxRoom.summary.displayName;
|
||||
|
||||
// bwi: #5226 us12 add federation icons to navigationViewTitle
|
||||
if (self.pillImageView)
|
||||
{
|
||||
if ([self.mxRoom isDirect])
|
||||
{
|
||||
if ([self.mxRoom isDMFederated])
|
||||
{
|
||||
self.pillImageView.hidden = false;
|
||||
self.displayNameTextField.rightViewMode = UITextFieldViewModeAlways;
|
||||
self.displayNameTextField.rightView = [FederationIconHelper.shared getRoomFederationPillViewWithTextView:self.displayNameTextField];
|
||||
}
|
||||
else
|
||||
{
|
||||
self.pillImageView.hidden = true;
|
||||
self.displayNameTextField.rightViewMode = UITextFieldViewModeNever;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([self.mxRoom isRoomFederated])
|
||||
{
|
||||
self.pillImageView.hidden = false;
|
||||
self.displayNameTextField.rightViewMode = UITextFieldViewModeAlways;
|
||||
self.displayNameTextField.rightView = [FederationIconHelper.shared getRoomFederationPillViewWithTextView:self.displayNameTextField];
|
||||
}
|
||||
else
|
||||
{
|
||||
self.pillImageView.hidden = true;
|
||||
self.displayNameTextField.rightViewMode = UITextFieldViewModeNever;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!self.displayNameTextField.text.length)
|
||||
{
|
||||
self.displayNameTextField.text = [VectorL10n roomDisplaynameEmptyRoom];
|
||||
|
||||
@@ -19,6 +19,8 @@ import Foundation
|
||||
@objc class FederationIconHelper: NSObject {
|
||||
@objc static let shared = FederationIconHelper()
|
||||
|
||||
// MARK: Federation pill with text
|
||||
|
||||
// bwi: 5216 and 5204 - federation
|
||||
@objc func roomNameWithFederationPill(roomDisplayName: String?, font: UIFont) -> NSAttributedString? {
|
||||
guard let roomDisplayName = roomDisplayName else {
|
||||
@@ -27,6 +29,43 @@ import Foundation
|
||||
|
||||
let attributedString = NSMutableAttributedString(string: roomDisplayName + " ")
|
||||
|
||||
// get the correct asset for the current theme and language
|
||||
let image: UIImage
|
||||
image = getFederationPillImage()
|
||||
|
||||
// append the pill to the room name
|
||||
if image.size.width > 0.0 && image.size.height > 0.0 {
|
||||
let attachment = NSTextAttachment()
|
||||
attachment.image = image
|
||||
attachment.bounds = calculateFederationPillBounds(image:image, pillHeight: CGFloat(20.0), font: font)
|
||||
attributedString.append(NSAttributedString(attachment: attachment))
|
||||
}
|
||||
|
||||
return attributedString
|
||||
}
|
||||
|
||||
// #5226 us12 add federation pill to navigationViewTitle
|
||||
@objc func getRoomFederationPillView(textView: UITextField) -> UIView {
|
||||
if let font = textView.font {
|
||||
let image = getFederationPillImage()
|
||||
if image.size.width > 0.0 && image.size.height > 0.0 {
|
||||
let imageView = UIImageView(frame: calculateFederationPillBounds(image: image, pillHeight: textView.frame.size.height, font: font))
|
||||
imageView.contentMode = .center
|
||||
imageView.clipsToBounds = true
|
||||
let view = UIView()
|
||||
view.bounds = calculateFederationPillBounds(image: image, pillHeight: textView.frame.size.height, font: font)
|
||||
view.addSubview(imageView)
|
||||
imageView.image = image
|
||||
return view
|
||||
} else {
|
||||
return UIView()
|
||||
}
|
||||
} else {
|
||||
return UIView()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func getFederationPillImage() -> UIImage {
|
||||
// get the correct asset for the current theme and language
|
||||
let image: UIImage
|
||||
if Locale.current.languageCode == "de" {
|
||||
@@ -35,21 +74,18 @@ import Foundation
|
||||
image = ThemeService.shared().isCurrentThemeDark() ? Asset.Images.federationPillEnBumDark.image : Asset.Images.federationPillEnBumLight.image
|
||||
}
|
||||
|
||||
// append the pill to the room name
|
||||
if image.size.width > 0.0 && image.size.height > 0.0 {
|
||||
let aspectRatio = image.size.width / image.size.height
|
||||
let pillHeight: CGFloat = 20.0
|
||||
let offset = 0.5 * (font.capHeight - pillHeight)
|
||||
|
||||
let attachment = NSTextAttachment()
|
||||
attachment.image = image
|
||||
attachment.bounds = CGRect(x: 0, y: offset, width: pillHeight * aspectRatio, height: pillHeight)
|
||||
attributedString.append(NSAttributedString(attachment: attachment))
|
||||
}
|
||||
|
||||
return attributedString
|
||||
return image
|
||||
}
|
||||
|
||||
private func calculateFederationPillBounds(image: UIImage, pillHeight: CGFloat, font: UIFont) -> CGRect
|
||||
{
|
||||
let aspectRatio = image.size.width / image.size.height
|
||||
let offset = 0.5 * (font.capHeight - pillHeight)
|
||||
return CGRect(x: 0, y: offset, width: pillHeight * aspectRatio, height: pillHeight)
|
||||
}
|
||||
|
||||
// MARK: Federation icon
|
||||
|
||||
// Calculate the size and position of the federated pill for an avatar ImageView
|
||||
@objc func getFederatedIconImageView(avatarFrame: CGRect) -> UIImageView {
|
||||
// because of svg we use fixed values here for the raw image size
|
||||
|
||||
Reference in New Issue
Block a user