Commit be21473bac94274b3b954847c24b916c9c9456cf
1 parent
5608678a
添加交互0.4.4
Showing
10 changed files
with
135 additions
and
7 deletions
CNLiveVideoClassifyKit.podspec
CNLiveVideoClassifyKit/Classes/Manager/CNLiveClassifyJumpBridge.h
| ... | ... | @@ -60,6 +60,13 @@ NS_ASSUME_NONNULL_BEGIN |
| 60 | 60 | /// 展示登录窗口 |
| 61 | 61 | /// @param loginPrepositionUrl 为appdelegate属性赋值字符串 |
| 62 | 62 | + (void)showLoginViewWithString:(NSString *)loginPrepositionUrl; |
| 63 | +/// 打开用户个人视频页 | |
| 64 | +/// @param params 传递参数 | |
| 65 | ++ (void)openPersonMessage:(NSDictionary *)params; | |
| 66 | +/// 打开视频播放页面 | |
| 67 | +/// @param currentIndex 当前选中 | |
| 68 | +/// @param dataList 视频数组 | |
| 69 | ++ (void)openVideoPlayerVCWithCurrentIndex:(NSString *)currentIndex dataList:(NSArray *)dataList; | |
| 63 | 70 | @end |
| 64 | 71 | |
| 65 | 72 | NS_ASSUME_NONNULL_END | ... | ... |
CNLiveVideoClassifyKit/Classes/Manager/CNLiveClassifyJumpBridge.m
| ... | ... | @@ -72,4 +72,10 @@ |
| 72 | 72 | + (void)showLoginViewWithString:(NSString *)loginPrepositionUrl{ |
| 73 | 73 | [[CNLiveClassifyJumpBridge shareInstance].protocol showLoginViewWithString:loginPrepositionUrl]; |
| 74 | 74 | } |
| 75 | ++ (void)openPersonMessage:(NSDictionary *)params{ | |
| 76 | + [[CNLiveClassifyJumpBridge shareInstance].protocol openPersonMessage:params]; | |
| 77 | +} | |
| 78 | ++ (void)openVideoPlayerVCWithCurrentIndex:(NSString *)currentIndex dataList:(NSArray *)dataList{ | |
| 79 | + [[CNLiveClassifyJumpBridge shareInstance].protocol openVideoPlayerVCWithCurrentIndex:currentIndex dataList:dataList]; | |
| 80 | +} | |
| 75 | 81 | @end | ... | ... |
CNLiveVideoClassifyKit/Classes/Manager/CNLiveListManager.h
| ... | ... | @@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN |
| 12 | 12 | @interface CNLiveListManager : NSObject |
| 13 | 13 | @property (nonatomic, copy) void (^scrollViewDidScrollBlock)(BOOL isUp); |
| 14 | 14 | @property (nonatomic, assign) BOOL isHiddenFirst; |
| 15 | +@property (nonatomic, strong)NSDictionary *personMessage; | |
| 15 | 16 | |
| 16 | 17 | +(instancetype)shareListManager; |
| 17 | 18 | //第一分类是否隐藏:yes为隐藏 |
| ... | ... | @@ -20,6 +21,9 @@ NS_ASSUME_NONNULL_BEGIN |
| 20 | 21 | + (CNCategoryBaseViewController *)CNCategoryBaseViewController; |
| 21 | 22 | /// 跳转目击者搜索页 |
| 22 | 23 | + (void)pushWitnessSearchVC; |
| 24 | +/// 用户信息变动,修改关注状态 | |
| 25 | +/// @param jsonStr 返回参数 | |
| 26 | ++ (void)personMessageChange:(NSString *)jsonStr; | |
| 23 | 27 | @end |
| 24 | 28 | |
| 25 | 29 | NS_ASSUME_NONNULL_END | ... | ... |
CNLiveVideoClassifyKit/Classes/Manager/CNLiveListManager.m
| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | #import "CNLiveListManager.h" |
| 9 | 9 | #import "CNLiveClassifySegmentController.h" |
| 10 | 10 | #import "CNWitnessSearchViewController.h" |
| 11 | +#import "CNWitnessSearchModel.h" | |
| 11 | 12 | |
| 12 | 13 | @interface CNLiveListManager() |
| 13 | 14 | { |
| ... | ... | @@ -49,4 +50,8 @@ |
| 49 | 50 | _isHiddenFirst = isHiddenFirst; |
| 50 | 51 | !self.scrollViewDidScrollBlock ?: self.scrollViewDidScrollBlock(isHiddenFirst); |
| 51 | 52 | } |
| 53 | ++ (void)personMessageChange:(NSString *)jsonStr | |
| 54 | +{ | |
| 55 | + [CNLiveListManager shareListManager].personMessage = [jsonStr mj_keyValues]; | |
| 56 | +} | |
| 52 | 57 | @end | ... | ... |
CNLiveVideoClassifyKit/Classes/Manager/CNLiveVideoClassifyProtocol.h
| ... | ... | @@ -101,6 +101,14 @@ NS_ASSUME_NONNULL_BEGIN |
| 101 | 101 | /// @param shopType 按着后台给的传 |
| 102 | 102 | /// @param currentVC 当前控制器 |
| 103 | 103 | -(void)skipType:(nonnull NSString*)type to:(nonnull NSString*)to shopType:(nonnull NSString*)shopType currentVC:(nonnull UIViewController*)currentVC; |
| 104 | + | |
| 105 | +/// 打开用户个人视频页 | |
| 106 | +/// @param params 传递参数 | |
| 107 | +- (void)openPersonMessage:(NSDictionary *)params; | |
| 108 | +/// 打开视频播放页面 | |
| 109 | +/// @param currentIndex 当前选中 | |
| 110 | +/// @param dataList 视频数组 | |
| 111 | +- (void)openVideoPlayerVCWithCurrentIndex:(NSString *)currentIndex dataList:(NSArray *)dataList; | |
| 104 | 112 | @end |
| 105 | 113 | |
| 106 | 114 | NS_ASSUME_NONNULL_END | ... | ... |
CNLiveVideoClassifyKit/Classes/SearchView/View/CNWitnessSearchPersonCell.h
| ... | ... | @@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN |
| 12 | 12 | |
| 13 | 13 | @interface CNWitnessSearchPersonCell : UICollectionViewCell |
| 14 | 14 | @property (nonatomic, strong)CNPersonMessageModel *model; |
| 15 | +@property (nonatomic, strong)void (^selectPersonBlock)(NSDictionary *dic); | |
| 15 | 16 | @end |
| 16 | 17 | |
| 17 | 18 | NS_ASSUME_NONNULL_END | ... | ... |
CNLiveVideoClassifyKit/Classes/SearchView/View/CNWitnessSearchPersonCell.m
| ... | ... | @@ -96,6 +96,14 @@ |
| 96 | 96 | CAShapeLayer *maskLayer = [CAShapeLayer layer]; |
| 97 | 97 | maskLayer.path = path.CGPath; |
| 98 | 98 | _logoImage.layer.mask = maskLayer; |
| 99 | + _logoImage.userInteractionEnabled = YES; | |
| 100 | + weakself | |
| 101 | + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { | |
| 102 | + if (weakSelf.selectPersonBlock) { | |
| 103 | + weakSelf.selectPersonBlock([weakSelf.model mj_keyValues]); | |
| 104 | + } | |
| 105 | + }]; | |
| 106 | + [_logoImage addGestureRecognizer:tap]; | |
| 99 | 107 | } |
| 100 | 108 | return _logoImage; |
| 101 | 109 | } | ... | ... |
CNLiveVideoClassifyKit/Classes/SearchView/ViewController/CNWitnessSearchDetailController.m
| ... | ... | @@ -11,6 +11,7 @@ |
| 11 | 11 | #import "CNWitnessSearchPersonCell.h" |
| 12 | 12 | #import "CNWitnessSearchModel.h" |
| 13 | 13 | #import "CNCollectionViewLayout.h" |
| 14 | +#import "CNLiveListManager.h" | |
| 14 | 15 | |
| 15 | 16 | static NSString *const CNWitnessSearchVideoCellID = @"CNWitnessSearchVideoCell"; |
| 16 | 17 | static NSString *const CNWitnessSearchPersonCellID = @"CNWitnessSearchPersonCell"; |
| ... | ... | @@ -20,6 +21,8 @@ static NSString *const CNWitnessSearchPersonCellID = @"CNWitnessSearchPersonCell |
| 20 | 21 | @property (nonatomic, assign)NSInteger page;//请求页数 |
| 21 | 22 | @property (nonatomic, strong)NSString *ts; |
| 22 | 23 | @property (nonatomic, strong)NSMutableArray *dataSource; |
| 24 | +@property (nonatomic, strong)NSMutableArray *personIDArray; | |
| 25 | +@property (nonatomic, strong)NSMutableArray *videoIDArray; | |
| 23 | 26 | @end |
| 24 | 27 | |
| 25 | 28 | @implementation CNWitnessSearchDetailController |
| ... | ... | @@ -57,10 +60,28 @@ static NSString *const CNWitnessSearchPersonCellID = @"CNWitnessSearchPersonCell |
| 57 | 60 | } |
| 58 | 61 | [self.emptyView removeFromSuperview]; |
| 59 | 62 | [self.dataSource addObjectsFromArray:dataArray]; |
| 63 | + if (weakSelf.type == CNWitnessSearchDetailTypeVideo) { | |
| 64 | + [dataArray enumerateObjectsUsingBlock:^(CNWitnessSearchDetailModel *model, NSUInteger idx, BOOL * _Nonnull stop) { | |
| 65 | + [weakSelf.videoIDArray addObject:model.pid]; | |
| 66 | + }]; | |
| 67 | + }else{ | |
| 68 | + [dataArray enumerateObjectsUsingBlock:^(CNPersonMessageModel *model, NSUInteger idx, BOOL * _Nonnull stop) { | |
| 69 | + [weakSelf.personIDArray addObject:model.id]; | |
| 70 | + }]; | |
| 71 | + } | |
| 72 | + | |
| 60 | 73 | [self.collectionView reloadData]; |
| 61 | 74 | }]; |
| 62 | 75 | } |
| 63 | - | |
| 76 | +- (void)dealloc | |
| 77 | +{ | |
| 78 | + if (self.type == CNWitnessSearchDetailTypeVideo) { | |
| 79 | + [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
| 80 | + }else{ | |
| 81 | + [[CNLiveListManager shareListManager] removeObserver:self forKeyPath:@"personMessage"]; | |
| 82 | + } | |
| 83 | + | |
| 84 | +} | |
| 64 | 85 | - (instancetype)initWithPageType:(CNWitnessSearchDetailType)type |
| 65 | 86 | { |
| 66 | 87 | if (self = [super init]) { |
| ... | ... | @@ -81,6 +102,12 @@ static NSString *const CNWitnessSearchPersonCellID = @"CNWitnessSearchPersonCell |
| 81 | 102 | pan.delegate = self; |
| 82 | 103 | [self.view addGestureRecognizer:pan]; |
| 83 | 104 | } |
| 105 | + if (self.type == CNWitnessSearchDetailTypeVideo) { | |
| 106 | + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoChangeWithParam:) name:@"WjjWitnessLikeStatusNotification" object:nil]; | |
| 107 | + }else{ | |
| 108 | + [[CNLiveListManager shareListManager] addObserver:self forKeyPath:@"personMessage" options:NSKeyValueObservingOptionNew context:NULL]; | |
| 109 | + } | |
| 110 | + | |
| 84 | 111 | } |
| 85 | 112 | - (void)panGestureEvent:(UIPanGestureRecognizer *)gesture{ |
| 86 | 113 | if (self.panGestureBlock) { |
| ... | ... | @@ -90,11 +117,42 @@ static NSString *const CNWitnessSearchPersonCellID = @"CNWitnessSearchPersonCell |
| 90 | 117 | - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ |
| 91 | 118 | return YES; |
| 92 | 119 | } |
| 120 | +#pragma KVO||Notification | |
| 121 | +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{ | |
| 122 | + if ([keyPath isEqualToString:@"personMessage"]) { | |
| 123 | + NSDictionary *dic = change[NSKeyValueChangeNewKey]; | |
| 124 | + CNPersonMessageModel *model = [CNPersonMessageModel mj_objectWithKeyValues:dic]; | |
| 125 | + if ([self.personIDArray containsObject:model.id]) { | |
| 126 | + NSInteger index = [self.personIDArray indexOfObject:model.id]; | |
| 127 | + [self.dataSource replaceObjectAtIndex:index withObject:model]; | |
| 128 | + [self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]]; | |
| 129 | + } | |
| 130 | + } | |
| 131 | +} | |
| 132 | +- (void)videoChangeWithParam:(NSNotification *)noti{ | |
| 133 | + NSString *pid = [noti.userInfo objectForKey:@"contentId"]; | |
| 134 | + if ([self.videoIDArray containsObject:pid]) { | |
| 135 | + NSInteger index = [self.videoIDArray indexOfObject:pid]; | |
| 136 | + NSString *selected = [noti.userInfo objectForKey:@"selected"]; | |
| 137 | + NSString *likesNumber = [noti.userInfo objectForKey:@"likesNum"]; | |
| 138 | + CNWitnessSearchDetailModel *model = self.dataSource[index]; | |
| 139 | + model.tool.liked = [selected isEqualToString:@"true"]; | |
| 140 | + model.tool.likesNum = likesNumber.integerValue; | |
| 141 | + [self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]]; | |
| 142 | + } | |
| 143 | +} | |
| 93 | 144 | #pragma mark - UIGestureRecognizerDelegate |
| 94 | 145 | |
| 95 | 146 | -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ |
| 96 | 147 | [self.view endEditing:YES]; |
| 97 | 148 | } |
| 149 | +#pragma mark - UICollectionViewDelegate | |
| 150 | +- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ | |
| 151 | + if (self.type == CNWitnessSearchDetailTypeVideo) { | |
| 152 | + NSArray *dicArray = [NSDictionary mj_keyValuesArrayWithObjectArray:self.dataSource]; | |
| 153 | + [CNLiveClassifyJumpBridge openVideoPlayerVCWithCurrentIndex:[NSString stringWithFormat:@"%ld",indexPath.row] dataList:dicArray.copy]; | |
| 154 | + } | |
| 155 | +} | |
| 98 | 156 | #pragma mark - UICollectionViewDataSource |
| 99 | 157 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ |
| 100 | 158 | return self.dataSource.count; |
| ... | ... | @@ -107,9 +165,16 @@ static NSString *const CNWitnessSearchPersonCellID = @"CNWitnessSearchPersonCell |
| 107 | 165 | }else{ |
| 108 | 166 | CNWitnessSearchPersonCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CNWitnessSearchPersonCellID forIndexPath:indexPath]; |
| 109 | 167 | cell.model = self.dataSource[indexPath.row]; |
| 168 | + weakself | |
| 169 | + cell.selectPersonBlock = ^(NSDictionary * _Nonnull dic) { | |
| 170 | + [weakSelf openPersonMessage:dic]; | |
| 171 | + }; | |
| 110 | 172 | return cell; |
| 111 | 173 | } |
| 112 | 174 | } |
| 175 | +- (void)openPersonMessage:(NSDictionary *)param{ | |
| 176 | + [CNLiveClassifyJumpBridge openPersonMessage:param]; | |
| 177 | +} | |
| 113 | 178 | #pragma mark - CNWaterFallLayoutDelegate |
| 114 | 179 | //通过代理得到每个item 的一个高度 |
| 115 | 180 | - (CGFloat)collectionViewLayout:(CNCollectionViewLayout*)layout heightAtIndexPath:(NSIndexPath*)indexPath{ |
| ... | ... | @@ -131,6 +196,12 @@ static NSString *const CNWitnessSearchPersonCellID = @"CNWitnessSearchPersonCell |
| 131 | 196 | if (![_searchStr isEqualToString:searchStr]) { |
| 132 | 197 | _searchStr = searchStr; |
| 133 | 198 | [self.dataSource removeAllObjects]; |
| 199 | + if (self.type == CNWitnessSearchDetailTypeVideo) { | |
| 200 | + [self.videoIDArray removeAllObjects]; | |
| 201 | + }else{ | |
| 202 | + [self.personIDArray removeAllObjects]; | |
| 203 | + } | |
| 204 | + | |
| 134 | 205 | [self.collectionView reloadData]; |
| 135 | 206 | self.page = 1; |
| 136 | 207 | [self requestData]; |
| ... | ... | @@ -170,10 +241,6 @@ static NSString *const CNWitnessSearchPersonCellID = @"CNWitnessSearchPersonCell |
| 170 | 241 | weakSelf.page ++; |
| 171 | 242 | [weakSelf requestData]; |
| 172 | 243 | }]; |
| 173 | -// UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { | |
| 174 | -// [weakSelf.view endEditing:YES]; | |
| 175 | -// }]; | |
| 176 | -// [_collectionView addGestureRecognizer:pan]; | |
| 177 | 244 | } |
| 178 | 245 | return _collectionView; |
| 179 | 246 | } |
| ... | ... | @@ -184,6 +251,18 @@ static NSString *const CNWitnessSearchPersonCellID = @"CNWitnessSearchPersonCell |
| 184 | 251 | } |
| 185 | 252 | return _dataSource; |
| 186 | 253 | } |
| 254 | +- (NSMutableArray *)personIDArray{ | |
| 255 | + if (!_personIDArray) { | |
| 256 | + _personIDArray = [NSMutableArray array]; | |
| 257 | + } | |
| 258 | + return _personIDArray; | |
| 259 | +} | |
| 260 | +- (NSMutableArray *)videoIDArray{ | |
| 261 | + if (!_videoIDArray) { | |
| 262 | + _videoIDArray = [NSMutableArray array]; | |
| 263 | + } | |
| 264 | + return _videoIDArray; | |
| 265 | +} | |
| 187 | 266 | #pragma mark - JXCategoryListContentViewDelegate |
| 188 | 267 | - (UIView *)listView{ |
| 189 | 268 | return self.view; | ... | ... |
Example/CNLiveVideoClassifyKit/CNLiveClassifyKitImpl.m
| ... | ... | @@ -95,6 +95,16 @@ |
| 95 | 95 | - (void)skipType:(nonnull NSString *)type to:(nonnull NSString *)to shopType:(nonnull NSString *)shopType currentVC:(nonnull UIViewController *)currentVC { |
| 96 | 96 | |
| 97 | 97 | } |
| 98 | - | |
| 98 | +/// 打开用户个人视频页 | |
| 99 | +/// @param params 传递参数 | |
| 100 | +- (void)openPersonMessage:(NSDictionary *)params{ | |
| 101 | + | |
| 102 | +} | |
| 103 | +/// 打开视频播放页面 | |
| 104 | +/// @param currentIndex 当前选中 | |
| 105 | +/// @param dataList 视频数组 | |
| 106 | +- (void)openVideoPlayerVCWithCurrentIndex:(NSString *)currentIndex dataList:(NSArray *)dataList{ | |
| 107 | + | |
| 108 | +} | |
| 99 | 109 | |
| 100 | 110 | @end | ... | ... |