Commit d0838c4bbb4624896d49132ef5ab8bf5fa5b9c15

Authored by zhangxiaowen
1 parent 5671f85d

no message

CNLiveCollectionModule/Classes/Controller/CNLiveCollectionController.m
@@ -23,8 +23,9 @@ @@ -23,8 +23,9 @@
23 #import "CNLiveCollectionCell.h" 23 #import "CNLiveCollectionCell.h"
24 #import "CNLiveCollectionModel.h" 24 #import "CNLiveCollectionModel.h"
25 25
  26 +#import "CNLiveCollectionRequest.h"
26 27
27 -@interface CNLiveCollectionController ()<UITableViewDelegate, UITableViewDataSource,CNLiveCollectionNavigationBarDelegate> 28 +@interface CNLiveCollectionController ()<UITableViewDelegate, UITableViewDataSource,CNLiveCollectionNavigationBarDelegate,CNLiveCollectionCellDelegate>
28 @property (nonatomic, strong) CNLiveCollectionNavigationBar *navigationBar; 29 @property (nonatomic, strong) CNLiveCollectionNavigationBar *navigationBar;
29 @property (nonatomic, strong) UITableView *tableView; 30 @property (nonatomic, strong) UITableView *tableView;
30 @property (nonatomic, strong) NSMutableArray *data; 31 @property (nonatomic, strong) NSMutableArray *data;
@@ -35,6 +36,8 @@ @@ -35,6 +36,8 @@
35 @end 36 @end
36 37
37 @implementation CNLiveCollectionController 38 @implementation CNLiveCollectionController
  39 +static const CGFloat timeValue = 1.5;
  40 +
38 #pragma mark - 数据 41 #pragma mark - 数据
39 - (void)loadData{ 42 - (void)loadData{
40 NSDictionary *params = @{ 43 NSDictionary *params = @{
@@ -153,6 +156,7 @@ @@ -153,6 +156,7 @@
153 cell.selectionStyle = UITableViewCellSelectionStyleNone; 156 cell.selectionStyle = UITableViewCellSelectionStyleNone;
154 CNLiveCollectionModel *model = self.data[indexPath.row]; 157 CNLiveCollectionModel *model = self.data[indexPath.row];
155 cell.model = model; 158 cell.model = model;
  159 + cell.delegate = self;
156 return cell; 160 return cell;
157 } 161 }
158 162
@@ -160,6 +164,31 @@ @@ -160,6 +164,31 @@
160 164
161 } 165 }
162 166
  167 +#pragma mark - CNLiveCollectionCellDelegate
  168 +- (void)cancelCollection:(CNLiveCollectionCell *)cell{
  169 + [QMUITips showLoadingInView:self.view];
  170 + __weak typeof(self) weakSelf = self;
  171 + [CNLiveCollectionRequest cancelCollection:cell.model.collectionId block:^(BOOL isSuccess, NSError * _Nonnull error) {
  172 + [QMUITips hideAllToastInView:weakSelf.view animated:YES];
  173 + if (error) {
  174 + [QMUITips showError:error.localizedDescription inView:weakSelf.view hideAfterDelay:timeValue];
  175 + return;
  176 + }
  177 + 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;
  185 + }
  186 + weakSelf.tableView.mj_footer.hidden = weakSelf.data.count == 0;
  187 + }
  188 + }];
  189 +}
  190 +
  191 +#pragma mark - CNLiveCollectionNavigationBarDelegate
