Clean up ahead of PR.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-09-29 22:05:01 -04:00
parent 48e6cea207
commit a65a4b133c
5 changed files with 19 additions and 62 deletions

View File

@ -662,10 +662,6 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
[self createScrollDownButton];
[self createHeaderViews];
[self addNotificationListeners];
dispatch_async(dispatch_get_main_queue(), ^{
[self showGifPicker];
});
}
- (void)registerCustomMessageNibs

View File

@ -87,31 +87,25 @@ class GifPickerCell: UICollectionViewCell {
}
guard let fullRendition = imageInfo.pickGifRendition() else {
Logger.warn("\(TAG) could not pick gif rendition: \(imageInfo.giphyId)")
// imageInfo.log()
clearAssetRequest()
return
}
guard let stillRendition = imageInfo.pickStillRendition() else {
Logger.warn("\(TAG) could not pick still rendition: \(imageInfo.giphyId)")
// imageInfo.log()
clearAssetRequest()
return
}
// Logger.verbose("picked full: \(fullRendition.name)")
// Logger.verbose("picked still: \(stillRendition.name)")
if stillAsset == nil && fullAsset == nil && stillAssetRequest == nil {
stillAssetRequest = GifDownloader.sharedInstance.downloadAssetAsync(rendition:stillRendition,
priority:.high,
success: { [weak self] asset in
// Logger.verbose("downloaded still")
guard let strongSelf = self else { return }
strongSelf.clearStillAssetRequest()
strongSelf.stillAsset = asset
strongSelf.tryToDisplayAsset()
},
failure: { [weak self] in
// Logger.verbose("failed to download still")
guard let strongSelf = self else { return }
strongSelf.clearStillAssetRequest()
})
@ -120,14 +114,12 @@ class GifPickerCell: UICollectionViewCell {
fullAssetRequest = GifDownloader.sharedInstance.downloadAssetAsync(rendition:fullRendition,
priority:.low,
success: { [weak self] asset in
// Logger.verbose("downloaded full")
guard let strongSelf = self else { return }
strongSelf.clearAssetRequest()
strongSelf.fullAsset = asset
strongSelf.tryToDisplayAsset()
},
failure: { [weak self] in
// Logger.verbose("failed to download full")
guard let strongSelf = self else { return }
strongSelf.clearAssetRequest()
})

View File

@ -65,12 +65,6 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
createViews()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
search(query:"funny")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
@ -84,28 +78,18 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
view.backgroundColor = UIColor.black
// Search
// searchBar.searchBarStyle = .minimal
searchBar.searchBarStyle = .default
searchBar.delegate = self
searchBar.placeholder = NSLocalizedString("GIF_VIEW_SEARCH_PLACEHOLDER_TEXT",
comment:"Placeholder text for the search field in gif view")
// searchBar.backgroundColor = UIColor(white:0.6, alpha:1.0)
// searchBar.backgroundColor = UIColor.white
// searchBar.backgroundColor = UIColor.black
// searchBar.barTintColor = UIColor.red
searchBar.isTranslucent = false
// searchBar.backgroundColor = UIColor.white
searchBar.backgroundImage = UIImage(color:UIColor.clear)
searchBar.barTintColor = UIColor.black
searchBar.tintColor = UIColor.white
self.view.addSubview(searchBar)
searchBar.autoPinWidthToSuperview()
searchBar.autoPin(toTopLayoutGuideOf: self, withInset:0)
// [searchBar sizeToFit];
// if #available(iOS 10, *) {
// self.collectionView.isPrefetchingEnabled = false
// }
self.collectionView.delegate = self
self.collectionView.dataSource = self
self.collectionView.backgroundColor = UIColor.black

View File

@ -272,11 +272,6 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
}
[self updateBarButtonItems];
dispatch_async(dispatch_get_main_queue(), ^{
TSThread *thread = [self threadForIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
[self presentThread:thread keyboardOnViewAppearing:NO callOnViewAppearing:NO];
});
}
- (void)updateBarButtonItems

View File

@ -77,6 +77,10 @@ enum GiphyFormat {
let kMinDimension = UInt(101)
let kMaxFileSize = UInt(3 * 1024 * 1024)
private enum PickingStrategy {
case smallerIsBetter, largerIsBetter
}
public func log() {
Logger.verbose("giphyId: \(giphyId), \(renditions.count)")
for rendition in renditions {
@ -85,14 +89,23 @@ enum GiphyFormat {
}
public func pickStillRendition() -> GiphyRendition? {
return pickRendition(isStill:true)
return pickRendition(isStill:true, pickingStrategy:.smallerIsBetter, maxFileSize:kMaxFileSize)
}
public func pickGifRendition() -> GiphyRendition? {
return pickRendition(isStill:false)
// Try to pick a small file...
if let rendition = pickRendition(isStill:false, pickingStrategy:.largerIsBetter, maxFileSize:kMaxFileSize) {
return rendition
}
// ...but gradually relax the file restriction...
if let rendition = pickRendition(isStill:false, pickingStrategy:.smallerIsBetter, maxFileSize:kMaxFileSize * 2) {
return rendition
}
// ...and relax even more.
return pickRendition(isStill:false, pickingStrategy:.smallerIsBetter, maxFileSize:kMaxFileSize * 3)
}
private func pickRendition(isStill: Bool) -> GiphyRendition? {
private func pickRendition(isStill: Bool, pickingStrategy: PickingStrategy, maxFileSize: UInt) -> GiphyRendition? {
var bestRendition: GiphyRendition?
for rendition in renditions {
@ -106,7 +119,7 @@ enum GiphyFormat {
// Accept renditions without a valid file size.
guard rendition.width >= kMinDimension &&
rendition.height >= kMinDimension &&
rendition.fileSize <= kMaxFileSize
rendition.fileSize <= maxFileSize
else {
continue
}
@ -125,14 +138,14 @@ enum GiphyFormat {
rendition.height >= kMinDimension &&
rendition.height <= kMaxDimension &&
rendition.fileSize > 0 &&
rendition.fileSize <= kMaxFileSize
rendition.fileSize <= maxFileSize
else {
continue
}
}
if let currentBestRendition = bestRendition {
if isStill {
if pickingStrategy == .smallerIsBetter {
if rendition.width < currentBestRendition.width {
bestRendition = rendition
}
@ -174,7 +187,6 @@ enum GiphyFormat {
}
// TODO: Is this right?
let sessionConf = URLSessionConfiguration.ephemeral
// TODO: Is this right?
sessionConf.connectionProxyDictionary = [
kCFProxyHostNameKey as String: "giphy-proxy-production.whispersystems.org",
kCFProxyPortNumberKey as String: "80",
@ -235,8 +247,6 @@ enum GiphyFormat {
// MARK: Parse API Responses
private func parseGiphyImages(responseJson:Any?) -> [GiphyImageInfo]? {
// Logger.verbose("\(responseJson)")
guard let responseJson = responseJson else {
Logger.error("\(GifManager.TAG) Missing response.")
return nil
@ -295,7 +305,6 @@ enum GiphyFormat {
return nil
}
// Logger.debug("\(GifManager.TAG) Image successfully parsed.")
return GiphyImageInfo(giphyId : giphyId,
renditions : renditions,
originalRendition: originalRendition)
@ -322,7 +331,6 @@ enum GiphyFormat {
// Be lenient when parsing file sizes - we don't require them for stills.
let fileSize = parseLenientUInt(dict:renditionDict, key:"size")
guard let urlString = renditionDict["url"] as? String else {
// Logger.debug("\(GifManager.TAG) Rendition missing url.")
return nil
}
guard urlString.characters.count > 0 else {
@ -350,12 +358,7 @@ enum GiphyFormat {
Logger.warn("\(GifManager.TAG) Invalid file extension: \(fileExtension).")
return nil
}
// guard fileExtension.lowercased() == "gif" else {
//// Logger.verbose("\(GifManager.TAG) Rendition has invalid type: \(fileExtension).")
// return nil
// }
// Logger.debug("\(GifManager.TAG) Rendition successfully parsed.")
return GiphyRendition(
format : format,
name : renditionName,
@ -366,27 +369,14 @@ enum GiphyFormat {
)
}
// {
// height = 65;
// mp4 = "https://media3.giphy.com/media/42YlR8u9gV5Cw/100w.mp4";
// "mp4_size" = 34584;
// size = 246393;
// url = "https://media3.giphy.com/media/42YlR8u9gV5Cw/100w.gif";
// webp = "https://media3.giphy.com/media/42YlR8u9gV5Cw/100w.webp";
// "webp_size" = 63656;
// width = 100;
// }
private func parsePositiveUInt(dict: [String:Any], key: String, typeName: String) -> UInt? {
guard let value = dict[key] else {
// Logger.verbose("\(GifManager.TAG) \(typeName) missing \(key).")
return nil
}
guard let stringValue = value as? String else {
// Logger.verbose("\(GifManager.TAG) \(typeName) has invalid \(key): \(value).")
return nil
}
guard let parsedValue = UInt(stringValue) else {
// Logger.verbose("\(GifManager.TAG) \(typeName) has invalid \(key): \(stringValue).")
return nil
}
guard parsedValue > 0 else {