NCPhotosPickerViewController.swift 4.7 KB

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