MGNewDTNearByViewController.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //
  2. // MGNewDTNearByViewController.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2019/12/11.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "MGNewDTNearByViewController.h"
  9. #import "ReleaseTopicVC.h"
  10. #import "BGTopicTimeLineListController.h"
  11. @interface MGNewDTNearByViewController ()
  12. @property(nonatomic, strong) NSMutableArray *listArr;
  13. @property(nonatomic, assign) NSInteger pageIndex;
  14. @end
  15. @implementation MGNewDTNearByViewController
  16. - (instancetype)initWithType:(MGNEWDT_TYPE)type{
  17. MGNewDTNearByViewController *vc = [MGNewDTNearByViewController new];
  18. vc.type = type;
  19. return vc;
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. self.title = self.type == MGNEWDTTYPE_NEAR_PEOPLE ? ASLocalizedString(@"附近的人"): ASLocalizedString(@"全部话题");
  25. if (self.type == MGNEWDTTYPE_TOPIC) {
  26. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(clickSearch:) image:@"mg_topic_search" highImage:@"mg_topic_search"];
  27. }
  28. [self backBtnWithBlock];
  29. [self setUpView];
  30. self.pageIndex = 1;
  31. [self requestPageIndex:self.pageIndex];
  32. }
  33. - (void)viewWillAppear:(BOOL)animated {
  34. [super viewWillAppear:animated];
  35. self.navigationController.navigationBar.hidden = NO;
  36. }
  37. - (void)backBtnWithBlock
  38. {
  39. // 返回按钮
  40. [self setupBackBtnWithBlock:nil];
  41. }
  42. -(void)clickSearch:(UIBarButtonItem *)sender{
  43. //进入话题页面
  44. ReleaseTopicVC *tmpController = [[ReleaseTopicVC alloc]init];
  45. __weak __typeof(self)weakSelf = self;;
  46. tmpController.releaseTopicBlock = ^(MGDynamicTopicModel * _Nonnull topic) {
  47. BGTopicTimeLineListController *pushVC = [BGTopicTimeLineListController new];
  48. pushVC.topic = topic;
  49. [[AppDelegate sharedAppDelegate]pushViewController:pushVC animated:YES];
  50. // weakSelf.topicTipBtn.hidden = YES;
  51. // weakSelf.topicBtn.hidden = NO;
  52. // weakSelf.selectedTopicID = topic.t_id;
  53. // [weakSelf.topicBtn setTitle:[NSString stringWithFormat:@"#%@#",topic.name] forState:UIControlStateNormal];
  54. // CGSize btnSize = [self preferredSizeWithMaxWidth:kScreenW-100 view:weakSelf.topicBtn];
  55. //
  56. // weakSelf.topicBtn.frame = CGRectMake(kScreenW-btnSize.width-10, 15, btnSize.width, 24);
  57. };
  58. [self.navigationController pushViewController:tmpController animated:YES];
  59. }
  60. - (void)requestPageIndex:(NSInteger)pageIndex{
  61. if (pageIndex == 1) {
  62. self.listArr = [NSMutableArray array];
  63. }
  64. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  65. [parmDict setObject:@"dynamic" forKey:@"ctl"];
  66. if (self.type == MGNEWDTTYPE_NEAR_PEOPLE) {
  67. [parmDict setObject:@"fujin_user" forKey:@"act"];
  68. }else if (self.type == MGNEWDTTYPE_TOPIC){
  69. [parmDict setObject:@"dynamic_theme" forKey:@"act"];
  70. [parmDict setObject:@"" forKey:@"key_word"];
  71. [parmDict setObject:@"0" forKey:@"all"];//1取全部,0是取分页数据
  72. }
  73. [parmDict setObject:[NSString stringWithFormat:@"%ld",pageIndex] forKey:@"p"];
  74. FWWeakify(self)
  75. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  76. if ([[responseJson valueForKey:@"status"] integerValue] == 1) {
  77. NSArray *arr = responseJson[@"data"];
  78. if ([arr isKindOfClass:[NSArray class]])
  79. {
  80. if (arr.count > 0)
  81. {
  82. for (NSDictionary *dic in arr)
  83. {
  84. if (self.type == MGNEWDTTYPE_NEAR_PEOPLE) {
  85. MGNewDTNearlistModel *model = [MGNewDTNearlistModel modelWithDictionary:dic];
  86. [self.listArr addObject:model];
  87. }else if(self.type == MGNEWDTTYPE_TOPIC){
  88. MGDynamicTopicModel *model = [MGDynamicTopicModel itemWithDic:dic];
  89. // modelWithDictionary:dic];
  90. [self.listArr addObject:model];
  91. }
  92. }
  93. }
  94. }
  95. [self.tableView reloadData];
  96. }else{
  97. [BGHUDHelper alert:[responseJson valueForKey:@"error"]];
  98. }
  99. [self.tableView.mj_header endRefreshing];
  100. [self.tableView.mj_footer endRefreshing];
  101. } FailureBlock:^(NSError *error) {
  102. [self.tableView.mj_header endRefreshing];
  103. [self.tableView.mj_footer endRefreshing];
  104. }];
  105. }
  106. -(void)setUpView{
  107. self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH - kTopHeight) style:UITableViewStylePlain];
  108. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  109. _tableView.dataSource =self;
  110. _tableView.delegate =self;
  111. _tableView.backgroundColor = kWhiteColor;
  112. [_tableView registerClass:[MGNewDTNearPeopleCell class] forCellReuseIdentifier:@"MGNewDTNearPeopleCell"];
  113. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  114. [self.view addSubview:self.tableView];
  115. [BGMJRefreshManager refresh:self.tableView target:self headerRereshAction:@selector(refreshHeader) footerRereshAction:@selector(refreshFooter)];
  116. }
  117. -(void)refreshHeader{
  118. self.pageIndex = 1;
  119. [self requestPageIndex:self.pageIndex];
  120. }
  121. -(void)refreshFooter{
  122. self.pageIndex ++ ;
  123. [self requestPageIndex:self.pageIndex];
  124. }
  125. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  126. return 1;
  127. }
  128. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  129. return self.listArr.count;
  130. }
  131. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  132. return kRealValue(60);
  133. }
  134. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  135. MGNewDTNearPeopleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MGNewDTNearPeopleCell"];
  136. if (self.listArr.count > 0) {
  137. [cell resetModelWithModel:self.listArr[indexPath.row] type:self.type];
  138. }
  139. if (self.type == MGNEWDTTYPE_TOPIC) {
  140. cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"com_arrow_right_1"]];
  141. }
  142. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  143. return cell;
  144. }
  145. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  146. if (self.type == MGNEWDTTYPE_TOPIC) {
  147. MGDynamicTopicModel *topicModel = self.listArr[indexPath.row];
  148. BGTopicTimeLineListController *pushVC = [BGTopicTimeLineListController new];
  149. pushVC.topic = topicModel;
  150. [[AppDelegate sharedAppDelegate]pushViewController:pushVC animated:YES];
  151. }else if (self.type == MGNEWDTTYPE_NEAR_PEOPLE){
  152. MGNewDTNearlistModel *nearModel = self.listArr[indexPath.row];
  153. SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  154. tmpController.user_id = nearModel.id;
  155. tmpController.type = 0;
  156. [[AppDelegate sharedAppDelegate]pushViewController:tmpController animated:YES];
  157. }
  158. }
  159. @end