@ -18,9 +18,10 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
private var progressPoller : ProgressPoller ?
private var progressPoller : ProgressPoller ?
var loadViewController : SAELoadViewController ?
var loadViewController : SAELoadViewController ?
let shareViewNavigationController : UINavigationController = UINavigationController ( )
override open func loadView ( ) {
override open func loadView ( ) {
super . loadView ( )
super . loadView ( )
Logger . debug ( " \( self . logTag ) \( #function ) " )
Logger . debug ( " \( self . logTag ) \( #function ) " )
// T h i s s h o u l d b e t h e f i r s t t h i n g w e d o .
// T h i s s h o u l d b e t h e f i r s t t h i n g w e d o .
@ -56,7 +57,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
// m o s t o f t h e s i n g l e t o n s , e t c . ) . W e j u s t w a n t t o s h o w a n e r r o r v i e w a n d
// m o s t o f t h e s i n g l e t o n s , e t c . ) . W e j u s t w a n t t o s h o w a n e r r o r v i e w a n d
// a b o r t .
// a b o r t .
isReadyForAppExtensions = OWSPreferences . isReadyForAppExtensions ( )
isReadyForAppExtensions = OWSPreferences . isReadyForAppExtensions ( )
if ! isReadyForAppExtensions {
guard isReadyForAppExtensions else {
// I f w e d o n ' t h a v e T S S S t o r a g e M a n a g e r , w e c a n ' t c o n s u l t T S A c c o u n t M a n a g e r
// I f w e d o n ' t h a v e T S S S t o r a g e M a n a g e r , w e c a n ' t c o n s u l t T S A c c o u n t M a n a g e r
// f o r i s R e g i s t e r e d , s o w e u s e O W S P r e f e r e n c e s w h i c h i s u s u a l l y - a c c u r a t e
// f o r i s R e g i s t e r e d , s o w e u s e O W S P r e f e r e n c e s w h i c h i s u s u a l l y - a c c u r a t e
// c o p y o f t h a t s t a t e .
// c o p y o f t h a t s t a t e .
@ -79,9 +80,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
}
}
Logger . debug ( " \( self . logTag ) setup is slow - showing loading screen " )
Logger . debug ( " \( self . logTag ) setup is slow - showing loading screen " )
self . showPrimaryViewController ( loadViewController )
let navigationController = UINavigationController ( rootViewController : loadViewController )
self . present ( navigationController , animated : true )
} . retainUntilComplete ( )
} . retainUntilComplete ( )
// W e s h o u l d n ' t s e t u p o u r e n v i r o n m e n t u n t i l a f t e r w e ' v e c o n s u l t e d i s R e a d y F o r A p p E x t e n s i o n s .
// W e s h o u l d n ' t s e t u p o u r e n v i r o n m e n t u n t i l a f t e r w e ' v e c o n s u l t e d i s R e a d y F o r A p p E x t e n s i o n s .
@ -117,6 +116,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
}
}
deinit {
deinit {
Logger . info ( " \( self . logTag ) dealloc " )
NotificationCenter . default . removeObserver ( self )
NotificationCenter . default . removeObserver ( self )
}
}
@ -298,7 +298,7 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
private func showErrorView ( title : String , message : String ) {
private func showErrorView ( title : String , message : String ) {
let viewController = SAEFailedViewController ( delegate : self , title : title , message : message )
let viewController = SAEFailedViewController ( delegate : self , title : title , message : message )
self . s etViewControllers( [ viewController ] , animated : false )
self . s howPrimaryViewController( viewController )
}
}
// MARK: V i e w L i f e c y c l e
// MARK: V i e w L i f e c y c l e
@ -363,22 +363,30 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE
// MARK: H e l p e r s
// MARK: H e l p e r s
// T h i s v i e w c o n t r o l l e r i s n o t v i s i b l e t o t h e u s e r . I t e x i s t s t o i n t e r c e p t t o u c h e s , s e t u p t h e
// e x t e n s i o n s d e p e n d e n c i e s , a n d e v e n t u a l l y p r e s e n t a v i s i b l e v i e w t o t h e u s e r .
// F o r s p e e d o f p r e s e n t a t i o n , w e o n l y p r e s e n t a s i n g l e m o d a l , a n d i f i t ' s a l r e a d y b e e n p r e s e n t e d
// w e s w a p o u t t h e c o n t e n t s .
// e . g . i f l o a d i n g i s t a k i n g a w h i l e , t h e u s e r w i l l s e e t h e l o a d s c r e e n p r e s e n t e d w i t h a m o d a l
// a n i m a t i o n . N e x t , w h e n l o a d i n g c o m p l e t e s , t h e l o a d v i e w w i l l b e s w i t c h e d o u t f o r t h e c o n t a c t
// p i c k e r v i e w .
private func showPrimaryViewController ( _ viewController : UIViewController ) {
shareViewNavigationController . setViewControllers ( [ viewController ] , animated : false )
if self . presentedViewController = = nil {
Logger . debug ( " \( self . logTag ) presenting modally: \( viewController ) " )
self . present ( shareViewNavigationController , animated : true )
} else {
Logger . debug ( " \( self . logTag ) modal already presented. swapping modal content for: \( viewController ) " )
assert ( self . presentedViewController = = shareViewNavigationController )
}
}
private func presentConversationPicker ( ) {
private func presentConversationPicker ( ) {
self . buildAttachment ( ) . then { attachment -> Void in
self . buildAttachment ( ) . then { attachment -> Void in
let conversationPicker = SharingThreadPickerViewController ( shareViewDelegate : self )
let conversationPicker = SharingThreadPickerViewController ( shareViewDelegate : self )
let navigationController = UINavigationController ( rootViewController : conversationPicker )
navigationController . isNavigationBarHidden = true
conversationPicker . attachment = attachment
conversationPicker . attachment = attachment
if let presentedViewController = self . presentedViewController {
self . shareViewNavigationController . isNavigationBarHidden = true
Logger . debug ( " \( self . logTag ) dismissing \( presentedViewController ) before presenting conversation picker " )
self . showPrimaryViewController ( conversationPicker )
self . dismiss ( animated : true ) {
self . present ( navigationController , animated : true )
}
} else {
Logger . debug ( " \( self . logTag ) no other modal, presenting conversation picker immediately " )
self . present ( navigationController , animated : true )
}
Logger . info ( " showing picker with attachment: \( attachment ) " )
Logger . info ( " showing picker with attachment: \( attachment ) " )
} . catch { error in
} . catch { error in
let alertTitle = NSLocalizedString ( " SHARE_EXTENSION_UNABLE_TO_BUILD_ATTACHMENT_ALERT_TITLE " , comment : " Shown when trying to share content to a Signal user for the share extension. Followed by failure details. " )
let alertTitle = NSLocalizedString ( " SHARE_EXTENSION_UNABLE_TO_BUILD_ATTACHMENT_ALERT_TITLE " , comment : " Shown when trying to share content to a Signal user for the share extension. Followed by failure details. " )