VideoDynamicView.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. //
  2. // VideoDynamicView.m
  3. // BuguLive
  4. //
  5. // Created by 岳克奎 on 17/4/17.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "VideoDynamicView.h"
  9. #import "UIImage+STCommon.h"
  10. #import "DTTopicModel.h"
  11. @implementation VideoDynamicView
  12. -(instancetype)initWithCoder:(NSCoder *)aDecoder{
  13. if (self = [super initWithCoder:aDecoder]) {
  14. self.backgroundColor = UIColor.clearColor;
  15. [self initModel];
  16. [self showSetSubView];
  17. }
  18. return self;
  19. }
  20. -(void)awakeFromNib
  21. {
  22. [super awakeFromNib];
  23. }
  24. -(void)showSetSubView
  25. {
  26. if (!self.tableView)
  27. {
  28. [self tableView];
  29. // self.tableView.tableFooterView = self.footerView;
  30. }
  31. [self registerCell];
  32. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  33. self.dataSoureMArray = @[].mutableCopy;
  34. }
  35. - (void)setVideoURL:(NSURL *)videoURL{
  36. _videoURL = videoURL;
  37. self.dataSoureMArray = @[].mutableCopy;
  38. AVURLAsset *asset1 = [AVURLAsset assetWithURL:videoURL];
  39. CMTime time = [asset1 duration];
  40. int seconds = ceil(time.value/time.timescale);
  41. if (seconds > 5) seconds = 5;
  42. for (int i = 0;i< seconds;i++) {
  43. UIImage *thumbnailImage = [UIImage st_thumbnailImageForVideo:videoURL atTime:i];
  44. [self.dataSoureMArray addObject:thumbnailImage];
  45. }
  46. self.recordSelectIndex = 0;
  47. dispatch_async(dispatch_get_main_queue(), ^{
  48. [self.tableView reloadData];
  49. });
  50. }
  51. -(void)initModel{
  52. self.actionArr = [NSMutableArray array];
  53. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  54. [parmDict setObject:@"publish" forKey:@"ctl"];
  55. [parmDict setObject:@"get_video_type" forKey:@"act"];
  56. [parmDict setObject:@"xr" forKey:@"itype"];
  57. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  58. {
  59. FWWeakify(self)
  60. if ([responseJson toInt:@"status"] == 1)
  61. {
  62. NSArray *arr = [responseJson valueForKey:@"info"];
  63. if ([arr isKindOfClass:[NSArray class]]) {
  64. for (NSDictionary *dic in arr) {
  65. MGBaseModel *model =[MGBaseModel mj_objectWithKeyValues: dic];
  66. [self.actionArr addObject:model];
  67. }
  68. }
  69. [self.tableView reloadData];
  70. }
  71. } FailureBlock:^(NSError *error)
  72. {
  73. }];
  74. }
  75. -(void)registerCell{
  76. // 视频封面显示cell
  77. [self.tableView registerNib:[UINib nibWithNibName:@"STTableShowVideoCell"
  78. bundle:nil]
  79. forCellReuseIdentifier:@"STTableShowVideoCell"];
  80. // 动态文本显示cell
  81. [self.tableView registerNib:[UINib nibWithNibName:@"STTableTextViewCell"
  82. bundle:nil]
  83. forCellReuseIdentifier:@"STTableTextViewCell"];
  84. //商品 显示cell
  85. [self.tableView registerNib:[UINib nibWithNibName:@"STTableLeftRightCell"
  86. bundle:nil]
  87. forCellReuseIdentifier:@"STTableLeftRightCell"];
  88. //地理坐标 显示cell
  89. [self.tableView registerNib:[UINib nibWithNibName:@"STTableLeftRightLabCell"
  90. bundle:nil]
  91. forCellReuseIdentifier:@"STTableLeftRightLabCell"];
  92. //提交功能 cell
  93. [self.tableView registerNib:[UINib nibWithNibName:@"STTableCommitBtnCell"
  94. bundle:nil]
  95. forCellReuseIdentifier:@"STTableCommitBtnCell"];
  96. // [self.tableView registerClass:[STVideoCateCell class] forCellReuseIdentifier:NSStringFromClass([STVideoCateCell class])];
  97. self.tableView.tableFooterView = self.footerView;
  98. }
  99. #pragma mark -- Row
  100. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  101. // if (self.dataSoureMArray.count == 0)
  102. // {
  103. // return 0;
  104. // }
  105. if (section == 1) {
  106. return 2;
  107. }
  108. return 1;
  109. }
  110. #pragma mark -- cell
  111. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  112. if(indexPath.section == 0 && indexPath.row == 0)
  113. {
  114. STTableShowVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"STTableShowVideoCell"
  115. forIndexPath:indexPath];
  116. //[cell setDelegate:self];
  117. //[cell.bgImgView setImage:[UIImage boxblurImage:self.dataSoureMArray[_recordSelectIndex] withBlurNumber:1]];
  118. // cell.bgImgView.hidden = NO;
  119. if (self.dataSoureMArray.count > 0) {
  120. [cell.videoCoverImgView setImage:self.dataSoureMArray[_recordSelectIndex]];
  121. }
  122. cell.videoCoverImgView.hidden = NO;
  123. cell.separatorView.hidden = YES;
  124. cell.changeCoverBtn.hidden = NO;
  125. // cell.changeVideoBtn.hidden = NO;
  126. // cell.changeVideoLab.hidden = NO;
  127. // cell.changeVideoIconImgeView.hidden = NO;
  128. // [cell.changeVideoIconImgeView setImage:[UIImage imageNamed:@"st_videoDynamic_changeVideo"]];
  129. cell.promptLab.hidden = NO;
  130. cell.promptLab.text = ASLocalizedString(@"请选择封面");
  131. [cell setDelegate:self];
  132. cell.backgroundColor = UIColor.clearColor;
  133. return cell;
  134. }
  135. // if(indexPath.section == 1 && indexPath.row == 0)
  136. // {
  137. // STTableTextViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"STTableTextViewCell"
  138. // forIndexPath:indexPath];
  139. // cell.separatorView.hidden = NO;
  140. // [cell setDelegate:self];
  141. // return cell;
  142. // }
  143. if(indexPath.section == 1 && indexPath.row == 3)
  144. {
  145. STVideoCateCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([STVideoCateCell class])];
  146. // cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  147. // cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"com_arrow_right_1"]];
  148. return cell;
  149. }
  150. if(indexPath.section == 1 && indexPath.row == 0)
  151. {
  152. STTableLeftRightCell *cell = [tableView dequeueReusableCellWithIdentifier:@"STTableLeftRightCell"
  153. forIndexPath:indexPath];
  154. cell.hidden = YES;
  155. cell.separatorView.hidden = YES;
  156. // STBMKCenter *stBMKCenter = [STBMKCenter shareManager];
  157. cell.rightLab.hidden = NO;
  158. // cell.leftLab.hidden = NO;
  159. // cell.leftLab.text = ASLocalizedString(@"所在位置");
  160. // if (!stBMKCenter.districtStr ||stBMKCenter.districtStr.length<2) {
  161. // cell.rightLab.text = ASLocalizedString(@"不显示");
  162. // }else{
  163. // cell.rightLab.text = stBMKCenter.districtStr;
  164. // }
  165. // cell.separatorView.backgroundColor = [UIColor groupTableViewBackgroundColor];
  166. return cell;
  167. }
  168. if(indexPath.section == 1 && indexPath.row == 1)
  169. {
  170. STTableLeftRightLabCell *cell = [tableView dequeueReusableCellWithIdentifier:@"STTableLeftRightLabCell"
  171. forIndexPath:indexPath];
  172. cell.separatorView.hidden = YES;
  173. STBMKCenter *stBMKCenter = [STBMKCenter shareManager];
  174. cell.rightLab.hidden = NO;
  175. // cell.leftLab.hidden = NO;
  176. // cell.leftLab.text = ASLocalizedString(@"所在位置");
  177. if (!stBMKCenter.districtStr ||stBMKCenter.districtStr.length<2) {
  178. cell.rightLab.text = ASLocalizedString(@"不显示");
  179. }else{
  180. cell.rightLab.text = stBMKCenter.districtStr;
  181. }
  182. cell.backgroundColor = UIColor.clearColor;
  183. // cell.separatorView.backgroundColor = [UIColor groupTableViewBackgroundColor];
  184. return cell;
  185. }
  186. if(indexPath.section == 2 && indexPath.row == 0)
  187. {
  188. STTableCommitBtnCell *cell = [tableView dequeueReusableCellWithIdentifier:@"STTableCommitBtnCell"
  189. forIndexPath:indexPath];
  190. // cell.commitBtn.backgroundColor = kAppMainColor;
  191. cell.commitBtn.layer.cornerRadius = 3;
  192. cell.commitBtn.layer.masksToBounds = YES;
  193. [cell.commitBtn setBackgroundImage:[UIImage imageNamed:@"widthBtnBg"] forState:UIControlStateNormal];
  194. [cell.commitBtn setTitle:ASLocalizedString(@"发布")forState:UIControlStateNormal];
  195. [cell.commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  196. cell.backgroundColor = UIColor.clearColor;
  197. return cell;
  198. }
  199. return nil;
  200. }
  201. #pragma mark ---section
  202. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  203. return 2;
  204. }
  205. #pragma mark -- row height
  206. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  207. if(indexPath.section == 1 && indexPath.row == 0)
  208. {
  209. return 0.01;
  210. }
  211. if(indexPath.section == 0)
  212. {
  213. return 320;
  214. }
  215. // if(indexPath.section == 1)
  216. // {
  217. // return 150;
  218. // }
  219. if(indexPath.section == 1)
  220. {
  221. return 55;
  222. }
  223. if(indexPath.section == 2)
  224. {
  225. return 55;
  226. }
  227. return 0;
  228. }
  229. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  230. if (indexPath.section == 3 && indexPath.row == 0)
  231. {
  232. if (_delegate &&[_delegate respondsToSelector:@selector(showMyVideoView)])
  233. {
  234. [_delegate showMyVideoView];
  235. }
  236. }
  237. if(indexPath.section == 1 && indexPath.row == 3)
  238. {
  239. //进入视频分类
  240. STVideoCateCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  241. if (_delegate && [_delegate respondsToSelector:@selector(goVCOnVideoDynamicView:STTableShowVideoCell:andChooseCateClick:)]) {
  242. [_delegate goVCOnVideoDynamicView:self STTableShowVideoCell:cell andChooseCateClick:cell.cateBtn];
  243. }
  244. }
  245. //选择商品
  246. if(indexPath.section == 1 && indexPath.row == 0)
  247. {
  248. STTableLeftRightCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  249. if (self.delegate && [self.delegate respondsToSelector:@selector(dynamicView:didSelectGood:)]) {
  250. [self.delegate dynamicView:self didSelectGood:cell];
  251. }
  252. }
  253. //百度地图定位
  254. if(indexPath.section == 1 && indexPath.row == 1)
  255. {
  256. [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"定位中...")];
  257. //加载地图
  258. [self startLocation];
  259. }
  260. }
  261. - (void)submitAction{
  262. [self endEditing:YES];
  263. if (_delegate &&[_delegate respondsToSelector:@selector(submitData)])
  264. {
  265. [_delegate submitData];
  266. }
  267. }
  268. -(void)startLocation{
  269. if ([CLLocationManager locationServicesEnabled]) {//判断定位操作是否被允许
  270. self.locationManager = [[CLLocationManager alloc] init];
  271. self.locationManager.delegate = self;//遵循代理
  272. self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
  273. self.locationManager.distanceFilter = 10.0f;
  274. [_locationManager requestWhenInUseAuthorization];//使用程序其间允许访问位置数据(iOS8以上版本定位需要)
  275. [self.locationManager startUpdatingLocation];//开始定位
  276. }else{//不能定位用户的位置的情况再次进行判断,并给与用户提示
  277. //1.提醒用户检查当前的网络状况
  278. //2.提醒用户打开定位开关
  279. [[BGHUDHelper sharedInstance] syncStopLoading];
  280. }
  281. }
  282. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
  283. //当前所在城市的坐标值
  284. CLLocation *currLocation = [locations lastObject];
  285. NSLog(ASLocalizedString(@"经度=%f 纬度=%f 高度=%f"), currLocation.coordinate.latitude, currLocation.coordinate.longitude, currLocation.altitude);
  286. //根据经纬度反向地理编译出地址信息
  287. CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
  288. [geoCoder reverseGeocodeLocation:currLocation completionHandler:^(NSArray *placemarks, NSError *error) {
  289. for (CLPlacemark * placemark in placemarks) {
  290. NSDictionary *address = [placemark addressDictionary];
  291. // Country(国家) State(省) City(市)
  292. NSLog(@"#####%@",address);
  293. NSLog(@"%@", [address objectForKey:@"Country"]);
  294. NSLog(@"%@", [address objectForKey:@"State"]);
  295. NSLog(@"%@", [address objectForKey:@"City"]);
  296. STTableLeftRightLabCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]];
  297. cell.rightLab.text = [address objectForKey:@"City"];
  298. [[BGHUDHelper sharedInstance] syncStopLoading];
  299. }
  300. }];
  301. }
  302. -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
  303. [[BGHUDHelper sharedInstance] syncStopLoading];
  304. if ([error code] == kCLErrorDenied){
  305. //访问被拒绝
  306. [FanweMessage alertHUD:ASLocalizedString(@"访问被拒绝")];
  307. }
  308. if ([error code] == kCLErrorLocationUnknown) {
  309. //无法获取位置信息
  310. [FanweMessage alertHUD:ASLocalizedString(@"无法获取位置信息")];
  311. }
  312. }
  313. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger) buttonIndex
  314. {
  315. if (buttonIndex != self.actionArr.count) {
  316. self.videoModel = self.actionArr[buttonIndex];
  317. STTableLeftRightLabCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:2]];
  318. cell.rightLab.text = self.videoModel.title;
  319. }
  320. }
  321. #pragma mark *********************** Deleagte 协议方法 *****************************
  322. #pragma mark ---------- STTableTextViewCellDeleagte 协议方法
  323. -(void)showSTTableTextViewCell:(STTableTextViewCell *)stTableTextViewCell
  324. {
  325. _recordTextViewStr = stTableTextViewCell.textView.text;
  326. NSLog(@"-----text view text ---- %@--------",_recordTextViewStr);
  327. }
  328. //STTableShowVideoCell
  329. #pragma mark ---------- STTableShowVideoCell
  330. - (void)videoCell:(STTableShowVideoCell *)videoCell didChangeText:(NSString *)text{
  331. _recordTextViewStr = text;
  332. }
  333. -(void)showSystemIPC:(BOOL)isSystemIPC andMaxSelectNum:(int)maxSelectNum
  334. {
  335. if (_delegate &&[_delegate respondsToSelector:@selector(showMyVideoView)])
  336. {
  337. [_delegate showMyVideoView];
  338. }
  339. }
  340. #pragma mark -------- 去封面选择页面
  341. -(void)showSTTableShowVideoCell:(STTableShowVideoCell *)stTableShowVideoCell andChangeVideoCoverClick:(UIButton *)changeVideoCoverClick
  342. {
  343. if (_delegate &&[_delegate respondsToSelector:@selector(showOnVideoDynamicView:STTableShowVideoCell:andChangeVideoCoverClick:)])
  344. {
  345. [_delegate showOnVideoDynamicView:self
  346. STTableShowVideoCell:stTableShowVideoCell
  347. andChangeVideoCoverClick:changeVideoCoverClick];
  348. }
  349. }
  350. -(void)setDelegate:(id<VideoDynamicViewDelegate>)delegate
  351. {
  352. _delegate = delegate;
  353. }
  354. - (UIView *)footerView{
  355. if (!_footerView) {
  356. _footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 140)];
  357. _footerView.backgroundColor = UIColor.clearColor;
  358. UIButton * btn = ({
  359. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  360. // [btn setBackgroundImage:[UIImage imageNamed:@"短视频发布按钮"] forState:UIControlStateNormal];
  361. // [btn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateSelected];
  362. [btn setTitle:ASLocalizedString(@"发布")forState:UIControlStateNormal];
  363. [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  364. btn.titleLabel.font = [UIFont systemFontOfSize:14];
  365. [btn setBackgroundImage:[UIImage imageNamed:@"widthBtnBg"] forState:UIControlStateNormal];
  366. [btn addTarget:self action:@selector(submitAction) forControlEvents:UIControlEventTouchUpInside];
  367. // btn.clipsToBounds = YES;
  368. // btn.layer.cornerRadius = 20;
  369. btn;
  370. });
  371. [_footerView addSubview:btn];
  372. [btn mas_makeConstraints:^(MASConstraintMaker *make) {
  373. make.top.mas_equalTo(100);
  374. make.left.equalTo(_footerView).offset(62);
  375. make.right.equalTo(_footerView).offset(-62);
  376. make.height.mas_equalTo(@45);
  377. }];
  378. }
  379. return _footerView;
  380. }
  381. @end