QuotedMessageView.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. #import "QuotedMessageView.h"
  6. #import "NCAppBranding.h"
  7. #import "NextcloudTalk-Swift.h"
  8. @interface QuotedMessageView ()
  9. @property (nonatomic, strong) UIView *quoteView;
  10. @end
  11. @implementation QuotedMessageView
  12. - (instancetype)init
  13. {
  14. self = [super initWithFrame:CGRectMake(0, 0, 50, 50)];
  15. if (self) {
  16. [self configureSubviews];
  17. }
  18. return self;
  19. }
  20. - (void)configureSubviews
  21. {
  22. self.backgroundColor = [NCAppBranding backgroundColor];
  23. self.layer.borderColor = [NCAppBranding placeholderColor].CGColor;
  24. self.layer.borderWidth = 1.0;
  25. self.layer.cornerRadius = 8.0;
  26. [self addSubview:self.quoteView];
  27. [self addSubview:self.actorLabel];
  28. [self addSubview:self.messageLabel];
  29. [self addSubview:self.avatarView];
  30. NSDictionary *views = @{@"quoteView": self.quoteView,
  31. @"actorLabel": self.actorLabel,
  32. @"messageLabel": self.messageLabel,
  33. @"avatarView": self.avatarView
  34. };
  35. NSDictionary *metrics = @{
  36. @"padding": @8,
  37. @"avatarSize": @20,
  38. };
  39. [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-padding-[quoteView(padding)]-[avatarView(avatarSize)]-padding-[actorLabel]-|" options:0 metrics:metrics views:views]];
  40. [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-padding-[quoteView(padding)]-[messageLabel]-|" options:0 metrics:metrics views:views]];
  41. [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-padding-[quoteView(44)]-padding-|" options:0 metrics:metrics views:views]];
  42. [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-padding-[actorLabel(20)]-4-[messageLabel(20)]-padding-|" options:0 metrics:metrics views:views]];
  43. [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-padding-[avatarView(20)]-4-[messageLabel(20)]-padding-|" options:0 metrics:metrics views:views]];
  44. }
  45. #pragma mark - Getters
  46. - (UIView *)quoteView
  47. {
  48. if (!_quoteView) {
  49. _quoteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 4, 60)];
  50. _quoteView.translatesAutoresizingMaskIntoConstraints = NO;
  51. _quoteView.backgroundColor = [UIColor systemFillColor];
  52. _quoteView.layer.cornerRadius = 4.0;
  53. }
  54. return _quoteView;
  55. }
  56. - (UILabel *)actorLabel
  57. {
  58. if (!_actorLabel) {
  59. _actorLabel = [UILabel new];
  60. _actorLabel.translatesAutoresizingMaskIntoConstraints = NO;
  61. _actorLabel.backgroundColor = [UIColor clearColor];
  62. _actorLabel.userInteractionEnabled = NO;
  63. _actorLabel.numberOfLines = 1;
  64. _actorLabel.contentMode = UIViewContentModeLeft;
  65. _actorLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
  66. _actorLabel.textColor = [UIColor secondaryLabelColor];
  67. }
  68. return _actorLabel;
  69. }
  70. - (UILabel *)messageLabel
  71. {
  72. if (!_messageLabel) {
  73. _messageLabel = [UILabel new];
  74. _messageLabel.translatesAutoresizingMaskIntoConstraints = NO;
  75. _messageLabel.backgroundColor = [UIColor clearColor];
  76. _messageLabel.userInteractionEnabled = NO;
  77. _messageLabel.numberOfLines = 0;
  78. _messageLabel.contentMode = UIViewContentModeLeft;
  79. _messageLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
  80. _messageLabel.textColor = [NCAppBranding chatForegroundColor];
  81. }
  82. return _messageLabel;
  83. }
  84. - (AvatarImageView *)avatarView
  85. {
  86. if (!_avatarView) {
  87. _avatarView = [[AvatarImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
  88. _avatarView.translatesAutoresizingMaskIntoConstraints = NO;
  89. _avatarView.layer.cornerRadius = 10;
  90. _avatarView.layer.masksToBounds = YES;
  91. }
  92. return _avatarView;
  93. }
  94. #pragma mark - Setters
  95. - (void)setHighlighted:(BOOL)highlighted
  96. {
  97. _highlighted = highlighted;
  98. if (_highlighted) {
  99. _quoteView.backgroundColor = [NCAppBranding themeColor];
  100. } else {
  101. _quoteView.backgroundColor = [UIColor systemFillColor];
  102. }
  103. }
  104. @end