2
0

ConversationCell.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // ConversationCell.m
  3. // ShareExtension
  4. //
  5. // Created by Tom Lee on 2020/10/15.
  6. // Copyright © 2020 WildFireChat. All rights reserved.
  7. //
  8. #import "ConversationCell.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. #import "ShareUtility.h"
  11. @implementation ConversationCell
  12. - (void)awakeFromNib {
  13. [super awakeFromNib];
  14. for (UIView *view in self.subviews) {
  15. [view removeFromSuperview];
  16. }
  17. }
  18. - (void)setConversation:(SharedConversation *)sc {
  19. _conversation = sc;
  20. self.nameLabel.text = sc.title;
  21. if (sc.type == 0) { //Single_Type
  22. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:sc.portraitUrl] placeholderImage:[UIImage imageNamed:@"PersonalChat"]];
  23. } else if(sc.type == 1) { //Group_Type
  24. if (sc.portraitUrl.length) {
  25. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:sc.portraitUrl] placeholderImage:[UIImage imageNamed:@"GroupChat"]];
  26. } else {
  27. [self.portraitView sd_setImageWithURL:[ShareUtility getSavedGroupGridPortrait:sc.target] placeholderImage:[UIImage imageNamed:@"GroupChat"]];
  28. }
  29. } else if(sc.type == 3) { //Channel_Type
  30. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:sc.portraitUrl] placeholderImage:[UIImage imageNamed:@"ChannelChat"]];
  31. } else if(sc.type == 5) { //SecretChat_Type
  32. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:sc.portraitUrl] placeholderImage:[UIImage imageNamed:@"PersonalChat"]];
  33. }
  34. }
  35. - (UIImageView *)portraitView {
  36. if (!_portraitView) {
  37. _portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 40, 40)];
  38. _portraitView.layer.cornerRadius = 3.f;
  39. _portraitView.layer.masksToBounds = YES;
  40. [self.contentView addSubview:_portraitView];
  41. }
  42. return _portraitView;
  43. }
  44. - (UILabel *)nameLabel {
  45. if (!_nameLabel) {
  46. _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(56, 18, self.bounds.size.width - 56 - 16, 20)];
  47. _nameLabel.font = [UIFont systemFontOfSize:16];
  48. [self.contentView addSubview:_nameLabel];
  49. }
  50. return _nameLabel;
  51. }
  52. @end