Commit 57db134a authored by CZ1004's avatar CZ1004

BUG处理优化

parent 8b5f7b67
...@@ -11,6 +11,10 @@ import UserMessagingPlatform ...@@ -11,6 +11,10 @@ import UserMessagingPlatform
class AdvManager : NSObject,FullScreenContentDelegate { class AdvManager : NSObject,FullScreenContentDelegate {
private static let REWARDED_INTERSTITIALAD_KEY : String = "ca-app-pub-3480207748580737/4276457203"
private static let INTERSTITIALAD_KEY : String = "ca-app-pub-3480207748580737/5836950888"
static let shared : AdvManager = AdvManager() static let shared : AdvManager = AdvManager()
// 看完广告的回调 // 看完广告的回调
...@@ -87,7 +91,7 @@ class AdvManager : NSObject,FullScreenContentDelegate { ...@@ -87,7 +91,7 @@ class AdvManager : NSObject,FullScreenContentDelegate {
func loadRewardedInterstitialAd() async { func loadRewardedInterstitialAd() async {
do { do {
rewardedInterstitialAd = try await RewardedInterstitialAd.load( rewardedInterstitialAd = try await RewardedInterstitialAd.load(
with: "ca-app-pub-3940256099942544/6978759866", request: Request()) with: AdvManager.REWARDED_INTERSTITIALAD_KEY, request: Request())
rewardedInterstitialAd?.fullScreenContentDelegate = self rewardedInterstitialAd?.fullScreenContentDelegate = self
} catch { } catch {
print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)") print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
...@@ -100,8 +104,7 @@ class AdvManager : NSObject,FullScreenContentDelegate { ...@@ -100,8 +104,7 @@ class AdvManager : NSObject,FullScreenContentDelegate {
fileprivate func loadInterstitial() async { fileprivate func loadInterstitial() async {
do { do {
interstitial = try await InterstitialAd.load( interstitial = try await InterstitialAd.load(
// fixme: 需要更改这个值 with: AdvManager.INTERSTITIALAD_KEY, request: Request())
with: "ca-app-pub-3940256099942544/4411468910", request: Request())
interstitial?.fullScreenContentDelegate = self interstitial?.fullScreenContentDelegate = self
} catch { } catch {
print("Failed to load interstitial ad with error: \(error.localizedDescription)") print("Failed to load interstitial ad with error: \(error.localizedDescription)")
......
...@@ -57,7 +57,7 @@ class HomeInfoViewController:BaseViewController { ...@@ -57,7 +57,7 @@ class HomeInfoViewController:BaseViewController {
} }
func deleteOp(imgs : [AssetModel]){ func deleteOp(imgs : [AssetModel],isAfterAdv:Bool){
var tempStringArray : [String] = [] var tempStringArray : [String] = []
for item in imgs { for item in imgs {
tempStringArray.append(item.localIdentifier) tempStringArray.append(item.localIdentifier)
...@@ -66,7 +66,9 @@ class HomeInfoViewController:BaseViewController { ...@@ -66,7 +66,9 @@ class HomeInfoViewController:BaseViewController {
guard let self else {return} guard let self else {return}
// 更新免费次数 // 更新免费次数
updateFreeTimes() if isAfterAdv == false {
updateFreeTimes()
}
// 删除缓存数据 // 删除缓存数据
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: imgs) PhotoDataManager.manager.removeDataWhenDeleteInPage(data: imgs)
...@@ -81,14 +83,15 @@ class HomeInfoViewController:BaseViewController { ...@@ -81,14 +83,15 @@ class HomeInfoViewController:BaseViewController {
self?.ids = model.titleModelArray[1].assets self?.ids = model.titleModelArray[1].assets
} }
if self?.type == .SimilarVideos { if self?.type == .SimilarVideos {
self?.ids = model.otherModelArray[1].assets self?.ids = model.otherModelArray[3].assets
} }
if self?.type == .similarScreenshots { if self?.type == .similarScreenshots {
self?.ids = model.otherModelArray[3].assets self?.ids = model.otherModelArray[1].assets
} }
self?.tablewView.ids = self?.ids
} }
}) })
self.tablewView.deleteModel() self.tablewView.deleteModel(array: imgs)
func updateFreeTimes(){ func updateFreeTimes(){
...@@ -139,7 +142,7 @@ class HomeInfoViewController:BaseViewController { ...@@ -139,7 +142,7 @@ class HomeInfoViewController:BaseViewController {
} }
}else { }else {
// 如果小于直接删除 // 如果小于直接删除
deleteOp(imgs: array as! [AssetModel]) deleteOp(imgs: array as! [AssetModel],isAfterAdv: false)
} }
}else{ }else{
...@@ -166,7 +169,7 @@ class HomeInfoViewController:BaseViewController { ...@@ -166,7 +169,7 @@ class HomeInfoViewController:BaseViewController {
} }
}else{ }else{
// 如果只是一张,直接删除 // 如果只是一张,直接删除
deleteOp(imgs: array as! [AssetModel]) deleteOp(imgs: array as! [AssetModel],isAfterAdv: false)
} }
} }
} }
...@@ -186,42 +189,18 @@ class HomeInfoViewController:BaseViewController { ...@@ -186,42 +189,18 @@ class HomeInfoViewController:BaseViewController {
// 广告看完再结束 // 广告看完再结束
AdvManager.shared.finisedCallBack = { AdvManager.shared.finisedCallBack = {
DispatchQueue.main.async { DispatchQueue.main.async {
deleteOp(imgs: tempArr) deleteOp(imgs: tempArr,isAfterAdv: true)
} }
} }
} else { } else {
DispatchQueue.main.async { DispatchQueue.main.async {
deleteOp(imgs: tempArr) deleteOp(imgs: tempArr,isAfterAdv: false)
} }
} }
} }
}else { }else {
deleteOp(imgs: array as! [AssetModel]) deleteOp(imgs: array as! [AssetModel],isAfterAdv: false)
} }
//
// if HomePayModel.share.isNoAd == false {
// // 重复
// if self.type == .duplicates {
// HomePayViewController.show {
//
// deleteOp(array)
// }
// }else if self.type == .similar {
// // 相似
// HomeNoAdsViewController.show {
// deleteOp(array)
// }
// }else{
// HomeNoAdsViewController.show {
// deleteOp(array)
// }
// }
// }else {
// deleteOp(array)
// }
//
} }
return sview return sview
......
...@@ -411,7 +411,7 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti ...@@ -411,7 +411,7 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti
} }
}else { }else {
// 如果小于直接删除 // 如果小于直接删除
deleteAction(count: self.selectedModel.count) deleteAction(count: self.selectedModel.count,isAfterAdv: false)
} }
}else{ }else{
...@@ -438,7 +438,7 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti ...@@ -438,7 +438,7 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti
} }
}else{ }else{
// 如果只是一张,直接删除 // 如果只是一张,直接删除
deleteAction(count: self.selectedModel.count) deleteAction(count: self.selectedModel.count,isAfterAdv: false)
} }
} }
} }
...@@ -447,14 +447,14 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti ...@@ -447,14 +447,14 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti
self.popAdverTisement() self.popAdverTisement()
// 广告看完再结束 // 广告看完再结束
AdvManager.shared.finisedCallBack = { AdvManager.shared.finisedCallBack = {
self.deleteAction(count: deleteCount) self.deleteAction(count: deleteCount,isAfterAdv: true)
} }
} else { } else {
self.deleteAction(count: deleteCount) self.deleteAction(count: deleteCount,isAfterAdv: false)
} }
} }
}else{ }else{
deleteAction(count: self.selectedModel.count) deleteAction(count: self.selectedModel.count,isAfterAdv: false)
} }
...@@ -465,7 +465,7 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti ...@@ -465,7 +465,7 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti
func popAdverTisement(){ func popAdverTisement(){
AdvManager.shared.showInterstitialAd(vc: self) AdvManager.shared.showInterstitialAd(vc: self)
} }
func deleteAction(count:Int){ func deleteAction(count:Int,isAfterAdv:Bool){
// 删除当前选择 // 删除当前选择
let tempArray = Array(self.selectedModel.prefix(count)) let tempArray = Array(self.selectedModel.prefix(count))
self.selectedModel = tempArray self.selectedModel = tempArray
...@@ -476,7 +476,9 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti ...@@ -476,7 +476,9 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti
}){ success, error in }){ success, error in
if(success){ if(success){
print("删除文件成功") print("删除文件成功")
self.updateFreeTimes() if isAfterAdv == false {
self.updateFreeTimes()
}
self.updateCurrentPageWhenDeleteAny() self.updateCurrentPageWhenDeleteAny()
}else { }else {
if let error = error { if let error = error {
...@@ -500,14 +502,14 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti ...@@ -500,14 +502,14 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti
for item in self.selectedModel { for item in self.selectedModel {
// 移除当前数据 // 移除当前数据
self.resourceData.removeAll{ $0.localIdentifier == item.localIdentifier } self.resourceData.removeAll{ $0.localIdentifier == item.localIdentifier }
// 更新下头部数量
DispatchQueue.main.async {
if self.currentHeaderView != nil {
self.currentHeaderView?.countLabel.text = "\(self.resourceData.count) Photos"
}
}
} }
// 更新下头部数量
DispatchQueue.main.async {
if self.currentHeaderView != nil {
self.currentHeaderView?.countLabel.text = "\(self.resourceData.count) Photos"
}
}
// 清理下缓存数据 // 清理下缓存数据
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel) PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel)
......
...@@ -355,7 +355,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie ...@@ -355,7 +355,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
} }
}else { }else {
// 如果小于直接删除 // 如果小于直接删除
deleteAction(count: self.selectedModel.count) deleteAction(count: self.selectedModel.count,isAfterAdv: false)
} }
}else{ }else{
...@@ -382,7 +382,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie ...@@ -382,7 +382,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
} }
}else{ }else{
// 如果只是一张,直接删除 // 如果只是一张,直接删除
deleteAction(count: self.selectedModel.count) deleteAction(count: self.selectedModel.count,isAfterAdv: false)
} }
} }
...@@ -393,14 +393,14 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie ...@@ -393,14 +393,14 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
self.popAdverTisement() self.popAdverTisement()
// 广告看完再结束 // 广告看完再结束
AdvManager.shared.finisedCallBack = { AdvManager.shared.finisedCallBack = {
self.deleteAction(count: deleteCount) self.deleteAction(count: deleteCount,isAfterAdv: true)
} }
} else { } else {
self.deleteAction(count: deleteCount) self.deleteAction(count: deleteCount,isAfterAdv: false)
} }
} }
}else{ }else{
deleteAction(count: self.selectedModel.count) deleteAction(count: self.selectedModel.count,isAfterAdv: false)
} }
} }
...@@ -419,7 +419,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie ...@@ -419,7 +419,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
AdvManager.shared.showInterstitialAd(vc: self) AdvManager.shared.showInterstitialAd(vc: self)
} }
func deleteAction(count:Int){ func deleteAction(count:Int,isAfterAdv:Bool){
let tempArray = Array(self.selectedModel.prefix(count)) let tempArray = Array(self.selectedModel.prefix(count))
self.selectedModel = tempArray self.selectedModel = tempArray
// 删除当前选择 // 删除当前选择
...@@ -429,7 +429,10 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie ...@@ -429,7 +429,10 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
}){ success, error in }){ success, error in
if(success){ if(success){
print("删除文件成功") print("删除文件成功")
self.updateFreeTimes() // 如果是看广告删除的,且还有免费次数
if isAfterAdv == false {
self.updateFreeTimes()
}
// 移除当前总数据源的数据 // 移除当前总数据源的数据
self.updateCurrentPageWhenDeleteAny() self.updateCurrentPageWhenDeleteAny()
}else { }else {
...@@ -442,20 +445,12 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie ...@@ -442,20 +445,12 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
} }
func updateCurrentPageWhenDeleteAny(){ func updateCurrentPageWhenDeleteAny(){
for item in self.selectedModel { for item in self.selectedModel {
// 移除当前数据 // 移除当前数据
self.resourceData.removeAll{ $0.localIdentifier == item.localIdentifier } self.resourceData.removeAll{ $0.localIdentifier == item.localIdentifier }
// 更新下头部数量
DispatchQueue.main.async {
self.selectedModel.removeAll()
self.deleteButton.backgroundColor = UIColor(red: 0.7, green: 0.7, blue: 0.7, alpha: 1)
self.deleteButton.setTitle("Delete", for: .normal)
if self.currentHeaderView != nil {
self.currentHeaderView?.sizeLabel.text = "\(self.resourceData.count) Videos"
}
}
} }
// 清理下缓存数据 // 清理下缓存数据
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel) PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel)
...@@ -467,6 +462,14 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie ...@@ -467,6 +462,14 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
// 更新页面 // 更新页面
DispatchQueue.main.async { DispatchQueue.main.async {
self.selectedModel.removeAll()
self.deleteButton.backgroundColor = UIColor(red: 0.7, green: 0.7, blue: 0.7, alpha: 1)
self.deleteButton.setTitle("Delete", for: .normal)
if self.currentHeaderView != nil {
self.currentHeaderView?.sizeLabel.text = "\(self.resourceData.count) Videos"
}
UIView.transition(with: self.collectionView, duration: 0.3, options: .transitionCrossDissolve, animations: { UIView.transition(with: self.collectionView, duration: 0.3, options: .transitionCrossDissolve, animations: {
self.collectionView.reloadData() self.collectionView.reloadData()
}, completion: nil) }, completion: nil)
......
...@@ -167,36 +167,49 @@ class HomeInfoView :UIView{ ...@@ -167,36 +167,49 @@ class HomeInfoView :UIView{
func getSelectedArray() -> [AssetModel] { func getSelectedArray() -> [AssetModel] {
var selectedArray:[AssetModel] = [] var selectedArray:[AssetModel] = []
for smodel in models { for smodel in models {
for smodel2 in smodel.smodels ?? []{ for smodel2 in smodel.smodels ?? []{
if smodel2.isSeleted ?? false { if smodel2.isSeleted ?? false {
if selectedArray.count < Singleton.shared.maxDeleteCount { if selectedArray.count < Singleton.shared.maxDeleteCount {
selectedArray.append(smodel2.id!) selectedArray.append(smodel2.id!)
}else{
smodel2.isSeleted = false
} }
} }
} }
} }
return selectedArray return selectedArray
} }
func deleteModel() { func deleteModel(array:[AssetModel]) {
var modelRecord : [Int] = [] var newModel : [HomeInfoTableItem] = []
for i in 0..<models.count { for i in 0..<models.count {
// 过滤掉 isSelected 为 true 的 smodel2 // 过滤掉 isSelected 为 true 的 smodel2
let array : [ImageSeletedCollectionItem] = models[i].smodels! var arrayT : [ImageSeletedCollectionItem] = models[i].smodels!
for item in array { for item in array {
if item.isSeleted == true { arrayT = arrayT.filter { !($0.id?.localIdentifier == item.localIdentifier) }
modelRecord.append(i) }
break if (arrayT.count >= 2){
} let temModel : HomeInfoTableItem = HomeInfoTableItem()
temModel.type = models[i].type
temModel.smodels = updateSelectToDesSelect(data: arrayT)
temModel.titleText = models[i].titleText
newModel.append(models[i])
}
}
// 将新的数据全部改成未被选中状态
func updateSelectToDesSelect(data:[ImageSeletedCollectionItem])->[ImageSeletedCollectionItem]{
var dataArray : [ImageSeletedCollectionItem] = []
for item in data {
item.isSeleted = false
dataArray.append(item)
} }
models[i].smodels = models[i].smodels?.filter { !($0.isSeleted ?? false) } return dataArray
} }
self.models = newModel
// 更新下首页数据以及缓存数据 // 更新下首页数据以及缓存数据
let dataUpdated = Notification.Name("DataUpdatedNotification") let dataUpdated = Notification.Name("DataUpdatedNotification")
NotificationCenter.default.post(name: dataUpdated, object: nil, userInfo: nil) NotificationCenter.default.post(name: dataUpdated, object: nil, userInfo: nil)
......
...@@ -236,21 +236,19 @@ class SecretViewController: BaseViewController { ...@@ -236,21 +236,19 @@ class SecretViewController: BaseViewController {
guard let self = self else { return } guard let self = self else { return }
// 先弹出广告 // 先弹出广告
popAdverTisement() popAdverTisement()
AdvManager.shared.finisedCallBack = {
if b.state == .add { if b.state == .add {
self.AddAction.show(); self.AddAction.show();
self.AddAction.callback = { idx in self.AddAction.callback = { idx in
self.AddImagePicker(idx) self.AddImagePicker(idx)
}
}else{
self.deleteData()
} }
}else{
self.deleteData()
} }
func popAdverTisement(){ func popAdverTisement(){
if AdvManager.shared.advTimeAfterInAPP <= 0 { AdvManager.shared.showInterstitialAd(vc: self)
AdvManager.shared.showInterstitialAd(vc: self)
}
} }
} }
return b return b
}() }()
......
...@@ -61,6 +61,7 @@ class PhotoAndVideoMananger { ...@@ -61,6 +61,7 @@ class PhotoAndVideoMananger {
func setAssets() { func setAssets() {
let fetchOptions = PHFetchOptions() let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
let photoAllAssets = PHAsset.fetchAssets(with: .image, options: fetchOptions) let photoAllAssets = PHAsset.fetchAssets(with: .image, options: fetchOptions)
...@@ -933,25 +934,40 @@ class PhotoAndVideoMananger { ...@@ -933,25 +934,40 @@ class PhotoAndVideoMananger {
var allDuplicateGroups: [[AssetModel]] = [] var allDuplicateGroups: [[AssetModel]] = []
let chunkSize = 10 // 每次处理 10 张图片 let chunkSize = 10 // 每次处理 10 张图片
func isGroupDuplicate(_ newGroup: [AssetModel]) -> Bool { func convertToAssetModels(_ assets: [PHAsset]) -> [AssetModel] {
for existingGroup in allDuplicateGroups { return assets.compactMap { asset in
if Set(newGroup.map { $0.localIdentifier }) == Set(existingGroup.map { $0.localIdentifier }) { guard let creationDate = asset.creationDate else { return nil }
return true return AssetModel(localIdentifier: asset.localIdentifier, assetSize: self.findAssetSize(asset: asset), createDate: creationDate)
}
}
func findGroupIndex(for hash: String, in groups: [[AssetModel]]) -> Int? {
for (index, group) in groups.enumerated() {
if let firstAssetModel = group.first {
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [firstAssetModel.localIdentifier], options: nil)
if fetchResult.count > 0 {
let firstAsset = fetchResult.object(at: 0)
let existingHash = self.calculateHash(for: firstAsset)
if existingHash == hash {
return index
}
}
} }
} }
return false return nil
} }
for chunk in assets.chunked(into: chunkSize) { for chunk in assets.chunked(into: chunkSize) {
for asset in chunk { for asset in chunk {
if let hash = self.calculateHash(for: asset) { if let hash = self.calculateHash(for: asset) {
hashToAssets[hash, default: []].append(asset) hashToAssets[hash, default: []].append(asset)
if hashToAssets[hash]!.count > 1 && hashToAssets[hash]!.count == 2 { if hashToAssets[hash]!.count > 1 {
var currentGroup: [AssetModel] = [] let currentGroup = convertToAssetModels(hashToAssets[hash]!)
for asset in hashToAssets[hash]! { if let existingGroupIndex = findGroupIndex(for: hash, in: allDuplicateGroups) {
currentGroup.append(AssetModel(localIdentifier: asset.localIdentifier, assetSize: self.findAssetSize(asset: asset), createDate: asset.creationDate!)) // 如果已存在组,更新该组
} allDuplicateGroups[existingGroupIndex] = currentGroup
if !isGroupDuplicate(currentGroup) { } else {
// 如果不存在组,添加新组
allDuplicateGroups.append(currentGroup) allDuplicateGroups.append(currentGroup)
} }
// 持续返回已处理好的分组数据 // 持续返回已处理好的分组数据
...@@ -960,25 +976,11 @@ class PhotoAndVideoMananger { ...@@ -960,25 +976,11 @@ class PhotoAndVideoMananger {
} }
} }
} }
// 过滤出重复的分组
let duplicateGroups = hashToAssets.filter { $0.value.count > 1 }.map { $0.value }
for (_, group) in duplicateGroups.enumerated() {
var currentGroup: [AssetModel] = []
for asset in group {
currentGroup.append(AssetModel(localIdentifier: asset.localIdentifier, assetSize: self.findAssetSize(asset: asset), createDate: asset.creationDate!))
}
if !isGroupDuplicate(currentGroup) {
allDuplicateGroups.append(currentGroup)
}
// 持续返回已处理好的分组数据
progressCompletion(allDuplicateGroups)
}
// 全部找完之后返回所有重复组 // 全部找完之后返回所有重复组
completion(allDuplicateGroups) completion(allDuplicateGroups)
} }
} }
// 计算图片的 PHash 值 // 计算图片的 PHash 值
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<false/> <false/>
</dict> </dict>
<key>GADApplicationIdentifier</key> <key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string> <string>ca-app-pub-3480207748580737~4236262472</string>
<key>SKAdNetworkItems</key> <key>SKAdNetworkItems</key>
<array> <array>
<dict> <dict>
......
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