ContactCell.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2012-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "ContactCell.h"
  21. #import "Contact.h"
  22. #import "ContactNameLabel.h"
  23. #import "BundleUtil.h"
  24. #import "AvatarMaker.h"
  25. #import "UserSettings.h"
  26. #import "BundleUtil.h"
  27. #import "Utils.h"
  28. @implementation ContactCell
  29. - (void)awakeFromNib {
  30. [super awakeFromNib];
  31. _threemaTypeIcon.image = [Utils threemaTypeIcon];
  32. if (@available(iOS 11.0, *)) {
  33. _contactImage.accessibilityIgnoresInvertColors = true;
  34. _threemaTypeIcon.accessibilityIgnoresInvertColors = true;
  35. }
  36. }
  37. - (void)setContact:(Contact *)contact {
  38. _contact = contact;
  39. self.nameLabel.contact = contact;
  40. self.contactImage.image = [BundleUtil imageNamed:@"Unknown"];
  41. [[AvatarMaker sharedAvatarMaker] avatarForContact:contact size:40.0f masked:YES onCompletion:^(UIImage *avatarImage) {
  42. dispatch_async(dispatch_get_main_queue(), ^{
  43. self.contactImage.image = avatarImage;
  44. });
  45. }];
  46. if (contact.publicNickname && contact.publicNickname.length > 0) {
  47. NSString *nickname = contact.publicNickname;
  48. if ([contact.publicNickname isEqualToString:contact.identity] == NO) {
  49. nickname = [NSString stringWithFormat:@"%@", contact.publicNickname];
  50. } else {
  51. nickname = @" ";
  52. }
  53. self.nicknameLabel.text = nickname;
  54. } else {
  55. self.nicknameLabel.text = @" ";
  56. }
  57. self.identityLabel.text = contact.identity;
  58. self.verificationLevel.image = [contact verificationLevelImageSmall];
  59. [self updateState];
  60. self.nameLabel.highlightedTextColor = self.nameLabel.textColor;
  61. _threemaTypeIcon.hidden = [Utils hideThreemaTypeIconForContact:self.contact];
  62. }
  63. - (void)updateState {
  64. CGFloat alpha;
  65. if (_contact.isActive) {
  66. alpha = 1.0;
  67. } else {
  68. alpha = 0.5;
  69. }
  70. self.contactImage.alpha = alpha;
  71. self.verificationLevel.alpha = alpha;
  72. self.nicknameLabel.alpha = alpha;
  73. self.identityLabel.alpha = alpha;
  74. }
  75. - (NSString *)accessibilityLabel {
  76. NSMutableString *text = [NSMutableString stringWithString:_nameLabel.accessibilityLabel];
  77. [text appendFormat:@". %@.", _contact.identity];
  78. [text appendFormat:@". %@", [_contact verificationLevelAccessibilityLabel]];
  79. return text;
  80. }
  81. @end