feat: 添加云盘与消息中心功能
This commit is contained in:
@ -0,0 +1,149 @@
|
||||
//
|
||||
// CloudDriveDetailSheetViewController.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 云盘文件详情底部表单,用于查看文件信息并修改名称。
|
||||
final class CloudDriveDetailSheetViewController: UIViewController {
|
||||
private let file: CloudFile
|
||||
private let onSave: (String) -> Void
|
||||
private let dimView = UIView()
|
||||
private let panelView = UIView()
|
||||
private let titleLabel = UILabel()
|
||||
private let nameTitleLabel = UILabel()
|
||||
private let nameField = UITextField()
|
||||
private let infoLabel = UILabel()
|
||||
private let cancelButton = UIButton(type: .system)
|
||||
private let saveButton = UIButton(type: .system)
|
||||
|
||||
/// 初始化云盘文件详情表单。
|
||||
init(file: CloudFile, onSave: @escaping (String) -> Void) {
|
||||
self.file = file
|
||||
self.onSave = onSave
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
modalPresentationStyle = .overFullScreen
|
||||
modalTransitionStyle = .crossDissolve
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
setupUI()
|
||||
setupConstraints()
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
view.backgroundColor = .clear
|
||||
dimView.backgroundColor = UIColor.black.withAlphaComponent(0.35)
|
||||
dimView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(cancelTapped)))
|
||||
|
||||
panelView.backgroundColor = .white
|
||||
panelView.layer.cornerRadius = 18
|
||||
panelView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
|
||||
panelView.clipsToBounds = true
|
||||
|
||||
titleLabel.text = "详情"
|
||||
titleLabel.font = .app(.bodyMedium)
|
||||
titleLabel.textColor = AppColor.textPrimary
|
||||
titleLabel.textAlignment = .center
|
||||
|
||||
nameTitleLabel.text = "文件名称"
|
||||
nameTitleLabel.font = .app(.caption)
|
||||
nameTitleLabel.textColor = AppColor.textSecondary
|
||||
|
||||
nameField.text = file.name
|
||||
nameField.font = .app(.body)
|
||||
nameField.textColor = AppColor.textPrimary
|
||||
nameField.clearButtonMode = .whileEditing
|
||||
nameField.returnKeyType = .done
|
||||
nameField.delegate = self
|
||||
nameField.backgroundColor = AppColor.inputBackground
|
||||
nameField.layer.cornerRadius = AppRadius.xs
|
||||
nameField.leftView = UIView(frame: CGRect(x: 0, y: 0, width: AppSpacing.sm, height: 1))
|
||||
nameField.leftViewMode = .always
|
||||
|
||||
infoLabel.text = "\(file.createdAt) | \(CloudDriveFormatter.fileSize(file.fileSize))\n类型:\(CloudDriveFormatter.typeName(file.type))"
|
||||
infoLabel.font = .app(.caption)
|
||||
infoLabel.textColor = AppColor.textTertiary
|
||||
infoLabel.numberOfLines = 0
|
||||
|
||||
cancelButton.setTitle("取消", for: .normal)
|
||||
cancelButton.setTitleColor(AppColor.textSecondary, for: .normal)
|
||||
cancelButton.titleLabel?.font = .app(.body)
|
||||
cancelButton.addTarget(self, action: #selector(cancelTapped), for: .touchUpInside)
|
||||
|
||||
saveButton.setTitle("保存", for: .normal)
|
||||
saveButton.setTitleColor(.white, for: .normal)
|
||||
saveButton.titleLabel?.font = .app(.bodyMedium)
|
||||
saveButton.backgroundColor = AppColor.primary
|
||||
saveButton.layer.cornerRadius = AppRadius.xs
|
||||
saveButton.addTarget(self, action: #selector(saveTapped), for: .touchUpInside)
|
||||
|
||||
view.addSubview(dimView)
|
||||
view.addSubview(panelView)
|
||||
[titleLabel, nameTitleLabel, nameField, infoLabel, cancelButton, saveButton].forEach(panelView.addSubview)
|
||||
}
|
||||
|
||||
private func setupConstraints() {
|
||||
dimView.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
panelView.snp.makeConstraints { make in
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
}
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.top.leading.trailing.equalToSuperview()
|
||||
make.height.equalTo(54)
|
||||
}
|
||||
nameTitleLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(titleLabel.snp.bottom).offset(AppSpacing.sm)
|
||||
make.leading.trailing.equalToSuperview().inset(AppSpacing.md)
|
||||
}
|
||||
nameField.snp.makeConstraints { make in
|
||||
make.top.equalTo(nameTitleLabel.snp.bottom).offset(AppSpacing.xs)
|
||||
make.leading.trailing.equalTo(nameTitleLabel)
|
||||
make.height.equalTo(42)
|
||||
}
|
||||
infoLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(nameField.snp.bottom).offset(AppSpacing.md)
|
||||
make.leading.trailing.equalTo(nameTitleLabel)
|
||||
}
|
||||
cancelButton.snp.makeConstraints { make in
|
||||
make.top.equalTo(infoLabel.snp.bottom).offset(AppSpacing.lg)
|
||||
make.leading.equalToSuperview().offset(AppSpacing.md)
|
||||
make.height.equalTo(44)
|
||||
make.width.equalTo(saveButton)
|
||||
make.bottom.equalTo(view.safeAreaLayoutGuide).inset(AppSpacing.md)
|
||||
}
|
||||
saveButton.snp.makeConstraints { make in
|
||||
make.top.bottom.width.equalTo(cancelButton)
|
||||
make.leading.equalTo(cancelButton.snp.trailing).offset(AppSpacing.md)
|
||||
make.trailing.equalToSuperview().inset(AppSpacing.md)
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func cancelTapped() {
|
||||
dismiss(animated: true)
|
||||
}
|
||||
|
||||
@objc private func saveTapped() {
|
||||
let name = nameField.text ?? ""
|
||||
dismiss(animated: true) { [onSave] in
|
||||
onSave(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension CloudDriveDetailSheetViewController: UITextFieldDelegate {
|
||||
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
textField.resignFirstResponder()
|
||||
return true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user