WFCUFriendRequestTableViewCell.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // FriendRequestTableViewCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/10/23.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUFriendRequestTableViewCell.h"
  9. #import "SDWebImage.h"
  10. #import <WFChatClient/WFCChatClient.h>
  11. #import "UIFont+YH.h"
  12. #import "UIColor+YH.h"
  13. @interface WFCUFriendRequestTableViewCell()
  14. @property (nonatomic, strong)UIImageView *portraitView;
  15. @property (nonatomic, strong)UILabel *nameLabel;
  16. @property (nonatomic, strong)UILabel *reasonLabel;
  17. @property (nonatomic, strong)UIButton *acceptBtn;
  18. @end
  19. @implementation WFCUFriendRequestTableViewCell
  20. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  21. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  22. if (self) {
  23. [self initSubViews];
  24. }
  25. return self;
  26. }
  27. - (void)awakeFromNib {
  28. [super awakeFromNib];
  29. // Initialization code
  30. [self initSubViews];
  31. }
  32. - (void)initSubViews {
  33. for (UIView *view in self.contentView.subviews) {
  34. [view removeFromSuperview];
  35. }
  36. CGFloat width = [UIScreen mainScreen].bounds.size.width;
  37. self.separatorInset = UIEdgeInsetsMake(0, 76, 0, 0);
  38. self.portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(16, 10, 40, 40)];
  39. self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(16 + 40 + 20,11, width - 128, 16)];
  40. self.nameLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:15];
  41. self.nameLabel.textColor = [UIColor colorWithHexString:@"0x1d1d1d"];
  42. self.reasonLabel = [[UILabel alloc] initWithFrame:CGRectMake(16 + 40 + 20, 11 + 15 + 6, width - 128, 14)];
  43. self.reasonLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12];
  44. self.reasonLabel.textColor = [UIColor colorWithHexString:@"0xb3b3b3"];
  45. self.acceptBtn = [[UIButton alloc] initWithFrame:CGRectMake(width - (46 + 16), 16, 46, 28)];
  46. [self.acceptBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  47. [self.acceptBtn setTitle:WFCString(@"Accept") forState:UIControlStateNormal];
  48. [self.acceptBtn setBackgroundColor:[UIColor colorWithHexString:@"0x4764DC"]];
  49. self.acceptBtn.layer.cornerRadius = 4.f;
  50. self.acceptBtn.layer.masksToBounds = YES;
  51. [self.acceptBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  52. self.acceptBtn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12];
  53. [self.contentView addSubview:self.portraitView];
  54. [self.contentView addSubview:self.nameLabel];
  55. [self.contentView addSubview:self.reasonLabel];
  56. [self.contentView addSubview:self.acceptBtn];
  57. [self.acceptBtn addTarget:self action:@selector(onAddBtn:) forControlEvents:UIControlEventTouchDown];
  58. self.selectionStyle = UITableViewCellSelectionStyleNone;
  59. }
  60. - (void)onAddBtn:(id)sender {
  61. [self.delegate onAcceptBtn:self.friendRequest.target];
  62. }
  63. - (void)setFriendRequest:(WFCCFriendRequest *)friendRequest {
  64. _friendRequest = friendRequest;
  65. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:friendRequest.target refresh:NO];
  66. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:[userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage: [UIImage imageNamed:@"PersonalChat"]];
  67. self.nameLabel.text = userInfo.displayName;
  68. self.reasonLabel.text = friendRequest.reason;
  69. BOOL expired = NO;
  70. NSDate *date = [[NSDate alloc] init];
  71. if (date.timeIntervalSince1970*1000 - friendRequest.timestamp > 7 * 24 * 60 * 60 * 1000) {
  72. expired = YES;
  73. }
  74. if (friendRequest.status == 0 && !expired) {
  75. [self.acceptBtn setTitle:WFCString(@"Accept") forState:UIControlStateNormal];
  76. [self.acceptBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  77. [self.acceptBtn setBackgroundColor:[UIColor colorWithHexString:@"0x4764DC"]];
  78. [self.acceptBtn setEnabled:YES];
  79. } else if (friendRequest.status == 1) {
  80. [self.acceptBtn setTitle:WFCString(@"Accepted") forState:UIControlStateNormal];
  81. [self.acceptBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  82. [self.acceptBtn setBackgroundColor:self.backgroundColor];
  83. [self.acceptBtn setEnabled:NO];
  84. } else if (friendRequest.status == 2) {
  85. [self.acceptBtn setTitle:WFCString(@"Rejected") forState:UIControlStateNormal];
  86. [self.acceptBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  87. [self.acceptBtn setBackgroundColor:self.backgroundColor];
  88. [self.acceptBtn setEnabled:NO];
  89. } else { //expired
  90. [self.acceptBtn setTitle:WFCString(@"Expired") forState:UIControlStateNormal];
  91. [self.acceptBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  92. [self.acceptBtn setBackgroundColor:self.backgroundColor];
  93. [self.acceptBtn setEnabled:NO];
  94. }
  95. }
  96. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  97. [super setSelected:selected animated:animated];
  98. // Configure the view for the selected state
  99. }
  100. @end