PickerContactCell.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2015-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 "PickerContactCell.h"
  21. #import "AvatarMaker.h"
  22. #import "BundleUtil.h"
  23. #import "UserSettings.h"
  24. #import "Utils.h"
  25. @implementation PickerContactCell
  26. - (void)awakeFromNib {
  27. [super awakeFromNib];
  28. _nameLabel.font = [UIFont boldSystemFontOfSize: _nameLabel.font.pointSize];
  29. _threemaTypeIcon.image = [Utils threemaTypeIcon];
  30. }
  31. - (void)setContact:(Contact *)contact {
  32. if (_contact != contact) {
  33. _contact = contact;
  34. _nameLabel.contact = contact;
  35. _identityLabel.text = contact.identity;
  36. _verificationLevelImage.image = [contact verificationLevelImageSmall];
  37. _avatarImage.image = [BundleUtil imageNamed:@"Unknown"];
  38. [[AvatarMaker sharedAvatarMaker] avatarForContact:contact size:_avatarImage.frame.size.width masked:NO onCompletion:^(UIImage *avatarImage) {
  39. dispatch_async(dispatch_get_main_queue(), ^{
  40. _avatarImage.image = avatarImage;
  41. });
  42. }];
  43. _avatarImage.layer.cornerRadius = _avatarImage.frame.size.height /2;
  44. _avatarImage.layer.masksToBounds = YES;
  45. [self updateState];
  46. _nameLabel.highlightedTextColor = _nameLabel.textColor;
  47. _threemaTypeIcon.hidden = [Utils hideThreemaTypeIconForContact:self.contact];
  48. }
  49. }
  50. - (void)updateState {
  51. if ([_contact isActive]) {
  52. _verificationLevelImage.alpha = 1.0;
  53. _avatarImage.alpha = 1.0;
  54. _threemaTypeIcon.alpha = 1.0;
  55. self.userInteractionEnabled = YES;
  56. } else {
  57. _verificationLevelImage.alpha = 0.5;
  58. _avatarImage.alpha = 0.5;
  59. _threemaTypeIcon.alpha = 0.5;
  60. self.userInteractionEnabled = YES;
  61. }
  62. }
  63. @end