Commit 3bd07415 authored by shenyong's avatar shenyong

Merge branch 'develop_0409' into Adv_NewClean

# Conflicts:
#	PhoneManager/Class/Database/TrashDatabase.swift
parents 1a9ff85e ba9a2776
This diff is collapsed.
...@@ -50,6 +50,40 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -50,6 +50,40 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true return true
} }
func applicationWillTerminate(_ application: UIApplication) {
// 保存单利中所有垃圾桶的数据
saveDataToTrashDB(data: Singleton.shared.trashData)
// 保存单利中所有垃圾桶的数据
saveDataToKeepListhDB(data: Singleton.shared.keepList)
}
func saveDataToTrashDB(data : [TrashTypeEnum : [AssetModel]]){
for (key,value) in data {
for item in value {
let success = TrashDatabase.shared.insert(localIdentifier: item.localIdentifier, assetSize: item.assetSize, createDate: item.createDate, mediaType: key.dbType)
if !success {
Print("保存单利数据到数据库失败")
}
}
}
Singleton.shared.trashData = [:]
}
func saveDataToKeepListhDB(data : [TrashTypeEnum : [AssetModel]]){
for (key,value) in data {
let uniqueId = UUID().uuidString
for item in value {
let success = GroupDatabase.shared.insert(localIdentifier: item.localIdentifier, assetSize: item.assetSize, createDate: item.createDate, mediaType: key.dbType,groupId: uniqueId)
if !success {
Print("保存保留列表数据失败")
}
}
}
Singleton.shared.keepList = [:]
}
func applicationDidBecomeActive(_ application: UIApplication) { func applicationDidBecomeActive(_ application: UIApplication) {
NotificationCenter.default.post(name: Notification.Name("applicationDidBecomeActive"), object: nil) NotificationCenter.default.post(name: Notification.Name("applicationDidBecomeActive"), object: nil)
......
{
"images" : [
{
"filename" : "Frame.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Frame@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Frame@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "Frame.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Frame@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Frame@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "Group_1171275102.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Group_1171275102@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Group_1171275102@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
...@@ -254,7 +254,8 @@ class TrashDatabase { ...@@ -254,7 +254,8 @@ class TrashDatabase {
sqlite3_exec(db, rollbackTransaction, nil, nil, nil) sqlite3_exec(db, rollbackTransaction, nil, nil, nil)
return false return false
} }
deinit { deinit {
sqlite3_close(db) sqlite3_close(db)
} }
......
...@@ -26,7 +26,7 @@ class ChargeGuideController : BaseViewController,UIScrollViewDelegate,UINavigati ...@@ -26,7 +26,7 @@ class ChargeGuideController : BaseViewController,UIScrollViewDelegate,UINavigati
"Scroll the page and select Charger section", "Scroll the page and select Charger section",
"Select 'ls Connected' and 'Run lmmediately',then tap on Next", "Select 'ls Connected' and 'Run lmmediately',then tap on Next",
"Tap on New Blank Automation to connect the app", "Tap on New Blank Automation to connect the app",
"Type 'Cleanup' & select Run Charging Animation and tap on Done!" "Type 'PhoneManager' & select Run Charging Animation and tap on Done!"
] ]
let numberOfPages = 7 let numberOfPages = 7
......
...@@ -17,6 +17,8 @@ typealias CompressSelectCellCallback = (AssetModel,Bool)->Void ...@@ -17,6 +17,8 @@ typealias CompressSelectCellCallback = (AssetModel,Bool)->Void
class CompressSelectCell : UICollectionViewCell { class CompressSelectCell : UICollectionViewCell {
var indexPath : IndexPath?
var callBack : CompressSelectCellCallback = {model,choose in} var callBack : CompressSelectCellCallback = {model,choose in}
var currentMediaType : CompressType = .compressPhoto { var currentMediaType : CompressType = .compressPhoto {
...@@ -225,23 +227,31 @@ class CompressSelectCell : UICollectionViewCell { ...@@ -225,23 +227,31 @@ class CompressSelectCell : UICollectionViewCell {
@objc func imageClick(){ @objc func imageClick(){
if self.currentMediaType == .compressPhoto { if self.currentMediaType == .compressPhoto {
// 点击之后跳转详情页面 // 点击之后跳转详情页面
if let tempModel = self.model { if let tempModel = self.model {
let vc = PMShowImgVideoController() let vc = PMShowImgVideoController()
vc.state = .similarPhotos vc.state = .similarPhotos
vc.currentIdx = 0 vc.currentIdx = 0
vc.oldPageIndexPath = indexPath
let dataSource = ImageSeletedCollectionItem() let dataSource = ImageSeletedCollectionItem()
dataSource.isSeleted = true dataSource.isSeleted = self.choose
dataSource.id = tempModel dataSource.id = tempModel
// 获取image // 获取image
dataSource.image = PhotoAndVideoMananger.mananger.getImageFromAssetID(id: tempModel.localIdentifier) dataSource.image = PhotoAndVideoMananger.mananger.getImageFromAssetID(id: tempModel.localIdentifier)
vc.homeDataSource = [dataSource] vc.homeDataSource = [dataSource]
vc.backOrgPageCallBack = {[weak self]index,data in
guard let self else {return}
if let data = data{
if let item = data.first{
self.choose = item.isSeleted ?? false
}
}
}
self.responderViewController()?.navigationController?.pushViewController(vc, animated: true) self.responderViewController()?.navigationController?.pushViewController(vc, animated: true)
} }
}else{ }else{
...@@ -253,12 +263,21 @@ class CompressSelectCell : UICollectionViewCell { ...@@ -253,12 +263,21 @@ class CompressSelectCell : UICollectionViewCell {
let vc = PMShowImgVideoController() let vc = PMShowImgVideoController()
vc.state = .similarVideos vc.state = .similarVideos
vc.currentIdx = 0 vc.currentIdx = 0
vc.oldPageIndexPath = self.indexPath
let dataSource = ImageSeletedCollectionItem() let dataSource = ImageSeletedCollectionItem()
dataSource.isSeleted = true dataSource.isSeleted = self.choose
dataSource.id = tempModel dataSource.id = tempModel
dataSource.image = image dataSource.image = image
// 表示这个是视频 // 表示这个是视频
vc.homeDataSource = [dataSource] vc.homeDataSource = [dataSource]
vc.backOrgPageCallBack = {[weak self]index,data in
guard let self else {return}
if let data = data{
if let item = data.first{
self.choose = item.isSeleted ?? false
}
}
}
vc.getVideoURLFromLocalIdentifier(localIdentifier: tempModel.localIdentifier) { url, error in vc.getVideoURLFromLocalIdentifier(localIdentifier: tempModel.localIdentifier) { url, error in
if url != nil{ if url != nil{
DispatchQueue.main.async { DispatchQueue.main.async {
......
...@@ -19,8 +19,16 @@ class CompressCompletedViewController : BaseViewController{ ...@@ -19,8 +19,16 @@ class CompressCompletedViewController : BaseViewController{
var currentMediaType : CompressType = .compressPhoto var currentMediaType : CompressType = .compressPhoto
lazy var bacView : UIView = {
let view = UIView()
view.layer.cornerRadius = 115
view.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
return view
}()
lazy var animationView : LottieAnimationView = { lazy var animationView : LottieAnimationView = {
let animationView = LottieAnimationView(name: "CompressCompletedLight") let animationView = LottieAnimationView(name: "iOS压缩完成")
animationView.layer.cornerRadius = 12 animationView.layer.cornerRadius = 12
animationView.backgroundColor = .clear animationView.backgroundColor = .clear
animationView.loopMode = .loop animationView.loopMode = .loop
...@@ -153,6 +161,7 @@ class CompressCompletedViewController : BaseViewController{ ...@@ -153,6 +161,7 @@ class CompressCompletedViewController : BaseViewController{
self.view.backgroundColor = UIColor(red: 0.95, green: 0.96, blue: 0.99, alpha: 1) self.view.backgroundColor = UIColor(red: 0.95, green: 0.96, blue: 0.99, alpha: 1)
self.titleView.isHidden = true self.titleView.isHidden = true
self.view.addSubview(self.bacView)
self.view.addSubview(self.animationView) self.view.addSubview(self.animationView)
self.view.addSubview(self.tipLabel) self.view.addSubview(self.tipLabel)
self.view.addSubview(self.detailTiplabel) self.view.addSubview(self.detailTiplabel)
...@@ -168,7 +177,11 @@ class CompressCompletedViewController : BaseViewController{ ...@@ -168,7 +177,11 @@ class CompressCompletedViewController : BaseViewController{
self.infoView.addSubview(self.finalTipLabel) self.infoView.addSubview(self.finalTipLabel)
self.view.addSubview(self.completedButton) self.view.addSubview(self.completedButton)
self.bacView.snp.makeConstraints { make in
make.top.equalTo(statusBarHeight + 60)
make.width.height.equalTo(230)
make.centerX.equalToSuperview()
}
self.animationView.snp.makeConstraints { make in self.animationView.snp.makeConstraints { make in
make.top.equalTo(statusBarHeight + 60) make.top.equalTo(statusBarHeight + 60)
make.width.height.equalTo(230) make.width.height.equalTo(230)
...@@ -366,7 +379,7 @@ class CompressCompletedViewController : BaseViewController{ ...@@ -366,7 +379,7 @@ class CompressCompletedViewController : BaseViewController{
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
setUI() setUI()
self.animationView.play(fromProgress: 0, toProgress: 1,loopMode: .playOnce) self.animationView.play(fromProgress: 0, toProgress: 1,loopMode: .loop)
} }
......
...@@ -174,6 +174,7 @@ extension CompressController:WaterfallMutiSectionDelegate,UICollectionViewDataSo ...@@ -174,6 +174,7 @@ extension CompressController:WaterfallMutiSectionDelegate,UICollectionViewDataSo
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CompressSelectCell", for: indexPath) as! CompressSelectCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CompressSelectCell", for: indexPath) as! CompressSelectCell
cell.currentMediaType = self.currentResourceType cell.currentMediaType = self.currentResourceType
cell.model = self.resourceData[indexPath.row] cell.model = self.resourceData[indexPath.row]
cell.indexPath = indexPath
if self.selectedModel.count == 0 { if self.selectedModel.count == 0 {
cell.choose = false cell.choose = false
} }
......
//
// VideoViewController.swift
// PhoneManager
//
// Created by edy on 2025/5/13.
//
import Foundation
import AVKit
import MediaPlayer
class VideoViewController: UIViewController {
var url : URL?
var isAutoPlay : Bool = true
// 系统播放器控制器
let playerViewController = AVPlayerViewController()
override func viewDidLoad() {
super.viewDidLoad()
setupPlayer()
}
func setupPlayer() {
// 1. 创建播放器
if let url = self.url {
let player = AVPlayer(url: url)
// 2. 配置播放器控制器
playerViewController.player = player
playerViewController.delegate = self
playerViewController.showsPlaybackControls = true
// 3. 添加到当前视图
addChild(playerViewController)
view.addSubview(playerViewController.view)
playerViewController.view.frame = view.bounds
playerViewController.didMove(toParent: self)
// 4. 自动播放
if self.isAutoPlay {
player.play()
}
}
}
}
// MARK: - AVPlayerViewControllerDelegate
extension VideoViewController: AVPlayerViewControllerDelegate {
// 处理全屏切换
func playerViewController(_ playerViewController: AVPlayerViewController,
willBeginFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) {
}
func playerViewController(_ playerViewController: AVPlayerViewController,
willEndFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) {
}
}
...@@ -308,19 +308,15 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti ...@@ -308,19 +308,15 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti
cell.cellCallBack = {[weak self] ident,order in cell.cellCallBack = {[weak self] ident,order in
guard let self else {return} guard let self else {return}
DispatchQueue.main.async { DispatchQueue.main.async {
// 点击之后跳转详情页面 // 点击之后跳转详情页面
let vc = PMShowImgVideoController() if self.mediaType == .screenshots {
vc.state = .similarPhotos let vc = PhotoRemoveViewController(data: self.resourceData,currentIndex: indexPath.row,mediaType: .shot)
vc.currentIdx = 0 self.navigationController?.pushViewController(vc, animated: true)
let dataSource = ImageSeletedCollectionItem() }
dataSource.isSeleted = true if self.mediaType == .Other {
dataSource.id = ident let vc = PhotoRemoveViewController(data: self.resourceData,currentIndex: indexPath.row,mediaType: .other)
// 获取image self.navigationController?.pushViewController(vc, animated: true)
dataSource.image = PhotoAndVideoMananger.mananger.getImageFromAssetID(id: ident.localIdentifier) }
vc.homeDataSource = [dataSource]
self.navigationController?.pushViewController(vc, animated: true)
} }
} }
cell.clickCallBack = {[weak self] click,order in cell.clickCallBack = {[weak self] click,order in
......
...@@ -253,32 +253,8 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie ...@@ -253,32 +253,8 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
// 获取视频的图片 // 获取视频的图片
PhotoAndVideoMananger.mananger.getVideoImageByIdent(ident: ident) { image in PhotoAndVideoMananger.mananger.getVideoImageByIdent(ident: ident) { image in
// 点击之后跳转详情页面 // 点击之后跳转详情页面
let vc = PMShowImgVideoController() let vc = PhotoRemoveViewController(data: self.resourceData,currentIndex: indexPath.row,mediaType: .video)
vc.state = .similarVideos self.navigationController?.pushViewController(vc, animated: true)
vc.currentIdx = 0
let dataSource = ImageSeletedCollectionItem()
dataSource.isSeleted = true
dataSource.id = ident
dataSource.image = image
// 表示这个是视频
vc.homeDataSource = [dataSource]
vc.getVideoURLFromLocalIdentifier(localIdentifier: ident.localIdentifier) { url, error in
if url != nil{
DispatchQueue.main.async {
vc.url = url
self.navigationController?.pushViewController(vc, animated: true)
}
}else{
let alert = UIAlertController(title: nil, message: "ICloud video cannot be viewed", preferredStyle: .alert)
self.present(alert, animated: true, completion: nil)
// 2 秒后关闭弹窗
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
alert.dismiss(animated: true, completion: nil)
}
}
}
} errorHandler: { } errorHandler: {
DispatchQueue.main.async { DispatchQueue.main.async {
let alert = UIAlertController(title: nil, message: "Get Video image failure", preferredStyle: .alert) let alert = UIAlertController(title: nil, message: "Get Video image failure", preferredStyle: .alert)
......
...@@ -21,13 +21,13 @@ class PhotoSlideViewController: BaseViewController { ...@@ -21,13 +21,13 @@ class PhotoSlideViewController: BaseViewController {
private lazy var topView: AnchorRotatableView = { private lazy var topView: AnchorRotatableView = {
let view = AnchorRotatableView() let view = AnchorRotatableView()
view.configure(anchorPoint: CGPoint(x: 0.5, y: 0.5))
return view return view
}() }()
private lazy var bottomView: AnchorRotatableView = { private lazy var bottomView: AnchorRotatableView = {
let view = AnchorRotatableView() let view = AnchorRotatableView()
view.configure(anchorPoint: CGPoint(x: 0.5, y: 0.5))
return view return view
}() }()
...@@ -119,7 +119,8 @@ class PhotoSlideViewController: BaseViewController { ...@@ -119,7 +119,8 @@ class PhotoSlideViewController: BaseViewController {
updateCardTransform(translation: translation) updateCardTransform(translation: translation)
updateButtons(progress: progress,translation: translation) updateButtons(progress: progress,translation: translation)
case .ended, .cancelled: case .ended, .cancelled:
endDragAnimation(velocity: velocity) break
// endDragAnimation(velocity: velocity)
default: break default: break
} }
} }
......
...@@ -40,10 +40,3 @@ class AnchorRotatableView: UIView { ...@@ -40,10 +40,3 @@ class AnchorRotatableView: UIView {
} }
extension AnchorRotatableView {
func configure(anchorPoint: CGPoint) {
layer.anchorPoint = anchorPoint
}
}
...@@ -42,7 +42,7 @@ class HomeInfoView :UIView { ...@@ -42,7 +42,7 @@ class HomeInfoView :UIView {
lazy var headerView:HomeInfoTitleView = { lazy var headerView:HomeInfoTitleView = {
let sview:HomeInfoTitleView = HomeInfoTitleView(frame: CGRect(x: 0, y: 0, width: width, height: 84)) let sview:HomeInfoTitleView = HomeInfoTitleView(frame: CGRect(x: 0, y: 0, width: width, height: 84))
sview.titleLabel.text = self.titleText sview.titleLabel.text = self.titleText
sview.filterButton.isHidden = self.type != .similar sview.filterButton.isHidden = self.type != .similar && self.type != .SimilarVideos
tableView.addSubview(sview) tableView.addSubview(sview)
return sview return sview
}() }()
...@@ -117,7 +117,13 @@ class HomeInfoView :UIView { ...@@ -117,7 +117,13 @@ class HomeInfoView :UIView {
// 从源头获取相似数据 // 从源头获取相似数据
PhotoDataManager.manager.loadFromFileSystem(resultModel: {[weak self] model in PhotoDataManager.manager.loadFromFileSystem(resultModel: {[weak self] model in
guard let self else {return} guard let self else {return}
let tempData = self.filterDataByDate(orgModels: model.titleModelArray[1].assets, startDate: filterModel.startDate, endDate: filterModel.endDate) var dataS : [[AssetModel]] = []
if self.type == .SimilarVideos{
dataS = model.otherModelArray[3].assets
}else {
dataS = model.titleModelArray[1].assets
}
let tempData = self.filterDataByDate(orgModels: dataS , startDate: filterModel.startDate, endDate: filterModel.endDate)
// 重新更新下数据源 // 重新更新下数据源
self.ids = self.sortData(source: tempData, type: filterModel.sortType) self.ids = self.sortData(source: tempData, type: filterModel.sortType)
var tempModels : [HomeInfoTableItem] = [] var tempModels : [HomeInfoTableItem] = []
......
//
// PhotoRemoveNavView.swift
// PhoneManager
//
// Created by edy on 2025/5/13.
//
import UIKit
import SnapKit
class PhotoRemoveNavView: UIView {
public var backButton:UIButton!
public var sizeLbel : UILabel!
public var titleLbel : UILabel!
public var resetButton :UIButton!
private var topConstraint: Constraint?
public var mediaType : TrashTypeEnum = .shot {
didSet{
if mediaType == .video {
self.sizeLbel.isHidden = false
self.topConstraint?.update(offset: 22 + statusBarHeight)
}else{
self.sizeLbel.isHidden = true
self.topConstraint?.update(offset: 6 + statusBarHeight)
}
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
backgroundColor = .white
backButton = UIButton()
backButton.setImage(UIImage(named: "nav_back"), for: .normal)
backButton.addTarget(self, action: #selector(backBtnClick), for: .touchUpInside)
self.addSubview(backButton)
backButton.snp.makeConstraints { make in
make.centerY.equalTo(navCenterY)
make.left.equalToSuperview().offset(marginLR)
make.width.height.equalTo(iconWH)
}
sizeLbel = UILabel()
sizeLbel.textColor = UIColor(red: 0.07, green: 0.07, blue: 0.07, alpha: 1)
sizeLbel.font = UIFont.systemFont(ofSize: 12, weight: .medium)
self.addSubview(sizeLbel)
sizeLbel.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview().offset(statusBarHeight)
make.height.equalTo(22)
}
titleLbel = UILabel()
titleLbel.textColor = UIColor(red: 0.07, green: 0.07, blue: 0.07, alpha: 1)
titleLbel.font = UIFont.systemFont(ofSize: 12, weight: .medium)
self.addSubview(titleLbel)
titleLbel.snp.makeConstraints { make in
make.centerX.equalToSuperview()
self.topConstraint = make.top.equalToSuperview().offset(6 + statusBarHeight).constraint
make.height.equalTo(22)
}
resetButton = UIButton()
resetButton.setImage(UIImage(named: "Frame 3"), for: .normal)
resetButton.addTarget(self, action: #selector(resetButtonAction), for: .touchUpInside)
resetButton.isHidden = true
self.addSubview(resetButton)
resetButton.snp.makeConstraints { make in
make.centerY.equalTo(navCenterY)
make.right.equalToSuperview().offset(-marginLR)
make.width.height.equalTo(iconWH)
}
}
@objc private func backBtnClick() {
self.responderViewController()?.navigationController?.popViewController(animated: true)
}
@objc private func resetButtonAction() {
}
}
//
// AnchorRotatableView.swift
// AIClean
//
// Created by 赵前 on 2025/5/10.
//
import Foundation
import UIKit
class PhotosRemoveBaseView: UIView {
var currentIndex : Int?
var initialCenter: CGPoint = .zero
var url : URL?
var innerVideoController : VideoViewController?
func reload(index:Int) -> Void {
if let url = url {
self.innerVideoController = VideoViewController()
if let vc = self.innerVideoController {
vc.isAutoPlay = index == 0
vc.url = url
self.imageView.removeFromSuperview()
self.addSubview(vc.view)
vc.view.snp.makeConstraints { make in
make.left.top.bottom.right.equalToSuperview()
}
}
}
}
var mediaType : TrashTypeEnum?
lazy var maskTempleteView : UIView = {
let view = UIView(frame: CGRectMake(0, 0, self.width, self.height))
return view
}()
private let imageView = UIImageView()
private let leftButton = UIButton()
private let rightButton = UIButton()
override init(frame: CGRect) {
super.init(frame: frame)
self.layer.cornerRadius = 20
self.clipsToBounds = true
setupUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
// 配置图片视图
imageView.contentMode = .scaleAspectFit
addSubview(imageView)
leftButton.frame = CGRect(x: self.width / 2 - 45.5, y: self.height / 2 - 21, width: 95, height: 42)
leftButton.setTitle("Delete", for: .normal)
leftButton.backgroundColor = UIColor(red: 0.95, green: 0.21, blue: 0.21, alpha: 1)
leftButton.tintColor = .white
leftButton.layer.cornerRadius = 21
leftButton.clipsToBounds = true
leftButton.alpha = 0
addSubview(leftButton)
rightButton.frame = CGRect(x: self.width / 2 - 45.5, y: self.height / 2 - 21, width: 95, height: 42)
rightButton.setTitle("Retain", for: .normal)
rightButton.backgroundColor = UIColor(red: 0.18, green: 0.76, blue: 0.35, alpha: 1)
rightButton.tintColor = .white
rightButton.layer.cornerRadius = 21
rightButton.clipsToBounds = true
rightButton.alpha = 0
addSubview(rightButton)
}
func configure(with image: UIImage) {
imageView.image = image
imageView.frame = bounds
}
func showLeftButton() {
self.leftButton.center = self.center
UIView.animate(withDuration: 0.2) {
self.leftButton.alpha = 1
self.maskTempleteView.backgroundColor = UIColor(red: 0.95, green: 0.21, blue: 0.21, alpha: 0.4000)
self.addSubview(self.maskTempleteView)
self.rightButton.alpha = 0
}
}
func showRightButton() {
self.rightButton.center = self.center
UIView.animate(withDuration: 0.2) {
self.rightButton.alpha = 1
self.maskTempleteView.backgroundColor = UIColor(red: 0.26, green: 0.78, blue: 0.41, alpha: 0.4000)
self.addSubview(self.maskTempleteView)
self.leftButton.alpha = 0
}
}
func hideButtons() {
UIView.animate(withDuration: 0.2) {
self.leftButton.alpha = 0
self.rightButton.alpha = 0
self.maskTempleteView.removeFromSuperview()
self.leftButton.center = self.center
self.rightButton.center = self.center
}
}
}
//
// TrashSubView.swift
// PhoneManager
//
// Created by edy on 2025/5/13.
//
import UIKit
class TrashSubView: UIView {
var clearTashDataCallBack : ()->Void = {}
var presentTashDetailViewClickCallBack : ()->Void = {}
lazy var resourceCountlabel : UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 24, weight: .semibold)
label.textColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
return label
}()
lazy var tipLabel : UILabel = {
let label = UILabel()
label.text = "The photo in the trash can"
label.font = UIFont.systemFont(ofSize: 12, weight: .semibold)
label.textColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
label.numberOfLines = 0
return label
}()
lazy var emptyButton: UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "ic_delete_duplicates"), for: .normal)
button.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
button.setTitle("Empty the garbage", for: .normal)
button.setTitleColor(.white, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 12, weight: .semibold)
button.layer.cornerRadius = 19
button.clipsToBounds = true
button.addTarget(self, action: #selector(emptyButtonAction), for: .touchUpInside)
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
// 给当前视图添加手势
addTapGestureToSelf()
// 添加UI
addUIViews()
setUILocation()
}
private func addUIViews(){
self.addSubview(self.resourceCountlabel)
self.addSubview(self.tipLabel)
self.addSubview(self.emptyButton)
}
private func setUILocation(){
self.resourceCountlabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.centerY.equalToSuperview()
make.height.equalTo(22)
make.width.equalTo(30)
}
self.tipLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(17)
make.bottom.equalToSuperview().offset(-17)
make.left.equalTo(self.resourceCountlabel.snp.right).offset(11)
make.width.equalTo(100)
}
self.emptyButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-9)
make.height.equalTo(38)
make.centerY.equalToSuperview()
make.width.equalTo(145)
}
}
private func addTapGestureToSelf(){
self.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer()
tap.addTarget(self, action: #selector(tapHandle))
self.addGestureRecognizer(tap)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension TrashSubView {
@objc func emptyButtonAction(){
self.clearTashDataCallBack()
}
@objc func tapHandle(){
self.presentTashDetailViewClickCallBack()
}
}
...@@ -217,11 +217,26 @@ extension HomeInfoTableViewCell:UICollectionViewDelegate,UICollectionViewDataSou ...@@ -217,11 +217,26 @@ extension HomeInfoTableViewCell:UICollectionViewDelegate,UICollectionViewDataSou
// 显示保留按钮或者最佳匹配结果按钮 // 显示保留按钮或者最佳匹配结果按钮
cell.allKeepButton.isHidden = indexPath.item != 0 || self.type == .duplicates cell.allKeepButton.isHidden = indexPath.item != 0 || self.type == .duplicates
cell.bestResultButton.isHidden = indexPath.item != 0 || self.type == .duplicates cell.bestResultButton.isHidden = indexPath.item != 0 || self.type == .duplicates
cell.model = model?.smodels?[indexPath.row] cell.model = model?.smodels?[indexPath.row]
cell.photsFileType = model?.type cell.photsFileType = model?.type
cell.keepAllCallBack = {
//存到保留列表
saveAllDataToKeepList()
}
// 存全部数据到保留列表
func saveAllDataToKeepList(){
let uniqueId = UUID().uuidString
if let tempModel = self.model?.smodels {
for item in tempModel {
if let assetModel = item.id {
let success = GroupDatabase.shared.insert(localIdentifier: assetModel.localIdentifier, assetSize: assetModel.assetSize, createDate: assetModel.createDate, mediaType: self.type == .SimilarVideos ? 2 : 1 , groupId: uniqueId)
if success == false {
Print("存入当前数据到保留列表失败")
}
}
}
}
}
cell.callBack = {[weak self] _ in cell.callBack = {[weak self] _ in
guard let self else {return} guard let self else {return}
...@@ -253,9 +268,22 @@ extension HomeInfoTableViewCell:UICollectionViewDelegate,UICollectionViewDataSou ...@@ -253,9 +268,22 @@ extension HomeInfoTableViewCell:UICollectionViewDelegate,UICollectionViewDataSou
}else{ }else{
vc.state = .similarPhotos vc.state = .similarPhotos
} }
vc.oldPageIndexPath = indexPath
vc.currentIdx = indexPath.row vc.currentIdx = indexPath.row
vc.homeDataSource = self.model?.smodels vc.homeDataSource = self.model?.smodels
self.responderViewController()?.navigationController?.pushViewController(vc, animated: true) self.responderViewController()?.navigationController?.pushViewController(vc, animated: true)
vc.backOrgPageCallBack = {[weak self]index,data in
guard let self else {return}
self.model?.smodels = data
DispatchQueue.main.async{
if let view = self.collectionView{
UIView.transition(with: view, duration: 0.3, options: .transitionCrossDissolve, animations: {
view.reloadData()
}, completion: nil)
}
}
}
} }
} }
......
...@@ -19,6 +19,8 @@ class ImageSeletedCollectionCell:UICollectionViewCell { ...@@ -19,6 +19,8 @@ class ImageSeletedCollectionCell:UICollectionViewCell {
var callBack:callBack<Any> = {text in} var callBack:callBack<Any> = {text in}
var keepAllCallBack : ()->Void = {}
lazy var allKeepButton : UIButton = { lazy var allKeepButton : UIButton = {
let button = UIButton(type: .custom) let button = UIButton(type: .custom)
...@@ -37,8 +39,8 @@ class ImageSeletedCollectionCell:UICollectionViewCell { ...@@ -37,8 +39,8 @@ class ImageSeletedCollectionCell:UICollectionViewCell {
let button = UIButton(type: .custom) let button = UIButton(type: .custom)
button.layer.cornerRadius = 8 button.layer.cornerRadius = 8
button.clipsToBounds = true button.clipsToBounds = true
button.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1) button.backgroundColor = UIColor(red: 1, green: 0.65, blue: 0, alpha: 1)
button.setTitle( "Best result", for: .normal) button.setTitle( "Best", for: .normal)
button.setImage(UIImage(named: "Frame"), for: .normal) button.setImage(UIImage(named: "Frame"), for: .normal)
button.setTitleColor(.white, for: .normal) button.setTitleColor(.white, for: .normal)
button.isHidden = true button.isHidden = true
...@@ -179,7 +181,7 @@ class ImageSeletedCollectionCell:UICollectionViewCell { ...@@ -179,7 +181,7 @@ class ImageSeletedCollectionCell:UICollectionViewCell {
self.bestResultButton.snp.makeConstraints { make in self.bestResultButton.snp.makeConstraints { make in
make.left.bottom.equalToSuperview() make.left.bottom.equalToSuperview()
make.width.equalTo(81) make.width.equalTo(52)
make.height.equalTo(16) make.height.equalTo(16)
} }
...@@ -222,6 +224,8 @@ class ImageSeletedCollectionCell:UICollectionViewCell { ...@@ -222,6 +224,8 @@ class ImageSeletedCollectionCell:UICollectionViewCell {
extension ImageSeletedCollectionCell { extension ImageSeletedCollectionCell {
@objc func allKeepButtonAction(){ @objc func allKeepButtonAction(){
Print("点击了全部保留按钮") Print("点击了全部保留按钮")
self.keepAllCallBack()
} }
} }
...@@ -28,6 +28,21 @@ class PMShowImgCell: UICollectionViewCell { ...@@ -28,6 +28,21 @@ class PMShowImgCell: UICollectionViewCell {
scaleImg.icon = icon scaleImg.icon = icon
} }
} }
lazy var bestResultButton:UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "Frame"), for: .normal)
button.setTitle("Best", for: .normal)
button.setTitleColor(.white, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .semibold)
button.layer.cornerRadius = 10.5
button.clipsToBounds = true
button.backgroundColor = UIColor(red: 1, green: 0.65, blue: 0, alpha: 1)
contentView.addSubview(button)
return button
}()
private lazy var iconView: UIImageView = { private lazy var iconView: UIImageView = {
let info = UIImageView() let info = UIImageView()
...@@ -63,6 +78,14 @@ class PMShowImgCell: UICollectionViewCell { ...@@ -63,6 +78,14 @@ class PMShowImgCell: UICollectionViewCell {
} }
private func setup() -> Void { private func setup() -> Void {
bestResultButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(15)
make.top.equalToSuperview().offset(34)
make.width.equalTo(63)
make.height.equalTo(21)
}
iconView.snp.makeConstraints { make in iconView.snp.makeConstraints { make in
make.left.right.bottom.top.equalToSuperview() make.left.right.bottom.top.equalToSuperview()
} }
...@@ -74,5 +97,7 @@ class PMShowImgCell: UICollectionViewCell { ...@@ -74,5 +97,7 @@ class PMShowImgCell: UICollectionViewCell {
make.width.height.equalTo(iconWH) make.width.height.equalTo(iconWH)
make.bottom.equalToSuperview().offset(-10) make.bottom.equalToSuperview().offset(-10)
} }
self.contentView.bringSubviewToFront(self.bestResultButton)
} }
} }
...@@ -17,6 +17,8 @@ class PMShowVideoCell: UICollectionViewCell { ...@@ -17,6 +17,8 @@ class PMShowVideoCell: UICollectionViewCell {
var type : Int = 0 var type : Int = 0
var innerVideoController : VideoViewController?
func reload() -> Void { func reload() -> Void {
var url : URL? var url : URL?
if type == 0 { if type == 0 {
...@@ -25,25 +27,39 @@ class PMShowVideoCell: UICollectionViewCell { ...@@ -25,25 +27,39 @@ class PMShowVideoCell: UICollectionViewCell {
url = homeResouceUrl url = homeResouceUrl
} }
if let url = url { if let url = url {
player.playVideo(from: url) self.innerVideoController = VideoViewController()
if let vc = self.innerVideoController {
vc.url = url
self.contentView.addSubview(vc.view)
self.contentView.bringSubviewToFront(self.selectBtn)
vc.view.snp.makeConstraints { make in
make.left.top.bottom.right.equalToSuperview()
}
}
} }
} }
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
setup() self.contentView.addSubview(self.selectBtn)
selectBtn.snp.makeConstraints { make in
make.right.equalToSuperview()
make.width.height.equalTo(iconWH)
make.bottom.equalToSuperview().offset(-10)
}
bestResultButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(15)
make.top.equalToSuperview().offset(34)
make.width.equalTo(63)
make.height.equalTo(21)
}
self.contentView.bringSubviewToFront(self.bestResultButton)
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
private func setup() -> Void {
player.snp.makeConstraints { make in
make.left.top.bottom.right.equalToSuperview()
}
}
var zPlayer : SecretVideoPlayer { var zPlayer : SecretVideoPlayer {
get { get {
return player return player
...@@ -57,4 +73,44 @@ class PMShowVideoCell: UICollectionViewCell { ...@@ -57,4 +73,44 @@ class PMShowVideoCell: UICollectionViewCell {
contentView.addSubview(p) contentView.addSubview(p)
return p return p
}() }()
var callblock:(()->Void) = {}
@objc private func selectTap() -> Void {
callblock()
}
var isCurrent:Bool = false {
didSet {
selectBtn.isSelected = isCurrent
}
}
lazy var selectBtn: UIButton = {
let select = UIButton(type: .custom)
select.setImage(UIImage(named: "home_info_norl"), for: .normal)
select.setImage(UIImage(named: "home_info_seleted"), for: .selected)
select.addTarget(self, action: #selector(selectTap), for: .touchUpInside)
contentView.addSubview(select)
return select
}()
lazy var bestResultButton:UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "Frame"), for: .normal)
button.setTitle("Best", for: .normal)
button.setTitleColor(.white, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .semibold)
button.layer.cornerRadius = 10.5
button.clipsToBounds = true
button.backgroundColor = UIColor(red: 1, green: 0.65, blue: 0, alpha: 1)
contentView.addSubview(button)
return button
}()
} }
...@@ -21,16 +21,32 @@ class PMShowImgVideoController: BaseViewController { ...@@ -21,16 +21,32 @@ class PMShowImgVideoController: BaseViewController {
// 资源类型 0-图片 1-视频 // 资源类型 0-图片 1-视频
var homeMediaType : Int = 0 var homeMediaType : Int = 0
// 记录原来进来的
var oldPageIndexPath : IndexPath?
var state:ShowState = .secret var state:ShowState = .secret
var imageVideoPath:[String] = [] var imageVideoPath:[String] = []
// 首页过来的数据 // 首页过来的数据
var homeDataSource : [ImageSeletedCollectionItem]? var homeDataSource : [ImageSeletedCollectionItem]? {
didSet{
if let data = homeDataSource {
for (index,item) in data.enumerated() {
if item.isSeleted == true {
selectSet.add(index)
}
}
}
}
}
var currentIdx = 0 var currentIdx = 0
var selectSet = NSMutableSet() var selectSet = NSMutableSet()
var backOrgPageCallBack : (IndexPath?,[ImageSeletedCollectionItem]?)->Void = {index,data in}
var url : URL? var url : URL?
override func viewDidLoad() { override func viewDidLoad() {
...@@ -53,6 +69,19 @@ class PMShowImgVideoController: BaseViewController { ...@@ -53,6 +69,19 @@ class PMShowImgVideoController: BaseViewController {
self.MaxCollection.scrollToItem(at: IndexPath(row: currentIdx, section: 0), at: .centeredHorizontally, animated: false) self.MaxCollection.scrollToItem(at: IndexPath(row: currentIdx, section: 0), at: .centeredHorizontally, animated: false)
} }
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// 离开返回上一个把选择的数据带过去
for item in self.selectSet {
if let index = item as? Int {
self.homeDataSource?[index].isSeleted = true
}
}
self.backOrgPageCallBack(self.oldPageIndexPath,self.homeDataSource)
}
private lazy var MaxCollection: UICollectionView = { private lazy var MaxCollection: UICollectionView = {
let flowlayout = UICollectionViewFlowLayout() let flowlayout = UICollectionViewFlowLayout()
flowlayout.sectionInset = UIEdgeInsets() flowlayout.sectionInset = UIEdgeInsets()
...@@ -131,8 +160,10 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa ...@@ -131,8 +160,10 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if collectionView == bottItems { if collectionView == bottItems {
if selectSet.contains(indexPath.row) { if selectSet.contains(indexPath.row) {
self.homeDataSource?[indexPath.row].isSeleted = false
selectSet.remove(indexPath.row) selectSet.remove(indexPath.row)
}else{ }else{
self.homeDataSource?[indexPath.row].isSeleted = true
selectSet.add(indexPath.row) selectSet.add(indexPath.row)
} }
self.MaxCollection.reloadData() self.MaxCollection.reloadData()
...@@ -158,7 +189,7 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa ...@@ -158,7 +189,7 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
let showName = imageVideoPath[indexPath.row] let showName = imageVideoPath[indexPath.row]
if !showName.hasSuffix(".png") { if !showName.hasSuffix(".png") {
guard let zCell:PMShowVideoCell = cell as? PMShowVideoCell else { return } guard let zCell:PMShowVideoCell = cell as? PMShowVideoCell else { return }
zCell.zPlayer.pause() zCell.innerVideoController?.playerViewController.player?.pause()
} }
} }
} }
...@@ -172,12 +203,16 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa ...@@ -172,12 +203,16 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
showName.loadPhotoOrVideo { durs, icon in showName.loadPhotoOrVideo { durs, icon in
cell.icon = icon cell.icon = icon
} }
cell.bestResultButton.isHidden = indexPath.row != 0
cell.isCurrent = selectSet.contains(indexPath.row) cell.isCurrent = selectSet.contains(indexPath.row)
cell.callblock = {[weak self] in cell.callblock = {[weak self] in
guard let self = self else { return } guard let self = self else { return }
if self.selectSet.contains(indexPath.row){ if self.selectSet.contains(indexPath.row){
self.homeDataSource?[indexPath.row].isSeleted = false
self.selectSet.remove(indexPath.row) self.selectSet.remove(indexPath.row)
}else{ }else{
self.homeDataSource?[indexPath.row].isSeleted = true
self.selectSet.add(indexPath.row) self.selectSet.add(indexPath.row)
} }
self.MaxCollection.reloadData() self.MaxCollection.reloadData()
...@@ -186,8 +221,21 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa ...@@ -186,8 +221,21 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
return cell return cell
}else{ }else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowVideoCellID, for: indexPath) as! PMShowVideoCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowVideoCellID, for: indexPath) as! PMShowVideoCell
cell.isCurrent = selectSet.contains(indexPath.row)
cell.playURL = showName cell.playURL = showName
cell.reload() cell.reload()
cell.callblock = {[weak self] in
guard let self = self else { return }
if self.selectSet.contains(indexPath.row){
self.homeDataSource?[indexPath.row].isSeleted = false
self.selectSet.remove(indexPath.row)
}else{
self.homeDataSource?[indexPath.row].isSeleted = true
self.selectSet.add(indexPath.row)
}
self.MaxCollection.reloadData()
self.bottItems.reloadData()
}
return cell return cell
} }
}else{ }else{
...@@ -208,11 +256,14 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa ...@@ -208,11 +256,14 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowImgCellID, for: indexPath) as! PMShowImgCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowImgCellID, for: indexPath) as! PMShowImgCell
cell.icon = self.homeDataSource![indexPath.row].image ?? UIImage() cell.icon = self.homeDataSource![indexPath.row].image ?? UIImage()
cell.isCurrent = selectSet.contains(indexPath.row) cell.isCurrent = selectSet.contains(indexPath.row)
cell.bestResultButton.isHidden = indexPath.row != 0
cell.callblock = {[weak self] in cell.callblock = {[weak self] in
guard let self = self else { return } guard let self = self else { return }
if self.selectSet.contains(indexPath.row){ if self.selectSet.contains(indexPath.row){
self.homeDataSource?[indexPath.row].isSeleted = false
self.selectSet.remove(indexPath.row) self.selectSet.remove(indexPath.row)
}else{ }else{
self.homeDataSource?[indexPath.row].isSeleted = true
self.selectSet.add(indexPath.row) self.selectSet.add(indexPath.row)
} }
self.MaxCollection.reloadData() self.MaxCollection.reloadData()
...@@ -247,6 +298,20 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa ...@@ -247,6 +298,20 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
} }
// 表示这个是视频 // 表示这个是视频
cell.type = 1 cell.type = 1
cell.isCurrent = selectSet.contains(indexPath.row)
cell.bestResultButton.isHidden = indexPath.row != 0
cell.callblock = {[weak self] in
guard let self = self else { return }
if self.selectSet.contains(indexPath.row){
self.homeDataSource?[indexPath.row].isSeleted = false
self.selectSet.remove(indexPath.row)
}else{
self.homeDataSource?[indexPath.row].isSeleted = true
self.selectSet.add(indexPath.row)
}
self.MaxCollection.reloadData()
self.bottItems.reloadData()
}
return cell return cell
}else{ }else{
if indexPath.row < self.homeDataSource?.count ?? 0 { if indexPath.row < self.homeDataSource?.count ?? 0 {
......
...@@ -325,6 +325,16 @@ extension SecretViewController : UICollectionViewDelegate,UICollectionViewDataSo ...@@ -325,6 +325,16 @@ extension SecretViewController : UICollectionViewDelegate,UICollectionViewDataSo
let play = PMShowImgVideoController() let play = PMShowImgVideoController()
play.currentIdx = indexPath.row play.currentIdx = indexPath.row
play.imageVideoPath = dataSource play.imageVideoPath = dataSource
play.oldPageIndexPath = indexPath
play.backOrgPageCallBack = {[weak self]index,data in
guard let self else {return}
self.selectArray = play.selectSet
DispatchQueue.main.async{
UIView.transition(with: self.secretCollect, duration: 0.3, options: .transitionCrossDissolve, animations: {
self.secretCollect.reloadData()
}, completion: nil)
}
}
self.navigationController?.pushViewController(play, animated: true) self.navigationController?.pushViewController(play, animated: true)
} }
......
...@@ -22,6 +22,26 @@ class TrashViewController: UIViewController { ...@@ -22,6 +22,26 @@ class TrashViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
configUI() configUI()
getTrashDataAndRefreshPage()
}
/// 获取垃圾桶数据
private func getTrashDataAndRefreshPage(){
for item in self.source {
let data = TrashDataManager.getCurrentMediaTypeTrashData(mediaType: item)
for view in self.contentScrollView.subviews {
if view.isKind(of: TrashContenView.self){
let tempView = view as! TrashContenView
if tempView.trashType == item{
tempView.dataSource = data
DispatchQueue.main.async {
tempView.collectionView.reloadData()
}
}
}
}
}
} }
......
//
// TrashDataManager.swift
// PhoneManager
//
// Created by edy on 2025/5/14.
//
import UIKit
class TrashDataManager {
/// 清除当前垃圾桶的数据
static func clearTrashData(mediaType: TrashTypeEnum?, comlete:@escaping ()->Void){
let trashData = self.getCurrentMediaTypeTrashData(mediaType: mediaType)
if trashData.count > 0 {
PhotoAndVideoMananger.deleteAssets(localIdentifiers: trashData.map({$0.localIdentifier})) {
// 清空单利和数据库的数据
clearCurrentMediaTypeTrashSigtonData()
clearCurrentMediaTypeTrashDBData()
// 删除完成之后重新
comlete()
}
}else{
comlete()
}
func clearCurrentMediaTypeTrashSigtonData(){
if let type = mediaType {
Singleton.shared.trashData[type] = []
Print("删除单利中当前垃圾桶数据成功")
}
}
func clearCurrentMediaTypeTrashDBData(){
if let type = mediaType {
let dataDB = TrashDatabase.shared.queryByMediaType(type.dbType)
let success = TrashDatabase.shared.batchDelete(localIdentifiers: dataDB.map({$0.localIdentifier}))
if success {
Print("删除数据库当前垃圾桶数据成功")
}else {
Print("删除数据库当前垃圾桶数据失败")
}
}
}
}
static func getCurrentMediaTypeTrashData(mediaType: TrashTypeEnum?) -> [AssetModel]{
var assetModel : [AssetModel] = []
if let type = mediaType{
// 从数据库拿数据
let dataDB = TrashDatabase.shared.queryByMediaType(type.dbType)
for item in dataDB {
assetModel.append(AssetModel.init(localIdentifier: item.localIdentifier, assetSize: item.assetSize, createDate: item.createDate, mediaType: item.mediaType))
}
// 从单利拿数据
if let type = mediaType{
if let dataSg = Singleton.shared.trashData[type]{
assetModel = assetModel + dataSg
}
}
}
return assetModel
}
}
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import Foundation import Foundation
enum TrashTypeEnum{ enum TrashTypeEnum : CaseIterable{
case video,other,shot,chat case video,other,shot,chat
var dbType:Int{ var dbType:Int{
......
...@@ -19,6 +19,10 @@ class Singleton { ...@@ -19,6 +19,10 @@ class Singleton {
var maxDeleteCount : Int = 25 var maxDeleteCount : Int = 25
var trashData : [TrashTypeEnum : [AssetModel]] = [:]
var keepList : [TrashTypeEnum : [AssetModel]] = [:]
var photoPermission : PrivacyType? var photoPermission : PrivacyType?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment