NCPhotosPickerViewController.swift 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <marino.faggiana@nextcloud.com>
  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. import TLPhotoPicker
  25. class NCPhotosPickerViewController: NSObject {
  26. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  27. var sourceViewController : UIViewController
  28. @objc init (_ viewController : UIViewController) {
  29. sourceViewController = viewController
  30. }
  31. @objc func openPhotosPickerViewController(phAssets: @escaping ([PHAsset]) -> ()) {
  32. var selectedPhAssets = [PHAsset]()
  33. var configure = TLPhotosPickerConfigure()
  34. configure.cancelTitle = NSLocalizedString("_cancel_", comment: "")
  35. configure.defaultCameraRollTitle = NSLocalizedString("_camera_roll_", comment: "")
  36. configure.doneTitle = NSLocalizedString("_done_", comment: "")
  37. configure.emptyMessage = NSLocalizedString("_no_albums_", comment: "")
  38. configure.tapHereToChange = NSLocalizedString("_tap_here_to_change_", comment: "")
  39. configure.maxSelectedAssets = Int(k_pickerControllerMax)
  40. configure.selectedColor = NCBrandColor.sharedInstance.brand
  41. let viewController = customPhotoPickerViewController(withTLPHAssets: { (assets) in
  42. for asset: TLPHAsset in assets {
  43. if asset.phAsset != nil {
  44. selectedPhAssets.append(asset.phAsset!)
  45. }
  46. }
  47. phAssets(selectedPhAssets)
  48. }, didCancel: nil)
  49. viewController.didExceedMaximumNumberOfSelection = { (picker) in
  50. self.appDelegate.messageNotification("_info_", description: "_limited_dimension_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  51. }
  52. viewController.handleNoAlbumPermissions = { (picker) in
  53. self.appDelegate.messageNotification("_info_", description: "_denied_album_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  54. }
  55. viewController.handleNoCameraPermissions = { (picker) in
  56. self.appDelegate.messageNotification("_info_", description: "_denied_camera_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  57. }
  58. viewController.configure = configure
  59. sourceViewController.present(viewController, animated: true, completion: nil)
  60. }
  61. }
  62. class customPhotoPickerViewController: TLPhotosPickerViewController {
  63. override func makeUI() {
  64. super.makeUI()
  65. self.customNavItem.leftBarButtonItem?.tintColor = NCBrandColor.sharedInstance.brand
  66. self.customNavItem.rightBarButtonItem?.tintColor = NCBrandColor.sharedInstance.brand
  67. self.titleLabel.textColor = NCBrandColor.sharedInstance.brand
  68. self.subTitleLabel.textColor = NCBrandColor.sharedInstance.icon
  69. self.subTitleArrowImageView.image = CCGraphics.changeThemingColorImage(self.subTitleArrowImageView.image, multiplier: 1, color: NCBrandColor.sharedInstance.icon)
  70. }
  71. }