@@ -184,7 +184,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
184184 private let bannedSendVideos : ( Int32 , Bool ) ?
185185 private let canBoostToUnrestrict : Bool
186186 fileprivate let paidMediaAllowed : Bool
187- private let subject : Subject
187+ fileprivate let subject : Subject
188188 fileprivate let forCollage : Bool
189189 private let saveEditedPhotos : Bool
190190
@@ -1826,6 +1826,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
18261826 fileprivate let secondaryButtonStatePromise = Promise < AttachmentMainButtonState ? > ( nil )
18271827
18281828 private let mainButtonAction : ( ( ) -> Void ) ?
1829+ private let secondaryButtonAction : ( ( ) -> Void ) ?
18291830
18301831 public init (
18311832 context: AccountContext ,
@@ -1845,7 +1846,8 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
18451846 selectionContext: TGMediaSelectionContext ? = nil ,
18461847 saveEditedPhotos: Bool = false ,
18471848 mainButtonState: AttachmentMainButtonState ? = nil ,
1848- mainButtonAction: ( ( ) -> Void ) ? = nil
1849+ mainButtonAction: ( ( ) -> Void ) ? = nil ,
1850+ secondaryButtonAction: ( ( ) -> Void ) ? = nil
18491851 ) {
18501852 self . context = context
18511853
@@ -1865,6 +1867,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
18651867 self . saveEditedPhotos = saveEditedPhotos
18661868 self . mainButtonStatePromise. set ( . single( mainButtonState) )
18671869 self . mainButtonAction = mainButtonAction
1870+ self . secondaryButtonAction = secondaryButtonAction
18681871
18691872 let selectionContext = selectionContext ?? TGMediaSelectionContext ( )
18701873
@@ -1998,7 +2001,14 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
19982001 } else if collection == nil {
19992002 self . navigationItem. leftBarButtonItem = UIBarButtonItem ( title: self . presentationData. strings. Common_Cancel, style: . plain, target: self , action: #selector( self . cancelPressed) )
20002003
2004+ var hasSelect = false
20012005 if forCollage {
2006+ hasSelect = true
2007+ } else if case . story = mode {
2008+ hasSelect = true
2009+ }
2010+
2011+ if hasSelect {
20022012 self . navigationItem. rightBarButtonItem = UIBarButtonItem ( backButtonAppearanceWithTitle: self . presentationData. strings. Common_Select, target: self , action: #selector( self . selectPressed) )
20032013 } else {
20042014 if [ . createSticker] . contains ( mode) {
@@ -2338,6 +2348,9 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
23382348 let transition = ContainedViewLayoutTransition . animated ( duration: 0.25 , curve: . easeInOut)
23392349 var moreIsVisible = false
23402350 if case let . assets( _, mode) = self . subject, [ . story, . createSticker] . contains ( mode) {
2351+ if count == 1 {
2352+ self . requestAttachmentMenuExpansion ( )
2353+ }
23412354 moreIsVisible = true
23422355 } else if case let . media( media) = self . subject {
23432356 self . titleView. title = media. count == 1 ? self . presentationData. strings. Attachment_Pasteboard : self . presentationData. strings. Attachment_SelectedMedia ( count)
@@ -2381,7 +2394,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
23812394 transition. updateAlpha ( node: self . moreButtonNode. iconNode, alpha: moreIsVisible ? 1.0 : 0.0 )
23822395 transition. updateTransformScale ( node: self . moreButtonNode. iconNode, scale: moreIsVisible ? 1.0 : 0.1 )
23832396
2384- if self . selectionCount > 0 {
2397+ if case . assets ( _ , . story ) = self . subject , self . selectionCount > 0 {
23852398 //TODO:localize
23862399 var text = " Create 1 Story "
23872400 if self . selectionCount > 1 {
@@ -2390,7 +2403,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
23902403 self . mainButtonStatePromise. set ( . single( AttachmentMainButtonState ( text: text, badge: nil , font: . bold, background: . color( self . presentationData. theme. actionSheet. controlAccentColor) , textColor: self . presentationData. theme. list. itemCheckColors. foregroundColor, isVisible: true , progress: . none, isEnabled: true , hasShimmer: false , position: . top) ) )
23912404
23922405 if self . selectionCount > 1 && self . selectionCount <= 6 {
2393- self . secondaryButtonStatePromise. set ( . single( AttachmentMainButtonState ( text: " Combine into Collage " , badge: nil , font: . regular, background: . color( . clear) , textColor: self . presentationData. theme. actionSheet. controlAccentColor, isVisible: true , progress: . none, isEnabled: true , hasShimmer: false , iconName: " Media Editor/Collage " , position: . bottom) ) )
2406+ self . secondaryButtonStatePromise. set ( . single( AttachmentMainButtonState ( text: " Combine into Collage " , badge: nil , font: . regular, background: . color( . clear) , textColor: self . presentationData. theme. actionSheet. controlAccentColor, isVisible: true , progress: . none, isEnabled: true , hasShimmer: false , iconName: " Media Editor/Collage " , smallSpacing : true , position: . bottom) ) )
23942407 } else {
23952408 self . secondaryButtonStatePromise. set ( . single( nil ) )
23962409 }
@@ -2427,6 +2440,10 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
24272440 self . mainButtonAction ? ( )
24282441 }
24292442
2443+ func secondaryButtonPressed( ) {
2444+ self . secondaryButtonAction ? ( )
2445+ }
2446+
24302447 func dismissAllTooltips( ) {
24312448 self . undoOverlayController? . dismissWithCommitAction ( )
24322449 }
@@ -2810,7 +2827,7 @@ final class MediaPickerContext: AttachmentMediaPickerContext {
28102827 private weak var controller : MediaPickerScreenImpl ?
28112828
28122829 var selectionCount : Signal < Int , NoError > {
2813- if self . controller? . forCollage == true {
2830+ if let controller = self . controller, case . assets ( _ , . story ) = controller . subject {
28142831 return . single( 0 )
28152832 } else {
28162833 return Signal { [ weak self] subscriber in
@@ -2973,7 +2990,7 @@ final class MediaPickerContext: AttachmentMediaPickerContext {
29732990 }
29742991
29752992 func secondaryButtonAction( ) {
2976- self . controller? . mainButtonPressed ( )
2993+ self . controller? . secondaryButtonPressed ( )
29772994 }
29782995}
29792996
@@ -3162,7 +3179,7 @@ public func storyMediaPickerController(
31623179 selectionLimit: Int ? ,
31633180 getSourceRect: @escaping ( ) -> CGRect ,
31643181 completion: @escaping ( Any , UIView , CGRect , UIImage ? , @escaping ( Bool ? ) -> ( UIView , CGRect ) ? , @escaping ( ) -> Void ) -> Void ,
3165- multipleCompletion: @escaping ( [ Any ] ) -> Void ,
3182+ multipleCompletion: @escaping ( [ Any ] , Bool ) -> Void ,
31663183 dismissed: @escaping ( ) -> Void ,
31673184 groupsPresented: @escaping ( ) -> Void
31683185) -> ViewController {
@@ -3181,9 +3198,18 @@ public func storyMediaPickerController(
31813198 }
31823199 }
31833200
3184- let controller = AttachmentController ( context: context, updatedPresentationData: updatedPresentationData, chatLocation: nil , buttons: [ . standalone] , initialButton: . standalone, fromMenu: false , hasTextInput: false , makeEntityInputView: {
3185- return nil
3186- } )
3201+ let controller = AttachmentController (
3202+ context: context,
3203+ updatedPresentationData: updatedPresentationData,
3204+ chatLocation: nil ,
3205+ buttons: [ . standalone] ,
3206+ initialButton: . standalone,
3207+ fromMenu: false ,
3208+ hasTextInput: false ,
3209+ makeEntityInputView: {
3210+ return nil
3211+ }
3212+ )
31873213 controller. forceSourceRect = true
31883214 controller. getSourceRect = getSourceRect
31893215 controller. requestController = { _, present in
@@ -3207,7 +3233,18 @@ public func storyMediaPickerController(
32073233 results. append ( asset)
32083234 }
32093235 }
3210- multipleCompletion ( results)
3236+ multipleCompletion ( results, false )
3237+ }
3238+ } ,
3239+ secondaryButtonAction: { [ weak selectionContext] in
3240+ if let selectionContext, let selectedItems = selectionContext. selectedItems ( ) {
3241+ var results : [ Any ] = [ ]
3242+ for item in selectedItems {
3243+ if let item = item as? TGMediaAsset , let asset = item. backingAsset {
3244+ results. append ( asset)
3245+ }
3246+ }
3247+ multipleCompletion ( results, true )
32113248 }
32123249 }
32133250 )
0 commit comments