-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from marty-suzuki/refactor
Refactor
- Loading branch information
Showing
76 changed files
with
2,083 additions
and
1,324 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
ArtShredder/Common/Extension/DispatchQueue.extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// DispatchQueue.extension.swift | ||
// ArtShredder | ||
// | ||
// Created by marty-suzuki on 2018/12/03. | ||
// Copyright © 2018年 marty-suzuki. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension DispatchQueue: AdditionalCompatible {} | ||
|
||
extension Additional where Base: DispatchQueue { | ||
func throttle(delay: DispatchTimeInterval) -> (_ action: @escaping () -> ()) -> () { | ||
var lastFireTime: DispatchTime = .now() | ||
|
||
return { [weak base, delay] action in | ||
let deadline: DispatchTime = .now() + delay | ||
base?.asyncAfter(deadline: deadline) { [delay] in | ||
let now: DispatchTime = .now() | ||
let when: DispatchTime = lastFireTime + delay | ||
if now < when { return } | ||
lastFireTime = .now() | ||
action() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// GIFMaker.swift | ||
// ArtShredder | ||
// | ||
// Created by marty-suzuki on 2018/12/04. | ||
// Copyright © 2018年 marty-suzuki. All rights reserved. | ||
// | ||
|
||
import CoreImage | ||
import Foundation | ||
import MobileCoreServices | ||
import UIKit | ||
|
||
protocol GIFMakerType: AnyObject { | ||
var didCreateGIFWithURL: ((URL?) -> ())? { get set } | ||
func create(with imageHolder: ImageHolder) | ||
} | ||
|
||
final class GIFMaker: GIFMakerType { | ||
|
||
var didCreateGIFWithURL: ((URL?) -> ())? | ||
|
||
private let queue: DispatchQueue | ||
|
||
init(queue: DispatchQueue = .global()) { | ||
self.queue = queue | ||
} | ||
|
||
func create(with imageHolder: ImageHolder) { | ||
queue.async { [weak self] in | ||
let images = imageHolder.images | ||
let filename = imageHolder.filename | ||
|
||
guard | ||
let url = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(filename), | ||
let destination = CGImageDestinationCreateWithURL(url as CFURL, kUTTypeGIF, images.count, nil) | ||
else { | ||
self?.didCreateGIFWithURL?(nil) | ||
return | ||
} | ||
|
||
let delay = imageHolder.delay | ||
|
||
let properties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]] | ||
CGImageDestinationSetProperties(destination, properties as CFDictionary) | ||
|
||
let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: delay]] | ||
for image in images { | ||
if let cgImage = image.cgImage { | ||
CGImageDestinationAddImage(destination, cgImage, frameProperties as CFDictionary) | ||
} | ||
} | ||
|
||
guard CGImageDestinationFinalize(destination) else { | ||
self?.didCreateGIFWithURL?(nil) | ||
return | ||
} | ||
|
||
self?.didCreateGIFWithURL?(url) | ||
} | ||
} | ||
} | ||
|
||
struct ImageHolder { | ||
let images: [UIImage] | ||
let delay: TimeInterval | ||
let filename: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// LocalizedString.swift | ||
// ArtShredder | ||
// | ||
// Created by marty-suzuki on 2018/10/27. | ||
// Copyright © 2018年 marty-suzuki. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum LocalizedString { | ||
static let frameDescription = NSLocalizedString("frame_description", comment: "") | ||
static let selectImageName = NSLocalizedString("select_image_name", comment: "") | ||
static let saveGIFButton = NSLocalizedString("save_gif_button", comment: "") | ||
static let saveImageButton = NSLocalizedString("save_image_button", comment: "") | ||
static let didSaveToCameraRollTitle = NSLocalizedString("did_save_to_camera_roll_title", comment: "") | ||
static let didSaveToCameraRollMessage = NSLocalizedString("did_save_to_camera_roll_message", comment: "") | ||
static let closeAction = NSLocalizedString("close_action", comment: "") | ||
static let imageSourceSelectTitle = NSLocalizedString("image_source_select_title", comment: "") | ||
static let imageSourceSelectMessage = NSLocalizedString("image_source_select_message", comment: "") | ||
static let imageSourceSelectCamera = NSLocalizedString("image_source_select_camera", comment: "") | ||
static let imageSourceSelectCameraRoll = NSLocalizedString("image_source_select_camera_roll", comment: "") | ||
static let cancelAction = NSLocalizedString("cancel_action", comment: "") | ||
static let supportURL = NSLocalizedString("support_url", comment: "") | ||
static let supprotTitle = NSLocalizedString("supprot_title", comment: "") | ||
static let selectToAddArtTitle = NSLocalizedString("select_to_add_art_title", comment: "") | ||
static let arModeTitle = NSLocalizedString("ar_mode_title", comment: "") | ||
static let arNoRecognitionText = NSLocalizedString("ar_no_recognition_text", comment: "") | ||
} |
Oops, something went wrong.