Commit 1907e42f authored by shenyong's avatar shenyong

保留列表

parent 67999456
......@@ -136,7 +136,7 @@ class GroupDatabase {
// 查询所有数据
func queryAll() -> [(localIdentifier: String, assetSize: Double, createDate: Date, mediaType: Int, groupId: String)] {
let queryStatementString = "SELECT * FROM groups;"
let queryStatementString = "SELECT * FROM groups ORDER BY rowid DESC;"
var queryStatement: OpaquePointer?
var result: [(localIdentifier: String, assetSize: Double, createDate: Date, mediaType: Int, groupId: String)] = []
......
......@@ -261,13 +261,3 @@ class TrashDatabase {
}
}
extension TrashDatabase{
func dealHomeData(type:Int){
}
}
......@@ -232,6 +232,10 @@ actor PhotoDuplicateStateManager {
return pendingDuplicateGroups
}
func removeGroup(){
self.duplicateGroups.removeAll()
}
// MARK: - 缓存相关
func getCachedImage(for identifier: String) -> UIImage? {
......
......@@ -55,7 +55,8 @@ class PhotoDuplicateManager: @unchecked Sendable {
let groups = cachedGroups.map{$0.assets}
loacalHandler?(groups)
}
//返回本地数据后 清空
await stateManager.removeGroup()
// 4. 按特征预分组(分辨率、时间、文件大小)
var featureGroups: [[PHAsset]] = []
var tempGroups: [String: [PHAsset]] = [:] // 临时用于分组
......
......@@ -94,9 +94,7 @@ class PhotoManager{
var filterSimilarScreenShotModels:[[AssetModel]] = []
// 过滤垃圾桶/保留相似视频分组
var filterSimilarVideoModels:[[AssetModel]] = []
// // 过滤垃圾桶/保留重复图片分组
// var filterDuplicateModels:[[AssetModel]] = []
// 截图
var screenShotModels:[AssetModel] = []
// 视频
......@@ -700,3 +698,42 @@ extension PhotoManager{
}
extension PhotoManager{
// 处理app图片删除
func removeDataWhenDeleteInPage(data:[AssetModel]){
let deletes = data.compactMap{$0.localIdentifier}
let others = removeAssets(withIdentifiers: deletes, from: otherModels)
let videos = removeAssets(withIdentifiers: deletes, from: videoModels)
let screens = removeAssets(withIdentifiers: deletes, from: screenShotModels)
otherModels = others
videoModels = videos
screenShotModels = screens
// 保存到本地
saveToLocal(type: "video", models: self.videoModels)
saveToLocal(type: "other", models: self.otherModels)
saveToLocal(type: "screenshot", models: self.screenShotModels)
}
func removeAssets(withIdentifiers identifiers: [String], from assets: [AssetModel]) -> [AssetModel] {
let identifierSet = Set(identifiers)
return assets.filter { !identifierSet.contains($0.localIdentifier) }
}
func filterGroups(_ groups: [[AssetModel]], byExcludingIDs ids: [String]) -> [[AssetModel]] {
let excludeSet = Set(ids)
return groups.filter { group in
// 检查子数组中是否所有元素的ID都不在排除列表中
group.allSatisfy { !excludeSet.contains($0.localIdentifier) }
}
}
}
......@@ -91,3 +91,36 @@ struct DuplicateGroupModel: Codable {
let groupId: String
let assets: [AssetModel]
}
struct Match {
let groupIndex: Int
let matchedElements: [AssetModel]
}
extension Sequence where Element == [AssetModel] {
/// 判断二维数组中是否包含某个子数组,其元素的localIdentifier集合与给定数组完全相同(忽略顺序)
func containsGroup(matching elements: [AssetModel]) -> Bool {
let targetIDs = Set(elements.map { $0.localIdentifier })
return self.contains { group in
let groupIDs = Set(group.map { $0.localIdentifier })
return groupIDs == targetIDs
}
}
func matches(containingAny elements: [AssetModel]) -> [Match] {
let targetIDs = Set(elements.map { $0.localIdentifier })
var matches = [Match]()
for (index, group) in self.enumerated() {
let matched = group.filter { targetIDs.contains($0.localIdentifier) }
if !matched.isEmpty {
matches.append(Match(groupIndex: index, matchedElements: matched))
}
}
return matches
}
}
......@@ -94,7 +94,7 @@ class HomeInfoViewController:BaseViewController {
}
self.showDeleteSuccess(fileCount: tempStringArray.count, fileSize: fileSize)
// 删除缓存数据
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: imgs)
......
......@@ -113,41 +113,6 @@ class HomeViewController:BaseViewController {
// 调用下追踪权限
checkTrackingAuthorization()
// 获取主页数据
setupData()
//
let dataUpdated = Notification.Name("DataUpdatedNotification")
NotificationCenter.default.addObserver(self, selector: #selector(handleDataUpdated(_:)), name: dataUpdated, object: nil)
//
// // 视频
// let homeVideoResourceUpdate = Notification.Name("HomeVideoResourceUpdate")
// NotificationCenter.default.addObserver(self, selector: #selector(handleHomeVideoResourceUpdate(_:)), name: homeVideoResourceUpdate, object: nil)
//
// // 相似视频
// let homeSimilarVideoResourceUpdate = Notification.Name("HomeSimilarVideoResourceUpdate")
// NotificationCenter.default.addObserver(self, selector: #selector(handleHomeSimilarVideoResourceUpdate(_:)), name: homeSimilarVideoResourceUpdate, object: nil)
//
// // 相似截图
// let homeSimilarScreenshotResourceUpdate = Notification.Name("HomeSimilarScreenshotResourceUpdate")
// NotificationCenter.default.addObserver(self, selector: #selector(handleHomeSimilarScreenshotResourceUpdate(_:)), name: homeSimilarScreenshotResourceUpdate, object: nil)
//
// // 屏幕截图
// let homeScreenShotResourceUpdate = Notification.Name("HomeScreenShotResourceUpdate")
// NotificationCenter.default.addObserver(self, selector: #selector(handleHomeScreenShotResourceUpdate(_:)), name: homeScreenShotResourceUpdate, object: nil)
//
// // 其他
// let homeOtherResourceUpdate = Notification.Name("HomeOtherResourceUpdate")
// NotificationCenter.default.addObserver(self, selector: #selector(handleHomeOtherResourceUpdate(_:)), name: homeOtherResourceUpdate, object: nil)
//
// // 重复图片
// let homeDupImageResourceUpdate = Notification.Name("HomeDupImageResourceUpdate")
// NotificationCenter.default.addObserver(self, selector: #selector(handleHomeDupImageResourceUpdate(_:)), name: homeDupImageResourceUpdate, object: nil)
//
// // 相似图片
// let homeSimilarImageResourceUpdate = Notification.Name("HomeSimilarImageResourceUpdate")
// NotificationCenter.default.addObserver(self, selector: #selector(handleHomeSimilarImageResourceUpdate(_:)), name: homeSimilarImageResourceUpdate, object: nil)
homeView = HomeView(frame: view.bounds)
homeView?.y = cWindow?.safeAreaInsets.top ?? 20
homeView?.height = view.height - (cWindow?.safeAreaInsets.top ?? 20)
......@@ -224,36 +189,7 @@ class HomeViewController:BaseViewController {
view.addSubview(homeView!)
}
func setupData() {
// 详情数据
// PhotoDataManager.manager.loadFromFileSystem(resultModel: {[weak self] model in
// DispatchQueue.main.async {
// self?.homeView?.model = model
// self?.homeView?.collectionView.reloadData()
// }
// // 总数据 文件数量和文件大小
// PhotoAndVideoMananger.mananger.fetchAllFile {[weak self] index, FileSize in
// guard let self else {return}
// // 相当于进度条
// self.homeView?.model?.allFileNumber = index
// self.homeView?.model?.allFileSize = FileSize
// self.homeView?.setTitle()
// } completion: {[weak self] fileSize,index in
//
// guard let self else {return}
//
// self.homeView?.model?.allFileNumber = index
// self.homeView?.model?.allFileSize = fileSize
// self.homeView?.setTitle()
// }
// })
// PhotoManager.shared.getBaseAssetGroup()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
......@@ -271,183 +207,8 @@ class HomeViewController:BaseViewController {
}
isShowCharge = true
}
}
// 重新刷新下集合
// func reloadCollectionView(){
// DispatchQueue.main.async {
// if let collectionView = self.homeView?.collectionView {
//
// for section in 0..<collectionView.numberOfSections {
// for item in 0..<collectionView.numberOfItems(inSection: section) {
// if section == 0 || section == 1 {
// if let cell = collectionView.cellForItem(at: IndexPath(row: item, section: section)) as? HomeTitleCollectionCell {
// UIView.transition(with: cell.collectionView!, duration: 0.3, options: .transitionCrossDissolve, animations: {
// cell.collectionView?.reloadData()
// }, completion: nil)
// }
// }else{
// UIView.transition(with:collectionView, duration: 0.3, options: .transitionCrossDissolve, animations: {
// self.homeView?.collectionView.reloadItems(at: [IndexPath(row: item, section: section)])
// }, completion: nil)
// }
// }
// }
// }
// }
//
// }
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.barHidden = false
// 开启定时器
Singleton.shared.startCountdown {}
if !isShowCharge {
NotificationManager().configNotifications()
return
}
if !isShowPay {
isShowPay = true
if IAPManager.share.isSubscribed == false {
HomePayViewController.show {
NotificationManager().configNotifications()
}
}
}
}
// 重复图片
// @objc func handleHomeDupImageResourceUpdate(_ notification: Notification) {
// PhotoDataManager.manager.loadFromFileSystem {[weak self] model in
// guard let self else {return}
// let count = self.homeView?.model?.titleModelArray[0].assets.count
// self.homeView?.model = model
// DispatchQueue.main.async {
// if self.homeView?.dupHeadCell != nil && count == 0 && model.titleModelArray[0].assets.count != 0 {
// self.homeView?.collectionView.reloadItems(at: [IndexPath(row: 0, section: 0)])
// }
//
// let tempCell = self.homeView?.collectionView.cellForItem(at: IndexPath(row: 0, section: 0))
// if let homeTitleCell = tempCell as? HomeTitleCollectionCell {
// var tempCount : Int = 0
// for item in model.titleModelArray[0].assets {
// tempCount = tempCount + item.count
// }
// homeTitleCell.fileLabel?.text = "\(tempCount)" + " Photos " + (model.titleModelArray[0].allFileSize > 0 ? "(\(formatFileSize(model.titleModelArray[0].allFileSize)))" : "(Calculating...)")
// }
// }
// }
//
// }
// @objc func handleHomeSimilarImageResourceUpdate(_ notification: Notification) {
// PhotoDataManager.manager.loadFromFileSystem {[weak self] model in
// guard let self else {return}
// let count = self.homeView?.model?.titleModelArray[1].assets.count
// self.homeView?.model = model
// DispatchQueue.main.async {
// if self.homeView?.similarHeadCell != nil && count == 0 && model.titleModelArray[1].assets.count != 0 {
// self.homeView?.collectionView.reloadItems(at: [IndexPath(row: 1, section: 0)])
// }
// let tempCell = self.homeView?.collectionView.cellForItem(at: IndexPath(row: 1, section: 0))
// if let homeTitleCell = tempCell as? HomeTitleCollectionCell {
// var tempCount : Int = 0
// for item in model.titleModelArray[1].assets {
// tempCount = tempCount + item.count
// }
// homeTitleCell.fileLabel?.text = "\(tempCount)" + " Photos " + (model.titleModelArray[1].allFileSize > 0 ? "(\(formatFileSize(model.titleModelArray[1].allFileSize)))" : "(Calculating...)")
// }
// }
// }
//
// }
//
// @objc func handleHomeVideoResourceUpdate(_ notification: Notification) {
// PhotoDataManager.manager.loadFromFileSystem {[weak self] model in
// guard let self else {return}
// let count = self.homeView?.model?.otherModelArray[0].assets.count
// self.homeView?.model = model
// DispatchQueue.main.async {
// if count == 0{
// self.homeView?.collectionView.reloadItems(at: [IndexPath(row: 0, section: 1)])
// }
// }
// }
// }
// @objc func handleHomeSimilarScreenshotResourceUpdate(_ notification: Notification) {
// PhotoDataManager.manager.loadFromFileSystem {[weak self] model in
// guard let self else {return}
// let count = self.homeView?.model?.otherModelArray[1].assets.count
// self.homeView?.model = model
// DispatchQueue.main.async {
// if count == 0 && model.otherModelArray[1].assets.count != 0{
// self.homeView?.collectionView.reloadItems(at: [IndexPath(row: 1, section: 1)])
// }
// let tempCell = self.homeView?.collectionView.cellForItem(at: IndexPath(row: 1, section: 1))
// if let otherCell = tempCell as? HomeOtherCollectionCell{
// var tempCount : Int = 0
// for item in model.otherModelArray[1].assets {
// tempCount = tempCount + item.count
// }
// otherCell.countLabel.text = "\(tempCount) Photos"
// }
//
// }
// }
//
// }
//
// @objc func handleHomeScreenShotResourceUpdate(_ notification: Notification) {
// PhotoDataManager.manager.loadFromFileSystem {[weak self] model in
// guard let self else {return}
// let count = self.homeView?.model?.otherModelArray[2].assets.count
// self.homeView?.model = model
// DispatchQueue.main.async {
// if count == 0{
// self.homeView?.collectionView.reloadItems(at: [IndexPath(row: 2, section: 1)])
// }
//
// }
// }
//
// }
// @objc func handleHomeSimilarVideoResourceUpdate(_ notification: Notification) {
// PhotoDataManager.manager.loadFromFileSystem {[weak self] model in
// guard let self else {return}
// let count = self.homeView?.model?.otherModelArray[3].assets.count
// self.homeView?.model = model
// DispatchQueue.main.async {
// if count == 0{
// self.homeView?.collectionView.reloadItems(at: [IndexPath(row: 3, section: 1)])
// }
// }
// }
//
// }
// @objc func handleHomeOtherResourceUpdate(_ notification: Notification) {
//
// PhotoDataManager.manager.loadFromFileSystem {[weak self] model in
// guard let self else {return}
// let count = self.homeView?.model?.otherModelArray[4].assets.count
// self.homeView?.model = model
// DispatchQueue.main.async {
// if count == 0{
// self.homeView?.collectionView.reloadItems(at: [IndexPath(row: 4, section: 1)])
// }
// }
// }
// }
@objc func handleDataUpdated(_ notification: Notification) {
// 首页这里要重新获取下数据
setupData()
homeView?.viewModel.reloadTrashAndKeep()
}
}
......
......@@ -33,7 +33,7 @@ class HomeView:UIView {
// var viewModel:HomeviewModel
private var viewModel = HomeViewModel.shared
var viewModel = HomeViewModel.shared
var attribet:NSAttributedString?
......
......@@ -11,9 +11,17 @@ class HomeViewModel {
func config(){}
let trash = TrashDatabase.shared.queryAll().compactMap{$0.localIdentifier}
var trash = TrashDatabase.shared.queryAll().compactMap{$0.localIdentifier}
let keep = GroupDatabase.shared.queryAll().compactMap{$0.localIdentifier}
var keep = GroupDatabase.shared.queryAll().compactMap{$0.localIdentifier}
func reloadTrashAndKeep(){
trash = TrashDatabase.shared.queryAll().compactMap{$0.localIdentifier}
keep = GroupDatabase.shared.queryAll().compactMap{$0.localIdentifier}
filterResource()
}
// 封面图片资源缓存
// actor CoverCacheActor {
......
......@@ -9,22 +9,80 @@ import UIKit
class MaintaiDetailViewController: BaseViewController {
var dataSource:[[AssetModel]] = []
var viewModel:MaintaiViewModel = MaintaiViewModel()
var selectAsset:[[AssetModel]] = []
var needReloadBlock:(([[AssetModel]]) ->Void)?
var scrollIndex = 0
var isFirstLoad = true
// var tempUrl:URL?
override func viewDidLoad() {
super.viewDidLoad()
configUI()
getData()
dealBottomView()
}
func configUI(){
view.addSubview(tableView)
tableView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.top.equalTo(titleView.snp.bottom)
}
maintaiTipsAlertView.confirmBlock = {[weak self] in
guard let weakSelf = self else { return }
weakSelf.removeFromKeep()
weakSelf.maintaiTipsAlertView.disMiss()
}
maintaiBottomView.removeMaintaiBlock = {[weak self] in
guard let weakSelf = self else { return }
weakSelf.maintaiTipsAlertView.show()
}
}
func removeFromKeep(){
let ids = selectAsset.flatMap{$0}.compactMap{$0.localIdentifier}
if GroupDatabase.shared.batchDelete(localIdentifiers: ids){
getData()
selectAsset.removeAll()
}
}
func dealBottomView(){
if selectAsset.count > 0{
let count = selectAsset.flatMap{$0}.count
maintaiBottomView.numberL.text = "\(count)"
view.addSubview(maintaiBottomView)
maintaiBottomView.show()
}else{
maintaiBottomView.disMiss()
}
}
func getData(){
viewModel.refreshData {[weak self] in
guard let self = self else { return }
self.tableView.reloadData()
if self.isFirstLoad{
self.tableView.scrollToRow(at: IndexPath.init(row: self.scrollIndex, section: 0), at: .middle, animated: true)
self.isFirstLoad = false
}
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
needReloadBlock?(selectAsset)
}
lazy var tableView:UITableView = {
......@@ -33,6 +91,7 @@ class MaintaiDetailViewController: BaseViewController {
tableView.dataSource = self
tableView.separatorStyle = .none
tableView.showsVerticalScrollIndicator = false
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom:78+kSafeAreaInsets.bottom, right: 0)
tableView.register(UINib(nibName: "MaintaiDetailTableViewCell", bundle: nil), forCellReuseIdentifier: "MaintaiDetailTableViewCell")
tableView.register(UINib(nibName: "MaintaiDetailPicCell", bundle: nil), forCellReuseIdentifier: "MaintaiDetailPicCell")
tableView.register(UINib(nibName: "MaintaiDetialVideoCell", bundle: nil), forCellReuseIdentifier: "MaintaiDetialVideoCell")
......@@ -55,32 +114,112 @@ class MaintaiDetailViewController: BaseViewController {
extension MaintaiDetailViewController:UITableViewDelegate,UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.count
return viewModel.souces.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 360.RW()
return (ScreenW-14) + 74.RW() + 30 // 360.RW()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if dataSource[indexPath.row].first?.mediaType == 1,dataSource[indexPath.row].count > 1{
if viewModel.souces[indexPath.row].first?.mediaType == 1,viewModel.souces[indexPath.row].count > 1{
let cell = tableView.dequeueReusableCell(withIdentifier: "MaintaiDetailTableViewCell") as! MaintaiDetailTableViewCell
cell.source = dataSource[indexPath.row]
if let groupIndex = selectAsset.matches(containingAny: viewModel.souces[indexPath.row]).first?.groupIndex{
cell.selectAsset = selectAsset[groupIndex]
}else{
cell.selectAsset = []
}
// 拿到当前在选中数据的下标
let selectIndex = selectAsset.firstIndex(where: {
$0 == cell.selectAsset
})
// cell.selectAsset =
cell.source = viewModel.souces[indexPath.row]
cell.selectCallBack = {[weak self] selects in
guard let weakSelf = self else { return }
if let sIndex = selectIndex{
//已经有选中状态
Print("已经有选中数据",sIndex)
if selects.count > 0{
weakSelf.selectAsset[sIndex] = selects
}else{
weakSelf.selectAsset.remove(at: sIndex)
}
}else{
Print("没有任何选中数据")
weakSelf.selectAsset.append(selects)
}
weakSelf.dealMutilImagePick()
}
return cell
}
if dataSource[indexPath.row].first?.mediaType == 1,dataSource[indexPath.row].count == 1{
if viewModel.souces[indexPath.row].first?.mediaType == 1,viewModel.souces[indexPath.row].count == 1{
let cell = tableView.dequeueReusableCell(withIdentifier: "MaintaiDetailPicCell") as! MaintaiDetailPicCell
cell.model = dataSource[indexPath.row].first
cell.model = viewModel.souces[indexPath.row].first
cell.selectBtn.isSelected = selectAsset.contains(viewModel.souces[indexPath.row])
cell.selectChangeBlock = {[weak self] in
guard let weakSelf = self else { return }
weakSelf.dealPickAssetModel(index: indexPath.row)
weakSelf.tableView.reloadData()
}
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "MaintaiDetialVideoCell") as! MaintaiDetialVideoCell
cell.model = dataSource[indexPath.row].first
cell.model = viewModel.souces[indexPath.row].first
cell.selectBtn.isSelected = selectAsset.contains(viewModel.souces[indexPath.row])
cell.selectChangeBlock = {[weak self] in
guard let weakSelf = self else { return }
weakSelf.dealPickAssetModel(index: indexPath.row)
weakSelf.tableView.reloadData()
}
return cell
}
func dealMutilImagePick(){
if selectAsset.count > 0{
let count = selectAsset.flatMap{$0}.count
maintaiBottomView.numberL.text = "\(count)"
view.addSubview(maintaiBottomView)
maintaiBottomView.show()
}else{
maintaiBottomView.disMiss()
}
tableView.reloadData()
}
func dealPickAssetModel(index:Int){
if let index = selectAsset.firstIndex(where: {
$0 == viewModel.souces[index]
}) {
// 包含:移除元素
selectAsset.remove(at: index)
} else {
// 不包含:添加元素
selectAsset.append(viewModel.souces[index])
}
if selectAsset.count > 0{
let count = selectAsset.flatMap{$0}.count
maintaiBottomView.numberL.text = "\(count)"
view.addSubview(maintaiBottomView)
maintaiBottomView.show()
}else{
maintaiBottomView.disMiss()
}
}
}
......@@ -11,7 +11,10 @@ class MaintainViewListController: BaseViewController {
var selectAsset:[[AssetModel]] = []
var selectAssetDic:[String:[[AssetModel]]] = [:]
var viewModel:MaintaiViewModel = MaintaiViewModel()
override func viewDidLoad() {
super.viewDidLoad()
......@@ -44,9 +47,10 @@ class MaintainViewListController: BaseViewController {
func removeFromKeep(){
let ids = selectAsset.flatMap{$0}.compactMap{$0.localIdentifier}
if GroupDatabase.shared.batchDelete(localIdentifiers: ids){
getData()
selectAsset.removeAll()
}
}
......@@ -77,6 +81,7 @@ class MaintainViewListController: BaseViewController {
collectionView.delegate = self
collectionView.backgroundColor = .white
collectionView.dataSource = self
collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom:78+kSafeAreaInsets.bottom, right: 0)
collectionView.register(UINib(nibName: "MaintainViewListCell", bundle: nil), forCellWithReuseIdentifier: "MaintainViewListCell")
return collectionView
......@@ -109,22 +114,11 @@ extension MaintainViewListController:UICollectionViewDataSource,UICollectionView
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MaintainViewListCell", for: indexPath) as! MaintainViewListCell
let isSelect = selectAsset.contains(viewModel.souces[indexPath.row])
let isSelect = selectAsset.containsGroup(matching: viewModel.souces[indexPath.row])
cell.reloadData(viewModel.souces[indexPath.row], isSelect:isSelect)
cell.selectBlock = {[weak self] in
guard let weakSelf = self else { return }
weakSelf.view.addSubview(weakSelf.maintaiBottomView)
if let index = weakSelf.selectAsset.firstIndex(where: {
$0 == weakSelf.viewModel.souces[indexPath.row]
}) {
// 包含:移除元素
weakSelf.selectAsset.remove(at: index)
} else {
// 不包含:添加元素
weakSelf.selectAsset.append(weakSelf.viewModel.souces[indexPath.row])
}
weakSelf.dealPickAssetModel()
weakSelf.dealPickAssetModel(row: indexPath.row,isSelect: isSelect)
weakSelf.collectionView.reloadData()
}
......@@ -133,15 +127,36 @@ extension MaintainViewListController:UICollectionViewDataSource,UICollectionView
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
let vc = MaintaiDetailViewController()
vc.dataSource = viewModel.souces
vc.selectAsset = selectAsset
vc.scrollIndex = indexPath.row
vc.needReloadBlock = {[weak self] selects in
guard let weakSelf = self else { return }
weakSelf.selectAsset = selects
weakSelf.getData()
}
navigationController?.pushViewController(vc, animated: true)
}
func dealPickAssetModel(){
func dealPickAssetModel(row:Int,isSelect:Bool){
if let group = selectAsset.matches(containingAny: viewModel.souces[row]).first{
if group.matchedElements.count == viewModel.souces[row].count{
// 如果数量一致 说明选中了 取消全选
selectAsset.remove(at: group.groupIndex)
}else{
// 如果不一致 说明选中了部分 直接顶掉
selectAsset.remove(at: group.groupIndex)
selectAsset.append(viewModel.souces[row])
}
}else{
selectAsset.append(viewModel.souces[row])
}
if selectAsset.count > 0{
let count = selectAsset.flatMap{$0}.count
maintaiBottomView.numberL.text = "\(count)"
view.addSubview(maintaiBottomView)
maintaiBottomView.show()
}else{
maintaiBottomView.disMiss()
......
......@@ -10,23 +10,34 @@ import Foundation
class MaintaiViewModel{
var dataSouece:[String:[AssetModel]] = [:]
var dataSouece: [String: [AssetModel]] = [:]
var souceOrder: [String] = [] // 记录分组ID的添加顺序
var souces: [[AssetModel]] = []
var souces:[[AssetModel]] = []
func getMaintaiData(complect:() ->Void){
func getMaintaiData(complect: () -> Void) {
dataSouece.removeAll()
souceOrder.removeAll()
let list = GroupDatabase.shared.queryAll()
let list = GroupDatabase.shared.queryAll()
list.forEach { (localIdentifier: String, assetSize: Double, createDate: Date, mediaType: Int, groupId: String) in
if dataSouece[groupId] == nil {
dataSouece[groupId] = []
if mediaType == 2 {
// 视频不分组
let tempId = UUID().uuidString
dataSouece[tempId] = [AssetModel(localIdentifier: localIdentifier, assetSize: assetSize, createDate: createDate, mediaType: mediaType)]
souceOrder.append(tempId) // 记录添加顺序
} else {
if dataSouece[groupId] == nil {
dataSouece[groupId] = []
souceOrder.append(groupId) // 首次添加时记录顺序
}
dataSouece[groupId]?.append(AssetModel(localIdentifier: localIdentifier, assetSize: assetSize, createDate: createDate, mediaType: mediaType))
}
dataSouece[groupId]?.append(AssetModel(localIdentifier: localIdentifier, assetSize: assetSize, createDate: createDate, mediaType: mediaType))
}
souces = dataSouece.values.map{$0}
// 按照记录的顺序生成souces
souces = souceOrder.compactMap { dataSouece[$0] }
complect()
}
func refreshData(completion: @escaping () -> Void) {
......@@ -38,3 +49,5 @@ class MaintaiViewModel{
}
}
......@@ -12,9 +12,9 @@ class MaintaiDetailImageCell: UICollectionViewCell {
@IBOutlet weak var coverImage: UIImageView!
var selectBtn:UIButton!
var selectChangeBlock:(() ->Void)?
@IBOutlet weak var selectBtn: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
coverImage.layer.cornerRadius = 12
......@@ -33,11 +33,8 @@ class MaintaiDetailImageCell: UICollectionViewCell {
}
@objc func selectChange(){
@IBAction func selectClick(_ sender: Any) {
selectChangeBlock?()
}
}
......@@ -11,17 +11,17 @@
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="gTV-IL-0wX" customClass="MaintaiDetailImageCell" customModule="PhoneManager" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="229" height="274"/>
<rect key="frame" x="0.0" y="0.0" width="269" height="253"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="229" height="274"/>
<rect key="frame" x="0.0" y="0.0" width="269" height="253"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Rectangle_1543788350" translatesAutoresizingMaskIntoConstraints="NO" id="T4a-zL-UKQ">
<rect key="frame" x="0.0" y="0.0" width="229" height="274"/>
<rect key="frame" x="0.0" y="0.0" width="269" height="253"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oJ5-js-pjw">
<rect key="frame" x="199" y="244" width="30" height="30"/>
<rect key="frame" x="234" y="213" width="30" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="30" id="gGs-ha-T24"/>
<constraint firstAttribute="height" constant="30" id="mvi-bY-CFY"/>
......@@ -29,23 +29,27 @@
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" image="icon_maintai_unselect_big"/>
<state key="selected" image="icon_maintai_select_big"/>
<connections>
<action selector="selectClick:" destination="gTV-IL-0wX" eventType="touchUpInside" id="xAX-os-lxw"/>
</connections>
</button>
</subviews>
</view>
<viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="oJ5-js-pjw" secondAttribute="trailing" id="89b-qL-vQ2"/>
<constraint firstAttribute="bottom" secondItem="T4a-zL-UKQ" secondAttribute="bottom" id="B7R-M8-dpU"/>
<constraint firstAttribute="bottom" secondItem="oJ5-js-pjw" secondAttribute="bottom" constant="10" id="BfF-Td-Tcc"/>
<constraint firstAttribute="trailing" secondItem="oJ5-js-pjw" secondAttribute="trailing" constant="5" id="Iw9-UA-zNe"/>
<constraint firstItem="T4a-zL-UKQ" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" id="MoV-lR-Hqz"/>
<constraint firstAttribute="bottom" secondItem="oJ5-js-pjw" secondAttribute="bottom" id="Wa8-LG-Qmb"/>
<constraint firstItem="T4a-zL-UKQ" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" id="dJs-Pa-MhO"/>
<constraint firstAttribute="trailing" secondItem="T4a-zL-UKQ" secondAttribute="trailing" id="gyj-E3-guF"/>
</constraints>
<size key="customSize" width="229" height="274"/>
<size key="customSize" width="269" height="253"/>
<connections>
<outlet property="coverImage" destination="T4a-zL-UKQ" id="jMv-d1-6ah"/>
<outlet property="selectBtn" destination="oJ5-js-pjw" id="MVA-23-UWk"/>
</connections>
<point key="canvasLocation" x="243.51145038167937" y="98.591549295774655"/>
<point key="canvasLocation" x="274.04580152671753" y="91.197183098591552"/>
</collectionViewCell>
</objects>
<resources>
......
......@@ -24,7 +24,6 @@ class MaintaiDetailPicCell: UITableViewCell {
selectBtn = UIButton()
selectBtn.setImage(UIImage.init(named: "icon_maintai_unselect_big"), for: .normal)
selectBtn.setImage(UIImage.init(named: "icon_maintai_select_big"), for: .selected)
selectBtn.backgroundColor = .red
addSubview(selectBtn)
selectBtn.addTarget(self, action: #selector(selectChange), for: .touchUpInside)
selectBtn.snp.makeConstraints { make in
......
......@@ -20,22 +20,10 @@
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Rectangle_1543788350" translatesAutoresizingMaskIntoConstraints="NO" id="P9x-dp-1Do">
<rect key="frame" x="0.0" y="10" width="582" height="478"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="M1a-AV-qRW">
<rect key="frame" x="522" y="468" width="30" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="30" id="A2L-RK-3Li"/>
<constraint firstAttribute="height" constant="30" id="NVo-5n-WbH"/>
</constraints>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" image="icon_maintai_unselect_big"/>
<state key="selected" image="icon_maintai_select_big"/>
</button>
</subviews>
<constraints>
<constraint firstItem="P9x-dp-1Do" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="KvT-aU-rXa"/>
<constraint firstItem="P9x-dp-1Do" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="10" id="Qt9-R6-tFP"/>
<constraint firstAttribute="trailing" secondItem="M1a-AV-qRW" secondAttribute="trailing" constant="30" id="Uu9-Zr-OBB"/>
<constraint firstAttribute="bottom" secondItem="M1a-AV-qRW" secondAttribute="bottom" id="W3f-Hw-yYB"/>
<constraint firstAttribute="trailing" secondItem="P9x-dp-1Do" secondAttribute="trailing" id="bHi-TZ-Q3w"/>
<constraint firstAttribute="bottom" secondItem="P9x-dp-1Do" secondAttribute="bottom" constant="10" id="oJ9-2y-hx9"/>
</constraints>
......@@ -49,7 +37,5 @@
</objects>
<resources>
<image name="Rectangle_1543788350" width="222" height="299"/>
<image name="icon_maintai_select_big" width="18" height="18"/>
<image name="icon_maintai_unselect_big" width="18" height="18"/>
</resources>
</document>
......@@ -12,6 +12,10 @@ class MaintaiDetailTableViewCell: UITableViewCell {
@IBOutlet weak var mainCollectionView: UICollectionView!
@IBOutlet weak var pageCollectionView: UICollectionView!
var selectAsset:[AssetModel] = []
var selectCallBack:(([AssetModel]) ->Void)?
enum draggViewEnum{
case big,small,null
}
......@@ -62,11 +66,11 @@ class MaintaiDetailTableViewCell: UITableViewCell {
pageCollectionView.setCollectionViewLayout(layout, animated: false)
pageCollectionView.dataSource = self
pageCollectionView.delegate = self
let inset = ScreenW - smallW
let inset = (ScreenW - 32-24) - smallW
pageCollectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: inset)
pageCollectionView.backgroundColor = UIColor(hex: "#E2EEFF")
pageCollectionView.layer.cornerRadius = 8
pageCollectionView.register(UINib(nibName: "MaintaiDetailImageCell", bundle: nil), forCellWithReuseIdentifier: "MaintaiDetailImageCell")
pageCollectionView.register(UINib(nibName: "MaintaiDetailImageSmallCell", bundle: nil), forCellWithReuseIdentifier: "MaintaiDetailImageSmallCell")
}
......@@ -82,12 +86,43 @@ extension MaintaiDetailTableViewCell:UICollectionViewDelegate,UICollectionViewDa
if collectionView == mainCollectionView{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MaintaiDetailImageCell", for: indexPath) as! MaintaiDetailImageCell
cell.model = source[indexPath.row]
cell.selectBtn.isSelected = selectAsset.contains(source[indexPath.row])
cell.selectChangeBlock = {[weak self] in
guard let weakSelf = self else { return }
weakSelf.dealSelect(model: weakSelf.source[indexPath.row])
}
return cell
}
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MaintaiDetailImageSmallCell", for: indexPath) as! MaintaiDetailImageSmallCell
cell.model = source[indexPath.row]
cell.selectBtn.isSelected = selectAsset.contains(source[indexPath.row])
cell.selectChangeBlock = {[weak self] in
guard let weakSelf = self else { return }
weakSelf.dealSelect(model: weakSelf.source[indexPath.row])
}
return cell
}
func dealSelect(model:AssetModel){
if let index = selectAsset.firstIndex(where: {
$0 == model
}) {
// 包含:移除元素
selectAsset.remove(at: index)
} else {
// 不包含:添加元素
selectAsset.append(model)
}
mainCollectionView.reloadData()
pageCollectionView.reloadData()
selectCallBack?(selectAsset)
}
......
......@@ -27,7 +27,6 @@ class MaintaiDetialVideoCell: UITableViewCell {
selectBtn = UIButton()
selectBtn.setImage(UIImage.init(named: "icon_maintai_unselect_big"), for: .normal)
selectBtn.setImage(UIImage.init(named: "icon_maintai_select_big"), for: .selected)
selectBtn.backgroundColor = .red
contentView.addSubview(selectBtn)
contentView.bringSubviewToFront(selectBtn)
selectBtn.addTarget(self, action: #selector(selectChange), for: .touchUpInside)
......
......@@ -153,7 +153,7 @@ class SettingViewController : BaseViewController , UITableViewDelegate, UITableV
return
}
if title == "Restore Purchase"{
if title == "Keep List"{
let vc = MaintainViewListController()
navigationController?.pushViewController(vc, animated: true)
return
......
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