Add post progress view

This commit is contained in:
Shadowfacts 2018-09-12 09:19:51 -04:00
parent 80f0fca7f6
commit 6f424666d8
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 54 additions and 0 deletions

View File

@ -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 = "<group>"; };
04DACE8D212CC7CC009840C4 /* AvatarCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarCache.swift; sourceTree = "<group>"; };
04ED00B021481ED800567C53 /* SteppedProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SteppedProgressView.swift; sourceTree = "<group>"; };
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 = "<group>"; };
D61099AE2144B0CC00432DC2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -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 */,

View File

@ -147,13 +147,19 @@
<constraint firstAttribute="bottom" secondItem="WID-nQ-ZzS" secondAttribute="bottom" id="yTD-d9-Cr8"/>
</constraints>
</scrollView>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progressViewStyle="bar" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="qAh-id-u7z" customClass="SteppedProgressView" customModule="Tusker" customModuleProvider="target">
<rect key="frame" x="0.0" y="64" width="375" height="2.5"/>
</progressView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="L3H-aB-fGr" firstAttribute="leading" secondItem="qto-r6-ocp" secondAttribute="leading" id="01l-qs-Ff4"/>
<constraint firstItem="L3H-aB-fGr" firstAttribute="top" secondItem="qto-r6-ocp" secondAttribute="topMargin" constant="-64" id="7BB-7k-gaN"/>
<constraint firstAttribute="trailing" secondItem="qAh-id-u7z" secondAttribute="trailing" id="EMl-GI-anW"/>
<constraint firstItem="WID-nQ-ZzS" firstAttribute="width" secondItem="qto-r6-ocp" secondAttribute="width" constant="-32" id="Fer-8I-o1H"/>
<constraint firstAttribute="trailing" secondItem="L3H-aB-fGr" secondAttribute="trailing" id="NWJ-dh-7ED"/>
<constraint firstItem="qAh-id-u7z" firstAttribute="top" secondItem="7ws-AM-scc" secondAttribute="top" id="hEb-Hg-oRI"/>
<constraint firstItem="qAh-id-u7z" firstAttribute="leading" secondItem="qto-r6-ocp" secondAttribute="leading" id="jVP-AN-LtR"/>
<constraint firstItem="7ws-AM-scc" firstAttribute="bottom" secondItem="L3H-aB-fGr" secondAttribute="bottom" id="uZs-Y8-hGM"/>
</constraints>
<viewLayoutGuide key="safeArea" id="7ws-AM-scc"/>
@ -175,6 +181,8 @@
<outlet property="inReplyToUsernameLabel" destination="neM-1F-PcJ" id="Lej-ut-yp9"/>
<outlet property="mediaStackView" destination="gcH-tf-prn" id="oM2-hc-rXY"/>
<outlet property="paddingView" destination="VuB-eX-IiL" id="wDo-4O-g30"/>
<outlet property="postButton" destination="wg4-nL-Q7B" id="6EL-Dd-jPb"/>
<outlet property="progressView" destination="qAh-id-u7z" id="sw0-dq-eNa"/>
<outlet property="scrollView" destination="L3H-aB-fGr" id="kbS-H5-K2I"/>
<outlet property="statusTextView" destination="gQU-rc-mM7" id="FVL-nk-159"/>
<outlet property="visibilityButton" destination="caP-6L-HWj" id="89p-Bl-cRH"/>

View File

@ -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)
}
}

View File

@ -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
}
}
}