163 - (void)navigationBar:(CNLiveCollectionNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{ 192 - (void)navigationBar:(CNLiveCollectionNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
164 if ([actionEvents isEqualToString:@"1"]) { 193 if ([actionEvents isEqualToString:@"1"]) {
165 [self goBack]; 194 [self goBack];
CNLiveCollectionModule/Classes/Model/CNLiveCollectionModel.h
1 // 1 //
2 -// CNLiveQrCodeModel.h 2 +// CNLiveCollectionModel.h
3 // CNLiveCollectionModule 3 // CNLiveCollectionModule
4 // 4 //
5 // Created by 153993236@qq.com on 11/12/2019. 5 // Created by 153993236@qq.com on 11/12/2019.
CNLiveCollectionModule/Classes/Model/CNLiveCollectionModel.m
1 // 1 //
2 -// CNLiveQrCodeModel.m 2 +// CNLiveCollectionModel.m
3 // CNLiveCollectionModule 3 // CNLiveCollectionModule
4 // 4 //
5 // Created by 153993236@qq.com on 11/12/2019. 5 // Created by 153993236@qq.com on 11/12/2019.
CNLiveCollectionModule/Classes/Model/CNLiveCollectionRequest.h 0 → 100644
  1 +//
  2 +// CNLiveCollectionRequest.h
  3 +// CNLiveCollectionModule
  4 +//
  5 +// Created by 153993236@qq.com on 11/12/2019.
  6 +// Copyright © 2019 153993236@qq.com. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +typedef void(^Block)(BOOL isSuccess, NSError *error);
  13 +
  14 +@interface CNLiveCollectionRequest : NSObject
  15 +
  16 ++ (void)cancelCollection:(NSString *)ID block:(Block)block;
  17 +
  18 +@end
  19 +
  20 +NS_ASSUME_NONNULL_END
CNLiveCollectionModule/Classes/Model/CNLiveCollectionRequest.m 0 → 100644
  1 +//
  2 +// CNLiveCollectionRequest.m
  3 +// CNLiveCollectionModule
  4 +//
  5 +// Created by 153993236@qq.com on 11/12/2019.
  6 +// Copyright © 2019 153993236@qq.com. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveCollectionRequest.h"
  10 +#import "CNLiveCategory.h"
  11 +#import "CNLiveNetworking.h"
  12 +#import "CNLiveEnvironment.h"
  13 +#import "CNUserInfoManager.h"
  14 +
  15 +@implementation CNLiveCollectionRequest
  16 +
  17 ++ (void)cancelCollection:(NSString *)ID block:(Block)block{
  18 + NSDictionary *params = @{@"appId":AppId,
  19 + @"plat":@"i",
  20 + @"sid":CNUserShareModel.uid,
  21 + @"collectionId":ID
  22 + };
  23 + [CNLiveNetworking setAllowRequestDefaultArgument:YES];
  24 + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNDarenSubsDeleteCollectionUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
  25 + if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
  26 + NSString *errorCode = [NSString stringWithFormat:@"%@", responseObject[@"errorCode"]];
  27 + if ([errorCode isEqualToString:@"0"]) {
  28 + NSArray *array = [ID componentsSeparatedByString:@":h5:"];//将字符串整体作为分割条件 返回值为NSArray不可变数组
  29 + if(array.count == 2){
  30 + NSDictionary *dic = @{
  31 + @"contentId":array[1]?array[1]:@"",
  32 + @"selected":@"false",
  33 + @"model":@"3_witness"
  34 + };
  35 + [[NSNotificationCenter defaultCenter] postNotificationName:@"WjjWitnessCollectStatusNotification" object:nil userInfo:dic];
  36 + }
  37 + }
  38 + block([errorCode isEqualToString:@"0"], error);
  39 + }
  40 +
  41 + }];
  42 +}
  43 +
  44 +
  45 +@end
  46 +
CNLiveCollectionModule/Classes/View/CNLiveCollectionCell.h
@@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
14 @class CNLiveCollectionCell; 14 @class CNLiveCollectionCell;
15 15
16 @protocol CNLiveCollectionCellDelegate <NSObject> 16 @protocol CNLiveCollectionCellDelegate <NSObject>
17 -- (void)clickedCellButton:(CNLiveCollectionCell *)cell type:(NSString *)type; 17 +- (void)cancelCollection:(CNLiveCollectionCell *)cell;
18 18
19 @end 19 @end
20 @interface CNLiveCollectionCell : UITableViewCell 20 @interface CNLiveCollectionCell : UITableViewCell
CNLiveCollectionModule/Classes/View/CNLiveCollectionCell.m
@@ -116,6 +116,7 @@ static const NSInteger margin = 10; @@ -116,6 +116,7 @@ static const NSInteger margin = 10;
116 - (void)playerDidClicked:(UIButton *)btn{ 116 - (void)playerDidClicked:(UIButton *)btn{
117 117
118 } 118 }
  119 +
119 #pragma mark - 长按手势 120 #pragma mark - 长按手势
120 - (void)longPressToDo:(UILongPressGestureRecognizer *)gesture { 121 - (void)longPressToDo:(UILongPressGestureRecognizer *)gesture {
121 //直接return掉,不在开始的状态里面添加任何操作,则长按手势就会被少调用一次了 122 //直接return掉,不在开始的状态里面添加任何操作,则长按手势就会被少调用一次了
@@ -126,12 +127,9 @@ static const NSInteger margin = 10; @@ -126,12 +127,9 @@ static const NSInteger margin = 10;
126 QMUIAlertAction *action = [QMUIAlertAction actionWithTitle:@"取消收藏" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { 127 QMUIAlertAction *action = [QMUIAlertAction actionWithTitle:@"取消收藏" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
127 __strong typeof(weakSelf) strongSelf = weakSelf; 128 __strong typeof(weakSelf) strongSelf = weakSelf;
128 if(!strongSelf) return ; 129 if(!strongSelf) return ;
129 - 130 + [strongSelf cancelCollection];
130 }]; 131 }];
131 QMUIAlertAction *cancel = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { 132 QMUIAlertAction *cancel = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
132 - __strong typeof(weakSelf) strongSelf = weakSelf;  
133 - if(!strongSelf) return ;  
134 -  
135 }]; 133 }];
136 134
137 QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:QMUIAlertControllerStyleActionSheet]; 135 QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:QMUIAlertControllerStyleActionSheet];
@@ -151,6 +149,14 @@ static const NSInteger margin = 10; @@ -151,6 +149,14 @@ static const NSInteger margin = 10;
151 [alertController showWithAnimated:YES]; 149 [alertController showWithAnimated:YES];
152 } 150 }
153 151
  152 +#pragma mark - 取消收藏方法
  153 +- (void)cancelCollection{
  154 + if (self.delegate && [self.delegate respondsToSelector:@selector(cancelCollection:)]) {
  155 + [self.delegate cancelCollection:self];//滑动响应实现
  156 + }
  157 +}
  158 +
  159 +
154 #pragma mark - 懒加载 160 #pragma mark - 懒加载
155 - (UIView *)bgView { 161 - (UIView *)bgView {
156 if (!_bgView) { 162 if (!_bgView) {