NCPhotosPickerViewController.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. var maxSelectedAssets = 1
  29. @objc init (_ viewController: UIViewController, maxSelectedAssets: Int) {
  30. sourceViewController = viewController
  31. self.maxSelectedAssets = maxSelectedAssets
  32. }
  33. @objc func openPhotosPickerViewController(phAssets: @escaping ([PHAsset]) -> ()) {
  34. var selectedPhAssets = [PHAsset]()
  35. var configure = TLPhotosPickerConfigure()
  36. configure.cancelTitle = NSLocalizedString("_cancel_", comment: "")
  37. configure.doneTitle = NSLocalizedString("_done_", comment: "")
  38. configure.emptyMessage = NSLocalizedString("_no_albums_", comment: "")
  39. configure.tapHereToChange = NSLocalizedString("_tap_here_to_change_", comment: "")
  40. configure.maxSelectedAssets = self.maxSelectedAssets
  41. configure.selectedColor = NCBrandColor.sharedInstance.brand
  42. let viewController = customPhotoPickerViewController(withTLPHAssets: { (assets) in
  43. for asset: TLPHAsset in assets {
  44. if asset.phAsset != nil {
  45. selectedPhAssets.append(asset.phAsset!)
  46. }
  47. }
  48. phAssets(selectedPhAssets)
  49. }, didCancel: nil)
  50. viewController.didExceedMaximumNumberOfSelection = { (picker) in
  51. self.appDelegate.messageNotification("_info_", description: "_limited_dimension_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  52. }
  53. viewController.handleNoAlbumPermissions = { (picker) in
  54. self.appDelegate.messageNotification("_info_", description: "_denied_album_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  55. }
  56. viewController.handleNoCameraPermissions = { (picker) in
  57. self.appDelegate.messageNotification("_info_", description: "_denied_camera_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  58. }
  59. viewController.configure = configure
  60. sourceViewController.present(viewController, animated: true, completion: nil)
  61. }
  62. }
  63. class customPhotoPickerViewController: TLPhotosPickerViewController {
  64. override var preferredStatusBarStyle: UIStatusBarStyle {
  65. return .lightContent
  66. }
  67. override func makeUI() {
  68. super.makeUI()
  69. self.customNavItem.leftBarButtonItem?.tintColor = NCBrandColor.sharedInstance.textView
  70. self.customNavItem.rightBarButtonItem?.tintColor = NCBrandColor.sharedInstance.textView
  71. self.titleLabel.textColor = NCBrandColor.sharedInstance.icon
  72. self.subTitleLabel.textColor = NCBrandColor.sharedInstance.graySoft
  73. self.subTitleArrowImageView.image = CCGraphics.changeThemingColorImage(self.subTitleArrowImageView.image, multiplier: 1, color: NCBrandColor.sharedInstance.graySoft)
  74. self.collectionView.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  75. self.view.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  76. if CCUtility.getDarkMode() {
  77. self.navigationBar.barStyle = .black
  78. }
  79. self.titleLabel.textColor = NCBrandColor.sharedInstance.textView
  80. self.subTitleLabel.textColor = NCBrandColor.sharedInstance.textView
  81. }
  82. }