|
@@ -11,31 +11,52 @@ import RxSwift
|
|
|
import SwiftyJSON
|
|
|
import Photos
|
|
|
|
|
|
+enum PublishMediaType {
|
|
|
+ case image
|
|
|
+ case video
|
|
|
+}
|
|
|
+
|
|
|
class PublishEditController: BaseViewController {
|
|
|
|
|
|
+ var mediaType: PublishMediaType = .image
|
|
|
+
|
|
|
var imgCount: Int = 0
|
|
|
+ var majorImageUrl: String?
|
|
|
+ var imageUrlArray: Array<String> = []
|
|
|
var imageArr: Array<UIImage>? {
|
|
|
didSet {
|
|
|
imgCount = self.imageArr?.count ?? 0
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 话题id
|
|
|
+ var topic_ids: String = ""
|
|
|
+ // 标题
|
|
|
+ var pubTitle: String = ""
|
|
|
+ // 内容
|
|
|
+ var pubContent: String = ""
|
|
|
+ // 位置
|
|
|
+ var location: String = ""
|
|
|
+
|
|
|
+ // MARK: 控制器生命周期
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
setupViews()
|
|
|
setupData()
|
|
|
}
|
|
|
|
|
|
+ override func viewWillAppear(_ animated: Bool) {
|
|
|
+ // imageUrlArray每次进入页面需置空
|
|
|
+ imageUrlArray = []
|
|
|
+ rightButton.isEnabled = false
|
|
|
+ rightButton.backgroundColor = kd8d8d8Color
|
|
|
+ uploadAllImages(totalTimes: 0)
|
|
|
+ }
|
|
|
+
|
|
|
override func setupViews() {
|
|
|
self.view.backgroundColor = kffffffColor
|
|
|
|
|
|
navigationBar.title = ""
|
|
|
- navigationBar.wr_setRightButton(title: "发布", titleColor: k333333Color)
|
|
|
- navigationBar.onClickRightButton = {
|
|
|
- [weak self] in
|
|
|
- print("----点击了发布")
|
|
|
- }
|
|
|
-
|
|
|
navigationBar.wr_setLeftButton(image: kImage(name: "navbar_back_black")!)
|
|
|
navigationBar.onClickLeftButton = {
|
|
|
[weak self] in
|
|
@@ -47,9 +68,36 @@ class PublishEditController: BaseViewController {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ view.addSubview(rightButton)
|
|
|
+ rightButton.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalToSuperview().offset(kSafeStatusBarHeight+8)
|
|
|
+ make.right.equalTo(-14)
|
|
|
+ make.width.equalTo(64)
|
|
|
+ make.height.equalTo(26)
|
|
|
+ }
|
|
|
+
|
|
|
+ view.addSubview(progressBackView)
|
|
|
+ progressBackView.addSubview(progressView)
|
|
|
+ progressBackView.addSubview(subLabel)
|
|
|
+
|
|
|
+ progressBackView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalToSuperview().offset(kNavBarTotalHeight)
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ make.height.equalTo(38)
|
|
|
+ }
|
|
|
+ progressView.snp.makeConstraints { (make) in
|
|
|
+ make.top.left.right.equalToSuperview()
|
|
|
+ make.height.equalTo(3)
|
|
|
+ }
|
|
|
+ subLabel.snp.makeConstraints { (make) in
|
|
|
+ make.left.equalTo(14)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.height.equalTo(20)
|
|
|
+ }
|
|
|
+
|
|
|
view.addSubview(tableView)
|
|
|
tableView.snp.makeConstraints { (make) in
|
|
|
- make.top.equalToSuperview().offset(kNavBarTotalHeight)
|
|
|
+ make.top.equalTo(progressBackView.snp_bottom)
|
|
|
make.left.right.bottom.equalToSuperview()
|
|
|
}
|
|
|
}
|
|
@@ -70,6 +118,46 @@ class PublishEditController: BaseViewController {
|
|
|
return tableView
|
|
|
}()
|
|
|
|
|
|
+ private lazy var rightButton: UIButton = {
|
|
|
+ let rightButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ rightButton.setTitle("发布", for: UIControl.State.normal)
|
|
|
+ rightButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
|
|
|
+ rightButton.titleLabel?.font = kMediumFont13
|
|
|
+ rightButton.cornerRadius = 16
|
|
|
+ rightButton.masksToBounds = true
|
|
|
+ rightButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
+ self?.communityPublishApi()
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+ return rightButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var progressBackView: UIView = {
|
|
|
+ let progressBackView = UIView()
|
|
|
+ progressBackView.backgroundColor = kffffffColor
|
|
|
+ return progressBackView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var progressView: UIProgressView = {
|
|
|
+ let progressView = UIProgressView(progressViewStyle: .default)
|
|
|
+// progressView.frame = CGRect(x: 0, y: 0, width: 200, height: 10)
|
|
|
+// progressView.layer.position = CGPoint(x: self.view.frame.width/2, y: 90)
|
|
|
+ progressView.setProgress(0, animated: false)
|
|
|
+ progressView.progressTintColor = k62CC74Color //进度颜色
|
|
|
+ progressView.trackTintColor = kd8d8d8Color //剩余进度颜色
|
|
|
+ //通过改变进度条高度(宽度不变,高度变为默认的2倍)
|
|
|
+// progressView.transform = CGAffineTransform(scaleX: 1.0, y: 2.0)
|
|
|
+ return progressView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var subLabel: UILabel = {
|
|
|
+ let subLabel = UILabel()
|
|
|
+ subLabel.text = "图片正在上传中(0/\(imageArr?.count ?? 0))..."
|
|
|
+ subLabel.textColor = k333333Color
|
|
|
+ subLabel.font = kRegularFont14
|
|
|
+ subLabel.textAlignment = .left
|
|
|
+ return subLabel
|
|
|
+ }()
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// MARK: - tableView dataSource && delegate
|
|
@@ -96,19 +184,23 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
|
|
|
picCell.delPicTransBlock = {
|
|
|
[weak self] (picIdx) in
|
|
|
self?.imageArr?.remove(at: picIdx!)
|
|
|
+ self?.imageUrlArray.remove(at: picIdx!)
|
|
|
self?.tableView.reloadData()
|
|
|
}
|
|
|
return picCell
|
|
|
case 1:
|
|
|
let titleCell = PublishEditTitleCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ titleCell.topicTextClosure = {
|
|
|
+ [weak self] (text) in
|
|
|
+ self?.pubTitle = text
|
|
|
+ }
|
|
|
return titleCell
|
|
|
case 2:
|
|
|
let desCell = PublishEditDescribeCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
-// actCell.allSelectBlock = {
|
|
|
-// [weak self] (isAllSel) in
|
|
|
-// self?.isAllSelected = isAllSel
|
|
|
-// self?.allSelectedAction(isAllSel)
|
|
|
-// }
|
|
|
+ desCell.commentTextViewClosure = {
|
|
|
+ [weak self] (text) in
|
|
|
+ self?.pubContent = text
|
|
|
+ }
|
|
|
return desCell
|
|
|
case 3:
|
|
|
let topicCell = PublishEditAddTopicCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
@@ -123,20 +215,6 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
|
|
|
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
switch indexPath.row {
|
|
|
-// case 0:
|
|
|
-// let picCell = PublishEditAddPicCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
-// return picCell
|
|
|
-// case 1:
|
|
|
-// let titleCell = PublishEditTitleCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
-// return titleCell
|
|
|
-// case 2:
|
|
|
-// let desCell = PublishEditDescribeCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
-// // actCell.allSelectBlock = {
|
|
|
-// // [weak self] (isAllSel) in
|
|
|
-// // self?.isAllSelected = isAllSel
|
|
|
-// // self?.allSelectedAction(isAllSel)
|
|
|
-// // }
|
|
|
-// return desCell
|
|
|
case 3:
|
|
|
let vc = PublishAddTopicController()
|
|
|
self.navigationController?.pushViewController(vc, animated: true)
|
|
@@ -144,7 +222,7 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
|
|
|
let vc = PublishAddAddressController()
|
|
|
self.navigationController?.pushViewController(vc, animated: true)
|
|
|
default:
|
|
|
- print("----点击了-\(indexPath.row)")
|
|
|
+ break
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -181,5 +259,72 @@ extension PublishEditController : UITableViewDelegate, UITableViewDataSource {
|
|
|
// MARK: - 逻辑处理
|
|
|
extension PublishEditController {
|
|
|
|
|
|
+ func uploadAllImages(totalTimes: Int) {
|
|
|
+
|
|
|
+ var curTimes: Int = totalTimes
|
|
|
+
|
|
|
+ print("-----StartUpload,totalTimes == \(totalTimes)")
|
|
|
+ SwiftMoyaNetWorkServiceConfig.shared().configUploadSingleImgApi(imageArray: [imageArr![totalTimes]]) {
|
|
|
+ [weak self] (imgUrl) -> (Void) in
|
|
|
+ let urlStr: String = imgUrl as! String
|
|
|
+ self?.imageUrlArray.append(urlStr)
|
|
|
+ if curTimes == 0 {
|
|
|
+ // 设置主图
|
|
|
+ self?.majorImageUrl = urlStr
|
|
|
+ }
|
|
|
+
|
|
|
+ print("-----FinishUpload,Times == \(curTimes)")
|
|
|
+ curTimes += 1
|
|
|
+ // 更新进度
|
|
|
+ self?.progressView.setProgress(Float(curTimes/(self?.imageArr!.count)!), animated: true)
|
|
|
+ if curTimes == self?.imageArr!.count {
|
|
|
+ self?.subLabel.text = "图片上传成功!"
|
|
|
+ } else {
|
|
|
+ self?.subLabel.text = "图片正在上传中(\(curTimes)/\(self?.imageArr?.count ?? 0))..."
|
|
|
+ }
|
|
|
+
|
|
|
+ if curTimes < self?.imageArr?.count ?? 0 {
|
|
|
+ self?.uploadAllImages(totalTimes: curTimes)
|
|
|
+ } else {
|
|
|
+ self?.rightButton.isEnabled = true
|
|
|
+ self?.rightButton.backgroundColor = k62CC74Color
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发布Api
|
|
|
+ func communityPublishApi() {
|
|
|
+
|
|
|
+ if pubTitle.count > 20 {
|
|
|
+ SwiftProgressHUD.shared().showText("标题最多输入20个字符")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if pubContent.count == 0 {
|
|
|
+ SwiftProgressHUD.shared().showText("还没输入描述内容")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var typeStr: String = ""
|
|
|
+ if mediaType == .image {
|
|
|
+ typeStr = "image"
|
|
|
+ } else {
|
|
|
+ typeStr = "video"
|
|
|
+ }
|
|
|
+
|
|
|
+ let simuTopicIds: Array<String> = ["1","2"]
|
|
|
+ let simuTopicJsonStr = JSON(simuTopicIds).description
|
|
|
+// SwiftProgressHUD.shared().showText("还没选择话题哟")
|
|
|
+
|
|
|
+ let imgsJsonStr = JSON(imageUrlArray).description
|
|
|
+
|
|
|
+ print("----mediaType == \(typeStr)\n----pubTitle = \(pubTitle)\n----simuTopicJsonStr == \(simuTopicJsonStr)\n----imgsJsonStr == \(imgsJsonStr)")
|
|
|
+
|
|
|
+ SwiftMoyaNetWorkServiceCommunity.shared().communityPublishApi(type: typeStr, img: majorImageUrl ?? "", topic_ids: simuTopicJsonStr, video: "", title: pubTitle, content: pubContent, location: "", imgs: imgsJsonStr) {
|
|
|
+ [weak self] (communityPublishModel) -> (Void) in
|
|
|
+ let communityPublishModel = communityPublishModel as? CommunityPublishModel
|
|
|
+ print("----发布成功")
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|