YBShareView.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. //
  2. // YBShareView.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/8/29.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBShareView.h"
  9. #import "YBShareViewCell.h"
  10. #import <AssetsLibrary/AssetsLibrary.h>
  11. #import <AFNetworking.h>
  12. typedef NS_ENUM(NSInteger,RKDownType) {
  13. RKDownType_Save, //普通下载
  14. RKDownType_Chorus, //合拍下载
  15. };
  16. @interface YBShareView()<UIGestureRecognizerDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
  17. {
  18. BOOL _isDownLoading;
  19. MBProgressHUD *hud;
  20. NSURL *fullPathsss;
  21. NSArray *_shareArray;
  22. NSArray *_shareTitleArray;
  23. NSArray *_fucArray;
  24. NSArray *_funTitleArray;
  25. RKShareType _fromType;
  26. NSDictionary *_parameterDic;
  27. }
  28. @end
  29. static YBShareView *_noShareUIManager = nil;
  30. @implementation YBShareView
  31. - (void)awakeFromNib {
  32. [super awakeFromNib];
  33. self.frame = [UIScreen mainScreen].bounds;
  34. }
  35. #pragma mark - 分享显示-底部
  36. +(instancetype)showShareWithType:(RKShareType)fromType parameter:(NSDictionary *)parameter commplete:(ShareBlock)complete {
  37. YBShareView *sV = [[[NSBundle mainBundle]loadNibNamed:@"YBShareView" owner:nil options:nil]objectAtIndex:0];;
  38. if (complete) {
  39. sV.shareEvent = ^(int codeEvent,NSString *nums) {
  40. complete(codeEvent,nums);
  41. };
  42. }
  43. [sV setUpView:fromType parameter:parameter];
  44. return sV;
  45. }
  46. -(void)bottomViewParaInit {
  47. self.midBgView.hidden = YES;
  48. _isDownLoading = NO;
  49. _bgViewHeight.constant = 270+ShowDiff;
  50. _shareCollectionHeight.constant = 110;
  51. _fucCollectionHeight.constant = 110;
  52. self.frame = [UIScreen mainScreen].bounds;
  53. _titleL.text = YZMsg(@"分享至");
  54. _shareCollectionView.delegate = self;
  55. _shareCollectionView.dataSource = self;
  56. _fucCollectionView.delegate = self;
  57. _fucCollectionView.dataSource = self;
  58. [_shareCollectionView registerNib:[UINib nibWithNibName:@"YBShareViewCell" bundle:nil] forCellWithReuseIdentifier:@"ShareTypeCell"];
  59. [_fucCollectionView registerNib:[UINib nibWithNibName:@"YBShareViewCell" bundle:nil] forCellWithReuseIdentifier:@"SharefucCell"];
  60. }
  61. -(void)setUpView:(RKShareType)fromType parameter:(NSDictionary *)parameter{
  62. [self bottomViewParaInit];
  63. _fromType = fromType;
  64. _parameterDic = parameter;
  65. self.bgView.backgroundColor = self.shareCollectionView.backgroundColor = self.fucCollectionView.backgroundColor = (_fromType == RKShareType_Invite||_fromType == RKShareType_Liveing ||fromType == RKShareType_card)?[UIColor whiteColor] : Normal_Color;
  66. UITapGestureRecognizer *tagGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
  67. tagGes.delegate = self;
  68. [self addGestureRecognizer:tagGes];
  69. NSArray *shareA = [NSArray arrayWithArray:[common share_type]];
  70. NSMutableArray *m_arr = [NSMutableArray array];
  71. for (NSString *share_title in shareA) {
  72. NSString *show_title;
  73. if ([share_title isEqual:@"wx"]) {
  74. show_title = YZMsg(@"微信");
  75. }else if ([share_title isEqual:@"wchat"]){
  76. show_title = YZMsg(@"朋友圈");
  77. }else if ([share_title isEqual:@"qzone"]){
  78. show_title = YZMsg(@"QQ空间");
  79. }else if ([share_title isEqual:@"qq"]){
  80. show_title = @"QQ";
  81. }else if ([share_title isEqual:@"facebook"]){
  82. show_title = @"Facebook";
  83. }else if ([share_title isEqual:@"twitter"]){
  84. show_title = YZMsg(@"推特");
  85. }
  86. [m_arr addObject:show_title];
  87. }
  88. _shareArray = [NSArray arrayWithArray:shareA];
  89. _shareTitleArray = [NSArray arrayWithArray:m_arr];
  90. //fromType 0:视频界面分享 1:三级分销分享 2:直播主播预览界面分享(无UI) 3直播中分享 4发布界面分享(无UI)
  91. if (fromType == RKShareType_LookVdieo) {
  92. //视频
  93. /*
  94. _fucArray = @[@"举报",@"复制链接",@"合拍",@"保存",@"上热门"];
  95. _funTitleArray = @[YZMsg(@"举报"),YZMsg(@"复制链接"),YZMsg(@"合拍"),YZMsg(@"保存"),YZMsg(@"上热门")];
  96. NSString *ID = [NSString stringWithFormat:@"%@",[[_parameterDic valueForKey:@"userinfo"] valueForKey:@"id"]];
  97. if ([ID isEqual:[Config getOwnID]]) {
  98. _fucArray = @[@"删除",@"复制链接",@"合拍",@"保存",@"上热门"];
  99. _funTitleArray = @[YZMsg(@"删除"),YZMsg(@"复制链接"),YZMsg(@"合拍"),YZMsg(@"保存"),YZMsg(@"上热门")];
  100. }
  101. */
  102. [self lookVideoSubsWithColTitle:@"收藏"];
  103. }else if(fromType == RKShareType_Invite ) {
  104. //分销
  105. _fucArray = @[@"复制"];
  106. _funTitleArray = @[YZMsg(@"复制")];
  107. }else if (fromType == RKShareType_Liveing){
  108. //直播中
  109. _fucArray = @[];
  110. _funTitleArray = @[];
  111. }else if (fromType == RKShareType_card){
  112. //名片分享
  113. _fucArray = @[];
  114. _funTitleArray = @[];
  115. }
  116. if (fromType == RKShareType_LivePre){
  117. _titleL.textAlignment = NSTextAlignmentCenter;
  118. _closeBtn.hidden = YES;
  119. }
  120. if (_shareArray.count<=0) {
  121. _shareCollectionHeight.constant = 0;
  122. _bgViewHeight.constant -= 110;
  123. }
  124. if (_fucArray.count<=0) {
  125. _fucCollectionHeight.constant = 0;
  126. _bgViewHeight.constant -= 110;
  127. }
  128. /*
  129. if (_shareArray.count>4||_fucArray.count>4) {
  130. _titleL.text = YZMsg(@"分享至(左右滑动显示更多)");
  131. }
  132. */
  133. if (_shareArray.count>0||_fucArray.count>0) {
  134. [self showBottomView];
  135. }else {
  136. [MBProgressHUD showError:YZMsg(@"分享未开启")];
  137. }
  138. }
  139. -(void)lookVideoSubsWithColTitle:(NSString *)colTitle {
  140. _fucArray = @[@"上热门",colTitle,@"举报",@"合拍",@"保存",@"复制链接"];
  141. _funTitleArray = @[YZMsg(@"上热门"),YZMsg(colTitle),YZMsg(@"举报"),YZMsg(@"合拍"),YZMsg(@"保存"),YZMsg(@"复制链接")];
  142. if ([PublicObj isUp]) {
  143. _fucArray = @[colTitle,@"举报",@"合拍",@"保存",@"复制链接"];
  144. _funTitleArray = @[YZMsg(colTitle),YZMsg(@"举报"),YZMsg(@"合拍"),YZMsg(@"保存"),YZMsg(@"复制链接")];
  145. }
  146. NSString *ID = [NSString stringWithFormat:@"%@",[[_parameterDic valueForKey:@"userinfo"] valueForKey:@"id"]];
  147. if ([ID isEqual:[Config getOwnID]]) {
  148. _fucArray = @[@"上热门",colTitle,@"删除",@"合拍",@"保存",@"复制链接"];
  149. _funTitleArray = @[YZMsg(@"上热门"),YZMsg(colTitle),YZMsg(@"删除"),YZMsg(@"合拍"),YZMsg(@"保存"),YZMsg(@"复制链接")];
  150. if ([PublicObj isUp]) {
  151. _fucArray = @[colTitle,@"删除",@"合拍",@"保存",@"复制链接"];
  152. _funTitleArray = @[YZMsg(colTitle),YZMsg(@"删除"),YZMsg(@"合拍"),YZMsg(@"保存"),YZMsg(@"复制链接")];
  153. }
  154. }
  155. }
  156. - (void)setLimitDic:(NSDictionary *)limitDic{
  157. _limitDic = limitDic;
  158. int iscollection = [minstr([limitDic valueForKey:@"iscollection"]) intValue];
  159. if (iscollection == 1) {
  160. [self lookVideoSubsWithColTitle:@"已收藏"];
  161. }else{
  162. [self lookVideoSubsWithColTitle:@"收藏"];
  163. }
  164. [_fucCollectionView reloadData];
  165. }
  166. -(void)showBottomView {
  167. [_bgView layoutIfNeeded];
  168. [self layoutIfNeeded];
  169. UIBezierPath *maskPath ;
  170. maskPath = [UIBezierPath bezierPathWithRoundedRect:_bgView.bounds byRoundingCorners:UIRectCornerTopRight|UIRectCornerTopLeft cornerRadii:CGSizeMake(10, 10)];
  171. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  172. maskLayer.frame = _bgView.bounds;
  173. maskLayer.path = maskPath.CGPath;
  174. _bgView.layer.mask = maskLayer;
  175. _midBgView.hidden = YES;
  176. [[UIApplication sharedApplication].delegate.window addSubview:self];
  177. [UIView animateWithDuration:0.3 animations:^{
  178. } completion:^(BOOL finished) {
  179. self.backgroundColor = RGB_COLOR(@"#000000", 0.3);
  180. }];
  181. }
  182. #pragma mark - 无分享界面
  183. /*
  184. +(instancetype)noShareUIManager {
  185. static dispatch_once_t onceToken;
  186. dispatch_once(&onceToken, ^{
  187. _noShareUIManager = [[super allocWithZone:NULL]init];
  188. });
  189. return _noShareUIManager;
  190. }
  191. + (instancetype)allocWithZone:(struct _NSZone *)zone {
  192. return [self noShareUIManager];
  193. }
  194. */
  195. +(instancetype)noShareUIManager {
  196. YBShareView *view = [[YBShareView alloc]init];
  197. return view;
  198. }
  199. -(void)executeShareWithType:(RKShareType)fromType shareType:(NSString *)shareType parameter:(NSDictionary *)parameter complete:(ShareBlock)complete {
  200. _fromType = fromType;
  201. _parameterDic = parameter;
  202. if (complete) {
  203. self.shareEvent = ^(int codeEvent, NSString *nums) {
  204. complete(codeEvent,nums);
  205. };
  206. }
  207. [self goShare:shareType];
  208. }
  209. - (IBAction)clickCancleBtn:(UIButton *)sender {
  210. [self dismiss];
  211. }
  212. #pragma mark - 有分享界面 (弹窗性质-中部)
  213. +(instancetype)showMidPopShareType:(RKShareType)fromType parameter:(NSDictionary *)parameter commplete:(ShareBlock)complete;{
  214. YBShareView *sV = [[[NSBundle mainBundle]loadNibNamed:@"YBShareView" owner:nil options:nil]objectAtIndex:1];;
  215. if (complete) {
  216. sV.shareEvent = ^(int codeEvent,NSString *nums) {
  217. complete(codeEvent,nums);
  218. };
  219. }
  220. [sV setUpMidPopView:fromType parameter:parameter];
  221. return sV;
  222. }
  223. -(void)setUpMidPopView:(RKShareType)fromType parameter:(NSDictionary *)parameter{
  224. self.bgView.hidden = YES;
  225. _midDesL.text = YZMsg(@"作品已成功发布,可分享到:");
  226. _fromType = fromType;
  227. _parameterDic = parameter;
  228. NSArray *shareA = [NSArray arrayWithArray:[common share_type]];
  229. _shareArray = [NSArray arrayWithArray:shareA];
  230. //测试
  231. //_shareArray = @[@"wx",@"wchat",@"qzone",@"qq",@"wx",@"wchat",@"qzone",@"qq"];
  232. UIScrollView *shareScorllView = [[UIScrollView alloc]init];
  233. shareScorllView.showsHorizontalScrollIndicator = NO;
  234. shareScorllView.bounces = NO;
  235. [_midTypeBg addSubview:shareScorllView];
  236. shareScorllView.backgroundColor = UIColor.clearColor;
  237. [shareScorllView mas_makeConstraints:^(MASConstraintMaker *make) {
  238. make.width.height.centerX.centerY.equalTo(_midTypeBg);
  239. }];
  240. CGFloat space = 20;
  241. int max_show_num = 4.0;
  242. CGFloat per_con_w = (_midBgView.width -space*(max_show_num+1))/max_show_num;
  243. CGFloat all_content_w = (_shareArray.count+1)*space+_shareArray.count*per_con_w;
  244. shareScorllView.contentSize = CGSizeMake(all_content_w, 0);
  245. UIView *scrollConten = [[UIView alloc]init];
  246. scrollConten.backgroundColor = UIColor.clearColor;
  247. [shareScorllView addSubview:scrollConten];
  248. [scrollConten mas_makeConstraints:^(MASConstraintMaker *make) {
  249. make.width.mas_equalTo(all_content_w);
  250. make.height.centerY.equalTo(shareScorllView);
  251. if (_shareArray.count<=4) {
  252. make.centerX.equalTo(shareScorllView);
  253. }else{
  254. make.left.equalTo(shareScorllView.mas_left).offset(0);
  255. }
  256. }];
  257. MASViewAttribute *mas_left = scrollConten.mas_left;
  258. for (int i=0; i<_shareArray.count; i++) {
  259. UIButton *btn = [UIButton buttonWithType:0];
  260. btn.tag = 1000 + i;
  261. [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"分享-%@",_shareArray[i]]] forState:UIControlStateNormal];
  262. [btn addTarget:self action:@selector(clickMidShare:) forControlEvents:UIControlEventTouchUpInside];
  263. [scrollConten addSubview:btn];
  264. [btn mas_makeConstraints:^(MASConstraintMaker *make) {
  265. make.width.height.mas_equalTo(per_con_w);
  266. make.centerY.equalTo(scrollConten);
  267. make.left.equalTo(mas_left).offset(space);
  268. }];
  269. mas_left = btn.mas_right;
  270. }
  271. if (_shareArray.count>0) {
  272. [self showMidView];
  273. }else {
  274. [MBProgressHUD showError:YZMsg(@"分享未开启")];
  275. }
  276. }
  277. -(void)clickMidShare:(UIButton *)sender {
  278. int index = (int)sender.tag-1000;
  279. NSLog(@"mid===:%@",_shareArray[index]);
  280. [self goShare:_shareArray[index]];
  281. }
  282. -(void)showMidView {
  283. [[UIApplication sharedApplication].delegate.window addSubview:self];
  284. [UIView animateWithDuration:0.3 animations:^{
  285. } completion:^(BOOL finished) {
  286. self.backgroundColor = RGB_COLOR(@"#000000", 0.2);
  287. }];
  288. }
  289. - (IBAction)clickMidCancleBtn:(UIButton *)sender {
  290. [self dismiss];
  291. }
  292. #pragma mark - 公共
  293. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
  294. if ([touch.view isDescendantOfView:self.bgView] && _isDownLoading == NO) {
  295. return NO;
  296. }
  297. return YES;
  298. }
  299. -(void)dismiss {
  300. [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  301. [self removeFromSuperview];
  302. }
  303. #pragma mark - CollectionView 代理
  304. /*
  305. * minimumLineSpacing、minimumInteritemSpacing去设置
  306. */
  307. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  308. return CGSizeMake(_window_width/4,110);
  309. }
  310. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  311. return UIEdgeInsetsMake(0,0,0,0);
  312. }
  313. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  314. return 0.01;
  315. }
  316. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  317. return 0.01;
  318. }
  319. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  320. return 1;
  321. }
  322. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  323. if (collectionView == _shareCollectionView) {
  324. return _shareArray.count;
  325. }else {
  326. return _fucArray.count;
  327. }
  328. }
  329. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  330. YBShareViewCell *cell;
  331. if (collectionView == _shareCollectionView) {
  332. cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ShareTypeCell" forIndexPath:indexPath];
  333. cell.thumbIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"分享-%@",_shareArray[indexPath.row]]];
  334. cell.titleL.text = minstr(_shareTitleArray[indexPath.row]);
  335. }else if(collectionView == _fucCollectionView) {
  336. cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SharefucCell" forIndexPath:indexPath];
  337. cell.thumbIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"分享-%@",_fucArray[indexPath.row]]];
  338. cell.titleL.text = minstr(_funTitleArray[indexPath.row]);
  339. }
  340. return cell;
  341. }
  342. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  343. if (collectionView == _shareCollectionView) {
  344. //分享显示在底部或者显示在中部
  345. NSLog(@"fenxiang");
  346. [self clickShareSender:(int)indexPath.row];
  347. }else {
  348. //方法点击
  349. NSLog(@"fuc");
  350. [self clickfucSender:(int)indexPath.row];
  351. }
  352. }
  353. #pragma mark - 分享事件
  354. -(void)clickShareSender:(int)index {
  355. if (![minstr([_limitDic valueForKey:@"limit_status"]) isEqual:@"1"] && _fromType == RKShareType_LookVdieo) {
  356. [MBProgressHUD showError:YZMsg(@"该视频不能分享")];
  357. return;
  358. }
  359. NSString *eventStr = _shareArray[index];
  360. [self goShare:eventStr];
  361. }
  362. -(void)goShare:(NSString *)eventStr {
  363. if ([eventStr isEqual:@"wx"] || [eventStr isEqual:@"微信"]) {
  364. [self simplyShare:SSDKPlatformSubTypeWechatSession];
  365. }else if ([eventStr isEqual:@"wchat"] || [eventStr isEqual:@"朋友圈"]){
  366. [self simplyShare:SSDKPlatformSubTypeWechatTimeline];
  367. }else if ([eventStr isEqual:@"qzone"] || [eventStr isEqual:@"QQ空间"]){
  368. [self simplyShare:SSDKPlatformSubTypeQZone];
  369. }else if ([eventStr isEqual:@"qq"] || [eventStr isEqual:@"QQ"]){
  370. [self simplyShare:SSDKPlatformSubTypeQQFriend];
  371. }else if ([eventStr isEqual:@"facebook"] || [eventStr isEqual:@"Facebook"]){
  372. [self simplyShare:SSDKPlatformTypeFacebook];
  373. }else if ([eventStr isEqual:@"twitter"] || [eventStr isEqual:@"推特"]){
  374. [self simplyShare:SSDKPlatformTypeTwitter];
  375. }
  376. }
  377. - (void)simplyShare:(int)SSDKPlatformType {
  378. //fromType 0:视频界面分享 1:三级分销分享 2:直播主播预览界面分享(无UI) 3直播中分享 4发布界面分享(无UI)
  379. //默认分享视频
  380. NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
  381. int SSDKContentType = SSDKContentTypeAuto;
  382. NSString *shareTitle = [common video_share_title];
  383. NSString *userNiceName = minstr([[_parameterDic valueForKey:@"userinfo"] valueForKey:@"user_nickname"]);
  384. if ([shareTitle containsString:@"{username}"]) {
  385. shareTitle = [shareTitle stringByReplacingOccurrencesOfString:@"{username}" withString:userNiceName];
  386. }
  387. // NSString *shareDes = [NSString stringWithFormat:@"%@%@",[[_parameterDic valueForKey:@"userinfo"] valueForKey:@"user_nickname"],[common video_share_des]];
  388. NSString *videoTitle = minstr([_parameterDic valueForKey:@"title"]);
  389. NSString *shareDes = [PublicObj checkNull:videoTitle] ? minstr([common video_share_des]):videoTitle;
  390. NSString *thumbStr = minstr([_parameterDic valueForKey:@"thumb_s"]);
  391. NSString *shareUrlStr = [h5url stringByAppendingFormat:@"/appapi/video/index?videoid=%@&type=0",[_parameterDic valueForKey:@"id"]];
  392. shareUrlStr = [shareUrlStr stringByAppendingFormat:@"&lang=%@",[YBLanguageTools serviceLang]];
  393. if (_fromType == RKShareType_Invite) {
  394. //三级分销分享
  395. shareDes = [common agent_share_des];
  396. thumbStr = [Config getUserAvatarThumb];
  397. shareUrlStr = [NSString stringWithFormat:@"%@/appapi/agentshare/index?uid=%@",h5url,[Config getOwnID]];
  398. shareUrlStr = [shareUrlStr stringByAppendingFormat:@"&lang=%@",[YBLanguageTools serviceLang]];
  399. shareTitle = [common agent_share_title];
  400. }
  401. if (_fromType == RKShareType_LivePre|| _fromType == RKShareType_Liveing) {
  402. //直播间分享、qq、都是下载链接
  403. //20-6-24微信改为观看
  404. shareUrlStr = minstr([common app_ios]);
  405. if (SSDKPlatformType == SSDKPlatformSubTypeWechatSession || SSDKPlatformType == SSDKPlatformSubTypeWechatTimeline) {
  406. shareUrlStr = [[common live_wx_siteurl] stringByAppendingFormat:@"%@",[_parameterDic valueForKey:@"hostId"]];
  407. }
  408. //shareDes = [NSString stringWithFormat:@"%@%@",[_parameterDic valueForKey:@"hostName"],[common live_share_des]];
  409. shareTitle = minstr([common live_share_title]);
  410. userNiceName = minstr([_parameterDic valueForKey:@"hostName"]);
  411. if ([shareTitle containsString:@"{username}"]) {
  412. shareTitle = [shareTitle stringByReplacingOccurrencesOfString:@"{username}" withString:userNiceName];
  413. }
  414. NSString *liveTitle = minstr([_parameterDic valueForKey:@"liveTitle"]);
  415. shareDes = [PublicObj checkNull:liveTitle] ? minstr([common live_share_des]):liveTitle;
  416. }
  417. if (_fromType == RKShareType_VideoPublish || _fromType == RKShareType_VPMidPop) {
  418. //发布界面分享
  419. shareDes = minstr([_parameterDic valueForKey:@"publish_des"]);
  420. }
  421. UIImage *shareImg;
  422. if (_fromType == RKShareType_card) {
  423. SSDKContentType = SSDKContentTypeImage;
  424. shareDes = minstr([_parameterDic valueForKey:@"shareTitle"]);
  425. shareUrlStr = minstr([_parameterDic valueForKey:@"href"]);
  426. NSData *imageData = [_parameterDic objectForKey:@"shareImage"];
  427. if (imageData) {
  428. shareImg = [[UIImage alloc] initWithData:imageData];
  429. }
  430. // shareImg = [_parameterDic valueForKey:@"shareImage"];
  431. }
  432. shareUrlStr = [shareUrlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  433. [shareParams SSDKSetupShareParamsByText:shareDes
  434. images:_fromType == RKShareType_card ? shareImg:thumbStr
  435. url:[NSURL URLWithString:shareUrlStr]
  436. title:shareTitle
  437. type:SSDKContentType];
  438. [shareParams SSDKEnableUseClientShare];
  439. YBWeakSelf;
  440. //进行分享
  441. [ShareSDK share:SSDKPlatformType
  442. parameters:shareParams
  443. onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
  444. switch (state) {
  445. case SSDKResponseStateSuccess: {
  446. [MBProgressHUD showSuccess:YZMsg(@"分享成功")];
  447. if (_fromType == RKShareType_LookVdieo) {
  448. [weakSelf addShare];
  449. }
  450. break;
  451. }
  452. case SSDKResponseStateFail: {
  453. [MBProgressHUD showError:YZMsg(@"分享失败")];
  454. break;
  455. }
  456. case SSDKResponseStateCancel: {
  457. break;
  458. }
  459. default:
  460. break;
  461. }
  462. if (_fromType != RKShareType_LookVdieo ) {
  463. [weakSelf dismiss];
  464. }
  465. if ((_fromType == RKShareType_LivePre || _fromType == RKShareType_VideoPublish || _fromType == RKShareType_VPMidPop) && weakSelf.shareEvent) {
  466. //2:直播预览分享、无论成功失败都去开始直播
  467. //4:发布页面分享、无论成功失败都返回首页
  468. weakSelf.shareEvent(6, @"");
  469. }
  470. if (_fromType == RKShareType_LivePre || _fromType == RKShareType_Liveing) {
  471. //每日任务-直播分享
  472. [[YBDayTaskManager shareInstance]taskOfShareRoom];
  473. }
  474. }];
  475. }
  476. -(void)addShare{
  477. NSString *random_str = [PublicObj stringToMD5:[NSString stringWithFormat:@"%@-%@-#2hgfk85cm23mk58vncsark",[Config getOwnID],[_parameterDic valueForKey:@"id"]]];
  478. NSString *url = [NSString stringWithFormat:@"Video.addShare&uid=%@&videoid=%@&random_str=%@",[Config getOwnID],[_parameterDic valueForKey:@"id"],random_str];
  479. YBWeakSelf;
  480. [YBNetworking postWithUrl:url Dic:nil Suc:^(int code, id info, NSString *msg) {
  481. if (code == 0) {
  482. NSDictionary *infoDic = [info firstObject];
  483. if (weakSelf.shareEvent) {
  484. weakSelf.shareEvent(0, minstr([infoDic valueForKey:@"shares"]));
  485. [weakSelf dismiss];
  486. }
  487. }else{
  488. [MBProgressHUD showPop:msg];
  489. }
  490. } Fail:^(id fail) {
  491. }];
  492. }
  493. #pragma mark - 功能事件
  494. -(void)clickfucSender:(int)index {
  495. //条件判断不需要翻译
  496. NSString *eventStr = _fucArray[index];
  497. if ([eventStr isEqual:@"举报"] && _fromType == RKShareType_LookVdieo) {
  498. if (self.shareEvent) {
  499. self.shareEvent(2, @"");
  500. }
  501. [self dismiss];
  502. }else if ([eventStr isEqual:@"复制链接"] && _fromType == RKShareType_LookVdieo) {
  503. if (![minstr([_limitDic valueForKey:@"limit_status"]) isEqual:@"1"]) {
  504. [MBProgressHUD showError:YZMsg(@"该视频不能复制链接")];
  505. return;
  506. }
  507. UIPasteboard *paste = [UIPasteboard generalPasteboard];
  508. if (![PublicObj checkNull:[_parameterDic valueForKey:@"href"]]) {
  509. NSString *href = [NSString stringWithFormat:@"%@",[_parameterDic valueForKey:@"href_w"]];
  510. if (href.length <= 0) {
  511. [MBProgressHUD showError:YZMsg(@"该视频暂不支持复制链接")];
  512. return;
  513. }
  514. href = [PublicObj decrypt:href];
  515. paste.string = href;
  516. [MBProgressHUD showSuccess:YZMsg(@"复制成功")];
  517. }
  518. [self dismiss];
  519. }else if ([eventStr isEqual:@"删除"] && _fromType == RKShareType_LookVdieo) {
  520. YBWeakSelf;
  521. NSDictionary *contentDic = @{@"title":YZMsg(@"提示"),@"msg":YZMsg(@"确认删除?"),@"left":YZMsg(@"取消"),@"right":YZMsg(@"确定")};
  522. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  523. if (eventType == 1) {
  524. [weakSelf delVideo];
  525. }else{
  526. [weakSelf dismiss];
  527. }
  528. }];
  529. self.hidden = YES;
  530. }else if ([eventStr isEqual:@"保存"] && _fromType == RKShareType_LookVdieo){
  531. if (![minstr([_limitDic valueForKey:@"limit_status"]) isEqual:@"1"]) {
  532. [MBProgressHUD showError:YZMsg(@"该视频不能保存")];
  533. return;
  534. }
  535. _isDownLoading = YES;
  536. [self downloadVideo:RKDownType_Save];
  537. }else if ([eventStr isEqual:@"复制"] && _fromType == RKShareType_Invite) {
  538. //三级分销
  539. NSString *copyStr = [NSString stringWithFormat:@"%@/appapi/agentshare/index?uid=%@",h5url,[Config getOwnID]];
  540. copyStr = [copyStr stringByAppendingFormat:@"&lang=%@",[YBLanguageTools serviceLang]];
  541. UIPasteboard *paste = [UIPasteboard generalPasteboard];
  542. paste.string = copyStr;
  543. [MBProgressHUD showError:YZMsg(@"复制成功")];
  544. [self dismiss];
  545. }else if ([eventStr isEqual:@"合拍"] && _fromType == RKShareType_LookVdieo) {
  546. if ([[Config getOwnID]intValue]<0) {
  547. [self dismiss];
  548. [PublicObj warnLogin];
  549. return;
  550. }
  551. if (![minstr([_limitDic valueForKey:@"video_status"]) isEqual:@"1"]) {
  552. [MBProgressHUD showError:minstr([_limitDic valueForKey:@"video_msg"])];
  553. return;
  554. }
  555. if (![minstr([_limitDic valueForKey:@"limit_status"]) isEqual:@"1"]) {
  556. [MBProgressHUD showError:YZMsg(@"该视频不能合拍")];
  557. return;
  558. }
  559. _isDownLoading = YES;
  560. [self downloadVideo:RKDownType_Chorus];
  561. }else if ([eventStr isEqual:@"上热门"] && _fromType == RKShareType_LookVdieo) {
  562. if (self.shareEvent) {
  563. self.shareEvent(5, @"");
  564. }
  565. [self dismiss];
  566. }else if ([eventStr isEqual:@"收藏"] && _fromType == RKShareType_LookVdieo) {
  567. if (self.shareEvent) {
  568. self.shareEvent(7, @"");
  569. }
  570. [self dismiss];
  571. }
  572. }
  573. -(void)delVideo {
  574. //[_parameterDic valueForKey:@"id"]
  575. NSDictionary *subdic = @{
  576. @"uid":[Config getOwnID],
  577. @"token":[Config getOwnToken],
  578. @"videoid":[NSString stringWithFormat:@"%@",[_parameterDic valueForKey:@"id"]]
  579. };
  580. YBWeakSelf;
  581. [YBNetworking postWithUrl:@"Video.del" Dic:subdic Suc:^(int code, id info, NSString *msg) {
  582. if (code == 0) {
  583. [MBProgressHUD showSuccess:YZMsg(@"删除成功")];
  584. if (weakSelf.shareEvent) {
  585. weakSelf.shareEvent(3, @"");
  586. [weakSelf dismiss];
  587. }
  588. }else{
  589. weakSelf.hidden = NO;
  590. [MBProgressHUD showPop:msg];
  591. }
  592. } Fail:^(id fail) {
  593. weakSelf.hidden = NO;
  594. }];
  595. }
  596. //下载视频到本地
  597. -(void)downloadVideo:(RKDownType)downType{
  598. [self dismiss];
  599. NSString *href = [NSString stringWithFormat:@"%@",[_parameterDic valueForKey:@"href_w"]];
  600. if (downType == RKDownType_Chorus) {
  601. href = [NSString stringWithFormat:@"%@",[_parameterDic valueForKey:@"href"]];
  602. }
  603. href = [PublicObj decrypt:href];
  604. if (href.length <= 0 || [href containsString:@".m3u8"]) {
  605. if (downType == RKDownType_Save) {
  606. [MBProgressHUD showError:YZMsg(@"该视频暂不支持下载")];
  607. }else {
  608. [MBProgressHUD showError:YZMsg(@"该视频暂不支持合拍")];
  609. }
  610. _isDownLoading = NO;
  611. [self dismiss];
  612. return;
  613. }
  614. NSString *title = [NSString stringWithFormat:@"%@",[_parameterDic valueForKey:@"title"]];
  615. if (title.length == 0) {
  616. NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
  617. NSTimeInterval a=[dat timeIntervalSince1970]*1000;
  618. NSString *timeString = [NSString stringWithFormat:@"%d", (int)a];
  619. title = timeString;
  620. }
  621. hud = [MBProgressHUD showHUDAddedTo:[YBBaseAppDelegate sharedAppDelegate].topViewController.view animated:YES];
  622. hud.mode = MBProgressHUDModeAnnularDeterminate;
  623. NSString *showDesText = YZMsg(@"正在下载视频");
  624. downType == RKDownType_Save ? (showDesText = YZMsg(@"正在下载视频")):(showDesText = YZMsg(@"请稍等..."));
  625. hud.label.text = showDesText;
  626. //1.创建会话管理者
  627. //AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
  628. NSURL *url = [NSURL URLWithString:href];
  629. NSURLRequest *request = [NSURLRequest requestWithURL:url];
  630. NSMutableURLRequest *m_reques = [request mutableCopy];
  631. [m_reques addValue:h5url forHTTPHeaderField:@"referer"];
  632. request = [m_reques copy];
  633. NSURLSessionDownloadTask *download = [[YBNetworking ybnetManager] downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
  634. //hud.progress = downloadProgress.fractionCompleted;
  635. dispatch_async(dispatch_get_main_queue(), ^{
  636. hud.progress = downloadProgress.completedUnitCount / downloadProgress.totalUnitCount;
  637. });
  638. //监听下载进度
  639. //completedUnitCount 已经下载的数据大小
  640. //totalUnitCount 文件数据的中大小
  641. NSLog(@"%f",1.0 *downloadProgress.completedUnitCount / downloadProgress.totalUnitCount);
  642. } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
  643. NSString *fullPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:response.suggestedFilename];
  644. NSLog(@"targetPath:%@",targetPath);
  645. NSLog(@"fullPath:%@",fullPath);
  646. return [NSURL fileURLWithPath:fullPath];
  647. } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
  648. fullPathsss = filePath;
  649. NSLog(@"%@",filePath);
  650. if (downType == RKDownType_Save) {
  651. UISaveVideoAtPathToSavedPhotosAlbum([filePath path], self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
  652. }else {
  653. dispatch_async(dispatch_get_main_queue(), ^{
  654. _isDownLoading = NO;
  655. [self dismiss];
  656. [MBProgressHUD hideHUDForView:[YBBaseAppDelegate sharedAppDelegate].topViewController.view animated:YES];
  657. if ([PublicObj checkNull:[fullPathsss path]]) {
  658. [MBProgressHUD showPop:YZMsg(@"该视频暂不支持合拍")];
  659. return ;
  660. }
  661. if (self.shareEvent) {
  662. self.shareEvent(4, [fullPathsss path]);
  663. }
  664. });
  665. }
  666. }];
  667. //3.执行Task
  668. [download resume];
  669. }
  670. - (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo: (void *)contextInfo {
  671. if (error == nil) {
  672. NSLog(@"视频保存成功");
  673. hud.label.text = YZMsg(@"视频保存成功");
  674. }else{
  675. NSLog(@"视频保存失败");
  676. hud.label.text = YZMsg(@"频保存失败");
  677. }
  678. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  679. [MBProgressHUD hideHUDForView:[YBBaseAppDelegate sharedAppDelegate].topViewController.view animated:YES];
  680. _isDownLoading = NO;
  681. [self dismiss];
  682. });
  683. BOOL isOk = [[NSFileManager defaultManager] removeItemAtPath:[fullPathsss path] error:nil];
  684. NSLog(@"%d",isOk);
  685. }
  686. @end