@ -31,8 +31,8 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
public weak var delegate : GifPickerViewControllerDelegate ?
public weak var delegate : GifPickerViewControllerDelegate ?
var thread : TSThread ?
let thread : TSThread
var messageSender : MessageSender ?
let messageSender : MessageSender
let searchBar : UISearchBar
let searchBar : UISearchBar
let layout : GifPickerLayout
let layout : GifPickerLayout
@ -40,7 +40,7 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
var noResultsView : UILabel ?
var noResultsView : UILabel ?
var searchErrorView : UILabel ?
var searchErrorView : UILabel ?
var activityIndicator : UIActivityIndicatorView ?
var activityIndicator : UIActivityIndicatorView ?
var selectedCell : UICollectionViewCell ?
var imageInfos = [ GiphyImageInfo ] ( )
var imageInfos = [ GiphyImageInfo ] ( )
var reachability : Reachability ?
var reachability : Reachability ?
@ -53,15 +53,7 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
@ available ( * , unavailable , message : " use other constructor instead. " )
@ available ( * , unavailable , message : " use other constructor instead. " )
required init ? ( coder aDecoder : NSCoder ) {
required init ? ( coder aDecoder : NSCoder ) {
self . thread = nil
fatalError ( " \( #function ) is unimplemented. " )
self . messageSender = nil
self . searchBar = UISearchBar ( )
self . layout = GifPickerLayout ( )
self . collectionView = UICollectionView ( frame : CGRect . zero , collectionViewLayout : self . layout )
super . init ( coder : aDecoder )
owsFail ( " \( self . TAG ) invalid constructor " )
}
}
required init ( thread : TSThread , messageSender : MessageSender ) {
required init ( thread : TSThread , messageSender : MessageSender ) {
@ -295,36 +287,36 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
// MARK: - U I C o l l e c t i o n V i e w D e l e g a t e
// MARK: - U I C o l l e c t i o n V i e w D e l e g a t e
public func collectionView ( _ collectionView : UICollectionView , didSelectItemAt indexPath : IndexPath ) {
public func collectionView ( _ collectionView : UICollectionView , didSelectItemAt indexPath : IndexPath ) {
guard let cell = collectionView . cellForItem ( at : indexPath ) as ? GifPickerCell else {
guard let cell = collectionView . cellForItem ( at : indexPath ) as ? GifPickerCell else {
owsFail ( " \( TAG ) unexpected cell. " )
owsFail ( " \( TAG ) unexpected cell. " )
return
return
}
}
guard let asset = cell . animatedAsset else {
Logger . info ( " \( TAG ) unload cell selected. " )
guard self . selectedCell = = nil else {
return
owsFail ( " \( TAG ) Already selected cell " )
}
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
return
}
}
self . selectedCell = cell
// T O D O d i s a b l e c o l l e c t i o n v i e w s c r o l l / s e l e c t i o n
// T O D O s h o w l o a d i n g
cell . fetchRenditionForSending ( ) . then { ( asset : GiphyAsset ) -> Void in
let filePath = asset . filePath
guard let dataSource = DataSourcePath . dataSource ( withFilePath : filePath ) else {
owsFail ( " \( self . TAG ) couldn't load asset. " )
return
}
let attachment = SignalAttachment ( dataSource : dataSource , dataUTI : asset . rendition . utiType )
self . delegate ? . gifPickerWillSend ( )
self . delegate ? . gifPickerWillSend ( )
let outgoingMessage = ThreadUtil . sendMessage ( with : attachment , in : thread , messageSender : messageSender )
let outgoingMessage = ThreadUtil . sendMessage ( with : attachment , in : self . thread , messageSender : self . messageSender )
self . delegate ? . gifPickerDidSend ( outgoingMessage : outgoingMessage )
self . delegate ? . gifPickerDidSend ( outgoingMessage : outgoingMessage )
dismiss ( animated : true , completion : nil )
self . dismiss ( animated : true , completion : nil )
} . retainUntilComplete ( )
}
}
public func collectionView ( _ collectionView : UICollectionView , willDisplay cell : UICollectionViewCell , forItemAt indexPath : IndexPath ) {
public func collectionView ( _ collectionView : UICollectionView , willDisplay cell : UICollectionViewCell , forItemAt indexPath : IndexPath ) {