Commit c41d849d authored by CZ1004's avatar CZ1004

首页优化

parent 321e2eec
This diff is collapsed.
......@@ -305,6 +305,8 @@ class CompressCompletedViewController : BaseViewController{
}){ success, error in
if(success){
self.updateCompressData(flag: data.ident)
var deleteModel = AssetModel(localIdentifier: data.ident, assetSize: data.orgSize, createDate: data.createDate)
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: [deleteModel])
print("删除文件成功")
}else {
if let error = error {
......
......@@ -67,6 +67,10 @@ class HomeInfoViewController:BaseViewController {
}
}
}
// 删除缓存数据
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: array as! [AssetModel])
if HomePayModel.share.isNoAd == false {
if self.type == .duplicates { // 重复
HomePayViewController.show {
......
......@@ -357,8 +357,10 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti
print("删除文件成功")
// 移除当前总数据源的数据
for item in self.selectedModel {
// 移除当前数据
self.resourceData.removeAll{ $0.localIdentifier == item.localIdentifier }
}
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel)
}else {
if let error = error {
print("删除文件时出错: \(error.localizedDescription)")
......
......@@ -332,6 +332,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
for item in self.selectedModel {
self.resourceData.removeAll{ $0.localIdentifier == item.localIdentifier }
}
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel)
}else {
if let error = error {
print("删除文件时出错: \(error.localizedDescription)")
......
......@@ -18,9 +18,40 @@ class HomeViewController:BaseViewController {
super.viewDidLoad()
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)
view.backgroundColor = .green
homeView = HomeView(frame: view.bounds)
......@@ -120,12 +151,16 @@ class HomeViewController:BaseViewController {
}
func setupData() {
// 详情数据
PhotoDataManager.manager.loadFromFileSystem(resultModel: {[weak self] model in
self?.homeView?.model = model
DispatchQueue.main.async {
self?.homeView?.model = model
self?.homeView?.collectionView.reloadData()
}
})
......@@ -149,6 +184,18 @@ class HomeViewController:BaseViewController {
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// 可能是删除数据,重新获取下
PhotoDataManager.manager.loadFromFileSystem(resultModel: {[weak self] model in
DispatchQueue.main.async {
self?.homeView?.model = model
self?.homeView?.collectionView.reloadData()
}
})
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
......@@ -183,8 +230,126 @@ class HomeViewController:BaseViewController {
}
}
// 重复图片
@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) {
......
......@@ -16,6 +16,10 @@ class HomeView:UIView {
private var bottomView:UIView?
var dupHeadCell : HomeTitleCollectionCell?
var similarHeadCell : HomeTitleCollectionCell?
var titleCallBack:(HomePhotosModel,PhotsFileType)->Void = {model,type in}
var indexCallBack:callBack<Any> = {index in }
......@@ -32,7 +36,7 @@ class HomeView:UIView {
guard let self else {return}
self.collectionView.reloadData()
// self.collectionView.reloadData()
}
}
}
......@@ -235,6 +239,11 @@ extension HomeView:WaterfallMutiSectionDelegate,UICollectionViewDataSource,UICol
case 0:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HomeTitleCollectionCell.identifiers, for: indexPath) as! HomeTitleCollectionCell
cell.model = model?.titleModelArray[indexPath.row]
if indexPath.row == 0 {
self.dupHeadCell = cell
}else{
self.similarHeadCell = cell
}
return cell
case 1:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HomeOtherCollectionCell.identifier, for: indexPath) as! HomeOtherCollectionCell
......
......@@ -31,7 +31,7 @@ class HomeOtherCollectionCell: UICollectionViewCell {
}()
let countLabel: UILabel = {
public var countLabel: UILabel = {
let label = UILabel()
label.textColor = .white
label.font = .systemFont(ofSize: 10, weight: .medium)
......
......@@ -14,9 +14,9 @@ class HomeTitleCollectionCell:UICollectionViewCell {
private var titleLabel: UILabel?
private var fileLabel:UILabel?
public var fileLabel:UILabel?
private var collectionView: UICollectionView?
public var collectionView: UICollectionView?
private var nextImage:UIImageView?
......
......@@ -173,7 +173,7 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
return cell
}else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowItemCellID, for: indexPath) as! PMShowItemCell
cell.icon = self.homeDataSource![indexPath.row].image!
cell.icon = self.homeDataSource![indexPath.row].image
cell.isCurrent = (self.currentIdx == indexPath.row)
return cell
}
......
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