Store CW in drafts
This commit is contained in:
parent
2edb65d302
commit
2e6f7d8878
|
@ -37,8 +37,8 @@ class DraftsManager: Codable {
|
|||
return drafts.sorted(by: { $0.lastModified > $1.lastModified })
|
||||
}
|
||||
|
||||
func create(text: String, attachments: [DraftAttachment]) {
|
||||
drafts.append(Draft(text: text, lastModified: Date(), attachments: attachments))
|
||||
func create(text: String, contentWarning: String?, attachments: [DraftAttachment]) {
|
||||
drafts.append(Draft(text: text, contentWarning: contentWarning, lastModified: Date(), attachments: attachments))
|
||||
}
|
||||
|
||||
func remove(_ draft: Draft) {
|
||||
|
@ -52,18 +52,21 @@ extension DraftsManager {
|
|||
class Draft: Codable, Equatable {
|
||||
let id: UUID
|
||||
private(set) var text: String
|
||||
private(set) var contentWarning: String?
|
||||
private(set) var lastModified: Date
|
||||
private(set) var attachments: [DraftAttachment]
|
||||
|
||||
init(text: String, lastModified: Date, attachments: [DraftAttachment]) {
|
||||
init(text: String, contentWarning: String?, lastModified: Date, attachments: [DraftAttachment]) {
|
||||
self.id = UUID()
|
||||
self.text = text
|
||||
self.contentWarning = contentWarning
|
||||
self.lastModified = lastModified
|
||||
self.attachments = attachments
|
||||
}
|
||||
|
||||
func update(text: String, attachments: [DraftAttachment]) {
|
||||
func update(text: String, contentWarning: String?, attachments: [DraftAttachment]) {
|
||||
self.text = text
|
||||
self.contentWarning = contentWarning
|
||||
self.lastModified = Date()
|
||||
self.attachments = attachments
|
||||
}
|
||||
|
|
|
@ -271,9 +271,10 @@ class ComposeViewController: UIViewController {
|
|||
|
||||
func updateHasChanges() {
|
||||
if let currentDraft = currentDraft {
|
||||
hasChanges = statusTextView.text != currentDraft.text
|
||||
let cw = contentWarningEnabled ? contentWarningTextField.text : nil
|
||||
hasChanges = statusTextView.text != currentDraft.text || cw != currentDraft.contentWarning
|
||||
} else {
|
||||
hasChanges = !statusTextView.text.isEmpty
|
||||
hasChanges = !statusTextView.text.isEmpty || (contentWarningEnabled && !(contentWarningTextField.text?.isEmpty ?? true))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -319,10 +320,11 @@ class ComposeViewController: UIViewController {
|
|||
|
||||
attachments.append(DraftsManager.DraftAttachment(assetIdentifier: asset.localIdentifier, description: description))
|
||||
}
|
||||
let cw = contentWarningEnabled ? contentWarningTextField.text : nil
|
||||
if let currentDraft = self.currentDraft {
|
||||
currentDraft.update(text: self.statusTextView.text, attachments: attachments)
|
||||
currentDraft.update(text: self.statusTextView.text, contentWarning: cw, attachments: attachments)
|
||||
} else {
|
||||
DraftsManager.shared.create(text: self.statusTextView.text, attachments: attachments)
|
||||
DraftsManager.shared.create(text: self.statusTextView.text, contentWarning: cw, attachments: attachments)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -577,9 +579,11 @@ extension ComposeViewController: DraftsTableViewControllerDelegate {
|
|||
self.currentDraft = draft
|
||||
|
||||
statusTextView.text = draft.text
|
||||
contentWarningEnabled = draft.contentWarning != nil
|
||||
contentWarningTextField.text = draft.contentWarning
|
||||
|
||||
updatePlaceholder()
|
||||
updateCharactersRemaining()
|
||||
|
||||
|
||||
let result = PHAsset.fetchAssets(withLocalIdentifiers: draft.attachments.map { $0.assetIdentifier }, options: nil)
|
||||
var assets = [String: (asset: PHAsset, description: String)]()
|
||||
|
|
|
@ -11,12 +11,15 @@ import Photos
|
|||
|
||||
class DraftTableViewCell: UITableViewCell {
|
||||
|
||||
@IBOutlet weak var contentWarningLabel: UILabel!
|
||||
@IBOutlet weak var contentLabel: UILabel!
|
||||
@IBOutlet weak var lastModifiedLabel: UILabel!
|
||||
@IBOutlet weak var attachmentsStackViewContainer: UIView!
|
||||
@IBOutlet weak var attachmentsStackView: UIStackView!
|
||||
|
||||
func updateUI(for draft: DraftsManager.Draft) {
|
||||
contentWarningLabel.text = draft.contentWarning
|
||||
contentWarningLabel.isHidden = draft.contentWarning == nil
|
||||
contentLabel.text = draft.text
|
||||
lastModifiedLabel.text = draft.lastModified.timeAgoString()
|
||||
|
||||
|
|
|
@ -1,28 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14810.11" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14865.1" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
|
||||
<device id="retina4_7" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14766.13"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14819.2"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
<capability name="iOS 13.0 system colors" minToolsVersion="11.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" rowHeight="109" id="Q7N-Mt-RPF" customClass="DraftTableViewCell" customModule="Tusker" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="109"/>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" rowHeight="143" id="Q7N-Mt-RPF" customClass="DraftTableViewCell" customModule="Tusker" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="143"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Q7N-Mt-RPF" id="KVi-jA-AET">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="109"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="143"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="gaD-3B-qO1">
|
||||
<rect key="frame" x="15" y="11" width="352" height="90"/>
|
||||
<rect key="frame" x="15" y="11" width="352" height="124"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="zMS-88-DcM">
|
||||
<rect key="frame" x="0.0" y="0.0" width="352" height="32"/>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Content Warning" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VhS-ig-6Fu">
|
||||
<rect key="frame" x="0.0" y="0.0" width="352" height="18"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
|
||||
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zMS-88-DcM">
|
||||
<rect key="frame" x="0.0" y="26" width="352" height="40"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Content" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8eA-yd-rBp">
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" ambiguous="YES" text="Content" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8eA-yd-rBp">
|
||||
<rect key="frame" x="0.0" y="0.0" width="311.5" height="32"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
|
@ -31,7 +36,7 @@
|
|||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="2m" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="D2X-9O-iQw">
|
||||
<rect key="frame" x="327.5" y="0.0" width="24.5" height="20.5"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="secondaryLabelColor"/>
|
||||
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
|
@ -45,7 +50,7 @@
|
|||
</constraints>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="csc-gx-KVg">
|
||||
<rect key="frame" x="0.0" y="40" width="352" height="50"/>
|
||||
<rect key="frame" x="0.0" y="74" width="352" height="50"/>
|
||||
<subviews>
|
||||
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="htC-hf-vJ4">
|
||||
<rect key="frame" x="0.0" y="0.0" width="352" height="50"/>
|
||||
|
@ -77,9 +82,10 @@
|
|||
<outlet property="attachmentsStackView" destination="htC-hf-vJ4" id="kEX-m7-LuE"/>
|
||||
<outlet property="attachmentsStackViewContainer" destination="csc-gx-KVg" id="rIM-pj-TFX"/>
|
||||
<outlet property="contentLabel" destination="8eA-yd-rBp" id="Uy0-8G-WbU"/>
|
||||
<outlet property="contentWarningLabel" destination="VhS-ig-6Fu" id="jIU-vr-OsY"/>
|
||||
<outlet property="lastModifiedLabel" destination="D2X-9O-iQw" id="dx7-0E-RuM"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="-388" y="169.56521739130437"/>
|
||||
<point key="canvasLocation" x="-388" y="184.85757121439281"/>
|
||||
</tableViewCell>
|
||||
</objects>
|
||||
</document>
|
||||
|
|
Loading…
Reference in New Issue