JXFriendCell.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. //
  2. // JXFriendCell.m
  3. //
  4. // Created by flyeagleTang on 14-4-3.
  5. // Copyright (c) 2014年 Reese. All rights reserved.
  6. //
  7. #import "JXFriendCell.h"
  8. #import "JXLabel.h"
  9. #import "JXImageView.h"
  10. #import "AppDelegate.h"
  11. #import "JXFriendObject.h"
  12. #import "UIFactory.h"
  13. @implementation JXFriendCell
  14. @synthesize title,subtitle,rightTitle,bottomTitle,headImage,bage,user,target;
  15. + (instancetype)cellWithTableView:(UITableView *)tableView
  16. {
  17. static NSString *ID = @"JXFriendCell";
  18. JXFriendCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  19. if (!cell) {
  20. cell = [[JXFriendCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
  21. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  22. //cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
  23. }
  24. return cell;
  25. }
  26. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  27. {
  28. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  29. if(self){
  30. self.selectionStyle = UITableViewCellSelectionStyleNone;
  31. UIFont* f0 = g_factory.font14;
  32. UIFont* f1 = g_factory.font16;
  33. //时间
  34. _timeLab = [[JXLabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 115-15, 26, 115, 13)];
  35. _timeLab.textColor = HEXCOLOR(0x999999);
  36. _timeLab.userInteractionEnabled = NO;
  37. _timeLab.backgroundColor = [UIColor clearColor];
  38. _timeLab.textAlignment = NSTextAlignmentRight;
  39. _timeLab.font = SYSFONT(13);
  40. _timeLab.hidden = YES;
  41. // [self.contentView addSubview:_timeLab];
  42. [_timeLab setText:self.bottomTitle];
  43. _btn1 = [[UIButton alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH -64-15, 29, 64, 27)];
  44. _btn1.titleLabel.font = SYSFONT(13);
  45. [_btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  46. //_btn1.layer.masksToBounds = YES;
  47. // _btn1.layer.cornerRadius = 4.f;
  48. _btn1.backgroundColor = [UIColor whiteColor];
  49. _btn1.tag = self.tag;
  50. [self addSubview:_btn1];
  51. _btn2 = [[UIButton alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-64-15, 26, 64, 33)];
  52. _btn2.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  53. [_btn2 setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  54. _btn2.backgroundColor = [UIColor whiteColor];
  55. _btn2.layer.borderWidth = .5;
  56. _btn2.layer.borderColor = [THEMECOLOR CGColor];
  57. _btn2.layer.cornerRadius = 4.0;
  58. _btn2.layer.masksToBounds = YES;
  59. _btn2.tag = self.tag;
  60. //[self addSubview:_btn2];
  61. int n = 84;
  62. UIView* v = [[UIView alloc]initWithFrame:CGRectMake(0,0, JX_SCREEN_WIDTH, n)];
  63. v.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
  64. self.selectedBackgroundView = v;
  65. _lineView = [[UIView alloc]initWithFrame:CGRectMake(0,n-LINE_WH,JX_SCREEN_WIDTH,LINE_WH)];
  66. _lineView.backgroundColor = THE_LINE_COLOR;
  67. [self.contentView addSubview:_lineView];
  68. JXImageView* iv;
  69. iv = [[JXImageView alloc]init];
  70. iv.userInteractionEnabled = NO;
  71. iv.delegate = self;
  72. iv.didTouch = @selector(actionUser);
  73. iv.frame = CGRectMake(15,20,44,44);
  74. iv.layer.cornerRadius = iv.frame.size.width / 2;
  75. iv.layer.masksToBounds = YES;
  76. [self.contentView addSubview:iv];
  77. [g_server getHeadImageSmall:user.userId userName:user.userNickname imageView:iv];
  78. JXLabel* lb;
  79. //名字
  80. lb = [[JXLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(iv.frame)+14, 25, JX_SCREEN_WIDTH - 115 -CGRectGetMaxX(iv.frame)-14, 15)];
  81. lb.textColor = [UIColor blackColor];
  82. lb.userInteractionEnabled = NO;
  83. lb.font =[UIFont systemFontOfSize:16 weight:(UIFontWeightMedium)];//SYSFONT(15);
  84. lb.backgroundColor = [UIColor clearColor];
  85. lb.font = f1;
  86. [self.contentView addSubview:lb];
  87. [lb setText:self.title];
  88. //聊天消息
  89. lb = [[JXLabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(iv.frame)+14, n-13-25, JX_SCREEN_WIDTH-86-50, 13)];
  90. lb.textColor = [UIColor lightGrayColor];
  91. lb.userInteractionEnabled = NO;
  92. lb.font = SYSFONT(13);
  93. lb.backgroundColor = [UIColor clearColor];
  94. lb.font = f0;
  95. [self.contentView addSubview:lb];
  96. _lbSubtitle = lb;
  97. _lbSubtitle.text = [user getLastContent:user.userId];
  98. bageImage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"noread"]];
  99. bageImage.frame = CGRectMake(43, 8-10, 25, 25);
  100. bageImage.backgroundColor = [UIColor clearColor];
  101. bageNumber=[[UILabel alloc]initWithFrame:CGRectZero];
  102. bageNumber.userInteractionEnabled = NO;
  103. bageNumber.frame = CGRectMake(0,0, 25, 25);
  104. bageNumber.backgroundColor = [UIColor clearColor];
  105. bageNumber.textAlignment = NSTextAlignmentCenter;
  106. bageNumber.text = bage;
  107. bageNumber.textColor = [UIColor whiteColor];
  108. bageNumber.font = f0;
  109. if([bage intValue]>0){
  110. [self.contentView addSubview:bageImage];
  111. [bageImage addSubview:bageNumber];
  112. }
  113. [self update];
  114. }
  115. return self;
  116. }
  117. - (void) actionUser {
  118. if ([self.delegate respondsToSelector:@selector(friendCell:headImageAction:)]) {
  119. [self.delegate friendCell:self headImageAction:user.userId];
  120. }
  121. }
  122. -(void)dealloc{
  123. // NSLog(@"JXFriendCell.dealloc");
  124. self.title = nil;
  125. self.subtitle = nil;
  126. self.rightTitle = nil;
  127. self.bottomTitle = nil;
  128. self.headImage = nil;
  129. self.bage = nil;
  130. self.user = nil;
  131. self.target = nil;
  132. // [bageImage release];
  133. // [bageNumber release];
  134. // [super dealloc];
  135. }
  136. - (void)awakeFromNib
  137. {
  138. [super awakeFromNib];
  139. // Initialization code
  140. }
  141. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  142. {
  143. [super setSelected:selected animated:animated];
  144. // Configure the view for the selected state
  145. }
  146. -(void)setBage:(NSString *)s{
  147. bageImage.hidden = [s intValue]<=0;
  148. bageNumber.hidden = [s intValue]<=0;
  149. bageNumber.text = s;
  150. bage = s;
  151. }
  152. -(void)update{
  153. NSString* s = @"";SEL action=nil;
  154. NSString* s2 = @"";SEL action2=nil;
  155. if([user.isMySend boolValue]){
  156. switch ([user.type intValue]) {
  157. case XMPP_TYPE_SAYHELLO:
  158. user.status = [NSNumber numberWithInt:friend_status_addFriend];
  159. [user update];
  160. // s = @"再打招呼";
  161. // action = @selector(onSayHello:);
  162. _timeLab.hidden = NO;
  163. break;
  164. case XMPP_TYPE_PASS:
  165. _timeLab.hidden = NO;
  166. break;
  167. case XMPP_TYPE_FEEDBACK:
  168. if ([user.status intValue] == friend_status_hisAddFriend) {
  169. s = @"添加";// Localized(@"JX_Pass");
  170. action = @selector(onAddFriend:);
  171. s2 = Localized(@"JX_Talk");//同时显示两个按钮
  172. action2 = @selector(onFeedback:);
  173. }else {
  174. s2 = Localized(@"JX_Talk");
  175. action2 = @selector(onFeedback:);
  176. }
  177. _timeLab.hidden = YES;
  178. break;
  179. case XMPP_TYPE_NEWSEE:
  180. s = Localized(@"JX_SayHi");
  181. action = @selector(onSayHello:);
  182. _timeLab.hidden = YES;
  183. break;
  184. case XMPP_TYPE_DELSEE:
  185. // s = Localized(@"JX_FollowAngin");
  186. action = @selector(onSeeHim:);
  187. _timeLab.hidden = YES;
  188. break;
  189. case XMPP_TYPE_DELALL:
  190. // s = Localized(@"JX_FollowAngin");
  191. action = @selector(onSeeHim:);
  192. _timeLab.hidden = YES;
  193. break;
  194. default:
  195. break;
  196. }
  197. }else{
  198. switch ([user.type intValue]) {
  199. case XMPP_TYPE_SAYHELLO:
  200. _timeLab.hidden = YES;
  201. s = @"添加";// Localized(@"JX_Pass");//---
  202. action = @selector(onAddFriend:);
  203. s2 = Localized(@"JX_Talk");//同时显示两个按钮
  204. action2 = @selector(onFeedback:);
  205. user.status = [NSNumber numberWithInt:friend_status_hisAddFriend];
  206. [user update];
  207. break;
  208. case XMPP_TYPE_PASS:
  209. _timeLab.hidden = NO;
  210. break;
  211. case XMPP_TYPE_FEEDBACK:
  212. _timeLab.hidden = YES;
  213. if ([user.status intValue] == friend_status_hisAddFriend) {
  214. s = @"添加";// Localized(@"JX_Pass");
  215. action = @selector(onAddFriend:);
  216. s2 = Localized(@"JX_Talk");//同时显示两个按钮
  217. action2 = @selector(onFeedback:);
  218. }else {
  219. s2 = Localized(@"JX_Talk");
  220. action2 = @selector(onFeedback:);
  221. }
  222. break;
  223. case XMPP_TYPE_NEWSEE:
  224. _timeLab.hidden = YES;
  225. s = Localized(@"JX_AddFriend");
  226. action = @selector(onAddFriend:);
  227. break;
  228. case XMPP_TYPE_DELSEE:
  229. _timeLab.hidden = YES;
  230. if([user.status intValue]==friend_status_none){
  231. s = Localized(@"JX_Attion");
  232. action = @selector(onSeeHim:);
  233. }
  234. if([user.status intValue]==friend_status_see){
  235. s = Localized(@"JX_SayHi");
  236. action = @selector(onSayHello:);
  237. }
  238. break;
  239. case XMPP_TYPE_RECOMMEND:
  240. _timeLab.hidden = YES;
  241. if([user.status intValue]==friend_status_none){
  242. s = Localized(@"JX_Attion");
  243. action = @selector(onSeeHim:);
  244. }
  245. if([user.status intValue]==friend_status_see){
  246. s = Localized(@"JX_SayHi");
  247. action = @selector(onSayHello:);
  248. }
  249. break;
  250. default:
  251. break;
  252. }
  253. }
  254. _lbSubtitle.text = [user getLastContent:user.userId];
  255. _btn1.hidden = [s length]==0;
  256. [_btn1 setTitle:s forState:UIControlStateNormal];
  257. self.backgroundColor= [s length]==0?[UIColor whiteColor]:kRGBColor(250, 244, 245);
  258. [_btn1 addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
  259. if (([user.isMySend intValue]==1||[user.isMySend intValue]==0)&&([user.status intValue]==2)) {
  260. [_btn1 setTitle:@"已添加" forState:UIControlStateNormal];
  261. [_btn1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  262. _btn1.hidden = NO;
  263. }
  264. _btn2.hidden = [s2 length]==0;
  265. [_btn2 setTitle:s2 forState:UIControlStateNormal];
  266. [_btn2 addTarget:target action:action2 forControlEvents:UIControlEventTouchUpInside];
  267. if (!_btn1.hidden) {
  268. _lbSubtitle.frame = CGRectMake(_lbSubtitle.frame.origin.x, _lbSubtitle.frame.origin.y, JX_SCREEN_WIDTH - _lbSubtitle.frame.origin.x - (JX_SCREEN_WIDTH - _btn1.frame.origin.x) - 10, _lbSubtitle.frame.size.height);
  269. }else {
  270. if (!_btn2.hidden) {
  271. _lbSubtitle.frame = CGRectMake(_lbSubtitle.frame.origin.x, _lbSubtitle.frame.origin.y, JX_SCREEN_WIDTH - _lbSubtitle.frame.origin.x - (JX_SCREEN_WIDTH - _btn2.frame.origin.x) - 10, _lbSubtitle.frame.size.height);
  272. }else {
  273. _lbSubtitle.frame = CGRectMake(_lbSubtitle.frame.origin.x, _lbSubtitle.frame.origin.y, JX_SCREEN_WIDTH - _lbSubtitle.frame.origin.x - 10, _lbSubtitle.frame.size.height);
  274. }
  275. }
  276. }
  277. @end