Commit 36d4c4e3 authored by CZ1004's avatar CZ1004

【新增】首页筛选

parent 52802867
{
"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
}
}
//
// DateSelectButtonView.swift
// PhoneManager
//
// Created by edy on 2025/5/12.
//
import Foundation
class DateSelectButtonView : UIView {
var type : PikerDateType?
lazy var dateButton : UIButton = {
let button = UIButton(type: .custom)
button.setTitle("Start date", for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .semibold)
button.setTitleColor(UIColor(red: 0.07, green: 0.07, blue: 0.07, alpha: 1), for: .normal)
button.backgroundColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1)
button.layer.borderColor = UIColor(red: 0.96, green: 0.96, blue: 0.96, alpha: 1).cgColor
button.layer.borderWidth = 1.0
button.layer.cornerRadius = 21
button.clipsToBounds = true
return button
}()
lazy var closeButton : UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "ic_close_charging"), for: .normal)
button.addTarget(self, action: #selector(closeButtonAction), for: .touchUpInside)
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.addSubview(dateButton)
self.addSubview(closeButton)
self.dateButton.snp.makeConstraints { make in
make.left.bottom.right.equalToSuperview()
make.top.equalToSuperview().offset(4)
}
self.closeButton.snp.makeConstraints { make in
make.width.height.equalTo(16)
make.top.equalToSuperview()
make.right.equalToSuperview().offset(-5)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc func closeButtonAction(){
reSetButtonTitle()
}
func reSetButtonTitle() {
DispatchQueue.main.async {
let title = self.type == .start ? "Start date" : "Over date"
self.dateButton.setTitle(title, for: .normal)
self.closeButton.isHidden = true
}
}
}
......@@ -42,6 +42,7 @@ class HomeInfoView :UIView {
lazy var headerView:HomeInfoTitleView = {
let sview:HomeInfoTitleView = HomeInfoTitleView(frame: CGRect(x: 0, y: 0, width: width, height: 84))
sview.titleLabel.text = self.titleText
sview.filterButton.isHidden = self.type != .similar
tableView.addSubview(sview)
return sview
}()
......@@ -101,6 +102,38 @@ class HomeInfoView :UIView {
super.init(frame: frame)
setupUI()
self.headerView.sortViewSubmitCallBack = {[weak self]filterModel in
guard let self else {return}
// 从源头获取相似数据
PhotoDataManager.manager.loadFromFileSystem(resultModel: {[weak self] model in
guard let self else {return}
let tempData = self.filterDataByDate(orgModels: model.titleModelArray[1].assets, startDate: filterModel.startDate, endDate: filterModel.endDate)
// 重新更新下数据源
self.ids = self.sortData(source: tempData, type: filterModel.sortType)
var tempModels : [HomeInfoTableItem] = []
for array in self.ids ?? [] {
var smodels:[ImageSeletedCollectionItem] = []
for id in array {
let smodel = ImageSeletedCollectionItem()
smodel.id = id
smodel.isSeleted = false
smodels.append(smodel)
}
let smodel = HomeInfoTableItem()
smodel.type = type
smodel.smodels = smodels
smodel.titleText = titleText
tempModels.append(smodel)
}
models = tempModels
DispatchQueue.main.async {
// FIXME: 闪屏
self.tableView.reloadSections(IndexSet(integer: 0), with: .automatic)
}
})
}
}
required init?(coder: NSCoder) {
......@@ -275,6 +308,7 @@ extension HomeInfoView:UITableViewDataSource,UITableViewDelegate {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: HomeInfoTableViewCell.identifier, for: indexPath) as! HomeInfoTableViewCell
cell.type = self.type
cell.model = models[indexPath.row]
......@@ -303,10 +337,62 @@ extension HomeInfoView:UITableViewDataSource,UITableViewDelegate {
return UIView()
}
func filterDataByDate(orgModels : [[AssetModel]], startDate:Date? ,endDate : Date?)->[[AssetModel]]{
var tempArray : [[AssetModel]] = []
for item in orgModels {
var array = item
if startDate != nil {
array = array.filter({$0.createDate > startDate!})
}
if endDate != nil {
array = array.filter({$0.createDate < endDate!})
}
if array.count > 2 {
tempArray.append(item)
}
}
return tempArray
}
func sortData(source: [[AssetModel]], type: ResouceSortType) -> [[AssetModel]] {
switch type {
case .largest:
return source.sorted { subArray1, subArray2 in
let sum1 = subArray1.reduce(0) { $0 + $1.assetSize }
let sum2 = subArray2.reduce(0) { $0 + $1.assetSize }
return sum1 > sum2
}
case .smallest:
return source.sorted { subArray1, subArray2 in
let sum1 = subArray1.reduce(0) { $0 + $1.assetSize }
let sum2 = subArray2.reduce(0) { $0 + $1.assetSize }
return sum1 < sum2
}
case .latest:
return source.sorted { subArray1, subArray2 in
guard let max1 = subArray1.max(by: { $0.createDate < $1.createDate })?.createDate else { return false }
guard let max2 = subArray2.max(by: { $0.createDate < $1.createDate })?.createDate else { return true }
return max1 > max2
}
case .oldest:
return source.sorted { subArray1, subArray2 in
guard let min1 = subArray1.min(by: { $0.createDate < $1.createDate })?.createDate else { return false }
guard let min2 = subArray2.min(by: { $0.createDate < $1.createDate })?.createDate else { return true }
return min1 < min2
}
}
}
}
class HomeInfoTitleView:UIView {
var sortViewSubmitCallBack : (ResourceFilterBoxModel)->Void = {model in}
lazy var titleLabel:UILabel = {
let sview:UILabel = UILabel()
......@@ -333,6 +419,23 @@ class HomeInfoTitleView:UIView {
return sview
}()
// 筛选按钮
lazy var filterButton : UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "Frame 1"), for: .normal)
button.setTitle("The largest", for: .normal)
button.layer.cornerRadius = 14
button.clipsToBounds = true
button.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 0.1000)
button.titleLabel?.font = UIFont.systemFont(ofSize: 12, weight: .semibold)
button.setTitleColor(UIColor(red: 0.07, green: 0.07, blue: 0.07, alpha: 1), for: .normal)
button.addTarget(self, action: #selector(filterButtonAction), for: .touchUpInside)
button.isHidden = true
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
......@@ -348,6 +451,15 @@ class HomeInfoTitleView:UIView {
backgroundColor = .white
addSubview(titleLabel)
addSubview(numberLabel)
addSubview(self.filterButton)
self.filterButton.snp.makeConstraints { make in
make.top.equalToSuperview().offset(35)
make.right.equalToSuperview().offset(-15)
make.height.equalTo(28)
make.width.equalTo(98)
}
}
func changeContent(title:String,allNumber:Int,seletedCount:Int) {
......@@ -381,6 +493,20 @@ class HomeInfoTitleView:UIView {
numberLabel.attributedText = attributedString2
numberLabel.y = height - numberLabel.height - 8
}
@objc func filterButtonAction(){
if let cWindow = cWindow {
let filterView : ResourceFilterBoxView = ResourceFilterBoxView.init(frame: cWindow.bounds)
cWindow.addSubview(filterView)
filterView.submitCallBack = {model in
DispatchQueue.main.async {
self.filterButton.setTitle(model.sortType.rawValue, for: .normal)
}
self.sortViewSubmitCallBack(model)
}
}
}
}
......@@ -437,5 +563,7 @@ class HomeInfoDeleteView:UIView {
callBack(OperStatus.delete)
}
}
//
// YearMonthPickerView.swift
// PhoneManager
//
// Created by edy on 2025/5/12.
//
import Foundation
enum PikerDateType {
case start
case end
}
class YearMonthPickerView: UIView {
var type : PikerDateType = .start
// MARK: - Properties
private var selectedYear: Int = 0
private var selectedMonth: Int = 0
var onCancel: (() -> Void)?
var onConfirm: ((_ type : PikerDateType,_ year: Int, _ month: Int) -> Void)?
private let pickerView: UIPickerView = {
let picker = UIPickerView()
picker.backgroundColor = .white
return picker
}()
private let years = Array(Array(Calendar.current.component(.year, from: Date())-30...Calendar.current.component(.year, from: Date())).reversed())
private lazy var months: [String] = {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US")
return formatter.monthSymbols
}()
// MARK: - Initialization
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupView()
}
// MARK: - Setup
private func setupView() {
backgroundColor = .white
layer.cornerRadius = 12
layer.masksToBounds = true
// 按钮容器
let buttonContainer = UIView()
buttonContainer.backgroundColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1)
buttonContainer.translatesAutoresizingMaskIntoConstraints = false
// 取消按钮
let cancelButton = UIButton(type: .system)
cancelButton.setTitle("Cancel", for: .normal)
cancelButton.contentHorizontalAlignment = .left
cancelButton.addTarget(self, action: #selector(cancelAction), for: .touchUpInside)
cancelButton.translatesAutoresizingMaskIntoConstraints = false
cancelButton.setTitleColor(UIColor(red: 0.6, green: 0.6, blue: 0.6, alpha: 1), for: .normal)
cancelButton.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium)
// 确认按钮
let confirmButton = UIButton(type: .system)
confirmButton.setTitle("Completed", for: .normal)
confirmButton.contentHorizontalAlignment = .right
confirmButton.addTarget(self, action: #selector(confirmAction), for: .touchUpInside)
confirmButton.translatesAutoresizingMaskIntoConstraints = false
cancelButton.setTitleColor(UIColor(red: 0.07, green: 0.07, blue: 0.07, alpha: 1), for: .normal)
cancelButton.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium)
buttonContainer.addSubview(cancelButton)
buttonContainer.addSubview(confirmButton)
// 按钮容器约束
NSLayoutConstraint.activate([
buttonContainer.heightAnchor.constraint(equalToConstant: 42),
cancelButton.leadingAnchor.constraint(equalTo: buttonContainer.leadingAnchor, constant: 16),
cancelButton.centerYAnchor.constraint(equalTo: buttonContainer.centerYAnchor),
confirmButton.trailingAnchor.constraint(equalTo: buttonContainer.trailingAnchor, constant: -16),
confirmButton.centerYAnchor.constraint(equalTo: buttonContainer.centerYAnchor)
])
// 主布局
let stackView = UIStackView(arrangedSubviews: [buttonContainer, pickerView])
stackView.axis = .vertical
stackView.spacing = 0
stackView.translatesAutoresizingMaskIntoConstraints = false
addSubview(stackView)
NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: topAnchor),
stackView.leadingAnchor.constraint(equalTo: leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: trailingAnchor),
stackView.bottomAnchor.constraint(equalTo: bottomAnchor)
])
pickerView.delegate = self
pickerView.dataSource = self
// 设置初始选择
let currentYear = Calendar.current.component(.year, from: Date())
let currentMonth = Calendar.current.component(.month, from: Date())
selectedYear = currentYear
selectedMonth = currentMonth - 1
if let yearIndex = years.firstIndex(of: currentYear) {
pickerView.selectRow(yearIndex, inComponent: 1, animated: false)
}
pickerView.tintColor = .red
pickerView.selectRow(currentMonth - 1, inComponent: 0, animated: false)
}
// MARK: - 按钮操作
@objc private func cancelAction() {
onCancel?()
}
@objc private func confirmAction() {
onConfirm?(self.type,selectedYear, selectedMonth + 1)
}
}
// MARK: - UIPickerView DataSource & Delegate
extension YearMonthPickerView: UIPickerViewDataSource, UIPickerViewDelegate {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 2
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return component == 0 ? months.count : years.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return component == 0 ? months[row] : "\(years.reversed()[row])"
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if component == 0 {
selectedMonth = row
} else {
selectedYear = years.reversed()[row]
}
}
func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
return component == 0 ? self.width/2 : self.width/2
}
}
......@@ -20,6 +20,8 @@ class HomeInfoTableViewCell:UITableViewCell {
private var seletedAllBtn:UIButton?
var type : PhotsFileType?
var callBack:callBack<Any> = {text in}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
......@@ -112,13 +114,30 @@ class HomeInfoTableViewCell:UITableViewCell {
collectionView?.x = (backView?.x ?? 0) + marginLR
collectionView?.y = (backView?.y ?? 0) + (backView?.height ?? 0) - (collectionView?.height ?? 0) - 16
UIView.transition(with: collectionView!, duration: 0.3, options: .transitionCrossDissolve, animations: {
self.collectionView?.reloadData()
// self.reloadCollectionView()
}, completion: nil)
}
}
// 重新刷新下集合
func reloadCollectionView(){
DispatchQueue.main.async {
if let collectionView = self.collectionView {
for section in 0..<collectionView.numberOfSections {
for item in 0..<collectionView.numberOfItems(inSection: section) {
UIView.transition(with:collectionView, duration: 0.3, options: .transitionCrossDissolve, animations: {
collectionView.reloadItems(at: [IndexPath(row: item, section: section)])
}, completion: nil)
}
}
}
}
}
@objc func seletedAllBtnClick() {
DispatchQueue.main.async {[weak self] in
......@@ -131,8 +150,8 @@ class HomeInfoTableViewCell:UITableViewCell {
seletedAllBtn?.centerY = numberLabel?.centerY ?? 0
seletedAllBtn?.x = (backView?.x ?? 0) + (backView?.width ?? 0) - 12 - (seletedAllBtn?.width ?? 0)
}
for (index,smodel) in (model?.smodels ?? []).enumerated() {
if index == 0 {
......@@ -195,6 +214,11 @@ extension HomeInfoTableViewCell:UICollectionViewDelegate,UICollectionViewDataSou
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ImageSeletedCollectionCell.identifiers, for: indexPath) as! ImageSeletedCollectionCell
// 显示保留按钮或者最佳匹配结果按钮
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
......@@ -211,7 +235,7 @@ extension HomeInfoTableViewCell:UICollectionViewDelegate,UICollectionViewDataSou
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
// 计算 cell 宽度
// 计算 cell 宽度
/*return CGSize(width:collectionView.height, height: collectionView.height) */ // 宽高相等,形成网格
return CGSize(width:collectionView.height, height: collectionView.height)
......
......@@ -19,6 +19,34 @@ class ImageSeletedCollectionCell:UICollectionViewCell {
var callBack:callBack<Any> = {text in}
lazy var allKeepButton : UIButton = {
let button = UIButton(type: .custom)
button.backgroundColor = UIColor(red: 0.33, green: 0.77, blue: 0.49, alpha: 1)
button.layer.cornerRadius = 7
button.clipsToBounds = true
button.setTitle( "All retained", for: .normal)
button.setTitleColor(.white, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 9, weight: .semibold)
button.addTarget(self, action: #selector(allKeepButtonAction), for: .touchUpInside)
button.isHidden = true
return button
}()
lazy var bestResultButton : UIButton = {
let button = UIButton(type: .custom)
button.layer.cornerRadius = 8
button.clipsToBounds = true
button.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
button.setTitle( "Best result", for: .normal)
button.setImage(UIImage(named: "Frame"), for: .normal)
button.setTitleColor(.white, for: .normal)
button.isHidden = true
button.titleLabel?.font = UIFont.systemFont(ofSize: 10, weight: .semibold)
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
......@@ -132,9 +160,6 @@ class ImageSeletedCollectionCell:UICollectionViewCell {
self.backgroundColor = .clear
}
func addViews() {
......@@ -142,6 +167,22 @@ class ImageSeletedCollectionCell:UICollectionViewCell {
self.addSubview(backImageView!)
self.addSubview(seletedBtn!)
self.addSubview(self.extensionView)
self.addSubview(self.allKeepButton)
self.addSubview(self.bestResultButton)
self.allKeepButton.snp.makeConstraints { make in
make.top.left.equalToSuperview()
make.width.equalTo(58)
make.height.equalTo(14)
}
self.bestResultButton.snp.makeConstraints { make in
make.left.bottom.equalToSuperview()
make.width.equalTo(81)
make.height.equalTo(16)
}
}
@objc func seletedBtnClick() {
......@@ -178,3 +219,9 @@ class ImageSeletedCollectionCell:UICollectionViewCell {
}
extension ImageSeletedCollectionCell {
@objc func allKeepButtonAction(){
Print("点击了全部保留按钮")
}
}
//
// ResourceFilterBoxTableViewCell.swift
// PhoneManager
//
// Created by edy on 2025/5/12.
//
import Foundation
class ResourceFilterBoxTableViewCell : UITableViewCell {
var cellTag : Int = 0
var callBack : callBack<Any> = {cellTag in}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
self.contentView.addSubview(self.selectButton)
self.selectButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(0)
make.right.equalToSuperview().offset(0)
make.top.equalToSuperview().offset(7)
make.bottom.equalToSuperview().offset(-7)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
lazy var selectButton : UIButton = {
let view = UIButton(type: UIButton.ButtonType.custom)
view.backgroundColor = UIColor(red: 0.95, green: 0.96, blue: 0.99, alpha: 1)
view.layer.cornerRadius = 12
view.clipsToBounds = true
view.setTitleColor(UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1), for: .normal)
view.addTarget(self, action: #selector(selectAction), for: .touchUpInside)
view.layer.borderColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1).cgColor
return view
}()
@objc func selectAction(){
callBack(self.cellTag)
}
}
......@@ -60,6 +60,8 @@ func getSettingViewInfo() -> [SettingModel] {
[RowInfoModel(imageName: "ic_more_setting",title: "More Apps From Us")]),
SettingModel(sectionTitle: "UTILITIES",rowInfo:
[RowInfoModel(imageName: "ic_widgets_setting",title: "Widgets")]),
SettingModel(sectionTitle: "OTHERS",rowInfo:
[RowInfoModel(imageName: "ic_list_setting",title: "Keep List")]),
// SettingModel(sectionTitle: "SECRET SPACE",rowInfo: [
// RowInfoModel(imageName: "ic_pin_setting",title: "Use PIN")]),
SettingModel(sectionTitle: "STAY IN TOUCH",rowInfo:
......
......@@ -159,6 +159,9 @@ class SettingViewController : BaseViewController , UITableViewDelegate, UITableV
self.navigationController?.pushViewController(widget, animated: true)
break
case 3:
// 保留列表
break
case 4:
if indexPath.row == 0 { // 评分
self.review()
}else if indexPath.row == 1 { // 分享
......
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