Make sure user knows what they're picking

Abort selection until *some* kind of asset has been downloaded.

// FREEBIE
This commit is contained in:
Michael Kirk 2017-10-19 15:47:14 -07:00
parent e4ad169d71
commit 37177de7cb
2 changed files with 37 additions and 19 deletions

View File

@ -35,6 +35,14 @@ class GifPickerCell: UICollectionViewCell {
var animatedAssetRequest: GiphyAssetRequest?
var animatedAsset: GiphyAsset?
var imageView: YYAnimatedImageView?
var activityIndicator: UIActivityIndicatorView?
var isCellSelected: Bool = false {
didSet {
AssertIsOnMainThread()
ensureCellState()
}
}
// As another bandwidth saving measure, we only fetch the full sized GIF when the user selects it.
private var renditionForSending: GiphyRendition?
@ -59,6 +67,8 @@ class GifPickerCell: UICollectionViewCell {
animatedAssetRequest = nil
imageView?.removeFromSuperview()
imageView = nil
activityIndicator = nil
isCellSelected = false
}
private func clearStillAssetRequest() {
@ -202,6 +212,24 @@ class GifPickerCell: UICollectionViewCell {
}
imageView.image = image
self.backgroundColor = nil
if self.isCellSelected {
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
self.activityIndicator = activityIndicator
addSubview(activityIndicator)
activityIndicator.autoCenterInSuperview()
activityIndicator.startAnimating()
// Render activityIndicator on a white tile to ensure it's visible on
// when overalayed on a variety of potential gifs.
activityIndicator.backgroundColor = UIColor.white.withAlphaComponent(0.3)
activityIndicator.autoSetDimension(.width, toSize: 30)
activityIndicator.autoSetDimension(.height, toSize: 30)
activityIndicator.layer.cornerRadius = 3
} else {
self.activityIndicator?.stopAnimating()
self.activityIndicator = nil
}
}
public func requestRenditionForSending() -> Promise<GiphyAsset> {

View File

@ -293,6 +293,12 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
return
}
guard cell.stillAsset != nil || cell.animatedAsset != nil else {
// we don't want to let the user blindly select a gray cell
Logger.debug("\(TAG) ignoring selection of cell with no preview")
return
}
guard self.selectedCell == nil else {
owsFail("\(TAG) Already selected cell")
return
@ -302,13 +308,9 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
// Fade out all cells except the selected one.
let maskingView = OWSBezierPathView()
self.view.addSubview(maskingView)
maskingView.configureShapeLayerBlock = { [weak self] layer, bounds in
guard let strongSelf = self else {
return
}
let cellRect = self.collectionView.convert(cell.frame, to: self.view)
maskingView.configureShapeLayerBlock = { layer, bounds in
let path = UIBezierPath(rect: bounds)
let cellRect = strongSelf.collectionView.convert(cell.frame, to: strongSelf.view)
path.append(UIBezierPath(rect: cellRect))
layer.path = path.cgPath
@ -318,19 +320,7 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
}
maskingView.autoPinEdgesToSuperviewEdges()
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
cell.contentView.addSubview(activityIndicator)
activityIndicator.autoCenterInSuperview()
activityIndicator.startAnimating()
// Render activityIndicator on a white tile to ensure it's visible on
// when overalayed on a variety of potential gifs.
activityIndicator.backgroundColor = UIColor.white.withAlphaComponent(0.3)
activityIndicator.autoSetDimension(.width, toSize: 30)
activityIndicator.autoSetDimension(.height, toSize: 30)
activityIndicator.layer.cornerRadius = 3
cell.isCellSelected = true
self.collectionView.isUserInteractionEnabled = false
getFileForCell(cell)