diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index c351415b..876dfa93 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 04DACE8C212CB14B009840C4 /* MainTabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DACE8B212CB14B009840C4 /* MainTabBarViewController.swift */; }; 04DACE8E212CC7CC009840C4 /* AvatarCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DACE8D212CC7CC009840C4 /* AvatarCache.swift */; }; + 04ED00B121481ED800567C53 /* SteppedProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04ED00B021481ED800567C53 /* SteppedProgressView.swift */; }; D61099B42144B0CC00432DC2 /* Pachyderm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D61099AB2144B0CC00432DC2 /* Pachyderm.framework */; }; D61099BB2144B0CC00432DC2 /* PachydermTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D61099BA2144B0CC00432DC2 /* PachydermTests.swift */; }; D61099BD2144B0CC00432DC2 /* Pachyderm.h in Headers */ = {isa = PBXBuildFile; fileRef = D61099AD2144B0CC00432DC2 /* Pachyderm.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -161,6 +162,7 @@ /* Begin PBXFileReference section */ 04DACE8B212CB14B009840C4 /* MainTabBarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarViewController.swift; sourceTree = ""; }; 04DACE8D212CC7CC009840C4 /* AvatarCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarCache.swift; sourceTree = ""; }; + 04ED00B021481ED800567C53 /* SteppedProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SteppedProgressView.swift; sourceTree = ""; }; D61099AB2144B0CC00432DC2 /* Pachyderm.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pachyderm.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D61099AD2144B0CC00432DC2 /* Pachyderm.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Pachyderm.h; sourceTree = ""; }; D61099AE2144B0CC00432DC2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -568,6 +570,7 @@ D6C94D882139E6EC00CB5196 /* AttachmentView.swift */, D6333B762138D94E00CE884A /* ComposeMediaView.swift */, D641C77E213DC78A004B4513 /* InlineTextAttachment.swift */, + 04ED00B021481ED800567C53 /* SteppedProgressView.swift */, D641C78A213DD926004B4513 /* Status */, D641C78B213DD92F004B4513 /* Profile Header */, D641C78C213DD937004B4513 /* Notifications */, @@ -921,6 +924,7 @@ D667E5F82135C3040057A976 /* Mastodon+Equatable.swift in Sources */, 04DACE8E212CC7CC009840C4 /* AvatarCache.swift in Sources */, D6333B772138D94E00CE884A /* ComposeMediaView.swift in Sources */, + 04ED00B121481ED800567C53 /* SteppedProgressView.swift in Sources */, D663626421360D2300C9CBA2 /* AvatarStyle.swift in Sources */, D6BED174212667E900F02DA0 /* StatusTableViewCell.swift in Sources */, D64D0AAD2128D88B005A6F37 /* LocalData.swift in Sources */, diff --git a/Tusker/Screens/Compose/Compose.storyboard b/Tusker/Screens/Compose/Compose.storyboard index f6dc9cf9..42bfb0dd 100644 --- a/Tusker/Screens/Compose/Compose.storyboard +++ b/Tusker/Screens/Compose/Compose.storyboard @@ -147,13 +147,19 @@ + + + + + + @@ -175,6 +181,8 @@ + + diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index 3f763a5e..6839ca73 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -28,9 +28,11 @@ class ComposeViewController: UIViewController { @IBOutlet weak var inReplyToLabel: UILabel! @IBOutlet weak var statusTextView: UITextView! @IBOutlet weak var visibilityButton: UIButton! + @IBOutlet weak var postButton: UIButton! @IBOutlet weak var contentWarningTextField: UITextField! @IBOutlet weak var mediaStackView: UIStackView! @IBOutlet weak var paddingView: UIView! + @IBOutlet weak var progressView: SteppedProgressView! var scrolled = false @@ -96,6 +98,8 @@ class ComposeViewController: UIViewController { statusTextView.text += "@\(mentioning.acct) " statusTextView.textViewDidChange(statusTextView) } + + progressView.progress = 0 } override func viewDidLayoutSubviews() { @@ -175,6 +179,8 @@ class ComposeViewController: UIViewController { guard let text = statusTextView.text, !text.isEmpty else { return } + postButton.isEnabled = false + let contentWarning: String? if self.contentWarning, let text = contentWarningTextField.text, @@ -195,14 +201,19 @@ class ComposeViewController: UIViewController { let data = image.pngData() else { continue } let index = attachments.count attachments.append(nil) + progressView.steps += 1 group.enter() MastodonController.shared.client.upload(attachment: FormAttachment(pngData: data), description: mediaView.mediaDescription) { response in guard case let .success(attachment, _) = response else { fatalError() } attachments[index] = attachment + self.progressView.step() group.leave() } } + progressView.steps = 2 + attachments.count + progressView.currentStep = 1 + group.notify(queue: .main) { let attachments = attachments.compactMap { $0 } @@ -215,6 +226,7 @@ class ComposeViewController: UIViewController { guard case let .success(status, _) = response else { fatalError() } self.status = status DispatchQueue.main.async { + self.progressView.step() self.performSegue(withIdentifier: "postComplete", sender: self) } } diff --git a/Tusker/Views/SteppedProgressView.swift b/Tusker/Views/SteppedProgressView.swift new file mode 100644 index 00000000..1d81757e --- /dev/null +++ b/Tusker/Views/SteppedProgressView.swift @@ -0,0 +1,30 @@ +// +// SteppedProgressView.swift +// Tusker +// +// Created by Shadowfacts on 9/11/18. +// Copyright © 2018 Shadowfacts. All rights reserved. +// + +import UIKit + +class SteppedProgressView: UIProgressView { + + var currentStep: Int = 0 { + didSet { + guard steps > 0 else { return } + let progress = Float(currentStep) / Float(steps) + DispatchQueue.main.async { + self.setProgress(progress, animated: true) + } + } + } + var steps: Int = 0 + + func step() { + if currentStep < steps { + currentStep += 1 + } + } + +}