|
@@ -0,0 +1,145 @@
|
|
|
+//
|
|
|
+// PublishUploadProgressView.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by Christopher on 2019/7/21.
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
+// 发布进度のView
|
|
|
+
|
|
|
+import UIKit
|
|
|
+import RxSwift
|
|
|
+
|
|
|
+/// 跳转方式
|
|
|
+///
|
|
|
+/// - none: 默认
|
|
|
+/// - push: push
|
|
|
+enum UploadStatus{
|
|
|
+ case uploading
|
|
|
+ case success
|
|
|
+ case failure
|
|
|
+}
|
|
|
+
|
|
|
+class PublishUploadProgressView: BaseView {
|
|
|
+
|
|
|
+ typealias CloseViewClosure = () -> Void
|
|
|
+ var closeViewClosure : CloseViewClosure?
|
|
|
+
|
|
|
+ var curUploadStatus : UploadStatus? {
|
|
|
+ didSet {
|
|
|
+ judgeShowStatus()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var uploadProgress: Float? {
|
|
|
+ didSet {
|
|
|
+ progressView.setProgress(self.uploadProgress ?? 0, animated: true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ override func setupViews() {
|
|
|
+ self.backgroundColor = kffffffColor
|
|
|
+ addSubview(imageView)
|
|
|
+ addSubview(progressLabel)
|
|
|
+ addSubview(progressView)
|
|
|
+ addSubview(failedLabel)
|
|
|
+ addSubview(failedCloseButton)
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setupLayouts() {
|
|
|
+ imageView.snp.makeConstraints { (make) in
|
|
|
+ make.left.equalTo(14)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.size.equalTo(44)
|
|
|
+ }
|
|
|
+ progressLabel.snp.makeConstraints { (make) in
|
|
|
+ make.left.equalTo(imageView.snp_right).offset(10)
|
|
|
+ make.top.equalTo(14)
|
|
|
+ make.height.equalTo(20)
|
|
|
+ }
|
|
|
+ progressView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(progressLabel.snp_bottom).offset(10)
|
|
|
+ make.left.equalTo(imageView.snp_right).offset(10)
|
|
|
+ make.right.equalTo(-15)
|
|
|
+ make.height.equalTo(4)
|
|
|
+ }
|
|
|
+ failedLabel.snp.makeConstraints { (make) in
|
|
|
+ make.left.equalTo(imageView.snp_right).offset(10)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.height.equalTo(20)
|
|
|
+ }
|
|
|
+ failedCloseButton.snp.makeConstraints { (make) in
|
|
|
+ make.right.equalTo(-3)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.size.equalTo(44)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ lazy var imageView: UIImageView = {
|
|
|
+ let imageView = UIImageView()
|
|
|
+ imageView.image = kImage(name: "pic_preload")
|
|
|
+ imageView.contentMode = .scaleAspectFill
|
|
|
+ imageView.clipsToBounds = true
|
|
|
+ return imageView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var progressLabel: UILabel = {
|
|
|
+ let progressLabel = UILabel()
|
|
|
+ progressLabel.textColor = k333333Color
|
|
|
+ progressLabel.font = kRegularFont14
|
|
|
+ progressLabel.textAlignment = .left
|
|
|
+ return progressLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var progressView: UIProgressView = {
|
|
|
+ let progressView = UIProgressView(progressViewStyle: .default)
|
|
|
+ progressView.setProgress(0, animated: false)
|
|
|
+ progressView.progressTintColor = k62CC74Color //进度颜色
|
|
|
+ progressView.trackTintColor = kd8d8d8Color //剩余进度颜色
|
|
|
+ progressView.cornerRadius = 2
|
|
|
+ progressView.masksToBounds = true
|
|
|
+ return progressView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var failedLabel: UILabel = {
|
|
|
+ let failedLabel = UILabel()
|
|
|
+ failedLabel.text = "发布失败..."
|
|
|
+ failedLabel.textColor = k333333Color
|
|
|
+ failedLabel.font = kRegularFont14
|
|
|
+ failedLabel.textAlignment = .left
|
|
|
+ return failedLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var failedCloseButton: UIButton = {
|
|
|
+ let failedCloseButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ failedCloseButton.setImage(kImage(name: "popup_btn_close_black"), for: .normal)
|
|
|
+ failedCloseButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
+ if let closeViewClosure = self?.closeViewClosure {
|
|
|
+ closeViewClosure()
|
|
|
+ }
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+ return failedCloseButton
|
|
|
+ }()
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+extension PublishUploadProgressView {
|
|
|
+
|
|
|
+ func judgeShowStatus() -> Void {
|
|
|
+ switch curUploadStatus {
|
|
|
+ case .uploading?,
|
|
|
+ .success?:
|
|
|
+ progressLabel.isHidden = false
|
|
|
+ progressView.isHidden = false
|
|
|
+ failedLabel.isHidden = true
|
|
|
+ failedCloseButton.isHidden = true
|
|
|
+ case .failure?:
|
|
|
+ progressLabel.isHidden = true
|
|
|
+ progressView.isHidden = true
|
|
|
+ failedLabel.isHidden = false
|
|
|
+ failedCloseButton.isHidden = false
|
|
|
+ case .none:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|