LandscapeShareView.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. //
  2. // LandscapeShareView.m
  3. // YBVideo
  4. //
  5. // Created by ybRRR on 2023/7/12.
  6. // Copyright © 2023 cat. All rights reserved.
  7. //
  8. #import "LandscapeShareView.h"
  9. #import "YBShareViewCell.h"
  10. #import <ShareSDK/ShareSDK.h>
  11. #import <ShareSDK/ShareSDK+Base.h>
  12. @interface LandscapeShareView ()<UICollectionViewDelegate, UICollectionViewDataSource>
  13. {
  14. UICollectionView *collectionView;
  15. NSMutableArray *_shareArray;
  16. NSMutableArray *_shareTitleArray;
  17. NSArray *_fucArray;
  18. NSArray *_funTitleArray;
  19. NSDictionary *_parameterDic;
  20. }
  21. @end
  22. @implementation LandscapeShareView
  23. -(instancetype)initWithFrame:(CGRect)frame parameter:(NSDictionary *)parameter andlimitDic:(NSDictionary *)limDic
  24. {
  25. self = [super initWithFrame:frame];
  26. if(self){
  27. _parameterDic = parameter;
  28. _limitDic = limDic;
  29. self.backgroundColor = Normal_Color;
  30. UILabel *titleLb = [[UILabel alloc]init];
  31. titleLb.frame = CGRectMake(10, 10, 100, 20);
  32. titleLb.textColor = UIColor.whiteColor;
  33. titleLb.font = [UIFont systemFontOfSize:16];
  34. titleLb.text = YZMsg(@"分享至");
  35. [self addSubview:titleLb];
  36. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
  37. flow.scrollDirection = UICollectionViewScrollDirectionVertical;
  38. flow.itemSize = CGSizeMake((self.width-50)/4, 60);
  39. flow.minimumLineSpacing = 10;
  40. flow.minimumInteritemSpacing = 10;
  41. collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, titleLb.bottom+10, self.width, self.height-50) collectionViewLayout:flow];
  42. collectionView.delegate = self;
  43. collectionView.dataSource = self;
  44. collectionView.backgroundColor = Normal_Color;
  45. [collectionView registerNib:[UINib nibWithNibName:@"YBShareViewCell" bundle:nil] forCellWithReuseIdentifier:@"YBShareViewCell"];
  46. [self addSubview:collectionView];
  47. NSArray *shareA = [NSArray arrayWithArray:[common share_type]];
  48. NSMutableArray *m_arr = [NSMutableArray array];
  49. for (NSString *share_title in shareA) {
  50. NSString *show_title;
  51. if ([share_title isEqual:@"wx"]) {
  52. show_title = YZMsg(@"微信");
  53. }else if ([share_title isEqual:@"wchat"]){
  54. show_title = YZMsg(@"朋友圈");
  55. }else if ([share_title isEqual:@"qzone"]){
  56. show_title = YZMsg(@"QQ空间");
  57. }else if ([share_title isEqual:@"qq"]){
  58. show_title = @"QQ";
  59. }else if ([share_title isEqual:@"facebook"]){
  60. show_title = @"Facebook";
  61. }else if ([share_title isEqual:@"twitter"]){
  62. show_title = YZMsg(@"推特");
  63. }
  64. [m_arr addObject:show_title];
  65. }
  66. _shareArray = [NSMutableArray arrayWithArray:shareA];
  67. _shareTitleArray = [NSMutableArray arrayWithArray:m_arr];
  68. int iscollection = [minstr([limDic valueForKey:@"iscollection"]) intValue];
  69. if (iscollection == 1) {
  70. [self lookVideoSubsWithColTitle:@"已收藏"];
  71. }else{
  72. [self lookVideoSubsWithColTitle:@"收藏"];
  73. }
  74. [collectionView reloadData];
  75. }
  76. return self;
  77. }
  78. //- (void)setLimitDic:(NSDictionary *)limitDic{
  79. //}
  80. -(void)lookVideoSubsWithColTitle:(NSString *)colTitle {
  81. _fucArray = @[@"上热门",colTitle,@"举报",@"合拍",@"保存",@"复制链接"];
  82. _funTitleArray = @[YZMsg(@"上热门"),YZMsg(colTitle),YZMsg(@"举报"),YZMsg(@"合拍"),YZMsg(@"保存"),YZMsg(@"复制链接")];
  83. if ([PublicObj isUp]) {
  84. _fucArray = @[colTitle,@"举报",@"合拍",@"保存",@"复制链接"];
  85. _funTitleArray = @[YZMsg(colTitle),YZMsg(@"举报"),YZMsg(@"合拍"),YZMsg(@"保存"),YZMsg(@"复制链接")];
  86. }
  87. NSString *ID = [NSString stringWithFormat:@"%@",[[_parameterDic valueForKey:@"userinfo"] valueForKey:@"id"]];
  88. if ([ID isEqual:[Config getOwnID]]) {
  89. _fucArray = @[@"上热门",colTitle,@"删除",@"合拍",@"保存",@"复制链接"];
  90. _funTitleArray = @[YZMsg(@"上热门"),YZMsg(colTitle),YZMsg(@"删除"),YZMsg(@"合拍"),YZMsg(@"保存"),YZMsg(@"复制链接")];
  91. if ([PublicObj isUp]) {
  92. _fucArray = @[colTitle,@"删除",@"合拍",@"保存",@"复制链接"];
  93. _funTitleArray = @[YZMsg(colTitle),YZMsg(@"删除"),YZMsg(@"合拍"),YZMsg(@"保存"),YZMsg(@"复制链接")];
  94. }
  95. }
  96. [_shareArray addObjectsFromArray:_fucArray];
  97. [_shareTitleArray addObjectsFromArray:_funTitleArray];
  98. }
  99. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  100. return _shareArray.count;
  101. }
  102. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  103. {
  104. return UIEdgeInsetsMake(0, 0, 0, 0);
  105. }
  106. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  107. return 1;
  108. }
  109. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  110. YBShareViewCell *cell;
  111. // if (collectionView == _shareCollectionView) {
  112. // cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ShareTypeCell" forIndexPath:indexPath];
  113. // cell.thumbIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"分享-%@",_shareArray[indexPath.row]]];
  114. // cell.titleL.text = minstr(_shareTitleArray[indexPath.row]);
  115. // }else if(collectionView == _fucCollectionView) {
  116. cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YBShareViewCell" forIndexPath:indexPath];
  117. cell.thumbIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"分享-%@",_shareArray[indexPath.row]]];
  118. cell.titleL.text = minstr(_shareTitleArray[indexPath.row]);
  119. // }
  120. return cell;
  121. }
  122. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  123. // if (collectionView == _shareCollectionView) {
  124. // //分享显示在底部或者显示在中部
  125. NSLog(@"fenxiang");
  126. [self clickShareSender:(int)indexPath.row];
  127. // }else {
  128. // //方法点击
  129. // NSLog(@"fuc");
  130. // [self clickfucSender:(int)indexPath.row];
  131. // }
  132. }
  133. #pragma mark - 分享事件
  134. -(void)clickShareSender:(int)index {
  135. if (![minstr([_limitDic valueForKey:@"limit_status"]) isEqual:@"1"]) {
  136. [MBProgressHUD showError:YZMsg(@"该视频不能分享")];
  137. return;
  138. }
  139. NSString *eventStr = _shareArray[index];
  140. [self goShare:eventStr];
  141. }
  142. -(void)goShare:(NSString *)eventStr {
  143. if ([eventStr isEqual:@"wx"] || [eventStr isEqual:@"微信"]) {
  144. [self simplyShare:SSDKPlatformSubTypeWechatSession];
  145. }else if ([eventStr isEqual:@"wchat"] || [eventStr isEqual:@"朋友圈"]){
  146. [self simplyShare:SSDKPlatformSubTypeWechatTimeline];
  147. }else if ([eventStr isEqual:@"qzone"] || [eventStr isEqual:@"QQ空间"]){
  148. [self simplyShare:SSDKPlatformSubTypeQZone];
  149. }else if ([eventStr isEqual:@"qq"] || [eventStr isEqual:@"QQ"]){
  150. [self simplyShare:SSDKPlatformSubTypeQQFriend];
  151. }else if ([eventStr isEqual:@"facebook"] || [eventStr isEqual:@"Facebook"]){
  152. [self simplyShare:SSDKPlatformTypeFacebook];
  153. }else if ([eventStr isEqual:@"twitter"] || [eventStr isEqual:@"推特"]){
  154. [self simplyShare:SSDKPlatformTypeTwitter];
  155. }
  156. if ([eventStr isEqual:@"举报"] ) {
  157. if (self.shareEvent) {
  158. self.shareEvent(2, @"");
  159. }
  160. [self dismiss];
  161. }else if ([eventStr isEqual:@"复制链接"]) {
  162. if (self.shareEvent) {
  163. self.shareEvent(8, @"");
  164. }
  165. [self dismiss];
  166. }else if ([eventStr isEqual:@"删除"]) {
  167. YBWeakSelf;
  168. NSDictionary *contentDic = @{@"title":YZMsg(@"提示"),@"msg":YZMsg(@"确认删除?"),@"left":YZMsg(@"取消"),@"right":YZMsg(@"确定")};
  169. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  170. if (eventType == 1) {
  171. [weakSelf delVideo];
  172. }else{
  173. // [weakSelf dismiss];
  174. }
  175. }];
  176. self.hidden = YES;
  177. }else if ([eventStr isEqual:@"保存"]){
  178. if (self.shareEvent) {
  179. self.shareEvent(9, @"");
  180. }
  181. [self dismiss];
  182. }
  183. // else if ([eventStr isEqual:@"复制"] && _fromType == RKShareType_Invite) {
  184. // //三级分销
  185. // NSString *copyStr = [NSString stringWithFormat:@"%@/appapi/agentshare/index?uid=%@",h5url,[Config getOwnID]];
  186. // copyStr = [copyStr stringByAppendingFormat:@"&lang=%@",[YBLanguageTools serviceLang]];
  187. // UIPasteboard *paste = [UIPasteboard generalPasteboard];
  188. // paste.string = copyStr;
  189. // [MBProgressHUD showError:YZMsg(@"复制成功")];
  190. // [self dismiss];
  191. // }
  192. else if ([eventStr isEqual:@"合拍"] ) {
  193. if (self.shareEvent) {
  194. self.shareEvent(10, @"");
  195. }
  196. [self dismiss];
  197. }else if ([eventStr isEqual:@"上热门"] ) {
  198. if (self.shareEvent) {
  199. self.shareEvent(5, @"");
  200. }
  201. [self dismiss];
  202. }else if ([eventStr isEqual:@"收藏"] ) {
  203. if (self.shareEvent) {
  204. self.shareEvent(7, @"");
  205. }
  206. [self dismiss];
  207. }
  208. }
  209. -(void)dismiss{
  210. if(self.shareHideEvent){
  211. self.shareHideEvent();
  212. }
  213. }
  214. - (void)simplyShare:(int)SSDKPlatformType {
  215. //fromType 0:视频界面分享 1:三级分销分享 2:直播主播预览界面分享(无UI) 3直播中分享 4发布界面分享(无UI)
  216. //默认分享视频
  217. NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
  218. int SSDKContentType = SSDKContentTypeAuto;
  219. NSString *shareTitle = [common video_share_title];
  220. NSString *userNiceName = minstr([[_parameterDic valueForKey:@"userinfo"] valueForKey:@"user_nickname"]);
  221. if ([shareTitle containsString:@"{username}"]) {
  222. shareTitle = [shareTitle stringByReplacingOccurrencesOfString:@"{username}" withString:userNiceName];
  223. }
  224. // NSString *shareDes = [NSString stringWithFormat:@"%@%@",[[_parameterDic valueForKey:@"userinfo"] valueForKey:@"user_nickname"],[common video_share_des]];
  225. NSString *videoTitle = minstr([_parameterDic valueForKey:@"title"]);
  226. NSString *shareDes = [PublicObj checkNull:videoTitle] ? minstr([common video_share_des]):videoTitle;
  227. NSString *thumbStr = minstr([_parameterDic valueForKey:@"thumb_s"]);
  228. NSString *shareUrlStr = [h5url stringByAppendingFormat:@"/appapi/video/index?videoid=%@&type=0",[_parameterDic valueForKey:@"id"]];
  229. shareUrlStr = [shareUrlStr stringByAppendingFormat:@"&lang=%@",[YBLanguageTools serviceLang]];
  230. UIImage *shareImg;
  231. shareUrlStr = [shareUrlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  232. [shareParams SSDKSetupShareParamsByText:shareDes
  233. images:thumbStr
  234. url:[NSURL URLWithString:shareUrlStr]
  235. title:shareTitle
  236. type:SSDKContentType];
  237. [shareParams SSDKEnableUseClientShare];
  238. YBWeakSelf;
  239. //进行分享
  240. [ShareSDK share:SSDKPlatformType
  241. parameters:shareParams
  242. onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
  243. switch (state) {
  244. case SSDKResponseStateSuccess: {
  245. [MBProgressHUD showSuccess:YZMsg(@"分享成功")];
  246. // if (_fromType == RKShareType_LookVdieo) {
  247. [weakSelf addShare];
  248. // }
  249. break;
  250. }
  251. case SSDKResponseStateFail: {
  252. [MBProgressHUD showError:YZMsg(@"分享失败")];
  253. break;
  254. }
  255. case SSDKResponseStateCancel: {
  256. break;
  257. }
  258. default:
  259. break;
  260. }
  261. }];
  262. }
  263. -(void)addShare{
  264. NSString *random_str = [PublicObj stringToMD5:[NSString stringWithFormat:@"%@-%@-#2hgfk85cm23mk58vncsark",[Config getOwnID],[_parameterDic valueForKey:@"id"]]];
  265. NSString *url = [NSString stringWithFormat:@"Video.addShare&uid=%@&videoid=%@&random_str=%@",[Config getOwnID],[_parameterDic valueForKey:@"id"],random_str];
  266. YBWeakSelf;
  267. [YBNetworking postWithUrl:url Dic:nil Suc:^(int code, id info, NSString *msg) {
  268. if (code == 0) {
  269. NSDictionary *infoDic = [info firstObject];
  270. // if (weakSelf.shareEvent) {
  271. // weakSelf.shareEvent(0, minstr([infoDic valueForKey:@"shares"]));
  272. // [weakSelf dismiss];
  273. // }
  274. [weakSelf removeFromSuperview];
  275. // weakSelf = nil;
  276. }else{
  277. [MBProgressHUD showPop:msg];
  278. }
  279. } Fail:^(id fail) {
  280. }];
  281. }
  282. -(void)delVideo {
  283. //[_parameterDic valueForKey:@"id"]
  284. NSDictionary *subdic = @{
  285. @"uid":[Config getOwnID],
  286. @"token":[Config getOwnToken],
  287. @"videoid":[NSString stringWithFormat:@"%@",[_parameterDic valueForKey:@"id"]]
  288. };
  289. YBWeakSelf;
  290. [YBNetworking postWithUrl:@"Video.del" Dic:subdic Suc:^(int code, id info, NSString *msg) {
  291. if (code == 0) {
  292. [MBProgressHUD showSuccess:YZMsg(@"删除成功")];
  293. if (weakSelf.shareEvent) {
  294. weakSelf.shareEvent(3, @"");
  295. // [weakSelf dismiss];
  296. }
  297. }else{
  298. weakSelf.hidden = NO;
  299. [MBProgressHUD showPop:msg];
  300. }
  301. } Fail:^(id fail) {
  302. weakSelf.hidden = NO;
  303. }];
  304. }
  305. @end