PPAssetsActionConfig.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // This file is based on third party code, see below for the original author
  2. // and original license.
  3. // Modifications are (c) by Threema GmbH and licensed under the AGPLv3.
  4. // Copyright (c) 2016 Pavel Pantus <pantusp@gmail.com>
  5. // See Resources/License.html for original license
  6. import UIKit
  7. /**
  8. Configuration of Assets Action Controller.
  9. */
  10. public struct PPAssetsActionConfig {
  11. /// Tint Color. System's by default.
  12. public var tintColor = UIView().tintColor
  13. /// Font to be used on buttons.
  14. public var font = UIFont.systemFont(ofSize: 19.0)
  15. /// Text alignement to be used on buttons.
  16. public var textAlignment = NSTextAlignment.center
  17. /**
  18. Indicates whether Assets Action Controller should ask for photo permissions in case
  19. they were not previously granted.
  20. If false, no room will be allocated for Assets View Controller.
  21. */
  22. public var askPhotoPermissions = true
  23. /// Regular (folded) height of Assets View Controller.
  24. public var assetsPreviewRegularHeight: CGFloat = 150.0
  25. /// Expanded height of Assets View Controller.
  26. public var assetsPreviewExpandedHeight: CGFloat = 220.0
  27. /// Left, Right and Bottom insets of Assets Action Controller.
  28. public var inset: CGFloat = 16.0
  29. /// Spacing between Cancel and option buttons.
  30. public var sectionSpacing: CGFloat = 16.0
  31. /// Background color of Assets View Controller.
  32. public var backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.35)
  33. /// In and Out animation duration.
  34. public var animationDuration: TimeInterval = 0.5
  35. /// Max selectable assets
  36. public var maxSelectableAssets: Int = 0
  37. /// Height of each button (Options and Cancel).
  38. public var buttonHeight: CGFloat = 50.0
  39. /// If enabled shows live camera view as a first cell.
  40. public var showLiveCameraCell = true
  41. /// If enabled shows videos in Assets Collection Controller and autoplays them.
  42. public var showVideos = true
  43. /// If enabled shows all options when a asset is selected
  44. public var showOptionsWhenAssetIsSelected = true
  45. /// If enabled it will add a additional button if showOptionsWhenAssetIsSelected is disabled
  46. public var showAdditionalOptionWhenAssetIsSelected = false
  47. /// Title for additional option button
  48. public var additionalOptionText:String? = nil
  49. /// Use snap button as custom button
  50. public var useOwnSnapButton = false
  51. /// Title for snap button
  52. public var ownSnapButtonText:String? = nil
  53. public var ownSnapButtonIcon:UIImage? = nil
  54. /// Corner radius
  55. public var cornerRadius: CGFloat = 5.0
  56. /// Fetch limit
  57. public var fetchLimit: Int = 100
  58. public var showGalleryPreview:Bool = false
  59. public var previewReplacementText: String = NSLocalizedString("take_photo_or_video", comment: "")
  60. public var previewReplacementIcon: UIImage? = nil
  61. /***** BEGIN THREEMA MODIFICATION: tableBackground *********/
  62. public var tableBackground: UIColor? = nil
  63. /***** END THREEMA MODIFICATION: tableBackground *********/
  64. public init() {}
  65. public func showReplacementOptionInLandscape() -> Bool {
  66. if UIImagePickerController.isSourceTypeAvailable(.camera) && ((isLandscape() && UIDevice.current.userInterfaceIdiom != .pad) || UIAccessibility.isVoiceOverRunning || !showGalleryPreview) {
  67. return true
  68. }
  69. return false
  70. }
  71. public func isLandscape() -> Bool {
  72. if UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight {
  73. return true
  74. }
  75. return false
  76. }
  77. }