Sync OTG transfer photo list UI

This commit is contained in:
2026-07-08 11:00:44 +08:00
parent d642234b38
commit 87fba3d5d6
5 changed files with 837 additions and 89 deletions
@@ -17,10 +17,16 @@ final class WiredCameraTransferViewModel {
didSet { notifyStateChanged() }
}
private(set) var photos: [TravelAlbumOTGPhotoItem] = [] {
didSet { notifyStateChanged() }
didSet {
normalizeSelectedTimeSlot()
notifyStateChanged()
}
}
private(set) var selectedTab: TravelAlbumOTGTransferTab = .all {
didSet { notifyStateChanged() }
didSet {
normalizeSelectedTimeSlot()
notifyStateChanged()
}
}
private(set) var selectedPhotoIds: Set<String> = [] {
didSet { notifyStateChanged() }
@@ -28,6 +34,12 @@ final class WiredCameraTransferViewModel {
private(set) var selectUploadMode = false {
didSet { notifyStateChanged() }
}
private(set) var sidebarExpanded = true {
didSet { notifyStateChanged() }
}
private(set) var selectedTimeSlotId: String? {
didSet { notifyStateChanged() }
}
private(set) var sonyMTPHint: String?
private(set) var isContentCatalogReady = false
@@ -135,6 +147,32 @@ final class WiredCameraTransferViewModel {
}
}
/// 过滤后照片的半小时时间分段。
var photoSections: [TravelAlbumOTGPhotoSection] {
filteredPhotos().buildPhotoSections()
}
/// 过滤后照片的左侧时间导航分组。
var sidebarGroups: [TravelAlbumOTGDateGroup] {
filteredPhotos().buildSidebarGroups()
}
/// 当前可见列表中可被选择上传的照片 ID。
var selectableVisiblePhotoIds: Set<String> {
Set(filteredPhotos().filter(\.canSelectForUpload).map(\.id))
}
/// 当前可见列表中是否已全选可上传照片。
var allVisibleSelectablePhotosSelected: Bool {
let ids = selectableVisiblePhotoIds
return !ids.isEmpty && ids.isSubset(of: selectedPhotoIds)
}
/// 当前可见列表中已选择的可上传照片数量。
var selectedVisibleUploadCount: Int {
selectedPhotoIds.intersection(selectableVisiblePhotoIds).count
}
/// 绑定连接管理器并启动发现。
func start() {
connectionManager.configureLiveTransfer(albumID: albumId)
@@ -178,6 +216,17 @@ final class WiredCameraTransferViewModel {
selectedPhotoIds = selectedPhotoIds.intersection(Set(filteredPhotos().map(\.id)))
}
/// 展开或收起左侧时间快速导航。
func toggleSidebar() {
sidebarExpanded.toggle()
}
/// 选择左侧时间槽,并联动主列表滚动。
func selectTimeSlot(id: String) {
guard photoSections.contains(where: { $0.slotId == id }) else { return }
selectedTimeSlotId = id
}
/// 切换传输模式。
func selectTransferMode(_ option: String) {
guard option == "边拍边传" || option == "拍后传输" else { return }
@@ -252,6 +301,18 @@ final class WiredCameraTransferViewModel {
}
}
/// 切换当前可见照片的全选状态。
func toggleVisibleSelectablePhotos() {
guard selectUploadMode else { return }
let ids = selectableVisiblePhotoIds
guard !ids.isEmpty else { return }
if ids.isSubset(of: selectedPhotoIds) {
selectedPhotoIds.subtract(ids)
} else {
selectedPhotoIds.formUnion(ids)
}
}
/// 上传选中照片。
func uploadSelectedTransferPhotos() {
let ids = selectedPhotoIds
@@ -303,6 +364,17 @@ final class WiredCameraTransferViewModel {
photos = persistedItems.sorted { $0.capturedAt > $1.capturedAt }
}
private func normalizeSelectedTimeSlot() {
let sections = filteredPhotos().buildPhotoSections()
guard let firstSlotId = sections.first?.slotId else {
selectedTimeSlotId = nil
return
}
if selectedTimeSlotId == nil || !sections.contains(where: { $0.slotId == selectedTimeSlotId }) {
selectedTimeSlotId = firstSlotId
}
}
private func startUploadByIds(_ ids: Set<String>, emptyMessage: String) {
guard !isUploading else {
showMessage("正在上传,请稍候")