JXBlogRemindVC.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // JXBlogRemindVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2017/7/4.
  6. // Copyright © 2017年 Reese. All rights reserved.
  7. //
  8. #import "JXBlogRemindVC.h"
  9. #import "JXBlogRemind.h"
  10. #import "JXBlogRemindCell.h"
  11. #import "WeiboViewControlle.h"
  12. @interface JXBlogRemindVC ()
  13. @property (nonatomic, assign) BOOL isHaveMore;
  14. @end
  15. @implementation JXBlogRemindVC
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view.
  19. self.title = Localized(@"JX_NewMessage");
  20. self.isHaveMore = YES;
  21. self.isGotoBack = YES;
  22. self.heightHeader = JX_SCREEN_TOP;
  23. self.heightFooter = 0;
  24. [self createHeadAndFoot];
  25. self.isShowFooterPull = NO;
  26. UIButton* btn = [UIFactory createButtonWithTitle:Localized(@"JX_Clear") titleFont:[UIFont systemFontOfSize:15] titleColor:[UIColor whiteColor] normal:nil highlight:nil];
  27. [btn setTitleColor:THESIMPLESTYLE ? [UIColor blackColor] : [UIColor whiteColor] forState:UIControlStateNormal];
  28. [btn addTarget:self action:@selector(onClear) forControlEvents:UIControlEventTouchUpInside];
  29. btn.frame = CGRectMake(JX_SCREEN_WIDTH-32-15, JX_SCREEN_TOP - 30, 32, 15);
  30. [self.tableHeader addSubview:btn];
  31. if (self.isShowAll) {
  32. self.remindArray = [[JXBlogRemind sharedInstance] doFetch];
  33. self.isHaveMore = NO;
  34. [_table reloadData];
  35. }
  36. [g_notify addObserver:self selector:@selector(remindNotif:) name:kXMPPMessageWeiboRemind object:nil];
  37. }
  38. - (void) remindNotif:(NSNotification *)notif {
  39. _remindArray = [[JXBlogRemind sharedInstance] doFetchUnread];
  40. [_table reloadData];
  41. }
  42. - (void) onClear {
  43. [[JXBlogRemind sharedInstance] deleteAllMsg];
  44. [self.remindArray removeAllObjects];
  45. self.isHaveMore = NO;
  46. [_table reloadData];
  47. }
  48. #pragma mark ---------tableView协议----------------
  49. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  50. {
  51. if (indexPath.row == self.remindArray.count) {
  52. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellName"];
  53. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 30)];
  54. label.textColor = [UIColor grayColor];
  55. label.font = g_factory.font14;
  56. label.text = Localized(@"JX_GetPreviousMessage");
  57. label.textAlignment = NSTextAlignmentCenter;
  58. [cell.contentView addSubview:label];
  59. return cell;
  60. }
  61. NSString* cellName = [NSString stringWithFormat:@"JXBlogRemindCell"];
  62. JXBlogRemindCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  63. if(cell==nil){
  64. cell = [[JXBlogRemindCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];;
  65. }
  66. JXBlogRemind *br = self.remindArray[indexPath.row];
  67. [cell doRefresh:br];
  68. return cell;
  69. }
  70. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  71. {
  72. return 1;
  73. }
  74. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  75. {
  76. if (self.isHaveMore) {
  77. return self.remindArray.count + 1;
  78. }else {
  79. return self.remindArray.count;
  80. }
  81. }
  82. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84. if (indexPath.row >= self.remindArray.count) {
  85. return 85;
  86. }
  87. JXBlogRemind *br = self.remindArray[indexPath.row];
  88. NSString *content = br.content;
  89. if (br.toUserName.length > 0)
  90. content = [NSString stringWithFormat:@"%@%@: %@", Localized(@"JX_Reply"),br.toUserName, br.content];
  91. CGSize size = [content boundingRectWithSize:CGSizeMake(JX_SCREEN_WIDTH - 60 - 10 - 85, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:SYSFONT(15)} context:nil].size;
  92. if (size.height > 20) {
  93. return 85 - 20 + size.height;
  94. }
  95. return 85;
  96. }
  97. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  98. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  99. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  100. if (indexPath.row == self.remindArray.count) {
  101. self.remindArray = [[JXBlogRemind sharedInstance] doFetch];
  102. self.isHaveMore = NO;
  103. [_table reloadData];
  104. return;
  105. }
  106. JXBlogRemind *br = self.remindArray[indexPath.row];
  107. WeiboViewControlle *weibo = [WeiboViewControlle alloc];
  108. weibo.detailMsgId = br.objectId;
  109. weibo.isDetail = YES;
  110. weibo = [weibo init];
  111. // [g_window addSubview:weibo.view];
  112. [g_navigation pushViewController:weibo animated:YES];
  113. }
  114. - (void)didReceiveMemoryWarning {
  115. [super didReceiveMemoryWarning];
  116. // Dispose of any resources that can be recreated.
  117. }
  118. /*
  119. #pragma mark - Navigation
  120. // In a storyboard-based application, you will often want to do a little preparation before navigation
  121. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  122. // Get the new view controller using [segue destinationViewController].
  123. // Pass the selected object to the new view controller.
  124. }
  125. */
  126. @end