ContactsTableViewCell.m 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. #import "ContactsTableViewCell.h"
  6. #import "NCAppBranding.h"
  7. #import "NextcloudTalk-Swift.h"
  8. NSString *const kContactCellIdentifier = @"ContactCellIdentifier";
  9. NSString *const kContactsTableCellNibName = @"ContactsTableViewCell";
  10. CGFloat const kContactsTableCellHeight = 72.0f;
  11. CGFloat const kContactsTableCellTitleFontSize = 17.0f;
  12. @implementation ContactsTableViewCell
  13. - (void)awakeFromNib {
  14. [super awakeFromNib];
  15. self.contactImage.layer.cornerRadius = 24.0;
  16. self.contactImage.layer.masksToBounds = YES;
  17. self.contactImage.backgroundColor = [NCAppBranding placeholderColor];
  18. self.contactImage.contentMode = UIViewContentModeScaleToFill;
  19. }
  20. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  21. [super setSelected:selected animated:animated];
  22. // Configure the view for the selected state
  23. }
  24. - (void)prepareForReuse
  25. {
  26. [super prepareForReuse];
  27. // Fix problem of rendering downloaded image in a reused cell
  28. [self.contactImage cancelCurrentRequest];
  29. self.contactImage.image = nil;
  30. self.userStatusImageView.image = nil;
  31. self.userStatusImageView.backgroundColor = [UIColor clearColor];
  32. self.userStatusMessageLabel.text = @"";
  33. self.userStatusMessageLabel.hidden = YES;
  34. self.labelTitle.text = @"";
  35. self.labelTitle.textColor = [UIColor labelColor];
  36. self.labelTitle.font = [UIFont systemFontOfSize:kContactsTableCellTitleFontSize weight:UIFontWeightRegular];
  37. }
  38. - (void)setUserStatus:(NSString *)userStatus
  39. {
  40. UIImage *statusImage = nil;
  41. if ([userStatus isEqualToString:@"online"]) {
  42. statusImage = [UIImage imageNamed:@"user-status-online"];
  43. } else if ([userStatus isEqualToString:@"away"]) {
  44. statusImage = [UIImage imageNamed:@"user-status-away"];
  45. } else if ([userStatus isEqualToString:@"dnd"]) {
  46. statusImage = [UIImage imageNamed:@"user-status-dnd"];
  47. }
  48. if (statusImage) {
  49. [self setUserStatusIconWithImage:statusImage];
  50. }
  51. }
  52. - (void)setUserStatusIconWithImage:(UIImage *)image
  53. {
  54. [_userStatusImageView setImage:image];
  55. _userStatusImageView.contentMode = UIViewContentModeCenter;
  56. _userStatusImageView.layer.cornerRadius = 10;
  57. _userStatusImageView.clipsToBounds = YES;
  58. // When a background color is set directly to the cell it seems that there is no background configuration.
  59. _userStatusImageView.backgroundColor = (self.backgroundColor) ? self.backgroundColor : [[self backgroundConfiguration] backgroundColor];
  60. }
  61. - (void)setUserStatusMessage:(NSString *)userStatusMessage withIcon:(NSString *)userStatusIcon
  62. {
  63. if (userStatusMessage && ![userStatusMessage isEqualToString:@""]) {
  64. self.userStatusMessageLabel.text = userStatusMessage;
  65. if (userStatusIcon && ![userStatusIcon isEqualToString:@""]) {
  66. self.userStatusMessageLabel.text = [NSString stringWithFormat:@"%@ %@", userStatusIcon, userStatusMessage];
  67. }
  68. self.userStatusMessageLabel.hidden = NO;
  69. } else {
  70. self.userStatusMessageLabel.hidden = YES;
  71. }
  72. }
  73. @end