Sync OTG transfer photo list UI
This commit is contained in:
@ -7,6 +7,23 @@ import Kingfisher
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
private enum WiredTransferMetrics {
|
||||
static let sidebarWidth: CGFloat = 76
|
||||
static let rowHeight: CGFloat = 66
|
||||
static let sectionHeaderHeight: CGFloat = 28
|
||||
static let selectAllBarHeight: CGFloat = 44
|
||||
}
|
||||
|
||||
private struct WiredTransferListSection: Hashable {
|
||||
let id: String
|
||||
let title: String
|
||||
|
||||
init(_ section: TravelAlbumOTGPhotoSection) {
|
||||
id = section.slotId
|
||||
title = section.headerTitle
|
||||
}
|
||||
}
|
||||
|
||||
/// 有线相机传输页,对齐 Android OTG 页面并接入真实 ImageCaptureCore 传输。
|
||||
final class WiredCameraTransferViewController: BaseViewController {
|
||||
private let viewModel: WiredCameraTransferViewModel
|
||||
@ -27,9 +44,22 @@ final class WiredCameraTransferViewController: BaseViewController {
|
||||
private let formatButton = UIButton(type: .system)
|
||||
private let modeButton = UIButton(type: .system)
|
||||
private let statsCard = UIStackView()
|
||||
private let photoPanelView = UIView()
|
||||
private let selectAllBar = UIControl()
|
||||
private let selectAllIconView = UIImageView()
|
||||
private let selectAllTitleLabel = UILabel()
|
||||
private let selectAllCountLabel = UILabel()
|
||||
private let photoContentView = UIView()
|
||||
private let sidebarView = WiredTransferTimeSidebarView()
|
||||
private let sidebarDivider = UIView()
|
||||
private let listContainerView = UIView()
|
||||
private let expandSidebarButton = UIButton(type: .system)
|
||||
private let emptyLabel = UILabel()
|
||||
private var collectionView: UICollectionView!
|
||||
private var dataSource: UICollectionViewDiffableDataSource<Int, TravelAlbumOTGPhotoItem>!
|
||||
private var dataSource: UICollectionViewDiffableDataSource<WiredTransferListSection, TravelAlbumOTGPhotoItem>!
|
||||
private var currentSections: [WiredTransferListSection] = []
|
||||
private var pendingScrollSlotId: String?
|
||||
private var selectAllBarHeightConstraint: Constraint?
|
||||
private let bottomBar = UIView()
|
||||
private let batchButton = UIButton(type: .system)
|
||||
private let historyImportButton = UIButton(type: .system)
|
||||
@ -117,11 +147,34 @@ final class WiredCameraTransferViewController: BaseViewController {
|
||||
statsCard.axis = .horizontal
|
||||
statsCard.distribution = .fillEqually
|
||||
|
||||
photoPanelView.backgroundColor = .white
|
||||
selectAllBar.backgroundColor = .white
|
||||
selectAllIconView.contentMode = .scaleAspectFit
|
||||
selectAllTitleLabel.text = "全选"
|
||||
selectAllTitleLabel.font = .systemFont(ofSize: 13)
|
||||
selectAllTitleLabel.textColor = AppColor.textPrimary
|
||||
selectAllCountLabel.font = .systemFont(ofSize: 12)
|
||||
selectAllCountLabel.textColor = AppColor.textSecondary
|
||||
selectAllCountLabel.textAlignment = .right
|
||||
sidebarDivider.backgroundColor = AppColor.border
|
||||
listContainerView.backgroundColor = .white
|
||||
expandSidebarButton.setImage(UIImage(systemName: "chevron.right"), for: .normal)
|
||||
expandSidebarButton.tintColor = AppColor.textSecondary
|
||||
expandSidebarButton.backgroundColor = UIColor(hex: 0xF5F6F8)
|
||||
expandSidebarButton.layer.cornerRadius = 8
|
||||
expandSidebarButton.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMaxXMaxYCorner]
|
||||
|
||||
collectionView = UICollectionView(frame: .zero, collectionViewLayout: makeLayout())
|
||||
collectionView.backgroundColor = AppColor.pageBackground
|
||||
collectionView.backgroundColor = .white
|
||||
collectionView.delegate = self
|
||||
collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 8, right: 0)
|
||||
collectionView.register(WiredTransferPhotoCell.self, forCellWithReuseIdentifier: WiredTransferPhotoCell.reuseIdentifier)
|
||||
dataSource = UICollectionViewDiffableDataSource<Int, TravelAlbumOTGPhotoItem>(collectionView: collectionView) {
|
||||
collectionView.register(
|
||||
WiredTransferSectionHeaderView.self,
|
||||
forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
|
||||
withReuseIdentifier: WiredTransferSectionHeaderView.reuseIdentifier
|
||||
)
|
||||
dataSource = UICollectionViewDiffableDataSource<WiredTransferListSection, TravelAlbumOTGPhotoItem>(collectionView: collectionView) {
|
||||
[weak self] collectionView, indexPath, item in
|
||||
let cell = collectionView.dequeueReusableCell(
|
||||
withReuseIdentifier: WiredTransferPhotoCell.reuseIdentifier,
|
||||
@ -133,8 +186,18 @@ final class WiredCameraTransferViewController: BaseViewController {
|
||||
cell.onDelete = { [weak self] in self?.confirmDeletePhoto(item.id) }
|
||||
return cell
|
||||
}
|
||||
dataSource.supplementaryViewProvider = { [weak self] collectionView, kind, indexPath in
|
||||
guard kind == UICollectionView.elementKindSectionHeader else { return nil }
|
||||
let header = collectionView.dequeueReusableSupplementaryView(
|
||||
ofKind: kind,
|
||||
withReuseIdentifier: WiredTransferSectionHeaderView.reuseIdentifier,
|
||||
for: indexPath
|
||||
) as! WiredTransferSectionHeaderView
|
||||
header.apply(title: self?.currentSections[safe: indexPath.section]?.title ?? "")
|
||||
return header
|
||||
}
|
||||
|
||||
emptyLabel.text = "暂无照片"
|
||||
emptyLabel.text = "暂无传输文件"
|
||||
emptyLabel.font = .systemFont(ofSize: 14)
|
||||
emptyLabel.textColor = AppColor.textTertiary
|
||||
emptyLabel.textAlignment = .center
|
||||
@ -157,7 +220,17 @@ final class WiredCameraTransferViewController: BaseViewController {
|
||||
statusCard.addSubview(helpLabel)
|
||||
statusCard.addSubview(chipsStack)
|
||||
statusCard.addSubview(statsCard)
|
||||
view.addSubview(collectionView)
|
||||
view.addSubview(photoPanelView)
|
||||
photoPanelView.addSubview(selectAllBar)
|
||||
selectAllBar.addSubview(selectAllIconView)
|
||||
selectAllBar.addSubview(selectAllTitleLabel)
|
||||
selectAllBar.addSubview(selectAllCountLabel)
|
||||
photoPanelView.addSubview(photoContentView)
|
||||
photoContentView.addSubview(sidebarView)
|
||||
photoContentView.addSubview(sidebarDivider)
|
||||
photoContentView.addSubview(listContainerView)
|
||||
listContainerView.addSubview(collectionView)
|
||||
listContainerView.addSubview(expandSidebarButton)
|
||||
view.addSubview(emptyLabel)
|
||||
view.addSubview(bottomBar)
|
||||
bottomBar.addSubview(batchButton)
|
||||
@ -246,16 +319,47 @@ final class WiredCameraTransferViewController: BaseViewController {
|
||||
make.leading.equalTo(historyImportButton.snp.trailing).offset(8)
|
||||
make.trailing.equalToSuperview().offset(-16)
|
||||
}
|
||||
collectionView.snp.makeConstraints { make in
|
||||
photoPanelView.snp.makeConstraints { make in
|
||||
make.top.equalTo(statusCard.snp.bottom).offset(14)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
make.bottom.equalTo(bottomBar.snp.top).offset(-10)
|
||||
make.leading.trailing.equalToSuperview()
|
||||
make.bottom.equalTo(bottomBar.snp.top)
|
||||
}
|
||||
selectAllBar.snp.makeConstraints { make in
|
||||
make.top.leading.trailing.equalToSuperview()
|
||||
selectAllBarHeightConstraint = make.height.equalTo(WiredTransferMetrics.selectAllBarHeight).constraint
|
||||
}
|
||||
selectAllIconView.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview().offset(10)
|
||||
make.centerY.equalToSuperview()
|
||||
make.size.equalTo(20)
|
||||
}
|
||||
selectAllTitleLabel.snp.makeConstraints { make in
|
||||
make.leading.equalTo(selectAllIconView.snp.trailing).offset(8)
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
selectAllCountLabel.snp.makeConstraints { make in
|
||||
make.leading.greaterThanOrEqualTo(selectAllTitleLabel.snp.trailing).offset(8)
|
||||
make.trailing.equalToSuperview().offset(-10)
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
photoContentView.snp.makeConstraints { make in
|
||||
make.top.equalTo(selectAllBar.snp.bottom)
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
}
|
||||
collectionView.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
expandSidebarButton.snp.makeConstraints { make in
|
||||
make.leading.centerY.equalToSuperview()
|
||||
make.width.equalTo(24)
|
||||
make.height.equalTo(48)
|
||||
}
|
||||
emptyLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(statusCard.snp.bottom)
|
||||
make.leading.trailing.equalToSuperview()
|
||||
make.bottom.equalTo(bottomBar.snp.top)
|
||||
}
|
||||
updateSidebarLayout()
|
||||
}
|
||||
|
||||
override func bindActions() {
|
||||
@ -273,6 +377,13 @@ final class WiredCameraTransferViewController: BaseViewController {
|
||||
batchButton.addTarget(self, action: #selector(batchTapped), for: .touchUpInside)
|
||||
historyImportButton.addTarget(self, action: #selector(historyImportTapped), for: .touchUpInside)
|
||||
specifyButton.addTarget(self, action: #selector(specifyTapped), for: .touchUpInside)
|
||||
selectAllBar.addTarget(self, action: #selector(selectAllTapped), for: .touchUpInside)
|
||||
expandSidebarButton.addTarget(self, action: #selector(toggleSidebarTapped), for: .touchUpInside)
|
||||
sidebarView.onToggleSidebar = { [weak self] in self?.viewModel.toggleSidebar() }
|
||||
sidebarView.onTimeSlotSelected = { [weak self] slotId in
|
||||
self?.pendingScrollSlotId = slotId
|
||||
self?.viewModel.selectTimeSlot(id: slotId)
|
||||
}
|
||||
formatButton.menu = UIMenu(children: TravelAlbumOTGPhotoFormatOption.allCases.map { option in
|
||||
UIAction(title: option.rawValue) { [weak self] _ in self?.viewModel.selectPhotoFormat(option) }
|
||||
})
|
||||
@ -300,13 +411,25 @@ final class WiredCameraTransferViewController: BaseViewController {
|
||||
helpLabel.attributedText = helpText(viewModel.sonyMTPHint)
|
||||
|
||||
rebuildStats()
|
||||
var snapshot = NSDiffableDataSourceSnapshot<Int, TravelAlbumOTGPhotoItem>()
|
||||
snapshot.appendSections([0])
|
||||
snapshot.appendItems(viewModel.filteredPhotos())
|
||||
dataSource.apply(snapshot, animatingDifferences: true)
|
||||
let sections = viewModel.photoSections
|
||||
currentSections = sections.map(WiredTransferListSection.init)
|
||||
var snapshot = NSDiffableDataSourceSnapshot<WiredTransferListSection, TravelAlbumOTGPhotoItem>()
|
||||
snapshot.appendSections(currentSections)
|
||||
for (index, section) in sections.enumerated() {
|
||||
snapshot.appendItems(section.photos, toSection: currentSections[index])
|
||||
}
|
||||
dataSource.apply(snapshot, animatingDifferences: true) { [weak self] in
|
||||
self?.scrollToPendingTimeSlotIfNeeded()
|
||||
}
|
||||
|
||||
emptyLabel.isHidden = !viewModel.filteredPhotos().isEmpty
|
||||
collectionView.isHidden = viewModel.filteredPhotos().isEmpty
|
||||
sidebarView.apply(
|
||||
groups: viewModel.sidebarGroups,
|
||||
selectedSlotId: viewModel.selectedTimeSlotId
|
||||
)
|
||||
updateSelectAllBar()
|
||||
updateSidebarLayout()
|
||||
emptyLabel.isHidden = !sections.isEmpty
|
||||
photoPanelView.isHidden = sections.isEmpty
|
||||
if viewModel.selectUploadMode {
|
||||
let count = viewModel.selectedPhotoIds.count
|
||||
batchButton.setTitle(count > 0 ? "上传选中(\(count))" : "取消", for: .normal)
|
||||
@ -316,6 +439,53 @@ final class WiredCameraTransferViewController: BaseViewController {
|
||||
historyImportButton.setTitle("历史导入", for: .normal)
|
||||
}
|
||||
|
||||
private func updateSelectAllBar() {
|
||||
let showSelectAll = viewModel.selectUploadMode && !viewModel.photoSections.isEmpty
|
||||
selectAllBar.isHidden = !showSelectAll
|
||||
selectAllBarHeightConstraint?.update(offset: showSelectAll ? WiredTransferMetrics.selectAllBarHeight : 0)
|
||||
let allSelected = viewModel.allVisibleSelectablePhotosSelected
|
||||
selectAllIconView.image = UIImage(systemName: allSelected ? "checkmark.circle.fill" : "circle")
|
||||
selectAllIconView.tintColor = allSelected ? AppColor.primary : AppColor.textTertiary
|
||||
selectAllCountLabel.text = "已选 \(viewModel.selectedVisibleUploadCount) / \(viewModel.selectableVisiblePhotoIds.count)"
|
||||
selectAllBar.isEnabled = !viewModel.selectableVisiblePhotoIds.isEmpty
|
||||
selectAllBar.alpha = selectAllBar.isEnabled ? 1 : 0.55
|
||||
}
|
||||
|
||||
private func updateSidebarLayout() {
|
||||
let showSidebar = viewModel.sidebarExpanded && !viewModel.sidebarGroups.isEmpty
|
||||
sidebarView.isHidden = !showSidebar
|
||||
sidebarDivider.isHidden = !showSidebar
|
||||
expandSidebarButton.isHidden = viewModel.sidebarExpanded || viewModel.sidebarGroups.isEmpty
|
||||
sidebarView.snp.remakeConstraints { make in
|
||||
make.top.leading.bottom.equalToSuperview()
|
||||
make.width.equalTo(showSidebar ? WiredTransferMetrics.sidebarWidth : 0)
|
||||
}
|
||||
sidebarDivider.snp.remakeConstraints { make in
|
||||
make.top.bottom.equalToSuperview()
|
||||
make.leading.equalTo(sidebarView.snp.trailing)
|
||||
make.width.equalTo(showSidebar ? 1 : 0)
|
||||
}
|
||||
listContainerView.snp.remakeConstraints { make in
|
||||
make.top.bottom.trailing.equalToSuperview()
|
||||
make.leading.equalTo(sidebarDivider.snp.trailing)
|
||||
}
|
||||
}
|
||||
|
||||
private func scrollToPendingTimeSlotIfNeeded() {
|
||||
guard let slotId = pendingScrollSlotId,
|
||||
let sectionIndex = currentSections.firstIndex(where: { $0.id == slotId }),
|
||||
collectionView.numberOfItems(inSection: sectionIndex) > 0 else {
|
||||
pendingScrollSlotId = nil
|
||||
return
|
||||
}
|
||||
collectionView.scrollToItem(
|
||||
at: IndexPath(item: 0, section: sectionIndex),
|
||||
at: .top,
|
||||
animated: true
|
||||
)
|
||||
pendingScrollSlotId = nil
|
||||
}
|
||||
|
||||
private func rebuildStats() {
|
||||
statsCard.arrangedSubviews.forEach { view in
|
||||
statsCard.removeArrangedSubview(view)
|
||||
@ -373,16 +543,29 @@ final class WiredCameraTransferViewController: BaseViewController {
|
||||
}
|
||||
|
||||
private func makeLayout() -> UICollectionViewCompositionalLayout {
|
||||
UICollectionViewCompositionalLayout { _, environment in
|
||||
let spacing: CGFloat = 8
|
||||
let width = (environment.container.effectiveContentSize.width - spacing * 2) / 3
|
||||
let itemSize = NSCollectionLayoutSize(widthDimension: .absolute(width), heightDimension: .absolute(width + 58))
|
||||
UICollectionViewCompositionalLayout { _, _ in
|
||||
let itemSize = NSCollectionLayoutSize(
|
||||
widthDimension: .fractionalWidth(1),
|
||||
heightDimension: .estimated(WiredTransferMetrics.rowHeight)
|
||||
)
|
||||
let item = NSCollectionLayoutItem(layoutSize: itemSize)
|
||||
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(width + 58))
|
||||
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, repeatingSubitem: item, count: 3)
|
||||
group.interItemSpacing = .fixed(spacing)
|
||||
let groupSize = NSCollectionLayoutSize(
|
||||
widthDimension: .fractionalWidth(1),
|
||||
heightDimension: .estimated(WiredTransferMetrics.rowHeight)
|
||||
)
|
||||
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item])
|
||||
let section = NSCollectionLayoutSection(group: group)
|
||||
section.interGroupSpacing = 12
|
||||
let headerSize = NSCollectionLayoutSize(
|
||||
widthDimension: .fractionalWidth(1),
|
||||
heightDimension: .absolute(WiredTransferMetrics.sectionHeaderHeight)
|
||||
)
|
||||
let header = NSCollectionLayoutBoundarySupplementaryItem(
|
||||
layoutSize: headerSize,
|
||||
elementKind: UICollectionView.elementKindSectionHeader,
|
||||
alignment: .top
|
||||
)
|
||||
header.pinToVisibleBounds = true
|
||||
section.boundarySupplementaryItems = [header]
|
||||
return section
|
||||
}
|
||||
}
|
||||
@ -445,6 +628,14 @@ final class WiredCameraTransferViewController: BaseViewController {
|
||||
viewModel.onSpecifyUploadButtonClick()
|
||||
}
|
||||
|
||||
@objc private func selectAllTapped() {
|
||||
viewModel.toggleVisibleSelectablePhotos()
|
||||
}
|
||||
|
||||
@objc private func toggleSidebarTapped() {
|
||||
viewModel.toggleSidebar()
|
||||
}
|
||||
|
||||
@objc private func tabTapped(_ sender: UIButton) {
|
||||
guard let tab = TravelAlbumOTGTransferTab(rawValue: sender.tag) else { return }
|
||||
viewModel.selectTab(tab)
|
||||
@ -467,19 +658,47 @@ extension WiredCameraTransferViewController: UICollectionViewDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
/// 有线传输照片宫格 Cell。
|
||||
/// 有线传输照片列表时间段 Header。
|
||||
private final class WiredTransferSectionHeaderView: UICollectionReusableView {
|
||||
static let reuseIdentifier = "WiredTransferSectionHeaderView"
|
||||
|
||||
private let titleLabel = UILabel()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
backgroundColor = AppColor.pageBackground
|
||||
titleLabel.font = .systemFont(ofSize: 11)
|
||||
titleLabel.textColor = AppColor.textSecondary
|
||||
addSubview(titleLabel)
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.leading.trailing.equalToSuperview().inset(10)
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func apply(title: String) {
|
||||
titleLabel.text = title
|
||||
}
|
||||
}
|
||||
|
||||
/// 有线传输照片列表 Cell。
|
||||
private final class WiredTransferPhotoCell: UICollectionViewCell {
|
||||
static let reuseIdentifier = "WiredTransferPhotoCell"
|
||||
private static let previewImageSize = CGSize(width: 180, height: 180)
|
||||
private static let previewImageSize = CGSize(width: 96, height: 96)
|
||||
|
||||
private let selectionIconView = UIImageView()
|
||||
private let imageView = UIImageView()
|
||||
private let statusLabel = UILabel()
|
||||
private let titleLabel = UILabel()
|
||||
private let sizeLabel = UILabel()
|
||||
private let progressView = UIProgressView(progressViewStyle: .default)
|
||||
private let retryButton = UIButton(type: .system)
|
||||
private let deleteButton = UIButton(type: .system)
|
||||
private let selectionOverlay = UIImageView()
|
||||
private let menuButton = UIButton(type: .system)
|
||||
private let separatorView = UIView()
|
||||
|
||||
var onRetry: (() -> Void)?
|
||||
var onDelete: (() -> Void)?
|
||||
@ -500,9 +719,12 @@ private final class WiredTransferPhotoCell: UICollectionViewCell {
|
||||
imageView.image = nil
|
||||
onRetry = nil
|
||||
onDelete = nil
|
||||
menuButton.menu = nil
|
||||
}
|
||||
|
||||
func apply(item: TravelAlbumOTGPhotoItem, selectionMode: Bool, selected: Bool) {
|
||||
let canSelect = item.canSelectForUpload
|
||||
let rowAlpha: CGFloat = selectionMode && !canSelect ? 0.45 : 1
|
||||
if let url = item.thumbnailURL {
|
||||
let processor = DownsamplingImageProcessor(size: Self.previewImageSize)
|
||||
imageView.kf.setImage(
|
||||
@ -518,114 +740,301 @@ private final class WiredTransferPhotoCell: UICollectionViewCell {
|
||||
imageView.image = UIImage(systemName: "photo")
|
||||
imageView.tintColor = AppColor.textTertiary
|
||||
}
|
||||
imageView.alpha = rowAlpha
|
||||
titleLabel.text = item.fileName
|
||||
titleLabel.alpha = rowAlpha
|
||||
sizeLabel.text = item.fileSizeText
|
||||
statusLabel.text = statusText(item.status, progress: item.progress)
|
||||
statusLabel.backgroundColor = statusColor(item.status).withAlphaComponent(0.90)
|
||||
sizeLabel.alpha = rowAlpha
|
||||
statusLabel.text = statusText(item.status)
|
||||
statusLabel.textColor = statusTextColor(item.status)
|
||||
statusLabel.backgroundColor = statusBackgroundColor(item.status)
|
||||
progressView.isHidden = item.status != .uploading && item.status != .transferring
|
||||
progressView.progress = Float(item.progress) / 100.0
|
||||
retryButton.isHidden = item.status != .failed
|
||||
deleteButton.isHidden = selectionMode
|
||||
selectionOverlay.isHidden = !selectionMode
|
||||
selectionOverlay.image = UIImage(systemName: selected ? "checkmark.circle.fill" : "circle")
|
||||
selectionOverlay.tintColor = selected ? AppColor.primary : .white
|
||||
selectionIconView.isHidden = !selectionMode
|
||||
selectionIconView.image = UIImage(systemName: selected ? "checkmark.circle.fill" : "circle")
|
||||
selectionIconView.tintColor = canSelect ? (selected ? AppColor.primary : AppColor.textTertiary) : AppColor.textTertiary.withAlphaComponent(0.5)
|
||||
menuButton.isHidden = selectionMode
|
||||
menuButton.menu = makeMenu(canRetry: item.status == .failed || item.status == .pending)
|
||||
updateImageConstraints(selectionMode: selectionMode)
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
contentView.backgroundColor = .white
|
||||
contentView.layer.cornerRadius = 8
|
||||
contentView.clipsToBounds = true
|
||||
selectionIconView.contentMode = .scaleAspectFit
|
||||
imageView.contentMode = .scaleAspectFill
|
||||
imageView.clipsToBounds = true
|
||||
statusLabel.font = .systemFont(ofSize: 10, weight: .medium)
|
||||
statusLabel.textColor = .white
|
||||
imageView.layer.cornerRadius = 6
|
||||
statusLabel.font = .systemFont(ofSize: 9)
|
||||
statusLabel.textAlignment = .center
|
||||
statusLabel.layer.cornerRadius = 4
|
||||
statusLabel.layer.cornerRadius = 3
|
||||
statusLabel.clipsToBounds = true
|
||||
titleLabel.font = .systemFont(ofSize: 11, weight: .medium)
|
||||
titleLabel.font = .systemFont(ofSize: 12, weight: .medium)
|
||||
titleLabel.textColor = AppColor.textPrimary
|
||||
titleLabel.lineBreakMode = .byTruncatingMiddle
|
||||
sizeLabel.font = .systemFont(ofSize: 10)
|
||||
sizeLabel.textColor = AppColor.textTertiary
|
||||
retryButton.setImage(UIImage(systemName: "arrow.clockwise"), for: .normal)
|
||||
retryButton.tintColor = AppColor.danger
|
||||
deleteButton.setImage(UIImage(systemName: "trash"), for: .normal)
|
||||
deleteButton.tintColor = AppColor.textTertiary
|
||||
selectionOverlay.contentMode = .scaleAspectFit
|
||||
progressView.progressTintColor = AppColor.primary
|
||||
progressView.trackTintColor = AppColor.border
|
||||
menuButton.setImage(UIImage(systemName: "ellipsis"), for: .normal)
|
||||
menuButton.tintColor = AppColor.textSecondary
|
||||
menuButton.showsMenuAsPrimaryAction = true
|
||||
separatorView.backgroundColor = AppColor.border
|
||||
|
||||
contentView.addSubview(selectionIconView)
|
||||
contentView.addSubview(imageView)
|
||||
imageView.addSubview(statusLabel)
|
||||
imageView.addSubview(selectionOverlay)
|
||||
contentView.addSubview(titleLabel)
|
||||
contentView.addSubview(statusLabel)
|
||||
contentView.addSubview(sizeLabel)
|
||||
contentView.addSubview(progressView)
|
||||
contentView.addSubview(retryButton)
|
||||
contentView.addSubview(deleteButton)
|
||||
contentView.addSubview(menuButton)
|
||||
contentView.addSubview(separatorView)
|
||||
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.top.leading.trailing.equalToSuperview()
|
||||
make.height.equalTo(contentView.snp.width)
|
||||
selectionIconView.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview().offset(10)
|
||||
make.centerY.equalToSuperview()
|
||||
make.size.equalTo(20)
|
||||
}
|
||||
updateImageConstraints(selectionMode: true)
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(imageView).offset(1)
|
||||
make.leading.equalTo(imageView.snp.trailing).offset(8)
|
||||
make.trailing.equalTo(statusLabel.snp.leading).offset(-4)
|
||||
}
|
||||
statusLabel.snp.makeConstraints { make in
|
||||
make.top.leading.equalToSuperview().offset(5)
|
||||
make.height.equalTo(18)
|
||||
make.centerY.equalTo(titleLabel)
|
||||
make.trailing.equalTo(menuButton.snp.leading).offset(-4)
|
||||
make.height.equalTo(17)
|
||||
make.width.greaterThanOrEqualTo(44)
|
||||
}
|
||||
selectionOverlay.snp.makeConstraints { make in
|
||||
make.top.trailing.equalToSuperview().inset(6)
|
||||
make.size.equalTo(22)
|
||||
}
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(imageView.snp.bottom).offset(5)
|
||||
make.leading.equalToSuperview().offset(6)
|
||||
make.trailing.equalTo(deleteButton.snp.leading).offset(-4)
|
||||
}
|
||||
sizeLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(titleLabel.snp.bottom).offset(2)
|
||||
make.leading.trailing.equalTo(titleLabel)
|
||||
make.top.equalTo(titleLabel.snp.bottom).offset(5)
|
||||
make.leading.equalTo(titleLabel)
|
||||
make.trailing.equalToSuperview().offset(-10)
|
||||
}
|
||||
progressView.snp.makeConstraints { make in
|
||||
make.leading.trailing.bottom.equalToSuperview().inset(6)
|
||||
make.leading.equalTo(titleLabel)
|
||||
make.trailing.equalToSuperview().offset(-10)
|
||||
make.top.equalTo(sizeLabel.snp.bottom).offset(7)
|
||||
make.height.equalTo(2)
|
||||
}
|
||||
retryButton.snp.makeConstraints { make in
|
||||
menuButton.snp.makeConstraints { make in
|
||||
make.centerY.equalTo(titleLabel)
|
||||
make.trailing.equalToSuperview().offset(-2)
|
||||
make.size.equalTo(26)
|
||||
make.trailing.equalToSuperview().offset(-4)
|
||||
make.size.equalTo(32)
|
||||
}
|
||||
deleteButton.snp.makeConstraints { make in
|
||||
make.centerY.equalTo(titleLabel)
|
||||
make.trailing.equalToSuperview().offset(-2)
|
||||
make.size.equalTo(26)
|
||||
separatorView.snp.makeConstraints { make in
|
||||
make.leading.trailing.equalToSuperview().inset(10)
|
||||
make.bottom.equalToSuperview()
|
||||
make.height.equalTo(1 / UIScreen.main.scale)
|
||||
}
|
||||
|
||||
retryButton.addTarget(self, action: #selector(retryTapped), for: .touchUpInside)
|
||||
deleteButton.addTarget(self, action: #selector(deleteTapped), for: .touchUpInside)
|
||||
}
|
||||
|
||||
private func statusText(_ status: TravelAlbumOTGUploadStatus, progress: Int) -> String {
|
||||
private func makeMenu(canRetry: Bool) -> UIMenu {
|
||||
let retry = UIAction(title: "重传", image: UIImage(systemName: "arrow.clockwise")) { [weak self] _ in
|
||||
self?.onRetry?()
|
||||
}
|
||||
retry.attributes = canRetry ? [] : [.disabled]
|
||||
let delete = UIAction(title: "删除", image: UIImage(systemName: "trash"), attributes: .destructive) { [weak self] _ in
|
||||
self?.onDelete?()
|
||||
}
|
||||
return UIMenu(children: [retry, delete])
|
||||
}
|
||||
|
||||
private func updateImageConstraints(selectionMode: Bool) {
|
||||
imageView.snp.remakeConstraints { make in
|
||||
if selectionMode {
|
||||
make.leading.equalTo(selectionIconView.snp.trailing).offset(8)
|
||||
} else {
|
||||
make.leading.equalToSuperview().offset(10)
|
||||
}
|
||||
make.top.equalToSuperview().offset(8)
|
||||
make.size.equalTo(48)
|
||||
make.bottom.lessThanOrEqualToSuperview().offset(-8)
|
||||
}
|
||||
}
|
||||
|
||||
private func statusText(_ status: TravelAlbumOTGUploadStatus) -> String {
|
||||
switch status {
|
||||
case .pending: return "待上传"
|
||||
case .transferring: return "传输\(progress)%"
|
||||
case .uploading: return "上传\(progress)%"
|
||||
case .transferring: return "传输中"
|
||||
case .uploading: return "上传中"
|
||||
case .uploaded: return "已上传"
|
||||
case .failed: return "失败"
|
||||
case .failed: return "上传失败"
|
||||
}
|
||||
}
|
||||
|
||||
private func statusColor(_ status: TravelAlbumOTGUploadStatus) -> UIColor {
|
||||
private func statusTextColor(_ status: TravelAlbumOTGUploadStatus) -> UIColor {
|
||||
switch status {
|
||||
case .pending: return AppColor.textTertiary
|
||||
case .pending: return AppColor.textSecondary
|
||||
case .transferring, .uploading: return AppColor.primary
|
||||
case .uploaded: return UIColor(hex: 0x16A34A)
|
||||
case .failed: return AppColor.danger
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func retryTapped() {
|
||||
onRetry?()
|
||||
}
|
||||
|
||||
@objc private func deleteTapped() {
|
||||
onDelete?()
|
||||
private func statusBackgroundColor(_ status: TravelAlbumOTGUploadStatus) -> UIColor {
|
||||
switch status {
|
||||
case .pending:
|
||||
return AppColor.pageBackground
|
||||
case .transferring, .uploading:
|
||||
return AppColor.primary.withAlphaComponent(0.12)
|
||||
case .uploaded:
|
||||
return UIColor(hex: 0x16A34A).withAlphaComponent(0.12)
|
||||
case .failed:
|
||||
return AppColor.danger.withAlphaComponent(0.12)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 有线传输页左侧时间快速导航。
|
||||
private final class WiredTransferTimeSidebarView: UIView {
|
||||
var onToggleSidebar: (() -> Void)?
|
||||
var onTimeSlotSelected: ((String) -> Void)?
|
||||
|
||||
private let headerButton = UIButton(type: .system)
|
||||
private let scrollView = UIScrollView()
|
||||
private let stackView = UIStackView()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setupUI()
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func apply(groups: [TravelAlbumOTGDateGroup], selectedSlotId: String?) {
|
||||
stackView.arrangedSubviews.forEach { view in
|
||||
stackView.removeArrangedSubview(view)
|
||||
view.removeFromSuperview()
|
||||
}
|
||||
|
||||
for group in groups {
|
||||
let dateContainer = UIView()
|
||||
let dateLabel = UILabel()
|
||||
dateLabel.text = group.dateLabel
|
||||
dateLabel.font = .systemFont(ofSize: 12)
|
||||
dateLabel.textColor = AppColor.textTertiary
|
||||
dateContainer.addSubview(dateLabel)
|
||||
stackView.addArrangedSubview(dateContainer)
|
||||
dateContainer.snp.makeConstraints { make in
|
||||
make.height.equalTo(24)
|
||||
}
|
||||
dateLabel.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview().offset(10)
|
||||
make.trailing.equalToSuperview()
|
||||
make.bottom.equalToSuperview().offset(-4)
|
||||
}
|
||||
|
||||
for slot in group.slots {
|
||||
let row = TimeSlotRowView()
|
||||
row.apply(slot: slot, selected: slot.id == selectedSlotId)
|
||||
row.onTap = { [weak self] in self?.onTimeSlotSelected?(slot.id) }
|
||||
stackView.addArrangedSubview(row)
|
||||
row.snp.makeConstraints { make in
|
||||
make.height.equalTo(52)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
backgroundColor = UIColor(hex: 0xF5F6F8)
|
||||
headerButton.setTitle("收起", for: .normal)
|
||||
headerButton.setImage(UIImage(systemName: "chevron.left"), for: .normal)
|
||||
headerButton.tintColor = AppColor.textSecondary
|
||||
headerButton.setTitleColor(AppColor.textSecondary, for: .normal)
|
||||
headerButton.titleLabel?.font = .systemFont(ofSize: 11)
|
||||
headerButton.semanticContentAttribute = .forceLeftToRight
|
||||
headerButton.addTarget(self, action: #selector(toggleTapped), for: .touchUpInside)
|
||||
scrollView.showsVerticalScrollIndicator = false
|
||||
stackView.axis = .vertical
|
||||
|
||||
addSubview(headerButton)
|
||||
addSubview(scrollView)
|
||||
scrollView.addSubview(stackView)
|
||||
|
||||
headerButton.snp.makeConstraints { make in
|
||||
make.top.leading.trailing.equalToSuperview()
|
||||
make.height.equalTo(36)
|
||||
}
|
||||
scrollView.snp.makeConstraints { make in
|
||||
make.top.equalTo(headerButton.snp.bottom)
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
}
|
||||
stackView.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
make.width.equalToSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func toggleTapped() {
|
||||
onToggleSidebar?()
|
||||
}
|
||||
}
|
||||
|
||||
private final class TimeSlotRowView: UIControl {
|
||||
private let timeLabel = UILabel()
|
||||
private let countLabel = UILabel()
|
||||
private let arrowView = UIImageView(image: UIImage(systemName: "play.fill"))
|
||||
|
||||
var onTap: (() -> Void)?
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setupUI()
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func apply(slot: TravelAlbumOTGTimeSlot, selected: Bool) {
|
||||
backgroundColor = selected ? .white : .clear
|
||||
timeLabel.text = slot.slotStartLabel
|
||||
timeLabel.font = .systemFont(ofSize: 13, weight: selected ? .semibold : .regular)
|
||||
timeLabel.textColor = selected ? AppColor.primary : AppColor.textPrimary
|
||||
arrowView.tintColor = selected ? AppColor.primary : AppColor.textPrimary
|
||||
countLabel.text = "\(slot.photoCount)张"
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
arrowView.contentMode = .scaleAspectFit
|
||||
timeLabel.textAlignment = .center
|
||||
countLabel.font = .systemFont(ofSize: 10)
|
||||
countLabel.textColor = AppColor.textTertiary
|
||||
countLabel.textAlignment = .center
|
||||
addTarget(self, action: #selector(rowTapped), for: .touchUpInside)
|
||||
|
||||
addSubview(arrowView)
|
||||
addSubview(timeLabel)
|
||||
addSubview(countLabel)
|
||||
|
||||
arrowView.snp.makeConstraints { make in
|
||||
make.centerY.equalTo(timeLabel)
|
||||
make.trailing.equalTo(timeLabel.snp.leading).offset(-2)
|
||||
make.size.equalTo(10)
|
||||
}
|
||||
timeLabel.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(8)
|
||||
make.centerX.equalToSuperview().offset(6)
|
||||
}
|
||||
countLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(timeLabel.snp.bottom).offset(2)
|
||||
make.centerX.equalToSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func rowTapped() {
|
||||
onTap?()
|
||||
}
|
||||
}
|
||||
|
||||
private extension Array {
|
||||
subscript(safe index: Index) -> Element? {
|
||||
indices.contains(index) ? self[index] : nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user