Commit 0b99cbcb88a3e589d5206c8db9d08b94d954903e
1 parent
d0838c4b
no message
Showing
3 changed files
with
74 additions
and
49 deletions
CNLiveCollectionModule/Classes/Controller/CNLiveCollectionController.m
| @@ -40,55 +40,51 @@ static const CGFloat timeValue = 1.5; | @@ -40,55 +40,51 @@ static const CGFloat timeValue = 1.5; | ||
| 40 | 40 | ||
| 41 | #pragma mark - 数据 | 41 | #pragma mark - 数据 |
| 42 | - (void)loadData{ | 42 | - (void)loadData{ |
| 43 | - NSDictionary *params = @{ | ||
| 44 | - @"pageSize":@"10", | ||
| 45 | - @"pageNo":[NSString stringWithFormat:@"%ld",_pageNo], | ||
| 46 | - @"appId":AppId, | ||
| 47 | - @"plat":@"i", | ||
| 48 | - @"sid":CNUserShareModel.uid}; | ||
| 49 | - [CNLiveNetworking setAllowRequestDefaultArgument:YES]; | ||
| 50 | [QMUITips showLoadingInView:self.view]; | 43 | [QMUITips showLoadingInView:self.view]; |
| 51 | - [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNDarenCollectListDataSourceUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) { | ||
| 52 | - if(_pageNo == 1 && self.data.count > 0){ | ||
| 53 | - [self.data removeAllObjects]; | ||
| 54 | - } | ||
| 55 | - [QMUITips hideAllTipsInView:self.view]; | ||
| 56 | - [self hideEmptyView]; | 44 | + __weak typeof(self) weakSelf = self; |
| 45 | + [CNLiveCollectionRequest getCollectionList:CNUserShareModel.uid pageNo:[NSString stringWithFormat:@"%ld",_pageNo] block:^(BOOL isSuccess, NSArray * _Nonnull array, NSError * _Nonnull error) { | ||
| 46 | + __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 47 | + if(!strongSelf) return ; | ||
| 48 | + [QMUITips hideAllTipsInView:strongSelf.view]; | ||
| 49 | + [strongSelf hideEmptyView]; | ||
| 50 | + | ||
| 51 | + [strongSelf.tableView.mj_header endRefreshing]; | ||
| 52 | + [strongSelf.tableView.mj_footer endRefreshing]; | ||
| 57 | 53 | ||
| 58 | if (error) { | 54 | if (error) { |
| 59 | - if (self.data.count == 0) { | 55 | + if (strongSelf.data.count == 0) { |
| 60 | if (error.code == -1001||error.code == -1003||error.code == -1009) { | 56 | if (error.code == -1001||error.code == -1003||error.code == -1009) { |
| 61 | - [self showEmptyViewWithImage:[UIImage imageNamed:@"dd_wlcw"] text:@"无法连接网络" detailText:@"别紧张,试试看刷新页面~" buttonTitle:@" 重试 " buttonAction:@selector(loadData)]; | ||
| 62 | - [self setCNAPIErrorEmptyView]; | ||
| 63 | - self.tableView.mj_footer.hidden = self.data.count == 0; | 57 | + [strongSelf showEmptyViewWithImage:[UIImage imageNamed:@"dd_wlcw"] text:@"无法连接网络" detailText:@"别紧张,试试看刷新页面~" buttonTitle:@" 重试 " buttonAction:@selector(loadData)]; |
| 58 | + [strongSelf setCNAPIErrorEmptyView]; | ||
| 59 | + strongSelf.tableView.mj_footer.hidden = strongSelf.data.count == 0; | ||
| 64 | } | 60 | } |
| 65 | } | 61 | } |
| 66 | return; | 62 | return; |
| 67 | } | 63 | } |
| 68 | - [self.tableView.mj_header endRefreshing]; | ||
| 69 | - [self.tableView.mj_footer endRefreshing]; | ||
| 70 | - if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject[@"errorCode"] isEqualToString:@"0"]) { | ||
| 71 | - _isRefreshing = NO; | ||
| 72 | - _pageNo++; | ||
| 73 | - NSArray *arr = [CNLiveCollectionModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"list"]]; | ||
| 74 | - [self.data addObjectsFromArray:arr]; | ||
| 75 | - if (arr.count < 10) { | ||
| 76 | - [self.tableView.mj_footer endRefreshingWithNoMoreData]; | 64 | + |
| 65 | + if (isSuccess) { | ||
| 66 | + if(strongSelf.pageNo == 1 && strongSelf.data.count > 0){ | ||
| 67 | + [strongSelf.data removeAllObjects]; | ||
| 68 | + } | ||
| 69 | + strongSelf.isRefreshing = NO; | ||
| 70 | + strongSelf.pageNo++; | ||
| 71 | + [strongSelf.data addObjectsFromArray:array]; | ||
| 72 | + if (array.count < 10) { | ||
| 73 | + [strongSelf.tableView.mj_footer endRefreshingWithNoMoreData]; | ||
| 77 | 74 | ||
| 78 | } else { | 75 | } else { |
| 79 | - [self.tableView.mj_footer endRefreshing]; | 76 | + [strongSelf.tableView.mj_footer endRefreshing]; |
| 80 | 77 | ||
| 81 | } | 78 | } |
| 82 | } | 79 | } |
| 83 | - | ||
| 84 | - if (self.data.count == 0) {//显示empty | ||
| 85 | -// [self showEmptyViewWithImage:[UIImage imageNamed:@"zhuangtai_kong"] text:@"您现在没有相关内容哦" detailText:@"" buttonTitle:@"" buttonAction:nil]; | ||
| 86 | - [self setCNNoDataEmptyView]; | ||
| 87 | - self.tableView.tableFooterView = nil; | 80 | + |
| 81 | + if (strongSelf.data.count == 0) {//显示empty | ||
| 82 | + [strongSelf showEmptyViewWithImage:[UIImage imageNamed:@"zhuangtai_kong"] text:@"您现在没有相关内容哦" detailText:@"" buttonTitle:@"" buttonAction:nil]; | ||
| 83 | + [strongSelf setCNNoDataEmptyView]; | ||
| 84 | + strongSelf.tableView.tableFooterView = nil; | ||
| 88 | } | 85 | } |
| 89 | - self.tableView.mj_footer.hidden = self.data.count == 0; | ||
| 90 | - [self.tableView reloadData]; | ||
| 91 | - | 86 | + strongSelf.tableView.mj_footer.hidden = self.data.count == 0; |
| 87 | + [strongSelf.tableView reloadData]; | ||
| 92 | }]; | 88 | }]; |
| 93 | 89 | ||
| 94 | } | 90 | } |
| @@ -133,7 +129,6 @@ static const CGFloat timeValue = 1.5; | @@ -133,7 +129,6 @@ static const CGFloat timeValue = 1.5; | ||
| 133 | - (void)goBack { | 129 | - (void)goBack { |
| 134 | if (self.presentingViewController != nil) { | 130 | if (self.presentingViewController != nil) { |
| 135 | [self dismissViewControllerAnimated:YES completion:nil]; | 131 | [self dismissViewControllerAnimated:YES completion:nil]; |
| 136 | - | ||
| 137 | } | 132 | } |
| 138 | else { | 133 | else { |
| 139 | [self.navigationController popViewControllerAnimated:YES]; | 134 | [self.navigationController popViewControllerAnimated:YES]; |
| @@ -169,21 +164,23 @@ static const CGFloat timeValue = 1.5; | @@ -169,21 +164,23 @@ static const CGFloat timeValue = 1.5; | ||
| 169 | [QMUITips showLoadingInView:self.view]; | 164 | [QMUITips showLoadingInView:self.view]; |
| 170 | __weak typeof(self) weakSelf = self; | 165 | __weak typeof(self) weakSelf = self; |
| 171 | [CNLiveCollectionRequest cancelCollection:cell.model.collectionId block:^(BOOL isSuccess, NSError * _Nonnull error) { | 166 | [CNLiveCollectionRequest cancelCollection:cell.model.collectionId block:^(BOOL isSuccess, NSError * _Nonnull error) { |
| 172 | - [QMUITips hideAllToastInView:weakSelf.view animated:YES]; | 167 | + __strong typeof(weakSelf) strongSelf = weakSelf; |
| 168 | + if(!strongSelf) return ; | ||
| 169 | + [QMUITips hideAllToastInView:strongSelf.view animated:YES]; | ||
| 173 | if (error) { | 170 | if (error) { |
| 174 | - [QMUITips showError:error.localizedDescription inView:weakSelf.view hideAfterDelay:timeValue]; | 171 | + [QMUITips showError:error.localizedDescription inView:strongSelf.view hideAfterDelay:timeValue]; |
| 175 | return; | 172 | return; |
| 176 | } | 173 | } |
| 177 | if (isSuccess) { | 174 | if (isSuccess) { |
| 178 | - [weakSelf.data removeObject:cell.model]; | ||
| 179 | - [weakSelf.tableView reloadData]; | ||
| 180 | - [QMUITips showSucceed:@"取消收藏成功" inView:weakSelf.view hideAfterDelay:timeValue]; | ||
| 181 | - if (weakSelf.data.count == 0) { | ||
| 182 | - [weakSelf showEmptyViewWithImage:[UIImage imageNamed:@"zhuangtai_kong"] text:@"您现在没有相关内容哦" detailText:@"" buttonTitle:@"" buttonAction:nil]; | ||
| 183 | - [weakSelf setCNNoDataEmptyView]; | ||
| 184 | - weakSelf.tableView.tableFooterView = nil; | 175 | + [strongSelf.data removeObject:cell.model]; |
| 176 | + [strongSelf.tableView reloadData]; | ||
| 177 | + [QMUITips showSucceed:@"取消收藏成功" inView:strongSelf.view hideAfterDelay:timeValue]; | ||
| 178 | + if (strongSelf.data.count == 0) { | ||
| 179 | + [strongSelf showEmptyViewWithImage:[UIImage imageNamed:@"zhuangtai_kong"] text:@"您现在没有相关内容哦" detailText:@"" buttonTitle:@"" buttonAction:nil]; | ||
| 180 | + [strongSelf setCNNoDataEmptyView]; | ||
| 181 | + strongSelf.tableView.tableFooterView = nil; | ||
| 185 | } | 182 | } |
| 186 | - weakSelf.tableView.mj_footer.hidden = weakSelf.data.count == 0; | 183 | + strongSelf.tableView.mj_footer.hidden = strongSelf.data.count == 0; |
| 187 | } | 184 | } |
| 188 | }]; | 185 | }]; |
| 189 | } | 186 | } |
CNLiveCollectionModule/Classes/Model/CNLiveCollectionRequest.h
| @@ -9,11 +9,15 @@ | @@ -9,11 +9,15 @@ | ||
| 9 | #import <Foundation/Foundation.h> | 9 | #import <Foundation/Foundation.h> |
| 10 | 10 | ||
| 11 | NS_ASSUME_NONNULL_BEGIN | 11 | NS_ASSUME_NONNULL_BEGIN |
| 12 | -typedef void(^Block)(BOOL isSuccess, NSError *error); | 12 | + |
| 13 | +typedef void(^CollectionListBlock)(BOOL isSuccess, NSArray *array, NSError *error); | ||
| 14 | +typedef void(^CancelCollectionBlock)(BOOL isSuccess, NSError *error); | ||
| 13 | 15 | ||
| 14 | @interface CNLiveCollectionRequest : NSObject | 16 | @interface CNLiveCollectionRequest : NSObject |
| 15 | 17 | ||
| 16 | -+ (void)cancelCollection:(NSString *)ID block:(Block)block; | 18 | ++ (void)getCollectionList:(NSString *)ID pageNo:(NSString *)pageNo block:(CollectionListBlock)block; |
| 19 | + | ||
| 20 | ++ (void)cancelCollection:(NSString *)ID block:(CancelCollectionBlock)block; | ||
| 17 | 21 | ||
| 18 | @end | 22 | @end |
| 19 | 23 |
CNLiveCollectionModule/Classes/Model/CNLiveCollectionRequest.m
| @@ -12,9 +12,33 @@ | @@ -12,9 +12,33 @@ | ||
| 12 | #import "CNLiveEnvironment.h" | 12 | #import "CNLiveEnvironment.h" |
| 13 | #import "CNUserInfoManager.h" | 13 | #import "CNUserInfoManager.h" |
| 14 | 14 | ||
| 15 | +#import "CNLiveCollectionModel.h" | ||
| 16 | +#import "MJExtension.h" | ||
| 17 | + | ||
| 15 | @implementation CNLiveCollectionRequest | 18 | @implementation CNLiveCollectionRequest |
| 16 | 19 | ||
| 17 | -+ (void)cancelCollection:(NSString *)ID block:(Block)block{ | 20 | ++ (void)getCollectionList:(NSString *)ID pageNo:(NSString *)pageNo block:(CollectionListBlock)block{ |
| 21 | + NSDictionary *params = @{ | ||
| 22 | + @"pageSize":@"10", | ||
| 23 | + @"pageNo":pageNo, | ||
| 24 | + @"appId":AppId, | ||
| 25 | + @"plat":@"i", | ||
| 26 | + @"sid":ID}; | ||
| 27 | + [CNLiveNetworking setAllowRequestDefaultArgument:YES]; | ||
| 28 | + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNDarenCollectListDataSourceUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) { | ||
| 29 | + if (responseObject&&[responseObject isKindOfClass:[NSDictionary class]]) { | ||
| 30 | + NSString *errorCode = [NSString stringWithFormat:@"%@", responseObject[@"errorCode"]]; | ||
| 31 | + NSArray *arr = [CNLiveCollectionModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"list"]]; | ||
| 32 | + block?block([errorCode isEqualToString:@"0"], arr, error):@""; | ||
| 33 | + }else{ | ||
| 34 | + block?block(NO, nil, error):@""; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + }]; | ||
| 38 | + | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | ++ (void)cancelCollection:(NSString *)ID block:(CancelCollectionBlock)block{ | ||
| 18 | NSDictionary *params = @{@"appId":AppId, | 42 | NSDictionary *params = @{@"appId":AppId, |
| 19 | @"plat":@"i", | 43 | @"plat":@"i", |
| 20 | @"sid":CNUserShareModel.uid, | 44 | @"sid":CNUserShareModel.uid, |