|
@@ -0,0 +1,368 @@
|
|
|
+//
|
|
|
+// TSHXPhotoPickerManager.swift
|
|
|
+// TSLiveWallpaper
|
|
|
+//
|
|
|
+// Created by 100Years on 2025/7/31.
|
|
|
+//
|
|
|
+
|
|
|
+
|
|
|
+//import UIKit
|
|
|
+//import PhotosUI
|
|
|
+//import HXPhotoPicker
|
|
|
+//
|
|
|
+//class TSPhotoPickerManager: NSObject{
|
|
|
+//
|
|
|
+// lazy var cropSize: EditorConfiguration.ToolsView.Options = {
|
|
|
+// let cropSize = EditorConfiguration.ToolsView.Options(
|
|
|
+// imageType: HX.ImageResource.shared.editor.tools.cropSize,
|
|
|
+// type: .cropSize
|
|
|
+// )
|
|
|
+// return cropSize
|
|
|
+// }()
|
|
|
+//
|
|
|
+// lazy var aspectRatios: [EditorRatioToolConfig] = {
|
|
|
+// let aspectRatios:[EditorRatioToolConfig] = [
|
|
|
+// .init(title: .localized("原始比例"), ratio: .init(width: -1, height: -1)),
|
|
|
+// .init(title: .localized("自由格式"), ratio: .zero),
|
|
|
+// .init(title: .localized("正方形"), ratio: .init(width: 1, height: 1)),
|
|
|
+// .init(title: .custom("9:16"), ratio: .init(width: 9, height: 16)),
|
|
|
+// .init(title: .custom("16:9"), ratio: .init(width: 16, height: 9)),
|
|
|
+// .init(title: .custom("3:4"), ratio: .init(width: 3, height: 4)),
|
|
|
+// .init(title: .custom("4:3"), ratio: .init(width: 4, height: 3)),
|
|
|
+// .init(title: .custom("2:3"), ratio: .init(width: 2, height: 3)),
|
|
|
+// .init(title: .custom("3:2"), ratio: .init(width: 3, height: 2))
|
|
|
+// ]
|
|
|
+// return aspectRatios
|
|
|
+// }()
|
|
|
+//
|
|
|
+// var picker: PhotoPickerController?
|
|
|
+// var multipleConfig: PickerConfiguration{
|
|
|
+// var config = PickerConfiguration()
|
|
|
+// config.appearanceStyle = .dark
|
|
|
+// config.modalPresentationStyle = .overFullScreen
|
|
|
+// config.themeColor = .themeColor
|
|
|
+// config.selectOptions = .photo
|
|
|
+// config.selectMode = .multiple
|
|
|
+// config.maximumSelectedCount = 2
|
|
|
+// config.isSelectedOriginal = true
|
|
|
+// config.photoList.sort = .desc
|
|
|
+// config.photoList.finishSelectionAfterTakingPhoto = false
|
|
|
+// config.photoList.isSaveSystemAlbum = true
|
|
|
+// config.isCacheCameraAlbum = false
|
|
|
+// config.navigationTitleColor = .white
|
|
|
+// config.navigationTitleDarkColor = .white
|
|
|
+// config.navigationTintColor = .white
|
|
|
+// config.navigationDarkTintColor = .white
|
|
|
+// config.albumList.albumNameColor = .white
|
|
|
+// config.albumList.albumNameDarkColor = .white
|
|
|
+//
|
|
|
+// config.albumShowMode = .normal
|
|
|
+// config.photoList.takePictureCompletionToSelected = true
|
|
|
+//
|
|
|
+// config.previewView.backgroundColor = .black
|
|
|
+// config.previewView.bottomView.isHiddenOriginalButton = true
|
|
|
+//
|
|
|
+// config.photoList.bottomView.isHiddenOriginalButton = true
|
|
|
+// config.navigationBarStyle = .black
|
|
|
+//
|
|
|
+//// config.photoSelectionTapAction = .quickSelect
|
|
|
+//// config.photoList.bottomView.isHiddenPreviewButton = true
|
|
|
+//// config.photoList.bottomView.isShowSelectedView = false
|
|
|
+//
|
|
|
+// config.photoSelectionTapAction = .preview
|
|
|
+// config.photoList.bottomView.isHiddenPreviewButton = false
|
|
|
+// config.photoList.bottomView.isShowSelectedView = true
|
|
|
+// config.photoList.previewStyle = .push
|
|
|
+//
|
|
|
+// config.editor.toolsView = .init(toolOptions: [cropSize])
|
|
|
+// config.editor.cropSize.aspectRatios = aspectRatios
|
|
|
+//
|
|
|
+//
|
|
|
+//// var cameraConfig = SystemCameraConfiguration()
|
|
|
+//// cameraConfig.allowsEditing = false
|
|
|
+//// config.photoList.cameraType = .system(cameraConfig)
|
|
|
+//
|
|
|
+// var customCameraConfig = CameraConfiguration()
|
|
|
+// customCameraConfig.isSaveSystemAlbum = true
|
|
|
+// customCameraConfig.sessionPreset = .hd1920x1080
|
|
|
+// customCameraConfig.editor.toolsView = .init(toolOptions: [cropSize])
|
|
|
+// customCameraConfig.editor.cropSize.aspectRatios = aspectRatios
|
|
|
+// config.photoList.cameraType = .custom(customCameraConfig)
|
|
|
+//
|
|
|
+//
|
|
|
+// config.languageType = LanguageManager.shared.currentLanguage.languageType
|
|
|
+// config.customLanguages = [CustomLanguage(language: "it", bundle: Bundle(path: Bundle.main.path(forResource: "it", ofType: "lproj")!)!)]
|
|
|
+// config.photoList.isShowFilterItem = false
|
|
|
+//
|
|
|
+// config.textManager.picker.albumCameraRollTitle = .localized("HXAlbumCameraRoll")
|
|
|
+// config.textManager.picker.photoList.emptyTitle = .localized("没有照片")
|
|
|
+// config.textManager.picker.photoList.emptySubTitle = .localized("你可以使用相机拍些照片")
|
|
|
+//
|
|
|
+// return config
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// // MARK: - Properties
|
|
|
+// private weak var viewController: UIViewController?
|
|
|
+// private var completionHandler: (([UIImage]) -> Void)?
|
|
|
+// private var maxSelected:Int = 1
|
|
|
+// // MARK: - Initializers
|
|
|
+// init(viewController: UIViewController) {
|
|
|
+// self.viewController = viewController
|
|
|
+// }
|
|
|
+//
|
|
|
+// // MARK: - Public Methods
|
|
|
+// /// 打开照片选择器,单选一张照片
|
|
|
+// func pickPhoto(maxSelected:Int = 1,completion: @escaping ([UIImage]) -> Void) {
|
|
|
+// self.completionHandler = completion
|
|
|
+// self.maxSelected = maxSelected
|
|
|
+//
|
|
|
+// var config = multipleConfig
|
|
|
+// config.maximumSelectedCount = maxSelected
|
|
|
+//
|
|
|
+//
|
|
|
+// checkPhotoLibraryPermission { [weak self] authorized in
|
|
|
+// guard let self = self else { return }
|
|
|
+// if authorized {
|
|
|
+// let picker = PhotoPickerController(splitPicker: config)
|
|
|
+// picker.pickerDelegate = self
|
|
|
+// picker.autoDismiss = false
|
|
|
+// picker.modalTransitionStyle = .coverVertical
|
|
|
+// viewController?.present(picker, animated: true, completion: nil)
|
|
|
+// picker.reloadAlbumData()
|
|
|
+// self.picker = picker
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// self.showPermissionAlert()
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// var cameraController:CameraController?
|
|
|
+// func pickCameraPhoto(maxSelected:Int = 1,completion: @escaping ([UIImage]) -> Void) {
|
|
|
+// self.completionHandler = completion
|
|
|
+// checkVideoAuthorization { [weak self] authorized in
|
|
|
+// guard let self = self else { return }
|
|
|
+// if authorized {
|
|
|
+// var customCameraConfig = CameraConfiguration()
|
|
|
+// customCameraConfig.isSaveSystemAlbum = true
|
|
|
+// customCameraConfig.sessionPreset = .hd1920x1080
|
|
|
+// customCameraConfig.editor.toolsView = .init(toolOptions: [cropSize])
|
|
|
+// customCameraConfig.editor.cropSize.aspectRatios = aspectRatios
|
|
|
+// customCameraConfig.languageType = LanguageManager.shared.currentLanguage.languageType
|
|
|
+// customCameraConfig.customLanguages = [CustomLanguage(language: "it", bundle: Bundle(path: Bundle.main.path(forResource: "it", ofType: "lproj")!)!)]
|
|
|
+// customCameraConfig.modalPresentationStyle = .overFullScreen
|
|
|
+// let cameraController = CameraController(config: customCameraConfig, type: .photo,delegate: self)
|
|
|
+// viewController?.present(cameraController, animated: true, completion: nil)
|
|
|
+// self.cameraController = cameraController
|
|
|
+// } else {
|
|
|
+// self.showCameraPermissionAlert()
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// //选择本地图片
|
|
|
+// func pickLoactionPhoto(maxSelected:Int = 1,completion: @escaping ([UIImage]) -> Void) {
|
|
|
+//
|
|
|
+// self.completionHandler = completion
|
|
|
+// self.maxSelected = maxSelected
|
|
|
+//
|
|
|
+// PickerConfiguration.imageViewProtocol = KFImageView.self
|
|
|
+//
|
|
|
+// var config = multipleConfig
|
|
|
+// config.maximumSelectedCount = maxSelected
|
|
|
+// config.languageType = LanguageManager.shared.currentLanguage.languageType
|
|
|
+// config.customLanguages = [CustomLanguage(language: "it", bundle: Bundle(path: Bundle.main.path(forResource: "it", ofType: "lproj")!)!)]
|
|
|
+// config.selectOptions = []
|
|
|
+// config.photoList.allowAddCamera = false
|
|
|
+//
|
|
|
+// config.textManager.picker.albumCameraRollTitle = .custom("Used Photo".localized)
|
|
|
+// config.textManager.picker.photoList.emptyTitle = .custom("")
|
|
|
+// config.textManager.picker.photoList.emptySubTitle = .custom("No used photo. Select from Photos or take one to continue.".localized)
|
|
|
+// config.allowLoadPhotoLibrary = false
|
|
|
+//
|
|
|
+// var photoAsset:[PhotoAsset] = []
|
|
|
+// let allKeys = TSDBKeyManager.getAllKeys()
|
|
|
+// for item in allKeys {
|
|
|
+// let key = item.key
|
|
|
+// let url = URL(string:key)
|
|
|
+// photoAsset.append( PhotoAsset(
|
|
|
+// networkImageAsset:
|
|
|
+// NetworkImageAsset(
|
|
|
+// thumbnailURL: url,
|
|
|
+// originalURL: url,
|
|
|
+// thumbailCacheKey: key,
|
|
|
+// originalCacheKey: key
|
|
|
+// )
|
|
|
+// ))
|
|
|
+// }
|
|
|
+//
|
|
|
+// let picker = PhotoPickerController(splitPicker: config)
|
|
|
+// picker.pickerDelegate = self
|
|
|
+// picker.autoDismiss = false
|
|
|
+// picker.localAssetArray = photoAsset
|
|
|
+// picker.modalTransitionStyle = .coverVertical
|
|
|
+// viewController?.present(picker, animated: true, completion: nil)
|
|
|
+// self.picker = picker
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// // MARK: - Private Methods
|
|
|
+// /// 检查相册权限
|
|
|
+// private func checkPhotoLibraryPermission(completion: @escaping (Bool) -> Void) {
|
|
|
+// let status = PHPhotoLibrary.authorizationStatus()
|
|
|
+//
|
|
|
+// DispatchQueue.main.async {
|
|
|
+// switch status {
|
|
|
+// case .authorized:
|
|
|
+// completion(true)
|
|
|
+// case .notDetermined:
|
|
|
+// PHPhotoLibrary.requestAuthorization { newStatus in
|
|
|
+// DispatchQueue.main.async {
|
|
|
+// completion(newStatus == .authorized)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// default:
|
|
|
+// DispatchQueue.main.async {
|
|
|
+// completion(false)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /// 检查相机权限状态
|
|
|
+// func checkVideoAuthorization(completion: @escaping (Bool) -> Void) {
|
|
|
+// let status = AVCaptureDevice.authorizationStatus(for: .video)
|
|
|
+// DispatchQueue.main.async {
|
|
|
+// switch status {
|
|
|
+// case .authorized:
|
|
|
+// completion(true)
|
|
|
+// case .notDetermined:
|
|
|
+// AVCaptureDevice.requestAccess(for: .video) { granted in
|
|
|
+// DispatchQueue.main.async {
|
|
|
+// completion(granted)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// case .denied, .restricted:
|
|
|
+// completion(false)
|
|
|
+// @unknown default:
|
|
|
+// completion(false)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// /// 显示权限提示
|
|
|
+// private func showPermissionAlert() {
|
|
|
+// let alert = UIAlertController(
|
|
|
+// title: "No photos permission".localized,
|
|
|
+// message: "Please enable photo permission in settings to select photos".localized,
|
|
|
+// preferredStyle: .alert
|
|
|
+// )
|
|
|
+// alert.addAction(UIAlertAction(title: "Cancel".localized, style: .cancel, handler: nil))
|
|
|
+// alert.addAction(UIAlertAction(title: "Go to Settings".localized, style: .default) { _ in
|
|
|
+// if let url = URL(string: UIApplication.openSettingsURLString) {
|
|
|
+// UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
|
|
+// }
|
|
|
+// })
|
|
|
+// viewController?.present(alert, animated: true, completion: nil)
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// private func showCameraPermissionAlert() {
|
|
|
+// let alert = UIAlertController(
|
|
|
+// title: "No camera permission".localized,
|
|
|
+// message: "Please enable camera permission in settings to select camera".localized,
|
|
|
+// preferredStyle: .alert
|
|
|
+// )
|
|
|
+// alert.addAction(UIAlertAction(title: "Cancel".localized, style: .cancel, handler: nil))
|
|
|
+// alert.addAction(UIAlertAction(title: "Go to Settings".localized, style: .default) { _ in
|
|
|
+// if let url = URL(string: UIApplication.openSettingsURLString) {
|
|
|
+// UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
|
|
+// }
|
|
|
+// })
|
|
|
+// viewController?.present(alert, animated: true, completion: nil)
|
|
|
+// }
|
|
|
+//
|
|
|
+// deinit {
|
|
|
+// debugPrint("♻️♻️♻️ TSPhotoPickerManager -> TSPhotoPickerManager deinit ♻️♻️♻️")
|
|
|
+// }
|
|
|
+//
|
|
|
+// func dismissPageVC(){
|
|
|
+// self.picker?.view.isHidden = true
|
|
|
+// self.picker?.dismiss(animated: true)
|
|
|
+// self.picker = nil
|
|
|
+//
|
|
|
+// cameraController?.dismiss(animated: true)
|
|
|
+// cameraController = nil
|
|
|
+// }
|
|
|
+//}
|
|
|
+//
|
|
|
+//extension TSPhotoPickerManager: PhotoPickerControllerDelegate {
|
|
|
+// func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) {
|
|
|
+// result.getImage(compressionScale: 1.0) { images in
|
|
|
+// self.completionHandler?(images)
|
|
|
+// pickerController.dismiss(animated: true, completion: nil)
|
|
|
+// for image in images {
|
|
|
+// if let imageKey = image.uniqueIdentifier() {
|
|
|
+// TSDBKeyManager.addOrUpdateKey(imageKey)
|
|
|
+// TSImageStoreTool.storeImage(image: image, urlString: imageKey)
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// NotificationCenter.default.post(name: .kPhotoPickerCompleted, object: nil, userInfo: nil)
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// func pickerController(didCancel pickerController: PhotoPickerController) {
|
|
|
+// pickerController.dismiss(animated: true, completion: nil)
|
|
|
+// }
|
|
|
+//}
|
|
|
+//
|
|
|
+//
|
|
|
+//extension TSPhotoPickerManager : CameraControllerDelegate {
|
|
|
+// func cameraController(_ cameraController: HXPhotoPicker.CameraController, didFinishWithResult result: HXPhotoPicker.CameraController.Result, phAsset: PHAsset?, location: CLLocation?) {
|
|
|
+// switch result {
|
|
|
+// case .image(let image):
|
|
|
+// self.completionHandler?([image])
|
|
|
+// cameraController.dismiss(animated: true, completion: nil)
|
|
|
+// if let imageKey = image.uniqueIdentifier() {
|
|
|
+// TSDBKeyManager.addOrUpdateKey(imageKey)
|
|
|
+// TSImageStoreTool.storeImage(image: image, urlString: imageKey)
|
|
|
+// }
|
|
|
+// NotificationCenter.default.post(name: .kPhotoPickerCompleted, object: nil, userInfo: nil)
|
|
|
+//
|
|
|
+// default:
|
|
|
+// cameraController.dismiss(animated: true, completion: nil)
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// func cameraController(didCancel cameraController: HXPhotoPicker.CameraController) {
|
|
|
+// cameraController.dismiss(animated: true, completion: nil)
|
|
|
+// }
|
|
|
+//}
|
|
|
+//extension Notification.Name {
|
|
|
+// static let kPhotoPickerCompleted = Notification.Name("kPhotoPickerCompleted") //选择照片完成
|
|
|
+//}
|
|
|
+//
|
|
|
+//
|
|
|
+//import Foundation
|
|
|
+//import CommonCrypto
|
|
|
+//
|
|
|
+//extension UIImage {
|
|
|
+// func uniqueIdentifier() -> String? {
|
|
|
+// guard let imageData = self.jpegData(compressionQuality: 0.1) else { return nil }
|
|
|
+//
|
|
|
+// var digest = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
|
|
|
+// imageData.withUnsafeBytes {
|
|
|
+// _ = CC_SHA256($0.baseAddress, CC_LONG(imageData.count), &digest)
|
|
|
+// }
|
|
|
+// return digest.map { String(format: "%02hhx", $0) }.joined()
|
|
|
+// }
|
|
|
+//}
|