NCPhotosPickerViewController.swift 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // NCPhotosPickerViewController.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 11/11/2018.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. class NCPhotosPickerViewController: NSObject {
  25. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  26. var sourceViewController : UIViewController
  27. @objc init (_ viewController : UIViewController) {
  28. sourceViewController = viewController
  29. }
  30. @objc func openPhotosPickerViewController(phAssets: @escaping ([PHAsset]) -> ()) {
  31. var selectedPhAssets = [PHAsset]()
  32. var configure = TLPhotosPickerConfigure()
  33. configure.cancelTitle = NSLocalizedString("_cancel_", comment: "")
  34. configure.defaultCameraRollTitle = NSLocalizedString("_camera_roll_", comment: "")
  35. configure.doneTitle = NSLocalizedString("_done_", comment: "")
  36. configure.emptyMessage = NSLocalizedString("_no_albums_", comment: "")
  37. configure.tapHereToChange = NSLocalizedString("_tap_here_to_change_", comment: "")
  38. configure.maxSelectedAssets = Int(k_pickerControllerMax)
  39. configure.selectedColor = NCBrandColor.sharedInstance.brand
  40. let viewController = TLPhotosPickerViewController(withTLPHAssets: { (assets) in
  41. for asset: TLPHAsset in assets {
  42. if asset.phAsset != nil {
  43. selectedPhAssets.append(asset.phAsset!)
  44. }
  45. }
  46. phAssets(selectedPhAssets)
  47. }, didCancel: nil)
  48. viewController.didExceedMaximumNumberOfSelection = { (picker) in
  49. self.appDelegate.messageNotification("_info_", description: "_limited_dimension_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  50. }
  51. viewController.handleNoAlbumPermissions = { (picker) in
  52. self.appDelegate.messageNotification("_info_", description: "_denied_album_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  53. }
  54. viewController.handleNoCameraPermissions = { (picker) in
  55. self.appDelegate.messageNotification("_info_", description: "_denied_camera_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  56. }
  57. viewController.configure = configure
  58. sourceViewController.present(viewController, animated: true, completion: nil)
  59. }
  60. }