From 5f2deb65e1f45c51ed25bfd02c7b8fec32f9e661 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 11 Sep 2018 08:15:10 -0400 Subject: [PATCH] Start progress view --- Tusker.xcodeproj/project.pbxproj | 8 ++++ Tusker/Screens/Compose/Compose.storyboard | 20 +++++++- .../Compose/ComposeViewController.swift | 10 ++++ Tusker/Views/ProgressView.swift | 47 +++++++++++++++++++ Tusker/Views/SteppedProgressView.swift | 35 ++++++++++++++ 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 Tusker/Views/ProgressView.swift create mode 100644 Tusker/Views/SteppedProgressView.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 9b84c491..358fb566 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 04409A082142AC3800341FA7 /* ProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04409A072142AC3800341FA7 /* ProgressView.swift */; }; + 04409A0A2142AD8000341FA7 /* SteppedProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04409A092142AD8000341FA7 /* SteppedProgressView.swift */; }; 04DACE8A212CA6B7009840C4 /* Timeline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DACE89212CA6B7009840C4 /* Timeline.swift */; }; 04DACE8C212CB14B009840C4 /* MainTabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DACE8B212CB14B009840C4 /* MainTabBarViewController.swift */; }; 04DACE8E212CC7CC009840C4 /* AvatarCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DACE8D212CC7CC009840C4 /* AvatarCache.swift */; }; @@ -102,6 +104,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 04409A072142AC3800341FA7 /* ProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressView.swift; sourceTree = ""; }; + 04409A092142AD8000341FA7 /* SteppedProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SteppedProgressView.swift; sourceTree = ""; }; 04DACE89212CA6B7009840C4 /* Timeline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Timeline.swift; sourceTree = ""; }; 04DACE8B212CB14B009840C4 /* MainTabBarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarViewController.swift; sourceTree = ""; }; 04DACE8D212CC7CC009840C4 /* AvatarCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarCache.swift; sourceTree = ""; }; @@ -367,6 +371,8 @@ D6C94D882139E6EC00CB5196 /* AttachmentView.swift */, D6333B762138D94E00CE884A /* ComposeMediaView.swift */, D641C77E213DC78A004B4513 /* InlineTextAttachment.swift */, + 04409A072142AC3800341FA7 /* ProgressView.swift */, + 04409A092142AD8000341FA7 /* SteppedProgressView.swift */, D641C78A213DD926004B4513 /* Status */, D641C78B213DD92F004B4513 /* Profile Header */, D641C78C213DD937004B4513 /* Notifications */, @@ -611,6 +617,7 @@ D641C777213CAA9E004B4513 /* ActionNotificationTableViewCell.swift in Sources */, D64D0AB12128D9AE005A6F37 /* OnboardingViewController.swift in Sources */, D663626821360E2C00C9CBA2 /* PreferencesTableViewController.swift in Sources */, + 04409A0A2142AD8000341FA7 /* SteppedProgressView.swift in Sources */, D66362732136FFC600C9CBA2 /* UITextView+Placeholder.swift in Sources */, D66362752137068A00C9CBA2 /* Visibility+Helpers.swift in Sources */, D646C95A213B5D0500269FB5 /* LargeImageInteractionController.swift in Sources */, @@ -624,6 +631,7 @@ D663625F2135C75500C9CBA2 /* ConversationMainStatusTableViewCell.swift in Sources */, D667E5E721349D4C0057A976 /* ProfileTableViewController.swift in Sources */, D6D4DDD0212518A000E1C4BB /* AppDelegate.swift in Sources */, + 04409A082142AC3800341FA7 /* ProgressView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tusker/Screens/Compose/Compose.storyboard b/Tusker/Screens/Compose/Compose.storyboard index f6dc9cf9..e1b9da33 100644 --- a/Tusker/Screens/Compose/Compose.storyboard +++ b/Tusker/Screens/Compose/Compose.storyboard @@ -141,19 +141,36 @@ - + + + + + + + + + + + + + + + + + + @@ -175,6 +192,7 @@ + diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index 31c9ed0b..ce4903bc 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -31,6 +31,7 @@ class ComposeViewController: UIViewController { @IBOutlet weak var contentWarningTextField: UITextField! @IBOutlet weak var mediaStackView: UIStackView! @IBOutlet weak var paddingView: UIView! + @IBOutlet weak var postProgressView: SteppedProgressView! var scrolled = false @@ -98,6 +99,8 @@ class ComposeViewController: UIViewController { statusTextView.text += "@\(mentioning.acct) " statusTextView.textViewDidChange(statusTextView) } + + postProgressView.progress = 0 } override func viewDidLayoutSubviews() { @@ -191,6 +194,9 @@ class ComposeViewController: UIViewController { let visibility = self.visibility + postProgressView.steps = 2 + postProgressView.currentStep = 1 + var attachments: [Attachment?] = [] let group = DispatchGroup() for view in mediaStackView.arrangedSubviews { @@ -204,10 +210,13 @@ class ComposeViewController: UIViewController { MastodonController.shared.client.run(req) { result in guard case let .success(attachment, _) = result else { fatalError() } attachments[index] = attachment + self.postProgressView.step() group.leave() } } + postProgressView.steps += attachments.count + group.notify(queue: .main) { let mediaIDs = attachments.map { $0!.id } @@ -222,6 +231,7 @@ class ComposeViewController: UIViewController { guard case let .success(status, _) = result else { fatalError() } self.status = status DispatchQueue.main.async { + self.postProgressView.step() self.performSegue(withIdentifier: "postComplete", sender: self) } } diff --git a/Tusker/Views/ProgressView.swift b/Tusker/Views/ProgressView.swift new file mode 100644 index 00000000..db5284d1 --- /dev/null +++ b/Tusker/Views/ProgressView.swift @@ -0,0 +1,47 @@ +// +// ProgressView.swift +// Tusker +// +// Created by Shadowfacts on 9/7/18. +// Copyright © 2018 Shadowfacts. All rights reserved. +// + +import UIKit + +@IBDesignable +class ProgressView: UIView { + + @IBInspectable var progress: CGFloat = 0 { + didSet { + updateSublayer() + } + } + + var shapeLayer: CAShapeLayer! + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + updateSublayer() + } + + override init(frame: CGRect) { + super.init(frame: frame) + updateSublayer() + } + + func updateSublayer() { + if shapeLayer == nil { + shapeLayer = CAShapeLayer() + shapeLayer.fillColor = tintColor.cgColor + layer.addSublayer(shapeLayer) + } + let rect = CGRect(x: 0, y: 0, width: frame.width * progress, height: frame.height) + shapeLayer.path = CGPath(rect: rect, transform: nil) + } + + override func layoutSubviews() { + updateSublayer() + super.layoutSubviews() + } + +} diff --git a/Tusker/Views/SteppedProgressView.swift b/Tusker/Views/SteppedProgressView.swift new file mode 100644 index 00000000..4b04400c --- /dev/null +++ b/Tusker/Views/SteppedProgressView.swift @@ -0,0 +1,35 @@ +// +// SteppedProgressView.swift +// Tusker +// +// Created by Shadowfacts on 9/7/18. +// Copyright © 2018 Shadowfacts. All rights reserved. +// + +import UIKit + +@IBDesignable +class SteppedProgressView: ProgressView { + + @IBInspectable var steps: Int = 0 + @IBInspectable var currentStep: Int = 0 { + didSet { + progress = CGFloat(currentStep) / CGFloat(steps) + } + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + override init(frame: CGRect) { + super.init(frame: frame) + } + + func step() { + if currentStep < steps { + currentStep += 1 + } + } + +}