|
@@ -8,7 +8,6 @@
|
|
|
import PhotosUI
|
|
|
|
|
|
class TSEditLiveVC: TSBaseVC, UINavigationControllerDelegate {
|
|
|
-
|
|
|
lazy var editLiveSectionModel: TSEditLiveSectionModel = {
|
|
|
let section = TSEditLiveSectionModel()
|
|
|
section.items = [TSEditLiveItemModel()]
|
|
@@ -16,56 +15,48 @@ class TSEditLiveVC: TSBaseVC, UINavigationControllerDelegate {
|
|
|
}()
|
|
|
|
|
|
lazy var editLiveHistorySectionModel: TSImageDataSectionModel = {
|
|
|
- return kImageDataCenterShared.editLiveHistoryListArray.first!
|
|
|
+ kImageDataCenterShared.editLiveHistoryListArray.first!
|
|
|
}()
|
|
|
-
|
|
|
- var dataArray:[Component] = [Component]()
|
|
|
-
|
|
|
-
|
|
|
- lazy var navBarView: TSBaseNavContentBarView = {
|
|
|
- let navBarView = TSBaseNavContentBarView()
|
|
|
- let titleImageView = UIImageView.createImageView(imageName: "nav_title_editlive",contentMode: .scaleToFill)
|
|
|
-
|
|
|
- navBarView.barView.addSubview(titleImageView)
|
|
|
- titleImageView.snp.makeConstraints { make in
|
|
|
- make.centerY.equalToSuperview()
|
|
|
- make.left.equalTo(16)
|
|
|
- make.width.equalTo(252)
|
|
|
- make.height.equalTo(24)
|
|
|
- }
|
|
|
+
|
|
|
+ var dataArray: [Component] = [Component]()
|
|
|
+
|
|
|
+ lazy var navBarView: LWSubNavigationBar = {
|
|
|
+ let navBarView = LWSubNavigationBar()
|
|
|
+ navBarView.backButton.addTarget(self, action: #selector(pop), for: .touchUpInside)
|
|
|
+ navBarView.backButton.setImage(.icClose, for: .normal)
|
|
|
+ navBarView.titleLabel.text = "DIY Live Wallpaper"
|
|
|
return navBarView
|
|
|
}()
|
|
|
|
|
|
-
|
|
|
lazy var collectionComponent: CollectionViewComponent = {
|
|
|
let layout = UICollectionViewFlowLayout()
|
|
|
- let cp = CollectionViewComponent(frame: CGRect.zero, layout: layout, attributes: [ :])
|
|
|
+ let cp = CollectionViewComponent(frame: CGRect.zero, layout: layout, attributes: [:])
|
|
|
cp.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: k_Height_TabBar, right: 0)
|
|
|
-
|
|
|
- cp.itemActionHandler = { [weak self] cellCp, indexPath in
|
|
|
+
|
|
|
+ cp.itemActionHandler = { [weak self] _, _ in
|
|
|
guard let self = self else { return }
|
|
|
-
|
|
|
- //判断 vip
|
|
|
- if kPurchaseDefault.freeNumAvailable() == false{
|
|
|
- TSPurchaseVC.show(target: self) {[weak self] in
|
|
|
+
|
|
|
+ // 判断 vip
|
|
|
+ if kPurchaseDefault.freeNumAvailable() == false {
|
|
|
+ TSPurchaseVC.show(target: self) { [weak self] in
|
|
|
guard let self = self else { return }
|
|
|
reloadView()
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- //生成视频
|
|
|
+
|
|
|
+ // 生成视频
|
|
|
self.openVideoPicker()
|
|
|
}
|
|
|
-
|
|
|
- cp.itemDidSelectedHandler = { [weak self] (object, indexPath) in
|
|
|
+
|
|
|
+ cp.itemDidSelectedHandler = { [weak self] _, indexPath in
|
|
|
guard let self = self else { return }
|
|
|
let obj = dataArray.safeObj(At: indexPath.section)
|
|
|
if let liveModel = obj as? TSImageDataSectionModel {
|
|
|
- if liveModel.style == .homeLiveList{
|
|
|
- let vc = TSLiveWallpaperBrowseVC(itemModels: liveModel.items,currentIndex: indexPath.row)
|
|
|
+ if liveModel.style == .homeLiveList {
|
|
|
+ let vc = TSLiveWallpaperBrowseVC(itemModels: liveModel.items, currentIndex: indexPath.row)
|
|
|
vc.isCanDelete = true
|
|
|
- vc.deleteCompletion = {[weak self] item in
|
|
|
+ vc.deleteCompletion = { [weak self] item in
|
|
|
guard let self = self else { return }
|
|
|
if let itemModel = editLiveHistorySectionModel.items.safeObj(At: item) {
|
|
|
editLiveHistorySectionModel.items.remove(at: item)
|
|
@@ -84,30 +75,33 @@ class TSEditLiveVC: TSBaseVC, UINavigationControllerDelegate {
|
|
|
}()
|
|
|
|
|
|
override func createView() {
|
|
|
-
|
|
|
setViewBgImageNamed(named: "view_main_bg")
|
|
|
-
|
|
|
navBarContentView.addSubview(navBarView)
|
|
|
+ navBarContentView.snp.remakeConstraints { make in
|
|
|
+ make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
|
|
|
+ make.leading.trailing.equalToSuperview()
|
|
|
+ make.height.equalTo(44.0)
|
|
|
+ }
|
|
|
navBarView.snp.makeConstraints { make in
|
|
|
make.edges.equalToSuperview()
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
contentView.addSubview(collectionComponent.collectionView)
|
|
|
collectionComponent.collectionView.snp.makeConstraints { make in
|
|
|
make.edges.equalToSuperview()
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
reloadView()
|
|
|
}
|
|
|
-
|
|
|
- func reloadView(){
|
|
|
+
|
|
|
+ func reloadView() {
|
|
|
collectionComponent.clear()
|
|
|
- if editLiveHistorySectionModel.items.count > 0 {
|
|
|
- dataArray = [editLiveSectionModel,editLiveHistorySectionModel]
|
|
|
- }else{
|
|
|
+ if editLiveHistorySectionModel.items.count > 0 {
|
|
|
+ dataArray = [editLiveSectionModel, editLiveHistorySectionModel]
|
|
|
+ } else {
|
|
|
dataArray = [editLiveSectionModel]
|
|
|
}
|
|
|
- collectionComponent.reloadView(with:dataArray)
|
|
|
+ collectionComponent.reloadView(with: dataArray)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -117,7 +111,7 @@ extension TSEditLiveVC: UIImagePickerControllerDelegate {
|
|
|
TSToastShared.showLoading()
|
|
|
let picker = UIImagePickerController()
|
|
|
picker.sourceType = .photoLibrary
|
|
|
- picker.mediaTypes = [UTType.movie.identifier] // 仅允许选择视频
|
|
|
+ picker.mediaTypes = [UTType.movie.identifier] // 仅允许选择视频
|
|
|
picker.allowsEditing = true // 启用编辑功能
|
|
|
picker.delegate = self
|
|
|
picker.videoMaximumDuration = 3.0
|
|
@@ -125,9 +119,9 @@ extension TSEditLiveVC: UIImagePickerControllerDelegate {
|
|
|
self.hideLoading()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// 用户完成选择
|
|
|
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
|
|
|
-
|
|
|
hideLoading()
|
|
|
if let editedURL = info[.mediaURL] as? URL {
|
|
|
debugPrint("Selected video: \(editedURL)")
|
|
@@ -136,8 +130,7 @@ extension TSEditLiveVC: UIImagePickerControllerDelegate {
|
|
|
let cachesDirectory = TSFileManagerTool.editLiveVideoPathURL
|
|
|
let targetURL = cachesDirectory.appendingPathComponent("assemblePickerVideo").appendingPathExtension(editedURL.pathExtension)
|
|
|
TSFileManagerTool.copyFileWithOverwrite(from: editedURL, to: targetURL)
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
// LivePhotoUtil.convertVideo(targetURL.path) { success, msg in
|
|
|
// debugPrint(msg)
|
|
|
// }
|
|
@@ -145,7 +138,7 @@ extension TSEditLiveVC: UIImagePickerControllerDelegate {
|
|
|
// LivePhotoConverter.convertVideo(targetURL) { success, image, video, msg in
|
|
|
// debugPrint(msg)
|
|
|
// }
|
|
|
-
|
|
|
+
|
|
|
saveLive(videoPath: targetURL)
|
|
|
}
|
|
|
picker.dismiss(animated: true, completion: nil)
|
|
@@ -156,60 +149,54 @@ extension TSEditLiveVC: UIImagePickerControllerDelegate {
|
|
|
hideLoading()
|
|
|
picker.dismiss(animated: true, completion: nil)
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- func hideLoading(){
|
|
|
-
|
|
|
+
|
|
|
+ func hideLoading() {
|
|
|
kDelayMainShort {
|
|
|
TSToastShared.hideLoading()
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-extension TSEditLiveVC{
|
|
|
-
|
|
|
- func openVideoClipperVC(videoURL:URL) {
|
|
|
- let clipperController = GPVideoClipperController.clipperWithVideoURL(videoURL, makerBlock: { (maker) in
|
|
|
- maker.startTime = 0
|
|
|
- maker.endTime = 15
|
|
|
- maker.clippedVideoMinDuration = 1
|
|
|
- maker.clippedVideoMaxDuration = 3
|
|
|
- maker.leftSelectedImage = UIImage(named: "eidt_arrow_left")!
|
|
|
- maker.selectedBoxColor = .white
|
|
|
- maker.rightSelectedImage = UIImage(named: "eidt_arrow_right")!
|
|
|
- maker.leftMargin = 77
|
|
|
- maker.rightMargin = 37
|
|
|
- maker.selectedImageWidth = 14
|
|
|
- }) {[weak self] (videoURL, videoAsset, coverImage) in
|
|
|
- guard let self = self else { return }
|
|
|
- self.saveLive(videoPath: videoURL)
|
|
|
- }
|
|
|
-
|
|
|
+extension TSEditLiveVC {
|
|
|
+ func openVideoClipperVC(videoURL: URL) {
|
|
|
+ let clipperController = GPVideoClipperController.clipperWithVideoURL(videoURL, makerBlock: { maker in
|
|
|
+ maker.startTime = 0
|
|
|
+ maker.endTime = 15
|
|
|
+ maker.clippedVideoMinDuration = 1
|
|
|
+ maker.clippedVideoMaxDuration = 3
|
|
|
+ maker.leftSelectedImage = UIImage(named: "eidt_arrow_left")!
|
|
|
+ maker.selectedBoxColor = .white
|
|
|
+ maker.rightSelectedImage = UIImage(named: "eidt_arrow_right")!
|
|
|
+ maker.leftMargin = 77
|
|
|
+ maker.rightMargin = 37
|
|
|
+ maker.selectedImageWidth = 14
|
|
|
+ }) { [weak self] videoURL, _, _ in
|
|
|
+ guard let self = self else { return }
|
|
|
+ self.saveLive(videoPath: videoURL)
|
|
|
+ }
|
|
|
+
|
|
|
kPresentModalVC(target: self, modelVC: clipperController)
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- func saveLive(videoPath:URL){
|
|
|
+
|
|
|
+ func saveLive(videoPath: URL) {
|
|
|
TSToastShared.showLoading()
|
|
|
- LivePhotoConverter.convertVideo(videoPath) { success, imageURL, videoURL, errorMsg in
|
|
|
+ LivePhotoConverter.convertVideo(videoPath) { success, imageURL, videoURL, _ in
|
|
|
if success {
|
|
|
debugPrint("Live Photo Saved,The live photo was successfully saved to Photos.")
|
|
|
-
|
|
|
- if let imageURL = imageURL,let videoURL = videoURL {
|
|
|
- LivePhotoConverter.saveToLibrary(videoURL: videoURL, imageURL: imageURL) { success in
|
|
|
- kSavePhotoSuccesswShared.show(atView: self.view,text: "DIY Successfully".localized)
|
|
|
+
|
|
|
+ if let imageURL = imageURL, let videoURL = videoURL {
|
|
|
+ LivePhotoConverter.saveToLibrary(videoURL: videoURL, imageURL: imageURL) { _ in
|
|
|
+ kSavePhotoSuccesswShared.show(atView: self.view, text: "DIY Successfully".localized)
|
|
|
}
|
|
|
kPurchaseDefault.useOnceForFree()
|
|
|
-
|
|
|
+
|
|
|
let saveURL = TSFileManagerTool.saveLiveVideoPathURL
|
|
|
let timestampString = Date.timestampString
|
|
|
let saveImageURL = saveURL.appendingPathComponent("image\(timestampString).heic")
|
|
|
let saveVideoURL = saveURL.appendingPathComponent("video\(timestampString).mov")
|
|
|
TSFileManagerTool.copyFileWithOverwrite(from: imageURL, to: saveImageURL)
|
|
|
TSFileManagerTool.copyFileWithOverwrite(from: videoURL, to: saveVideoURL)
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
let itemModel = TSImageDataItemModel()
|
|
|
itemModel.imageUrl = TSFileManagerTool.getCacheSubPath(at: saveImageURL)!
|
|
|
itemModel.videoUrl = TSFileManagerTool.getCacheSubPath(at: saveVideoURL)!
|
|
@@ -217,28 +204,25 @@ extension TSEditLiveVC{
|
|
|
kImageDataCenterShared.editLiveHistoryListArray = [self.editLiveHistorySectionModel]
|
|
|
self.reloadView()
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
debugPrint("Live Photo Not Saved,The live photo was not saved to Photos.")
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
// let ts = Date().timeIntervalSince1970
|
|
|
// let documentURL = TSFileManagerTool.documentsDirectory.appendingPathComponent("\(Int(ts)).mov")
|
|
|
-// let documentURL = TSFileManagerTool.documentsDirectory
|
|
|
+// let documentURL = TSFileManagerTool.documentsDirectory
|
|
|
// Converter4Video(path: videoPath.path).resizeVideo(at: videoPath.path, outputPath: documentURL.path, outputSize: CGSize(width: 1080, height: 1920)) { success, error in
|
|
|
// guard success else{
|
|
|
// debugPrint(error)
|
|
|
// return
|
|
|
// }
|
|
|
-//
|
|
|
+//
|
|
|
// LivePhoto.generate(from: nil, videoURL: documentURL) { progress in
|
|
|
-//
|
|
|
+//
|
|
|
// } completion: {[weak self] (livePhoto, resources) in
|
|
|
// guard let self = self else { return }
|
|
|
-//
|
|
|
+//
|
|
|
// if let resources = resources {
|
|
|
// LivePhoto.saveToLibrary(resources, completion: { (success) in
|
|
|
// kExecuteOnMainThread {
|
|
@@ -249,7 +233,7 @@ extension TSEditLiveVC{
|
|
|
// }else {
|
|
|
// debugPrint("Live Photo Not Saved,The live photo was not saved to Photos.")
|
|
|
// }
|
|
|
-//
|
|
|
+//
|
|
|
// TSFileManagerTool.removeItem(from: resources.pairedImage)
|
|
|
// TSFileManagerTool.removeItem(from: resources.pairedVideo)
|
|
|
// }
|
|
@@ -257,16 +241,16 @@ extension TSEditLiveVC{
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
-
|
|
|
+
|
|
|
// LivePhoto.resizeVideoToFixedHeight(videoURL: videoPath, outputFolder: documentURL) { outputURL in
|
|
|
// if let outputURL = outputURL {
|
|
|
// print("Resized video saved to: \(outputURL)")
|
|
|
-//
|
|
|
+//
|
|
|
// LivePhoto.generate(from: nil, videoURL: outputURL) { progress in
|
|
|
-//
|
|
|
+//
|
|
|
// } completion: {[weak self] (livePhoto, resources) in
|
|
|
// guard let self = self else { return }
|
|
|
-//
|
|
|
+//
|
|
|
// if let resources = resources {
|
|
|
// LivePhoto.saveToLibrary(resources, completion: { (success) in
|
|
|
// kExecuteOnMainThread {
|
|
@@ -277,46 +261,41 @@ extension TSEditLiveVC{
|
|
|
// }else {
|
|
|
// debugPrint("Live Photo Not Saved,The live photo was not saved to Photos.")
|
|
|
// }
|
|
|
-//
|
|
|
+//
|
|
|
// TSFileManagerTool.removeItem(from: resources.pairedImage)
|
|
|
// TSFileManagerTool.removeItem(from: resources.pairedVideo)
|
|
|
// }
|
|
|
// })
|
|
|
// }
|
|
|
// }
|
|
|
-//
|
|
|
+//
|
|
|
// } else {
|
|
|
// print("Failed to resize video.")
|
|
|
// }
|
|
|
// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// VideoRecorder.shared.saveLivePhoto(duration: 2.5, outputDirectory: TSFileManagerTool.saveLiveVideoPathURL) { [weak self] recordHandler in
|
|
|
//
|
|
|
-//// recordHandler?()
|
|
|
-//
|
|
|
+ //// recordHandler?()
|
|
|
+//
|
|
|
// } completion: { [weak self] videoURL, imageURL, errorMsg in
|
|
|
// guard let self = self else { return }
|
|
|
-//// }
|
|
|
-//// LivePhotoCreater().saveLivePhoto(from: videoPath, outputDirectory: TSFileManagerTool.saveLiveVideoPathURL) { videoURL, imageURL, errorMsg in
|
|
|
+ //// }
|
|
|
+ //// LivePhotoCreater().saveLivePhoto(from: videoPath, outputDirectory: TSFileManagerTool.saveLiveVideoPathURL) { videoURL, imageURL, errorMsg in
|
|
|
// if let imageURL = imageURL,let videoURL = videoURL {
|
|
|
// LivePhotoConverter.saveToLibrary(videoURL: videoURL, imageURL: imageURL) { success in
|
|
|
// kSavePhotoSuccesswShared.show(atView: self.view)
|
|
|
// }
|
|
|
-//
|
|
|
-//
|
|
|
+//
|
|
|
+//
|
|
|
// let saveURL = TSFileManagerTool.saveLiveVideoPathURL
|
|
|
// let timestampString = Date.timestampString
|
|
|
// let saveImageURL = saveURL.appendingPathComponent("image\(timestampString).heic")
|
|
|
// let saveVideoURL = saveURL.appendingPathComponent("video\(timestampString).mov")
|
|
|
// TSFileManagerTool.copyFileWithOverwrite(from: imageURL, to: saveImageURL)
|
|
|
// TSFileManagerTool.copyFileWithOverwrite(from: videoURL, to: saveVideoURL)
|
|
|
-//
|
|
|
-//
|
|
|
+//
|
|
|
+//
|
|
|
// let itemModel = TSImageDataItemModel()
|
|
|
// itemModel.imageUrl = TSFileManagerTool.getCacheSubPath(at: saveImageURL)!
|
|
|
// itemModel.videoUrl = TSFileManagerTool.getCacheSubPath(at: saveVideoURL)!
|
|
@@ -326,32 +305,32 @@ extension TSEditLiveVC{
|
|
|
// }
|
|
|
// }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// func saveLivePhotoVideoRecorder(){
|
|
|
-//
|
|
|
-//
|
|
|
+//
|
|
|
+//
|
|
|
// VideoRecorder.shared.saveLivePhoto(duration: 3.0, outputDirectory: TSFileManagerTool.saveLiveVideoPathURL) { [weak self] recordHandler in
|
|
|
//
|
|
|
-//// recordHandler?()
|
|
|
-//
|
|
|
+ //// recordHandler?()
|
|
|
+//
|
|
|
// } completion: { [weak self] videoURL, imageURL, errorMsg in
|
|
|
// guard let self = self else { return }
|
|
|
-//// }
|
|
|
-//// LivePhotoCreater().saveLivePhoto(from: videoPath, outputDirectory: TSFileManagerTool.saveLiveVideoPathURL) { videoURL, imageURL, errorMsg in
|
|
|
+ //// }
|
|
|
+ //// LivePhotoCreater().saveLivePhoto(from: videoPath, outputDirectory: TSFileManagerTool.saveLiveVideoPathURL) { videoURL, imageURL, errorMsg in
|
|
|
// if let imageURL = imageURL,let videoURL = videoURL {
|
|
|
// LivePhotoConverter.saveToLibrary(videoURL: videoURL, imageURL: imageURL) { success in
|
|
|
// kSavePhotoSuccesswShared.show(atView: self.view)
|
|
|
// }
|
|
|
-//
|
|
|
-//
|
|
|
+//
|
|
|
+//
|
|
|
// let saveURL = TSFileManagerTool.saveLiveVideoPathURL
|
|
|
// let timestampString = Date.timestampString
|
|
|
// let saveImageURL = saveURL.appendingPathComponent("image\(timestampString).heic")
|
|
|
// let saveVideoURL = saveURL.appendingPathComponent("video\(timestampString).mov")
|
|
|
// TSFileManagerTool.copyFileWithOverwrite(from: imageURL, to: saveImageURL)
|
|
|
// TSFileManagerTool.copyFileWithOverwrite(from: videoURL, to: saveVideoURL)
|
|
|
-//
|
|
|
-//
|
|
|
+//
|
|
|
+//
|
|
|
// let itemModel = TSImageDataItemModel()
|
|
|
// itemModel.imageUrl = TSFileManagerTool.getCacheSubPath(at: saveImageURL)!
|
|
|
// itemModel.videoUrl = TSFileManagerTool.getCacheSubPath(at: saveVideoURL)!
|
|
@@ -362,29 +341,10 @@ extension TSEditLiveVC{
|
|
|
// }
|
|
|
// }
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
// MARK: - PHPickerViewControllerDelegate
|
|
|
-//extension TSEditLiveVC: PHPickerViewControllerDelegate {
|
|
|
+
|
|
|
+// extension TSEditLiveVC: PHPickerViewControllerDelegate {
|
|
|
//
|
|
|
// /// Present `PHPickerViewController`
|
|
|
// func pick(_ filter: PHPickerFilter) {
|
|
@@ -443,7 +403,4 @@ extension TSEditLiveVC{
|
|
|
// }
|
|
|
// return cachesDirectory
|
|
|
// }
|
|
|
-//}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+// }
|