mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Actually send GIFs.
// FREEBIE SQUASH ME. SQUASH ME.
This commit is contained in:
parent
c50ccf3eed
commit
2dfd7aa0e9
8 changed files with 78 additions and 396 deletions
|
@ -134,7 +134,7 @@ EXTERNAL SOURCES:
|
|||
OpenSSL:
|
||||
:git: https://github.com/WhisperSystems/OpenSSL-Pod
|
||||
SignalServiceKit:
|
||||
:path: .
|
||||
:path: "."
|
||||
SocketRocket:
|
||||
:git: https://github.com/facebook/SocketRocket.git
|
||||
|
||||
|
@ -176,6 +176,6 @@ SPEC CHECKSUMS:
|
|||
YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266
|
||||
YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54
|
||||
|
||||
PODFILE CHECKSUM: 00831faaa7677029090c311c00ceadaa44f65c0f
|
||||
PODFILE CHECKSUM: '00831faaa7677029090c311c00ceadaa44f65c0f'
|
||||
|
||||
COCOAPODS: 1.2.1
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#import "PushManager.h"
|
||||
#import "Release.h"
|
||||
#import "TSMessageAdapter.h"
|
||||
#import "ThreadUtil.h"
|
||||
#import "UIColor+OWS.h"
|
||||
#import "UIFont+OWS.h"
|
||||
#import "UIImage+OWS.h"
|
||||
|
|
|
@ -3211,7 +3211,8 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
|
|||
|
||||
- (void)showGifPicker
|
||||
{
|
||||
GifPickerViewController *view = [GifPickerViewController new];
|
||||
GifPickerViewController *view =
|
||||
[[GifPickerViewController alloc] initWithThread:self.thread messageSender:self.messageSender];
|
||||
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:view];
|
||||
[self presentViewController:navigationController animated:YES completion:nil];
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ class GifPickerCell: UICollectionViewCell {
|
|||
clearAssetRequest()
|
||||
return
|
||||
}
|
||||
Logger.verbose("\(TAG) picked rendition: \(rendition.name)")
|
||||
// Logger.verbose("\(TAG) picked rendition: \(rendition.name)")
|
||||
|
||||
assetRequest = GifDownloader.sharedInstance.downloadAssetAsync(rendition:rendition,
|
||||
success: { [weak self] asset in
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
//import MediaPlayer
|
||||
|
||||
class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollectionViewDataSource, UICollectionViewDelegate, GifPickerLayoutDelegate {
|
||||
let TAG = "[GifPickerViewController]"
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
var thread: TSThread?
|
||||
var messageSender: MessageSender?
|
||||
|
||||
let searchBar: UISearchBar
|
||||
let layout: GifPickerLayout
|
||||
let collectionView: UICollectionView
|
||||
|
@ -21,24 +23,29 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
|
||||
// MARK: Initializers
|
||||
|
||||
@available(*, unavailable, message:"use attachment: constructor instead.")
|
||||
@available(*, unavailable, message:"use other constructor instead.")
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
self.thread = nil
|
||||
self.messageSender = nil
|
||||
|
||||
self.searchBar = UISearchBar()
|
||||
self.layout = GifPickerLayout()
|
||||
self.collectionView = UICollectionView(frame:CGRect.zero, collectionViewLayout:self.layout)
|
||||
// self.attachment = SignalAttachment.empty()
|
||||
|
||||
super.init(coder: aDecoder)
|
||||
owsFail("\(self.TAG) invalid constructor")
|
||||
}
|
||||
|
||||
required init() {
|
||||
required init(thread: TSThread, messageSender: MessageSender) {
|
||||
self.thread = thread
|
||||
self.messageSender = messageSender
|
||||
|
||||
self.searchBar = UISearchBar()
|
||||
self.layout = GifPickerLayout()
|
||||
self.collectionView = UICollectionView(frame:CGRect.zero, collectionViewLayout:self.layout)
|
||||
// assert(!attachment.hasError)
|
||||
// self.attachment = attachment
|
||||
// self.successCompletion = successCompletion
|
||||
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
|
||||
self.layout.delegate = self
|
||||
}
|
||||
|
||||
|
@ -62,9 +69,12 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
super.viewWillAppear(animated)
|
||||
|
||||
search(query:"funny")
|
||||
}
|
||||
|
||||
// self.view.layoutSubviews()
|
||||
// updateImageLayout()
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
self.searchBar.becomeFirstResponder()
|
||||
}
|
||||
|
||||
// MARK: Views
|
||||
|
@ -112,7 +122,6 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
logoImageView.autoCenterInSuperview()
|
||||
|
||||
self.updateContents()
|
||||
// [self updateTableContents];
|
||||
}
|
||||
|
||||
private func setContentVisible(_ isVisible: Bool) {
|
||||
|
@ -133,363 +142,6 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
self.collectionView.reloadData()
|
||||
}
|
||||
|
||||
// override func viewDidLoad() {
|
||||
// super.viewDidLoad()
|
||||
//
|
||||
// view.backgroundColor = UIColor.white
|
||||
//
|
||||
// self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem:.stop,
|
||||
// target:self,
|
||||
// action:#selector(donePressed))
|
||||
// self.navigationItem.title = dialogTitle()
|
||||
//
|
||||
// createViews()
|
||||
// }
|
||||
//
|
||||
// private func dialogTitle() -> String {
|
||||
// guard let filename = formattedFileName() else {
|
||||
// return NSLocalizedString("ATTACHMENT_APPROVAL_DIALOG_TITLE",
|
||||
// comment: "Title for the 'attachment approval' dialog.")
|
||||
// }
|
||||
// return filename
|
||||
// }
|
||||
//
|
||||
// override func viewWillAppear(_ animated: Bool) {
|
||||
// super.viewWillAppear(animated)
|
||||
//
|
||||
// ViewControllerUtils.setAudioIgnoresHardwareMuteSwitch(true)
|
||||
// }
|
||||
//
|
||||
// override func viewWillDisappear(_ animated: Bool) {
|
||||
// super.viewWillDisappear(animated)
|
||||
//
|
||||
// ViewControllerUtils.setAudioIgnoresHardwareMuteSwitch(false)
|
||||
// }
|
||||
//
|
||||
// // MARK: - Create Views
|
||||
//
|
||||
// private func createViews() {
|
||||
// let previewTopMargin: CGFloat = 30
|
||||
// let previewHMargin: CGFloat = 20
|
||||
//
|
||||
// let attachmentPreviewView = UIView()
|
||||
// self.view.addSubview(attachmentPreviewView)
|
||||
// attachmentPreviewView.autoPinWidthToSuperview(withMargin:previewHMargin)
|
||||
// attachmentPreviewView.autoPin(toTopLayoutGuideOf: self, withInset:previewTopMargin)
|
||||
//
|
||||
// createButtonRow(attachmentPreviewView:attachmentPreviewView)
|
||||
//
|
||||
// if attachment.isAnimatedImage {
|
||||
// createAnimatedPreview(attachmentPreviewView:attachmentPreviewView)
|
||||
// } else if attachment.isImage {
|
||||
// createImagePreview(attachmentPreviewView:attachmentPreviewView)
|
||||
// } else if attachment.isVideo {
|
||||
// createVideoPreview(attachmentPreviewView:attachmentPreviewView)
|
||||
// } else if attachment.isAudio {
|
||||
// createAudioPreview(attachmentPreviewView:attachmentPreviewView)
|
||||
// } else {
|
||||
// createGenericPreview(attachmentPreviewView:attachmentPreviewView)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private func wrapViewsInVerticalStack(subviews: [UIView]) -> UIView {
|
||||
// assert(subviews.count > 0)
|
||||
//
|
||||
// let stackView = UIView()
|
||||
//
|
||||
// var lastView: UIView?
|
||||
// for subview in subviews {
|
||||
//
|
||||
// stackView.addSubview(subview)
|
||||
// subview.autoHCenterInSuperview()
|
||||
//
|
||||
// if lastView == nil {
|
||||
// subview.autoPinEdge(toSuperviewEdge:.top)
|
||||
// } else {
|
||||
// subview.autoPinEdge(.top, to:.bottom, of:lastView!, withOffset:10)
|
||||
// }
|
||||
//
|
||||
// lastView = subview
|
||||
// }
|
||||
//
|
||||
// lastView?.autoPinEdge(toSuperviewEdge:.bottom)
|
||||
//
|
||||
// return stackView
|
||||
// }
|
||||
//
|
||||
// private func createAudioPreview(attachmentPreviewView: UIView) {
|
||||
// guard let dataUrl = attachment.dataUrl else {
|
||||
// createGenericPreview(attachmentPreviewView:attachmentPreviewView)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// audioPlayer = OWSAudioAttachmentPlayer(mediaUrl: dataUrl, delegate: self)
|
||||
//
|
||||
// var subviews = [UIView]()
|
||||
//
|
||||
// let audioPlayButton = UIButton()
|
||||
// self.audioPlayButton = audioPlayButton
|
||||
// setAudioIconToPlay()
|
||||
// audioPlayButton.imageView?.layer.minificationFilter = kCAFilterTrilinear
|
||||
// audioPlayButton.imageView?.layer.magnificationFilter = kCAFilterTrilinear
|
||||
// audioPlayButton.addTarget(self, action:#selector(audioPlayButtonPressed), for:.touchUpInside)
|
||||
// let buttonSize = createHeroViewSize()
|
||||
// audioPlayButton.autoSetDimension(.width, toSize:buttonSize)
|
||||
// audioPlayButton.autoSetDimension(.height, toSize:buttonSize)
|
||||
// subviews.append(audioPlayButton)
|
||||
//
|
||||
// let fileNameLabel = createFileNameLabel()
|
||||
// if let fileNameLabel = fileNameLabel {
|
||||
// subviews.append(fileNameLabel)
|
||||
// }
|
||||
//
|
||||
// let fileSizeLabel = createFileSizeLabel()
|
||||
// subviews.append(fileSizeLabel)
|
||||
//
|
||||
// let audioStatusLabel = createAudioStatusLabel()
|
||||
// self.audioStatusLabel = audioStatusLabel
|
||||
// updateAudioStatusLabel()
|
||||
// subviews.append(audioStatusLabel)
|
||||
//
|
||||
// let stackView = wrapViewsInVerticalStack(subviews:subviews)
|
||||
// attachmentPreviewView.addSubview(stackView)
|
||||
// fileNameLabel?.autoPinWidthToSuperview(withMargin: 32)
|
||||
// stackView.autoPinWidthToSuperview()
|
||||
// stackView.autoVCenterInSuperview()
|
||||
// }
|
||||
//
|
||||
// private func createAnimatedPreview(attachmentPreviewView: UIView) {
|
||||
// guard attachment.isValidImage else {
|
||||
// return
|
||||
// }
|
||||
// let data = attachment.data
|
||||
// // Use Flipboard FLAnimatedImage library to display gifs
|
||||
// guard let animatedImage = FLAnimatedImage(gifData:data) else {
|
||||
// createGenericPreview(attachmentPreviewView:attachmentPreviewView)
|
||||
// return
|
||||
// }
|
||||
// let animatedImageView = FLAnimatedImageView()
|
||||
// animatedImageView.animatedImage = animatedImage
|
||||
// animatedImageView.contentMode = .scaleAspectFit
|
||||
// attachmentPreviewView.addSubview(animatedImageView)
|
||||
// animatedImageView.autoPinWidthToSuperview()
|
||||
// animatedImageView.autoPinHeightToSuperview()
|
||||
// }
|
||||
//
|
||||
// private func createImagePreview(attachmentPreviewView: UIView) {
|
||||
// var image = attachment.image
|
||||
// if image == nil {
|
||||
// image = UIImage(data:attachment.data)
|
||||
// }
|
||||
// guard image != nil else {
|
||||
// createGenericPreview(attachmentPreviewView:attachmentPreviewView)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// let imageView = UIImageView(image:image)
|
||||
// imageView.layer.minificationFilter = kCAFilterTrilinear
|
||||
// imageView.layer.magnificationFilter = kCAFilterTrilinear
|
||||
// imageView.contentMode = .scaleAspectFit
|
||||
// attachmentPreviewView.addSubview(imageView)
|
||||
// imageView.autoPinWidthToSuperview()
|
||||
// imageView.autoPinHeightToSuperview()
|
||||
// }
|
||||
//
|
||||
// private func createVideoPreview(attachmentPreviewView: UIView) {
|
||||
// guard let dataUrl = attachment.dataUrl else {
|
||||
// createGenericPreview(attachmentPreviewView:attachmentPreviewView)
|
||||
// return
|
||||
// }
|
||||
// guard let videoPlayer = MPMoviePlayerController(contentURL:dataUrl) else {
|
||||
// createGenericPreview(attachmentPreviewView:attachmentPreviewView)
|
||||
// return
|
||||
// }
|
||||
// videoPlayer.prepareToPlay()
|
||||
//
|
||||
// videoPlayer.controlStyle = .default
|
||||
// videoPlayer.shouldAutoplay = false
|
||||
//
|
||||
// attachmentPreviewView.addSubview(videoPlayer.view)
|
||||
// self.videoPlayer = videoPlayer
|
||||
// videoPlayer.view.autoPinWidthToSuperview()
|
||||
// videoPlayer.view.autoPinHeightToSuperview()
|
||||
// }
|
||||
//
|
||||
// private func createGenericPreview(attachmentPreviewView: UIView) {
|
||||
// var subviews = [UIView]()
|
||||
//
|
||||
// let imageView = createHeroImageView(imageName: "file-thin-black-filled-large")
|
||||
// subviews.append(imageView)
|
||||
//
|
||||
// let fileNameLabel = createFileNameLabel()
|
||||
// if let fileNameLabel = fileNameLabel {
|
||||
// subviews.append(fileNameLabel)
|
||||
// }
|
||||
//
|
||||
// let fileSizeLabel = createFileSizeLabel()
|
||||
// subviews.append(fileSizeLabel)
|
||||
//
|
||||
// let stackView = wrapViewsInVerticalStack(subviews:subviews)
|
||||
// attachmentPreviewView.addSubview(stackView)
|
||||
// fileNameLabel?.autoPinWidthToSuperview(withMargin: 32)
|
||||
// stackView.autoPinWidthToSuperview()
|
||||
// stackView.autoVCenterInSuperview()
|
||||
// }
|
||||
//
|
||||
// private func createHeroViewSize() -> CGFloat {
|
||||
// return ScaleFromIPhone5To7Plus(175, 225)
|
||||
// }
|
||||
//
|
||||
// private func createHeroImageView(imageName: String) -> UIView {
|
||||
// let imageSize = createHeroViewSize()
|
||||
// let image = UIImage(named:imageName)
|
||||
// assert(image != nil)
|
||||
// let imageView = UIImageView(image:image)
|
||||
// imageView.layer.minificationFilter = kCAFilterTrilinear
|
||||
// imageView.layer.magnificationFilter = kCAFilterTrilinear
|
||||
// imageView.layer.shadowColor = UIColor.black.cgColor
|
||||
// let shadowScaling = 5.0
|
||||
// imageView.layer.shadowRadius = CGFloat(2.0 * shadowScaling)
|
||||
// imageView.layer.shadowOpacity = 0.25
|
||||
// imageView.layer.shadowOffset = CGSize(width: 0.75 * shadowScaling, height: 0.75 * shadowScaling)
|
||||
// imageView.autoSetDimension(.width, toSize:imageSize)
|
||||
// imageView.autoSetDimension(.height, toSize:imageSize)
|
||||
//
|
||||
// return imageView
|
||||
// }
|
||||
//
|
||||
// private func labelFont() -> UIFont {
|
||||
// return UIFont.ows_regularFont(withSize:ScaleFromIPhone5To7Plus(18, 24))
|
||||
// }
|
||||
//
|
||||
// private func formattedFileExtension() -> String? {
|
||||
// guard let fileExtension = attachment.fileExtension else {
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// return String(format:NSLocalizedString("ATTACHMENT_APPROVAL_FILE_EXTENSION_FORMAT",
|
||||
// comment: "Format string for file extension label in call interstitial view"),
|
||||
// fileExtension.uppercased())
|
||||
// }
|
||||
//
|
||||
// private func formattedFileName() -> String? {
|
||||
// guard let sourceFilename = attachment.sourceFilename else {
|
||||
// return nil
|
||||
// }
|
||||
// let filename = sourceFilename.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
|
||||
// guard filename.characters.count > 0 else {
|
||||
// return nil
|
||||
// }
|
||||
// return filename
|
||||
// }
|
||||
//
|
||||
// private func createFileNameLabel() -> UIView? {
|
||||
// let filename = formattedFileName() ?? formattedFileExtension()
|
||||
//
|
||||
// guard filename != nil else {
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// let label = UILabel()
|
||||
// label.text = filename
|
||||
// label.textColor = UIColor.ows_materialBlue()
|
||||
// label.font = labelFont()
|
||||
// label.textAlignment = .center
|
||||
// label.lineBreakMode = .byTruncatingMiddle
|
||||
// return label
|
||||
// }
|
||||
//
|
||||
// private func createFileSizeLabel() -> UIView {
|
||||
// let label = UILabel()
|
||||
// let fileSize = attachment.dataLength
|
||||
// label.text = String(format:NSLocalizedString("ATTACHMENT_APPROVAL_FILE_SIZE_FORMAT",
|
||||
// comment: "Format string for file size label in call interstitial view. Embeds: {{file size as 'N mb' or 'N kb'}}."),
|
||||
// ViewControllerUtils.formatFileSize(UInt(fileSize)))
|
||||
//
|
||||
// label.textColor = UIColor.ows_materialBlue()
|
||||
// label.font = labelFont()
|
||||
// label.textAlignment = .center
|
||||
//
|
||||
// return label
|
||||
// }
|
||||
//
|
||||
// private func createAudioStatusLabel() -> UILabel {
|
||||
// let label = UILabel()
|
||||
// label.textColor = UIColor.ows_materialBlue()
|
||||
// label.font = labelFont()
|
||||
// label.textAlignment = .center
|
||||
//
|
||||
// return label
|
||||
// }
|
||||
//
|
||||
// private func createButtonRow(attachmentPreviewView: UIView) {
|
||||
// let buttonTopMargin = ScaleFromIPhone5To7Plus(30, 40)
|
||||
// let buttonBottomMargin = ScaleFromIPhone5To7Plus(25, 40)
|
||||
// let buttonHSpacing = ScaleFromIPhone5To7Plus(20, 30)
|
||||
//
|
||||
// let buttonRow = UIView()
|
||||
// self.view.addSubview(buttonRow)
|
||||
// buttonRow.autoPinWidthToSuperview()
|
||||
// buttonRow.autoPinEdge(toSuperviewEdge:.bottom, withInset:buttonBottomMargin)
|
||||
// buttonRow.autoPinEdge(.top, to:.bottom, of:attachmentPreviewView, withOffset:buttonTopMargin)
|
||||
//
|
||||
// // We use this invisible subview to ensure that the buttons are centered
|
||||
// // horizontally.
|
||||
// let buttonSpacer = UIView()
|
||||
// buttonRow.addSubview(buttonSpacer)
|
||||
// // Vertical positioning of this view doesn't matter.
|
||||
// buttonSpacer.autoPinEdge(toSuperviewEdge:.top)
|
||||
// buttonSpacer.autoSetDimension(.width, toSize:buttonHSpacing)
|
||||
// buttonSpacer.autoHCenterInSuperview()
|
||||
//
|
||||
// let cancelButton = createButton(title: CommonStrings.cancelButton,
|
||||
// color : UIColor.ows_destructiveRed(),
|
||||
// action: #selector(cancelPressed))
|
||||
// buttonRow.addSubview(cancelButton)
|
||||
// cancelButton.autoPinEdge(toSuperviewEdge:.top)
|
||||
// cancelButton.autoPinEdge(toSuperviewEdge:.bottom)
|
||||
// cancelButton.autoPinEdge(.right, to:.left, of:buttonSpacer)
|
||||
//
|
||||
// let sendButton = createButton(title: NSLocalizedString("ATTACHMENT_APPROVAL_SEND_BUTTON",
|
||||
// comment: "Label for 'send' button in the 'attachment approval' dialog."),
|
||||
// color : UIColor(rgbHex:0x2ecc71),
|
||||
// action: #selector(sendPressed))
|
||||
// buttonRow.addSubview(sendButton)
|
||||
// sendButton.autoPinEdge(toSuperviewEdge:.top)
|
||||
// sendButton.autoPinEdge(toSuperviewEdge:.bottom)
|
||||
// sendButton.autoPinEdge(.left, to:.right, of:buttonSpacer)
|
||||
// }
|
||||
//
|
||||
// private func createButton(title: String, color: UIColor, action: Selector) -> UIView {
|
||||
// let buttonWidth = ScaleFromIPhone5To7Plus(110, 140)
|
||||
// let buttonHeight = ScaleFromIPhone5To7Plus(35, 45)
|
||||
//
|
||||
// return OWSFlatButton.button(title:title,
|
||||
// titleColor:UIColor.white,
|
||||
// backgroundColor:color,
|
||||
// width:buttonWidth,
|
||||
// height:buttonHeight,
|
||||
// target:target,
|
||||
// selector:action)
|
||||
// }
|
||||
//
|
||||
// // MARK: - Event Handlers
|
||||
//
|
||||
// func donePressed(sender: UIButton) {
|
||||
// dismiss(animated: true, completion:nil)
|
||||
// }
|
||||
//
|
||||
// func cancelPressed(sender: UIButton) {
|
||||
// dismiss(animated: true, completion:nil)
|
||||
// }
|
||||
//
|
||||
// func sendPressed(sender: UIButton) {
|
||||
// let successCompletion = self.successCompletion
|
||||
// dismiss(animated: true, completion: {
|
||||
// successCompletion?()
|
||||
// })
|
||||
// }
|
||||
|
||||
// MARK: - UICollectionViewDataSource
|
||||
|
||||
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
|
@ -508,7 +160,31 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
// MARK: - UICollectionViewDelegate
|
||||
|
||||
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
let imageInfo = imageInfos[indexPath.row]
|
||||
guard let cell = collectionView.cellForItem(at:indexPath) as? GifPickerCell else {
|
||||
owsFail("\(TAG) unexpected cell.")
|
||||
return
|
||||
}
|
||||
guard let asset = cell.asset else {
|
||||
Logger.info("\(TAG) unload cell selected.")
|
||||
return
|
||||
}
|
||||
let filePath = asset.filePath
|
||||
guard let dataSource = DataSourcePath.dataSource(withFilePath:filePath) else {
|
||||
owsFail("\(TAG) couldn't load asset.")
|
||||
return
|
||||
}
|
||||
let attachment = SignalAttachment(dataSource : dataSource, dataUTI: asset.rendition.utiType())
|
||||
guard let thread = thread else {
|
||||
owsFail("\(TAG) Missing thread.")
|
||||
return
|
||||
}
|
||||
guard let messageSender = messageSender else {
|
||||
owsFail("\(TAG) Missing messageSender.")
|
||||
return
|
||||
}
|
||||
ThreadUtil.sendMessage(with: attachment, in: thread, messageSender: messageSender)
|
||||
|
||||
dismiss(animated: true, completion:nil)
|
||||
}
|
||||
|
||||
public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
|
||||
|
@ -516,6 +192,7 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
owsFail("\(TAG) unexpected cell.")
|
||||
return
|
||||
}
|
||||
// We only want to load the cells which are on-screen.
|
||||
cell.shouldLoad = true
|
||||
}
|
||||
|
||||
|
@ -548,6 +225,11 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
}
|
||||
|
||||
private func search(query: String) {
|
||||
self.searchBar.resignFirstResponder()
|
||||
imageInfos = []
|
||||
updateContents()
|
||||
self.collectionView.contentOffset = CGPoint.zero
|
||||
|
||||
GifManager.sharedInstance.search(query: query, success: { [weak self] imageInfos in
|
||||
guard let strongSelf = self else { return }
|
||||
Logger.info("\(strongSelf.TAG) search complete")
|
||||
|
|
|
@ -273,8 +273,6 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
|
|||
|
||||
[self updateBarButtonItems];
|
||||
|
||||
// [GifManager.sharedInstance test];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
TSThread *thread = [self threadForIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
|
||||
[self presentThread:thread keyboardOnViewAppearing:NO callOnViewAppearing:NO];
|
||||
|
|
|
@ -244,24 +244,13 @@ extension URLSessionTask {
|
|||
assetRequest.failure()
|
||||
return
|
||||
}
|
||||
Logger.verbose("\(GifDownloader.TAG) download succeeded: \(assetRequest.rendition.url)")
|
||||
// Logger.verbose("\(GifDownloader.TAG) download succeeded: \(assetRequest.rendition.url)")
|
||||
let asset = GiphyAsset(rendition: assetRequest.rendition, filePath : assetFilePath)
|
||||
assetRequest.success(asset)
|
||||
}
|
||||
|
||||
// MARK: URLSessionDownloadDelegate
|
||||
|
||||
private func fileExtension(forFormat format: GiphyFormat) -> String {
|
||||
switch format {
|
||||
case .gif:
|
||||
return "gif"
|
||||
case .webp:
|
||||
return "webp"
|
||||
case .mp4:
|
||||
return "mp4"
|
||||
}
|
||||
}
|
||||
|
||||
public func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
|
||||
let assetRequest = downloadTask.assetRequest
|
||||
guard !assetRequest.wasCancelled else {
|
||||
|
@ -271,7 +260,7 @@ extension URLSessionTask {
|
|||
}
|
||||
|
||||
let dirPath = NSTemporaryDirectory()
|
||||
let fileExtension = self.fileExtension(forFormat:assetRequest.rendition.format)
|
||||
let fileExtension = assetRequest.rendition.fileExtension()
|
||||
let fileName = (NSUUID().uuidString as NSString).appendingPathExtension(fileExtension)!
|
||||
let filePath = (dirPath as NSString).appendingPathComponent(fileName)
|
||||
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
import Foundation
|
||||
import ObjectiveC
|
||||
|
||||
// There's no UTI type for webp!
|
||||
enum GiphyFormat {
|
||||
case gif, webp, mp4
|
||||
case gif, mp4
|
||||
}
|
||||
|
||||
@objc class GiphyRendition: NSObject {
|
||||
|
@ -30,6 +31,24 @@ enum GiphyFormat {
|
|||
self.fileSize = fileSize
|
||||
self.url = url
|
||||
}
|
||||
|
||||
public func fileExtension() -> String {
|
||||
switch format {
|
||||
case .gif:
|
||||
return "gif"
|
||||
case .mp4:
|
||||
return "mp4"
|
||||
}
|
||||
}
|
||||
|
||||
public func utiType() -> String {
|
||||
switch format {
|
||||
case .gif:
|
||||
return kUTTypeGIF as String
|
||||
case .mp4:
|
||||
return kUTTypeMPEG4 as String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc class GiphyImageInfo: NSObject {
|
||||
|
@ -126,14 +145,6 @@ enum GiphyFormat {
|
|||
return sessionManager
|
||||
}
|
||||
|
||||
// TODO:
|
||||
public func test() {
|
||||
search(query:"monkey",
|
||||
success: { _ in
|
||||
}, failure: {
|
||||
})
|
||||
}
|
||||
|
||||
// MARK: Search
|
||||
|
||||
public func search(query: String, success: @escaping (([GiphyImageInfo]) -> Void), failure: @escaping (() -> Void)) {
|
||||
|
|
Loading…
Reference in a new issue