NCPhotosPickerViewController.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. if maxSelectedAssets == 1 {
  43. configure.singleSelectedMode = true
  44. }
  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. }, didCancel: nil)
  53. viewController.didExceedMaximumNumberOfSelection = { (picker) in
  54. self.appDelegate.messageNotification("_info_", description: "_limited_dimension_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  55. }
  56. viewController.handleNoAlbumPermissions = { (picker) in
  57. self.appDelegate.messageNotification("_info_", description: "_denied_album_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  58. }
  59. viewController.handleNoCameraPermissions = { (picker) in
  60. self.appDelegate.messageNotification("_info_", description: "_denied_camera_", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
  61. }
  62. viewController.configure = configure
  63. sourceViewController.present(viewController, animated: true, completion: nil)
  64. }
  65. }
  66. class customPhotoPickerViewController: TLPhotosPickerViewController {
  67. override var preferredStatusBarStyle: UIStatusBarStyle {
  68. return .lightContent
  69. }
  70. override func makeUI() {
  71. super.makeUI()
  72. self.customNavItem.leftBarButtonItem?.tintColor = NCBrandColor.sharedInstance.textView
  73. self.customNavItem.rightBarButtonItem?.tintColor = NCBrandColor.sharedInstance.textView
  74. self.titleLabel.textColor = NCBrandColor.sharedInstance.icon
  75. self.subTitleLabel.textColor = NCBrandColor.sharedInstance.graySoft
  76. self.subTitleArrowImageView.image = CCGraphics.changeThemingColorImage(self.subTitleArrowImageView.image, multiplier: 1, color: NCBrandColor.sharedInstance.graySoft)
  77. self.collectionView.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  78. self.view.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  79. if CCUtility.getDarkMode() {
  80. self.navigationBar.barStyle = .black
  81. }
  82. self.titleLabel.textColor = NCBrandColor.sharedInstance.textView
  83. self.subTitleLabel.textColor = NCBrandColor.sharedInstance.textView
  84. }
  85. }