123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- //
- // ShareCommunityView.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/7/10.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- import FWPopupView
- import RxSwift
- import SwiftyMediator
- enum ShareCommunityViewType {
- case postDetail
- case activity
- }
- class ShareCommunityView: FWPopupView {
-
- let disposeBag = DisposeBag()
-
- let platformTitles = ["微信","朋友圈","QQ","微博","复制链接","保存图片","删除"]
- let platformImages = ["edit_pic_wechat","edit_pic_moments","edit_pic_qq","edit_pic_sina","edit_pic_link","edit_pic_download","edit_pic_delete"]
-
- let platformTitles1 = ["微信","朋友圈","QQ","微博","复制链接","保存图片","举报"]
- let platformImages1 = ["edit_pic_wechat","edit_pic_moments","edit_pic_qq","edit_pic_sina","edit_pic_link","edit_pic_download","edit_pic_report"]
-
- private var title : String?
- private var detailTitle : String?
- private var sharedTitle : String?
- private var sharedDetailTitle : String?
- private var h5Str : String?
- private var thumbnailImg : UIImage?
- private var shareCommunityViewType : ShareCommunityViewType?
- var uid : Int?
- var postId : Int?
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- }
-
- typealias Completion = (() -> Void)
- var completion : Completion?
- typealias SaveCompletion = (() -> Void)
- var saveCompletion : SaveCompletion?
- typealias DeleteCompletion = (() -> Void)
- var deleteCompletion : DeleteCompletion?
- init(postId : Int = 0,uid:Int,title:String,detailTitle:String,h5Str:String,thumbnailImg:UIImage?,sharedTitle:String,sharedDetailTitle:String,shareCommunityViewType:ShareCommunityViewType) {
- self.init()
- self.postId = postId
- self.uid = uid
- self.title = title
- self.detailTitle = detailTitle
- self.h5Str = h5Str
- self.thumbnailImg = thumbnailImg
- self.sharedTitle = sharedTitle
- self.sharedDetailTitle = sharedDetailTitle
- self.shareCommunityViewType = shareCommunityViewType
- frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: 209 + kSafeTabBarHeight)
- configRectCorner(corner: [.topLeft,.topRight], radii: CGSize(width: 8, height: 8))
- setupViews()
- setupLayouts()
- setupData()
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func setupViews() {
- addSubview(titleLabel)
- addSubview(detailTitleLabel)
- addSubview(collectionView)
- addSubview(lineLabel)
- addSubview(cancelButton)
-
- }
-
- func setupLayouts() {
- titleLabel.snp.makeConstraints { (make) in
- make.top.equalTo(20)
- make.right.equalTo(-20)
- make.left.equalTo(20)
- make.height.equalTo(18)
- }
- detailTitleLabel.snp.makeConstraints { (make) in
- make.top.equalTo(titleLabel.snp.bottom).offset(10)
- make.right.equalTo(-30)
- make.left.equalTo(30)
- make.height.equalTo(18)
- }
- collectionView.snp.makeConstraints { (make) in
- make.top.equalTo(detailTitleLabel.snp.bottom).offset(20)
- make.height.equalTo(69)
- make.left.right.equalToSuperview()
- }
- lineLabel.snp.makeConstraints { (make) in
- make.top.equalTo(collectionView.snp.bottom).offset(10)
- make.left.right.equalToSuperview()
- make.height.equalTo(0.5)
- }
- cancelButton.snp.makeConstraints { (make) in
- make.top.equalTo(lineLabel.snp.bottom)
- make.height.equalTo(44)
- make.left.right.equalToSuperview()
- }
- }
-
- lazy var titleLabel: UILabel = {
- let titleLabel = UILabel()
- titleLabel.text = title
- titleLabel.textColor = k333333Color
- titleLabel.font = kRegularFont15
- titleLabel.textAlignment = .center
- return titleLabel
- }()
-
- lazy var detailTitleLabel: UILabel = {
- let detailTitleLabel = UILabel()
- detailTitleLabel.text = detailTitle
- detailTitleLabel.textColor = k333333Color
- detailTitleLabel.font = kRegularFont15
- detailTitleLabel.textAlignment = .center
- return detailTitleLabel
- }()
-
- private lazy var collectionView: UICollectionView = {
- let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
- collectionView.backgroundColor = UIColor.white
- collectionView.delegate = self;
- collectionView.dataSource = self;
- collectionView.showsVerticalScrollIndicator = false
- collectionView.showsHorizontalScrollIndicator = false
- return collectionView
- }()
-
- private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
- let collectionViewLayout = UICollectionViewFlowLayout.init()
- collectionViewLayout.minimumLineSpacing = 20
- collectionViewLayout.minimumInteritemSpacing = 0
- collectionViewLayout.scrollDirection = .horizontal
- return collectionViewLayout
- }()
-
- lazy var lineLabel: UILabel = {
- let lineLabel = UILabel()
- lineLabel.backgroundColor = kDDDDDDColor
- return lineLabel
- }()
-
- lazy var cancelButton: UIButton = {
- let cancelButton = UIButton(type: UIButton.ButtonType.custom)
- cancelButton.setTitle("取消", for: UIControl.State.normal)
- cancelButton.setTitleColor(k333333Color, for: UIControl.State.normal)
- cancelButton.titleLabel?.font = kRegularFont16
- return cancelButton
- }()
-
- func setupData() {
- cancelButton.rx.tap.subscribe(onNext: {
- [weak self] _ in
- self?.hide()
- }).disposed(by: disposeBag)
- }
-
-
- /// 分享内容
- class func shareCommunityView(postId:Int,uid:Int,title:String = kCommunityPostTitle,detailTitle:String = kCommunityPostDetailTitle, h5Str:String,thumbnailImg:UIImage?,sharedTitle:String,sharedDetailTitle:String,shareCommunityViewType:ShareCommunityViewType,completion: @escaping Completion) -> ShareCommunityView {
- let view = ShareCommunityView(
- postId:postId,
- uid:uid,
- title:title,
- detailTitle: detailTitle,
- h5Str: h5Str,
- thumbnailImg : thumbnailImg,
- sharedTitle: sharedTitle,
- sharedDetailTitle:sharedDetailTitle,
- shareCommunityViewType:shareCommunityViewType)
- view.completion = {
- completion()
- }
- let vProperty = FWPopupViewProperty()
- vProperty.popupCustomAlignment = .bottomCenter
- vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
- vProperty.popupAnimationType = .frame
- vProperty.maskViewColor = UIColor(white: 0, alpha: 0.5)
- vProperty.touchWildToHide = "1"
- view.vProperty = vProperty
- view.show()
- return view
- }
-
-
- /// 邀请好友
- class func inviteGoodFriends() {
- let shareCommunityView = ShareCommunityView.shareCommunityView(
- postId: 0, uid:0,
- title: kInviteGoodFriendsTitle,
- detailTitle: kInviteGoodFriendsDetailTitle,
- h5Str: kH5InviteUrl + "\(UserModel.shared().getModel()?.inviteCode ?? "")",
- thumbnailImg: UIImage.imageUrl(UserModel.shared().getModel()?.avatarurl),
- sharedTitle: kInviteGoodFriendsShareTitle,
- sharedDetailTitle: kInviteGoodFriendsShareDetailTitle,
- shareCommunityViewType: ShareCommunityViewType.activity,
- completion: {})
- shareCommunityView.saveCompletion = {
- Mediator.push(ShareRouterModuleType.pushShareActivity)
- }
- }
- }
- extension ShareCommunityView: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
- func numberOfSections(in collectionView: UICollectionView) -> Int {
- return 1
- }
-
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- if UserModel.shared().isEqualUid(uid: self.uid ?? 0) {
- return platformTitles.count
- }else {
- return platformTitles1.count
- }
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = ShareCommunityViewCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
- if UserModel.shared().isEqualUid(uid: self.uid ?? 0) {
- cell.titleIcon(title: platformTitles[indexPath.row], iconStr: platformImages[indexPath.row], textColor: k333333Color)
- }else {
- cell.titleIcon(title: platformTitles1[indexPath.row], iconStr: platformImages[indexPath.row], textColor: k333333Color)
- }
- return cell
-
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- switch indexPath.row {
- case 0:
- UMManager.shared.shareWebPage(to: UMSocialPlatformType.wechatSession, viewController: findViewController(), title: sharedTitle ?? "", descr: sharedDetailTitle ?? "", thumbImage: thumbnailImg as Any, webpageUrl: h5Str ?? "", completion: {
- self.completion!()
- })
- break
- case 1:
- UMManager.shared.shareWebPage(to: UMSocialPlatformType.wechatTimeLine, viewController: findViewController(), title: sharedTitle ?? "", descr: sharedDetailTitle ?? "", thumbImage: thumbnailImg as Any, webpageUrl: h5Str ?? "",completion: {
- self.completion!()
- })
- break
- case 2:
- UMManager.shared.shareWebPage(to: UMSocialPlatformType.QQ, viewController: findViewController(), title: sharedTitle ?? "", descr: sharedDetailTitle ?? "", thumbImage: thumbnailImg as Any, webpageUrl: h5Str ?? "",completion: {
- self.completion!()
- })
-
- break
- case 3:
- UMManager.shared.shareWebPage(to: UMSocialPlatformType.sina, viewController: findViewController(), title: sharedTitle ?? "", descr: sharedDetailTitle ?? "", thumbImage: thumbnailImg as Any, webpageUrl: h5Str ?? "",completion: {
- self.completion!()
- })
- break
- case 4:
- commonCopy(string: h5Str ?? "")
- break
- case 5:
- switch shareCommunityViewType {
- case .postDetail?:
- if let saveCompletion = self.saveCompletion {
- saveCompletion()
- }
- break
- case .activity?:
- if let saveCompletion = self.saveCompletion {
- saveCompletion()
- }
- break
- default:
- break
- }
- break
- case 6:
-
- if UserModel.shared().isEqualUid(uid: self.uid ?? 0) {
- if let deleteCompletion = self.deleteCompletion {
- deleteCompletion()
- }
-
- }else {
- Mediator.push(CommunityRouterModuleType.pushReport(postId: self.postId ?? 0))
- }
- break
- default:
- break
- }
- self.hide()
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- return CGSize(width:50, height: 69)
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
- return UIEdgeInsets(top: 0, left: 23, bottom: 0, right: 23)
- }
-
- }
|