GroupMemberCell.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2013-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 "GroupMemberCell.h"
  21. #import "Contact.h"
  22. #import <QuartzCore/QuartzCore.h>
  23. #import "AvatarMaker.h"
  24. #import "MyIdentityStore.h"
  25. #import "Utils.h"
  26. #import "BundleUtil.h"
  27. @implementation GroupMemberCell
  28. @synthesize contact;
  29. - (void)awakeFromNib {
  30. [super awakeFromNib];
  31. _threemaTypeIcon.image = [Utils threemaTypeIcon];
  32. if (@available(iOS 11.0, *)) {
  33. _threemaTypeIcon.accessibilityIgnoresInvertColors = true;
  34. _contactImage.accessibilityIgnoresInvertColors = true;
  35. }
  36. }
  37. - (void)setContact:(Contact *)newContact {
  38. contact = newContact;
  39. UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
  40. CGFloat size = fontDescriptor.pointSize;
  41. _nameLabel.font = [UIFont boldSystemFontOfSize:size];
  42. self.nameLabel.contact = contact;
  43. self.contactImage.layer.masksToBounds = YES;
  44. self.contactImage.layer.cornerRadius = 6.0f;
  45. if (_isSelfMember) {
  46. NSMutableDictionary *profilePicture = [[MyIdentityStore sharedMyIdentityStore] profilePicture];
  47. UIImage *image = [UIImage imageWithData:profilePicture[@"ProfilePicture"]];
  48. self.contactImage.image = [[AvatarMaker sharedAvatarMaker] maskedProfilePicture:image size:self.contactImage.frame.size.width];
  49. } else {
  50. self.contactImage.image = [BundleUtil imageNamed:@"Unknown"];
  51. [[AvatarMaker sharedAvatarMaker] avatarForContact:contact size:self.contactImage.frame.size.width masked:YES onCompletion:^(UIImage *avatarImage) {
  52. dispatch_async(dispatch_get_main_queue(), ^{
  53. self.contactImage.image = avatarImage;
  54. });
  55. }];
  56. }
  57. self.contactImage.alpha = (contact.state.intValue == kStateInactive) ? 0.5 : 1.0;
  58. [self updateThreemaTypeIcon];
  59. }
  60. - (void)updateThreemaTypeIcon {
  61. if (_isSelfMember) {
  62. _threemaTypeIcon.hidden = YES;
  63. } else {
  64. _threemaTypeIcon.hidden = [Utils hideThreemaTypeIconForContact:contact];
  65. }
  66. }
  67. @end