@@ -237,7 +237,13 @@ final class ShareViewController: UIViewController {
237
237
238
238
let hasItem = state. processedAttachment != nil
239
239
self . log ( attachmentState: state. attachmentState, itemState: state. itemPickerState)
240
- self . update ( item: state. expectedItem, attachment: state. expectedAttachment, attachmentState: state. attachmentState, defaultTitle: state. title)
240
+ update (
241
+ libraryIsFilesEditable: state. collectionPickerState. libraryIsFilesEditable,
242
+ item: state. expectedItem,
243
+ attachment: state. expectedAttachment,
244
+ attachmentState: state. attachmentState,
245
+ defaultTitle: state. title
246
+ )
241
247
self . update ( attachmentState: state. attachmentState, itemState: state. itemPickerState, hasItem: hasItem, isSubmitting: state. isSubmitting)
242
248
self . update ( collectionPicker: state. collectionPickerState, recents: state. recents)
243
249
self . update ( itemPicker: state. itemPickerState, hasExpectedItem: ( state. expectedItem != nil || state. expectedAttachment != nil ) )
@@ -287,7 +293,7 @@ final class ShareViewController: UIViewController {
287
293
self . updateBottomProgress ( for: state, itemState: itemState, hasItem: hasItem, isSubmitting: isSubmitting)
288
294
}
289
295
290
- private func update( item: ItemResponse ? , attachment: ( String , File ) ? , attachmentState: ExtensionViewModel . State . AttachmentState , defaultTitle title: String ? ) {
296
+ private func update( libraryIsFilesEditable : Bool , item: ItemResponse ? , attachment: ( String , File ) ? , attachmentState: ExtensionViewModel . State . AttachmentState , defaultTitle title: String ? ) {
291
297
self . translationContainer. isHidden = false
292
298
293
299
if item == nil && attachment == nil {
@@ -306,23 +312,52 @@ final class ShareViewController: UIViewController {
306
312
return
307
313
}
308
314
309
- self . itemContainer. isHidden = item == nil
310
- self . attachmentContainer. isHidden = attachment == nil
315
+ let itemFound : Bool
316
+ if let item {
317
+ itemFound = true
318
+ // Item was found, show its metadata.
319
+ let itemTitle = itemTitle ( for: item, schemaController: schemaController, defaultValue: title ?? " " )
320
+ setItem ( title: itemTitle, type: item. rawType)
321
+ itemContainer. isHidden = false
322
+ } else {
323
+ itemFound = false
324
+ itemContainer. isHidden = true
325
+ }
326
+ if libraryIsFilesEditable, let ( attachmentTitle, file) = attachment {
327
+ // The picked library allows file editing, and either item with attachment, or only attachment (local/remote file), was found, show its metadata.
328
+ setAttachment ( title: attachmentTitle, file: file, state: attachmentState)
329
+ attachmentContainerLeft. constant = itemFound ? Self . childAttachmentLeftOffset : 0
330
+ attachmentContainer. isHidden = false
331
+ } else {
332
+ attachmentContainer. isHidden = true
333
+ }
334
+
335
+ func setAttachment( title: String , file: File , state: ExtensionViewModel . State . AttachmentState ) {
336
+ attachmentTitleLabel. text = title
337
+ let type : Attachment . Kind = . file( filename: " " , contentType: file. mimeType, location: . local, linkType: . importedFile, compressed: false )
338
+ let iconState = FileAttachmentView . State. stateFrom ( type: type, progress: nil , error: state. error)
339
+ attachmentIcon. set ( state: iconState, style: . shareExtension)
311
340
312
- if let item = item, let ( attachmentTitle, file) = attachment {
313
- // Item with attachment was found, show their metadata
314
- let itemTitle = self . itemTitle ( for: item, schemaController: self . schemaController, defaultValue: title ?? " " )
315
- self . setItem ( title: itemTitle, type: item. rawType)
316
- self . attachmentContainerLeft. constant = ShareViewController . childAttachmentLeftOffset
317
- self . setAttachment ( title: attachmentTitle, file: file, state: attachmentState)
318
- } else if let item = item {
319
- // Only item was found, show metadata
320
- let title = self . itemTitle ( for: item, schemaController: self . schemaController, defaultValue: title ?? " " )
321
- self . setItem ( title: title, type: item. rawType)
322
- } else if let ( title, file) = attachment {
323
- // Only attachment (local/remote file) was found, show metadata
324
- self . attachmentContainerLeft. constant = 0
325
- self . setAttachment ( title: title, file: file, state: attachmentState)
341
+ switch state {
342
+ case . downloading( let progress) :
343
+ attachmentProgressView. isHidden = progress == 0
344
+ attachmentActivityIndicator. isHidden = progress > 0
345
+ attachmentProgressView. progress = CGFloat ( progress)
346
+ if progress == 0 && !attachmentActivityIndicator. isAnimating {
347
+ attachmentActivityIndicator. startAnimating ( )
348
+ }
349
+ attachmentIcon. alpha = 0.5
350
+ attachmentTitleLabel. alpha = 0.5
351
+
352
+ default :
353
+ attachmentProgressView. isHidden = true
354
+ if attachmentActivityIndicator. isAnimating {
355
+ attachmentActivityIndicator. stopAnimating ( )
356
+ }
357
+ attachmentActivityIndicator. isHidden = true
358
+ attachmentIcon. alpha = 1
359
+ attachmentTitleLabel. alpha = 1
360
+ }
326
361
}
327
362
}
328
363
@@ -335,37 +370,6 @@ final class ShareViewController: UIViewController {
335
370
self . itemIcon. image = UIImage ( named: ItemTypes . iconName ( for: type) )
336
371
}
337
372
338
- private func setAttachment( title: String , file: File , state: ExtensionViewModel . State . AttachmentState ) {
339
- self . attachmentTitleLabel. text = title
340
- let type : Attachment . Kind = . file( filename: " " , contentType: file. mimeType, location: . local, linkType: . importedFile, compressed: false )
341
- let iconState = FileAttachmentView . State. stateFrom ( type: type, progress: nil , error: state. error)
342
- self . attachmentIcon. set ( state: iconState, style: . shareExtension)
343
-
344
- switch state {
345
- case . downloading( let progress) :
346
- self . attachmentProgressView. isHidden = progress == 0
347
- self . attachmentActivityIndicator. isHidden = progress > 0
348
- self . attachmentProgressView. progress = CGFloat ( progress)
349
- if progress == 0 && !self . attachmentActivityIndicator. isAnimating {
350
- self . attachmentActivityIndicator. startAnimating ( )
351
- }
352
-
353
- self . attachmentIcon. alpha = 0.5
354
- self . attachmentTitleLabel. alpha = 0.5
355
-
356
- default :
357
- if !self . attachmentContainer. isHidden {
358
- self . attachmentProgressView. isHidden = true
359
- if self . attachmentActivityIndicator. isAnimating {
360
- self . attachmentActivityIndicator. stopAnimating ( )
361
- }
362
- self . attachmentActivityIndicator. isHidden = true
363
- self . attachmentIcon. alpha = 1
364
- self . attachmentTitleLabel. alpha = 1
365
- }
366
- }
367
- }
368
-
369
373
private func updateNavigationItems( for state: ExtensionViewModel . State . AttachmentState , isSubmitting: Bool ) {
370
374
if let error = state. error {
371
375
switch error {
0 commit comments