Merge branch 'charlesmchen/imageEditor5'

pull/1/head
Matthew Chen 7 years ago
commit 58cb02bc9e

@ -582,7 +582,11 @@ public class AttachmentApprovalViewController: UIPageViewController, UIPageViewC
} }
var attachments: [SignalAttachment] { var attachments: [SignalAttachment] {
return attachmentItems.map { self.processedAttachment(forAttachmentItem: $0) } return attachmentItems.map { (attachmentItem) in
autoreleasepool {
return self.processedAttachment(forAttachmentItem: attachmentItem)
}
}
} }
// For any attachments edited with the image editor, returns a // For any attachments edited with the image editor, returns a

@ -496,6 +496,36 @@ public class ImageEditorModel: NSObject {
}, changedItemIds: [item.itemId]) }, changedItemIds: [item.itemId])
} }
// MARK: - Temp Files
private var temporaryFilePaths = [String]()
@objc
public func temporaryFilePath(withFileExtension fileExtension: String) -> String {
AssertIsOnMainThread()
let filePath = OWSFileSystem.temporaryFilePath(withFileExtension: fileExtension)
temporaryFilePaths.append(filePath)
return filePath
}
deinit {
AssertIsOnMainThread()
let temporaryFilePaths = self.temporaryFilePaths
DispatchQueue.global(qos: .background).async {
for filePath in temporaryFilePaths {
guard OWSFileSystem.deleteFile(filePath) else {
Logger.error("Could not delete temp file: \(filePath)")
continue
}
}
}
}
// MARK: - Crop
@objc @objc
public func crop(unitCropRect: CGRect) { public func crop(unitCropRect: CGRect) {
guard let croppedImage = ImageEditorModel.crop(imagePath: contents.imagePath, guard let croppedImage = ImageEditorModel.crop(imagePath: contents.imagePath,
@ -510,7 +540,7 @@ public class ImageEditorModel: NSObject {
owsFailDebug("Could not convert cropped image to PNG.") owsFailDebug("Could not convert cropped image to PNG.")
return return
} }
let croppedImagePath = OWSFileSystem.temporaryFilePath(withFileExtension: "png") let croppedImagePath = temporaryFilePath(withFileExtension: "png")
do { do {
try croppedImageData.write(to: NSURL.fileURL(withPath: croppedImagePath), options: .atomicWrite) try croppedImageData.write(to: NSURL.fileURL(withPath: croppedImagePath), options: .atomicWrite)
} catch let error as NSError { } catch let error as NSError {

@ -11,21 +11,26 @@ public class ImageEditorView: UIView, ImageEditorModelDelegate {
private let model: ImageEditorModel private let model: ImageEditorModel
enum EditorMode: String { enum EditorMode: String {
case none
case brush case brush
case crop case crop
} }
private var editorMode = EditorMode.brush { private var editorMode = EditorMode.none {
didSet { didSet {
AssertIsOnMainThread() AssertIsOnMainThread()
switch editorMode { switch editorMode {
case .none:
editorGestureRecognizer?.isEnabled = false
case .brush: case .brush:
// Brush strokes can start and end (and return from) outside the view. // Brush strokes can start and end (and return from) outside the view.
editorGestureRecognizer?.shouldAllowOutsideView = true editorGestureRecognizer?.shouldAllowOutsideView = true
editorGestureRecognizer?.isEnabled = true
case .crop: case .crop:
// Crop gestures can start and end (and return from) outside the view. // Crop gestures can start and end (and return from) outside the view.
editorGestureRecognizer?.shouldAllowOutsideView = true editorGestureRecognizer?.shouldAllowOutsideView = true
editorGestureRecognizer?.isEnabled = true
} }
} }
} }
@ -209,6 +214,8 @@ public class ImageEditorView: UIView, ImageEditorModelDelegate {
AssertIsOnMainThread() AssertIsOnMainThread()
switch editorMode { switch editorMode {
case .none:
break
case .brush: case .brush:
handleBrushGesture(gestureRecognizer) handleBrushGesture(gestureRecognizer)
case .crop: case .crop:

Loading…
Cancel
Save