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] {
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

@ -496,6 +496,36 @@ public class ImageEditorModel: NSObject {
}, 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
public func crop(unitCropRect: CGRect) {
guard let croppedImage = ImageEditorModel.crop(imagePath: contents.imagePath,
@ -510,7 +540,7 @@ public class ImageEditorModel: NSObject {
owsFailDebug("Could not convert cropped image to PNG.")
return
}
let croppedImagePath = OWSFileSystem.temporaryFilePath(withFileExtension: "png")
let croppedImagePath = temporaryFilePath(withFileExtension: "png")
do {
try croppedImageData.write(to: NSURL.fileURL(withPath: croppedImagePath), options: .atomicWrite)
} catch let error as NSError {

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

Loading…
Cancel
Save