Commit 701a5e31 authored by CZ1004's avatar CZ1004

【优化】处理部分逻辑

parent e667bf42
......@@ -53,22 +53,36 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationWillTerminate(_ application: UIApplication) {
// 保存单利中所有垃圾桶的数据
saveDataToTrashDB()
saveDataToTrashDB(data: Singleton.shared.trashData)
// 保存单利中所有垃圾桶的数据
saveDataToKeepListhDB(data: Singleton.shared.keepList)
}
func saveDataToTrashDB(){
let data = Singleton.shared.trashData
var count = 0
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 {
count = count + 1
if !success {
Print("保存单利数据到数据库失败")
}
}
}
Singleton.shared.trashData = [:]
Print("保留单利数据到数据库--\(count)条")
}
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) {
......
{
"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
}
}
......@@ -50,8 +50,11 @@ class PhotoRemoveViewController: BaseViewController {
// MARK: - 初始化
init(data: [AssetModel],currentIndex:Int,mediaType:TrashTypeEnum) {
self.mediaType = mediaType
self.currentIndex = currentIndex
self.dataModel = data
let tempData = data
// 从currentIndex截断拼接在末尾,设置currentIndex为0
let result = Array(tempData[currentIndex...]) + Array(tempData[..<currentIndex])
self.currentIndex = 0
self.dataModel = result
super.init(nibName: nil, bundle: nil)
}
......@@ -101,6 +104,13 @@ class PhotoRemoveViewController: BaseViewController {
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
// 视图消失的时候存到数据库
saveDataToKeepListDB()
}
func changeDateToString() -> String{
let model = self.dataModel[self.currentIndex]
return formatter.string(from: model.createDate)
......@@ -184,7 +194,7 @@ class PhotoRemoveViewController: BaseViewController {
bringCurrentViewToFront()
}
// 当保留的时候存数据
// 存垃圾桶数据到单利
func saveDataToSigtonTrash(){
// 拿到单利数据
if let type = self.mediaType{
......@@ -198,6 +208,21 @@ class PhotoRemoveViewController: BaseViewController {
}
self.showCurrentPageUIWhenTashDataChanged()
}
// 存保留数据到单利
func saveDataToSigtonKeepList(){
// 拿到单利数据
if let type = self.mediaType{
if let dataSg = Singleton.shared.keepList[type]{
var tempArray = dataSg
tempArray.append(self.dataModel[currentIndex])
Singleton.shared.keepList[type] = tempArray
}else{
Singleton.shared.keepList[type] = [self.dataModel[currentIndex]]
}
}
}
func saveDataToTrashDB(){
if let type = self.mediaType{
if let dataSg = Singleton.shared.trashData[type]{
......@@ -213,26 +238,22 @@ class PhotoRemoveViewController: BaseViewController {
showCurrentPageUIWhenTashDataChanged()
}
// 将数据存到保留列表
func saveDataToKeepLib(){
// 如果单利中有数据,那么先把单利中的数据存到数据库
saveDataToTrashDB()
// 保留当前图片到保留列表
/// 将保留列表单利数据存到数据库
func saveDataToKeepListDB(){
let uinqueId = UUID().uuidString
if let type = self.mediaType{
let item = self.dataModel[currentIndex]
let success = GroupDatabase.shared.insert(localIdentifier: item.localIdentifier, assetSize: item.assetSize, createDate: item.createDate, mediaType: type.dbType, groupId: UUID().uuidString)
if success {
Print("存入保留列表成功")
}else{
Print("存入保留列表失败")
if let dataSg = Singleton.shared.keepList[type]{
for item in dataSg{
let success = GroupDatabase.shared.insert(localIdentifier: item.localIdentifier, assetSize: item.assetSize, createDate: item.createDate, mediaType: type.dbType,groupId: uinqueId)
if success == false {
Print("保留单利数据到数据库保留列表失败")
}
}
Singleton.shared.keepList[type] = []
}
}
}
// MARK: - 手势处理
@objc private func handlePan(_ gesture: UIPanGestureRecognizer) {
......@@ -267,8 +288,10 @@ class PhotoRemoveViewController: BaseViewController {
if abs(actualTranslation.x) > actionMargin || abs(velocity.x) > 500 {
removeCurrentView(translation: actualTranslation, velocity: velocity)
if actualTranslation.x > 0 {
// 保存垃圾桶数据到数据库
saveDataToTrashDB()
// 保留操作
saveDataToKeepLib()
saveDataToSigtonKeepList()
}
if actualTranslation.x < 0 {
// 删除操作,先存到单利
......@@ -346,6 +369,11 @@ class PhotoRemoveViewController: BaseViewController {
let removedView = photoViews.removeFirst()
removedView.removeFromSuperview()
// 当划到最后一张的时候就不再滑动了
if currentIndex == dataModel.count{
return
}
// 创建新视图并更新内容
let newView = PhotosRemoveBaseView()
newView.frame = CGRectMake(15, statusBarHeight + 44, self.view.width - 30, self.view.height - 78 - safeHeight - statusBarHeight - 44)
......
......@@ -82,7 +82,7 @@ class PhotoRemoveNavView: UIView {
}
resetButton = UIButton()
resetButton.setImage(UIImage(named: "nav_back"), for: .normal)
resetButton.setImage(UIImage(named: "Frame 3"), for: .normal)
resetButton.addTarget(self, action: #selector(resetButtonAction), for: .touchUpInside)
resetButton.isHidden = true
self.addSubview(resetButton)
......
......@@ -217,11 +217,26 @@ extension HomeInfoTableViewCell:UICollectionViewDelegate,UICollectionViewDataSou
// 显示保留按钮或者最佳匹配结果按钮
cell.allKeepButton.isHidden = indexPath.item != 0 || self.type == .duplicates
cell.bestResultButton.isHidden = indexPath.item != 0 || self.type == .duplicates
cell.model = model?.smodels?[indexPath.row]
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
guard let self else {return}
......
......@@ -19,6 +19,8 @@ class ImageSeletedCollectionCell:UICollectionViewCell {
var callBack:callBack<Any> = {text in}
var keepAllCallBack : ()->Void = {}
lazy var allKeepButton : UIButton = {
let button = UIButton(type: .custom)
......@@ -222,6 +224,8 @@ class ImageSeletedCollectionCell:UICollectionViewCell {
extension ImageSeletedCollectionCell {
@objc func allKeepButtonAction(){
Print("点击了全部保留按钮")
self.keepAllCallBack()
}
}
......@@ -21,6 +21,8 @@ class Singleton {
var trashData : [TrashTypeEnum : [AssetModel]] = [:]
var keepList : [TrashTypeEnum : [AssetModel]] = [:]
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