新增ai修图
@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "travel_album_preview_ai_edit.svg",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
<svg width="24" height="24" viewBox="0 -128 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill="#FFFFFF" d="M764 824q-40 40 -97 40t-97 -40l-544 -542v-320q0 -25 17.5 -43t42.5 -18h340l528 538q41 40 41 97t-41 97zM338 -29h-179q-26 0 -44.5 18.5t-18.5 45.5v196q12 -3 31 -9t65 -29.5t77 -53.5q29 -27 63.5 -86t38.5 -82h-33zM885 463l-435 -438q-73 119 -124 171q-15 15 -39.5 32t-48 31t-45.5 26t-35 19l-13 6l448 446q24 24 60.5 24t60.5 -25l171 -171q25 -26 25 -61.5t-25 -59.5zM611 315l-43 43l32 31l42 -42zM692 397l-42 42l126 127l43 -43z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 541 B |
@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "travel_album_preview_delete.svg",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
<svg width="24" height="24" viewBox="0 -128 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill="#FFFFFF" d="M368 440v-279q0 -13 8.5 -22t20.5 -9t20 8q9 10 9 23v279q0 13 -8.5 22.5t-20.5 9.5t-20.5 -9.5t-8.5 -22.5zM569 440v-279q0 -13 8.5 -22t20.5 -9t20.5 9t8.5 22v279q0 13 -8.5 22.5t-20.5 9.5t-20.5 -9.5t-8.5 -22.5zM283 -109h442q57 0 97 42t40 102v606h95q12 0 20.5 9.5t8.5 22.5t-8.5 22t-20.5 9h-259l-1 25q0 53 -35 101t-81 48h-154q-45 0 -80 -48t-36 -101v-25h-251q-12 0 -20.5 -9t-8.5 -22t8.5 -22.5t20.5 -9.5h87v-606q0 -60 40 -102t96 -42zM369 730q1 27 18.5 55t37.5 30h2h154q21 -2 39 -30t19 -55l1 -26h-272zM205 641h599v-606q0 -34 -23 -57.5t-56 -23.5h-442q-33 0 -55.5 23.5t-22.5 57.5v606v0z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 700 B |
@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "travel_album_preview_refresh.svg",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
<svg width="24" height="24" viewBox="0 -128 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill="#FFFFFF" d="M505.5 -127q-102.5 0 -196.5 39q-90 39 -159.5 108.5t-108.5 159.5q-39 94 -39 196.5t39 195.5q39 90 108.5 160t159.5 108q94 40 196.5 40t195.5 -40q90 -38 160 -108t108 -160q40 -93 40 -195.5t-40 -196.5q-38 -90 -108 -159.5t-160 -108.5q-93 -39 -195.5 -39zM505 819q-90 0 -172 -35q-80 -33 -141 -94.5t-95 -140.5q-35 -83 -35 -173t35 -172q34 -80 95 -141t141 -95q82 -35 172 -35t173 35q79 34 140.5 95t94.5 141q35 82 35 172t-35 173q-33 79 -94.5 140.5t-140.5 94.5q-83 35 -173 35zM595 472h-240l62 62q9 9 9 21.5t-9 21.5t-21.5 9t-21.5 -9l-113 -114q-9 -9 -9 -21.5t9 -21.5l113 -113q9 -9 21.5 -9t21.5 9t9 21.5t-9 21.5l-62 61h240q41 0 69.5 -28t28.5 -68t-28.5 -68.5t-69.5 -28.5h-221q-12 0 -21 -9t-9 -21.5t9 -21.5t21 -9h221q66 0 112 46.5t46 111.5t-46 111t-112 46z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 863 B |
@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
21
suixinkan/Assets.xcassets/TravelAlbumPurchasedDemo/purchased_alpine_lake.imageset/Contents.json
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "purchased_alpine_lake.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 970 KiB |
@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "purchased_forest_waterfall.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.2 MiB |
@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "purchased_grassland_path.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.1 MiB |
@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "purchased_lakeside_flowers.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.1 MiB |
@ -116,6 +116,8 @@ struct TravelAlbumAvailableOrder: Decodable, Sendable, Equatable, Hashable {
|
||||
|
||||
/// 旅拍相册素材实体,对齐 Android `TravelAlbumMaterialEntity`。
|
||||
struct TravelAlbumMaterial: Decodable, Sendable, Equatable, Hashable, Identifiable {
|
||||
private static let bundledImageURLPrefix = "asset://"
|
||||
|
||||
let id: Int
|
||||
let userEquityTravelId: Int
|
||||
let status: Int
|
||||
@ -175,6 +177,18 @@ struct TravelAlbumMaterial: Decodable, Sendable, Equatable, Hashable, Identifiab
|
||||
self.createdAt = createdAt
|
||||
self.updatedAt = updatedAt
|
||||
}
|
||||
|
||||
/// 将工程内图片资源转换为素材可识别的本地地址,仅供无接口数据的演示素材使用。
|
||||
static func bundledImageURL(assetName: String) -> String {
|
||||
bundledImageURLPrefix + assetName
|
||||
}
|
||||
|
||||
/// 返回本地演示素材对应的图片资源名;真实网络素材返回 `nil`。
|
||||
var bundledImageAssetName: String? {
|
||||
guard fileUrl.hasPrefix(Self.bundledImageURLPrefix) else { return nil }
|
||||
let assetName = String(fileUrl.dropFirst(Self.bundledImageURLPrefix.count))
|
||||
return assetName.isEmpty ? nil : assetName
|
||||
}
|
||||
}
|
||||
|
||||
/// 旅拍相册创建请求体,对齐 Android `TravelAlbumCreateRequest`。
|
||||
|
||||
@ -0,0 +1,316 @@
|
||||
//
|
||||
// TravelAlbumPhotoPreviewModels.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// 单张照片的 AI 修图状态,控制处理中禁用、结果对比以及再次修图覆盖。
|
||||
struct TravelAlbumAIEditResultState: Equatable, Sendable {
|
||||
/// 相册缩略图需要展示的 AI 修图状态。
|
||||
enum ThumbnailStatus: Equatable, Sendable {
|
||||
case none
|
||||
case processing
|
||||
case edited
|
||||
case cover
|
||||
case failed
|
||||
}
|
||||
|
||||
/// 当前预览展示的版本。
|
||||
enum DisplayMode: Equatable, Sendable {
|
||||
case original
|
||||
case edited
|
||||
case atmosphere
|
||||
case cover
|
||||
}
|
||||
|
||||
private(set) var isProcessing = false
|
||||
private(set) var didFailLastAttempt = false
|
||||
private(set) var appliedPresetID: String?
|
||||
private(set) var appliedAtmosphereOptionID: String?
|
||||
private(set) var appliedCoverTemplateID: String?
|
||||
private(set) var displayMode: DisplayMode = .original
|
||||
|
||||
/// 已经存在可查看的修图结果。
|
||||
var hasEditedResult: Bool {
|
||||
appliedPresetID != nil
|
||||
}
|
||||
|
||||
/// 处理期间禁止再次发起 AI 修图。
|
||||
var canStartEditing: Bool {
|
||||
!isProcessing
|
||||
}
|
||||
|
||||
/// 当前结果是否为封面模板生成的封面图。
|
||||
var isCover: Bool {
|
||||
appliedCoverTemplateID != nil
|
||||
}
|
||||
|
||||
/// 当前是否已经生成可独立查看的氛围感修图结果。
|
||||
var hasAtmosphereResult: Bool {
|
||||
appliedAtmosphereOptionID != nil
|
||||
}
|
||||
|
||||
/// 根据修图任务状态生成缩略图角标,处理中和失败优先于历史成功结果。
|
||||
var thumbnailStatus: ThumbnailStatus {
|
||||
if isProcessing {
|
||||
return .processing
|
||||
}
|
||||
if didFailLastAttempt {
|
||||
return .failed
|
||||
}
|
||||
if isCover {
|
||||
return .cover
|
||||
}
|
||||
return hasEditedResult ? .edited : .none
|
||||
}
|
||||
|
||||
/// 开始修图;已有结果保留到新结果完成,避免处理中画面回退。
|
||||
mutating func startProcessing() {
|
||||
guard !isProcessing else { return }
|
||||
isProcessing = true
|
||||
didFailLastAttempt = false
|
||||
}
|
||||
|
||||
/// 完成修图并覆盖旧预设结果,默认展示新的修图后版本。
|
||||
mutating func complete(
|
||||
presetID: String,
|
||||
atmosphereOptionID: String? = nil,
|
||||
coverTemplateID: String? = nil
|
||||
) {
|
||||
isProcessing = false
|
||||
didFailLastAttempt = false
|
||||
appliedPresetID = presetID
|
||||
appliedAtmosphereOptionID = atmosphereOptionID
|
||||
appliedCoverTemplateID = coverTemplateID
|
||||
displayMode = coverTemplateID == nil ? .edited : .cover
|
||||
}
|
||||
|
||||
/// 处理失败时恢复入口;已有成功结果继续保留。
|
||||
mutating func failProcessing() {
|
||||
isProcessing = false
|
||||
didFailLastAttempt = true
|
||||
}
|
||||
|
||||
/// 选择还原原图后清除历史修图结果和失败状态。
|
||||
mutating func restoreOriginal() {
|
||||
isProcessing = false
|
||||
didFailLastAttempt = false
|
||||
appliedPresetID = nil
|
||||
appliedAtmosphereOptionID = nil
|
||||
appliedCoverTemplateID = nil
|
||||
displayMode = .original
|
||||
}
|
||||
|
||||
/// 在已有结果时切换原图或修图后预览。
|
||||
mutating func selectDisplayMode(_ mode: DisplayMode) {
|
||||
guard hasEditedResult else {
|
||||
displayMode = .original
|
||||
return
|
||||
}
|
||||
if mode == .atmosphere, !hasAtmosphereResult {
|
||||
displayMode = .edited
|
||||
return
|
||||
}
|
||||
if mode == .cover, !isCover {
|
||||
displayMode = .edited
|
||||
return
|
||||
}
|
||||
displayMode = mode
|
||||
}
|
||||
}
|
||||
|
||||
/// 相册管理底部操作栏状态,用于在上传与多选操作之间切换。
|
||||
struct TravelAlbumSelectionToolbarState: Equatable, Sendable {
|
||||
let isSelectionMode: Bool
|
||||
let selectedCount: Int
|
||||
|
||||
/// 普通状态显示上传照片。
|
||||
var showsUpload: Bool {
|
||||
!isSelectionMode
|
||||
}
|
||||
|
||||
/// 多选状态显示 AI 修图和删除。
|
||||
var showsSelectionActions: Bool {
|
||||
isSelectionMode
|
||||
}
|
||||
|
||||
/// 至少选中一张照片后才允许执行批量操作。
|
||||
var selectionActionsEnabled: Bool {
|
||||
isSelectionMode && selectedCount > 0
|
||||
}
|
||||
}
|
||||
|
||||
/// 相册照片预览状态,维护当前照片位置并处理左右切换。
|
||||
struct TravelAlbumPhotoPreviewState: Equatable, Sendable {
|
||||
private(set) var materials: [TravelAlbumMaterial]
|
||||
private(set) var currentIndex: Int
|
||||
|
||||
init(materials: [TravelAlbumMaterial], initialIndex: Int) {
|
||||
self.materials = materials
|
||||
currentIndex = min(max(initialIndex, 0), max(materials.count - 1, 0))
|
||||
}
|
||||
|
||||
/// 当前正在预览的照片。
|
||||
var currentMaterial: TravelAlbumMaterial? {
|
||||
materials.indices.contains(currentIndex) ? materials[currentIndex] : nil
|
||||
}
|
||||
|
||||
/// 切换至下一张;已经是最后一张时保持不变。
|
||||
@discardableResult
|
||||
mutating func moveNext() -> Bool {
|
||||
guard currentIndex + 1 < materials.count else { return false }
|
||||
currentIndex += 1
|
||||
return true
|
||||
}
|
||||
|
||||
/// 切换至上一张;已经是第一张时保持不变。
|
||||
@discardableResult
|
||||
mutating func movePrevious() -> Bool {
|
||||
guard currentIndex > 0 else { return false }
|
||||
currentIndex -= 1
|
||||
return true
|
||||
}
|
||||
|
||||
/// 删除当前照片,并自动定位到相邻照片。
|
||||
@discardableResult
|
||||
mutating func removeCurrent() -> Bool {
|
||||
guard materials.indices.contains(currentIndex) else { return false }
|
||||
materials.remove(at: currentIndex)
|
||||
if currentIndex >= materials.count {
|
||||
currentIndex = max(materials.count - 1, 0)
|
||||
}
|
||||
return !materials.isEmpty
|
||||
}
|
||||
}
|
||||
|
||||
/// 相册照片 AI 修图预设,当前为本地演示数据,后续可替换为服务端下发的预设列表。
|
||||
struct TravelAlbumEditPreset: Hashable, Sendable, Identifiable {
|
||||
/// 图像效果类型,用于在预览页生成对应效果图。
|
||||
enum Effect: String, Hashable, Sendable {
|
||||
case original
|
||||
case portrait
|
||||
case vintage
|
||||
case brocade
|
||||
case distantMountain
|
||||
case mist
|
||||
case summer
|
||||
case rich
|
||||
}
|
||||
|
||||
let id: String
|
||||
let title: String
|
||||
let effect: Effect
|
||||
|
||||
/// AI 修图底部弹窗展示的默认预设,暂无接口时用于完整演示选择流程。
|
||||
static let defaultOptions: [TravelAlbumEditPreset] = [
|
||||
TravelAlbumEditPreset(id: "original", title: "还原为原图", effect: .original),
|
||||
TravelAlbumEditPreset(id: "portrait", title: "写真-简约肖像", effect: .portrait),
|
||||
TravelAlbumEditPreset(id: "vintage", title: "写真-清冷古风", effect: .vintage),
|
||||
TravelAlbumEditPreset(id: "brocade", title: "旅拍-锦绣", effect: .brocade),
|
||||
TravelAlbumEditPreset(id: "distant_mountain", title: "旅拍-远山", effect: .distantMountain),
|
||||
TravelAlbumEditPreset(id: "mist", title: "旅拍-薄雾", effect: .mist),
|
||||
TravelAlbumEditPreset(id: "summer", title: "油画-夏日", effect: .summer),
|
||||
TravelAlbumEditPreset(id: "rich", title: "油画-浓郁", effect: .rich),
|
||||
]
|
||||
}
|
||||
|
||||
/// 可选的氛围感修图样式;选中后在原图精修之外额外生成一张独立结果。
|
||||
struct TravelAlbumAtmosphereEditOption: Hashable, Sendable, Identifiable {
|
||||
let id: String
|
||||
let title: String
|
||||
let subtitle: String
|
||||
let effect: TravelAlbumEditPreset.Effect
|
||||
|
||||
/// 暂无接口时用于演示横向滚动单选的氛围感样式。
|
||||
static let defaultOptions: [TravelAlbumAtmosphereEditOption] = [
|
||||
TravelAlbumAtmosphereEditOption(
|
||||
id: "warm_sun",
|
||||
title: "日落暖阳",
|
||||
subtitle: "温暖柔和",
|
||||
effect: .summer
|
||||
),
|
||||
TravelAlbumAtmosphereEditOption(
|
||||
id: "retro_film",
|
||||
title: "复古胶片",
|
||||
subtitle: "怀旧颗粒感",
|
||||
effect: .vintage
|
||||
),
|
||||
TravelAlbumAtmosphereEditOption(
|
||||
id: "clear_blue",
|
||||
title: "清透蓝调",
|
||||
subtitle: "通透轻盈",
|
||||
effect: .mist
|
||||
),
|
||||
TravelAlbumAtmosphereEditOption(
|
||||
id: "forest_mist",
|
||||
title: "森系薄雾",
|
||||
subtitle: "低饱和自然感",
|
||||
effect: .distantMountain
|
||||
),
|
||||
TravelAlbumAtmosphereEditOption(
|
||||
id: "vivid_story",
|
||||
title: "浓郁故事",
|
||||
subtitle: "高饱和电影感",
|
||||
effect: .rich
|
||||
),
|
||||
]
|
||||
|
||||
/// 兼容现有结果测试与默认演示数据的首个氛围感样式。
|
||||
static let defaultOption = defaultOptions[0]
|
||||
}
|
||||
|
||||
/// 多图 AI 修图使用的封面风格模板,当前为本地演示数据,后续可替换为服务端配置。
|
||||
struct TravelAlbumCoverTemplate: Hashable, Sendable, Identifiable {
|
||||
/// 封面预览的排版样式,用于生成可辨识的本地效果图。
|
||||
enum PreviewStyle: String, Hashable, Sendable {
|
||||
case travelMemoir
|
||||
case minimal
|
||||
case scenicStory
|
||||
case film
|
||||
}
|
||||
|
||||
/// 触发展示封面模板选择的最少照片数量。
|
||||
static let minimumPhotoCount = 4
|
||||
|
||||
let id: String
|
||||
let title: String
|
||||
let previewStyle: PreviewStyle
|
||||
/// 当前消耗的精修额度;免费阶段为 0,后续收费可由服务端改为正数。
|
||||
let quotaCost: Int
|
||||
|
||||
/// 当前模板是否为赠送且不占用精修张数。
|
||||
var isFreeGift: Bool {
|
||||
quotaCost == 0
|
||||
}
|
||||
|
||||
/// 判断本次多选是否需要展示封面模板模块。
|
||||
static func shouldShow(for selectedPhotoCount: Int) -> Bool {
|
||||
selectedPhotoCount >= minimumPhotoCount
|
||||
}
|
||||
|
||||
/// 暂无接口时用于完整演示单选流程的封面模板。
|
||||
static let defaultOptions: [TravelAlbumCoverTemplate] = [
|
||||
TravelAlbumCoverTemplate(id: "travel_memoir", title: "旅行纪念册", previewStyle: .travelMemoir, quotaCost: 0),
|
||||
TravelAlbumCoverTemplate(id: "minimal", title: "简约留白", previewStyle: .minimal, quotaCost: 0),
|
||||
TravelAlbumCoverTemplate(id: "scenic_story", title: "景区故事", previewStyle: .scenicStory, quotaCost: 0),
|
||||
TravelAlbumCoverTemplate(id: "film", title: "电影胶片", previewStyle: .film, quotaCost: 0),
|
||||
]
|
||||
}
|
||||
|
||||
/// AI 修图弹窗最终提交的样式组合,统一承载原图精修、氛围感和封面模板。
|
||||
struct TravelAlbumAIEditSelection: Equatable, Sendable {
|
||||
let refinedPreset: TravelAlbumEditPreset
|
||||
let atmosphereOption: TravelAlbumAtmosphereEditOption?
|
||||
let coverTemplate: TravelAlbumCoverTemplate?
|
||||
|
||||
/// 每张普通照片需要生成的修图结果数量,不包含原图。
|
||||
var resultCountPerPhoto: Int {
|
||||
atmosphereOption == nil ? 1 : 2
|
||||
}
|
||||
|
||||
/// 弹窗当前展示并提交的样式类别数量。
|
||||
var selectedStyleCount: Int {
|
||||
1 + (atmosphereOption == nil ? 0 : 1) + (coverTemplate == nil ? 0 : 1)
|
||||
}
|
||||
}
|
||||
@ -52,6 +52,12 @@ struct TravelAlbumOTGPhotoSection: Hashable, Sendable {
|
||||
let photos: [TravelAlbumOTGPhotoItem]
|
||||
}
|
||||
|
||||
/// 有线传输照片预览上下文,保存可预览照片顺序和点击照片位置。
|
||||
struct TravelAlbumOTGPhotoPreviewContext: Equatable, Sendable {
|
||||
let photos: [TravelAlbumOTGPhotoItem]
|
||||
let initialIndex: Int
|
||||
}
|
||||
|
||||
/// OTG 传输页 Tab。
|
||||
enum TravelAlbumOTGTransferTab: Int, CaseIterable, Sendable {
|
||||
case all
|
||||
@ -80,6 +86,16 @@ enum TravelAlbumOTGTransferMode: String, CaseIterable, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
/// 模式选择弹窗中的业务说明。
|
||||
var detailText: String {
|
||||
switch self {
|
||||
case .liveUpload:
|
||||
return "相机拍摄后,照片自动传输并上传到当前相册"
|
||||
case .postTransfer:
|
||||
return "拍摄完成后,再选择照片批量传输"
|
||||
}
|
||||
}
|
||||
|
||||
/// 是否在新照片导入 App 后自动上传。
|
||||
var shouldAutoUploadNewImports: Bool {
|
||||
self == .liveUpload
|
||||
@ -113,6 +129,18 @@ extension TravelAlbumOTGPhotoItem {
|
||||
}
|
||||
|
||||
extension Array where Element == TravelAlbumOTGPhotoItem {
|
||||
/// 按当前列表顺序生成预览上下文,不可预览照片不会占用左右滑动页码。
|
||||
func previewContext(startingWith photoID: String) -> TravelAlbumOTGPhotoPreviewContext? {
|
||||
let previewablePhotos = filter { $0.thumbnailURL != nil }
|
||||
guard let initialIndex = previewablePhotos.firstIndex(where: { $0.id == photoID }) else {
|
||||
return nil
|
||||
}
|
||||
return TravelAlbumOTGPhotoPreviewContext(
|
||||
photos: previewablePhotos,
|
||||
initialIndex: initialIndex
|
||||
)
|
||||
}
|
||||
|
||||
/// 按 Android OTG 页规则构造半小时照片分段。
|
||||
func buildPhotoSections() -> [TravelAlbumOTGPhotoSection] {
|
||||
let pairs = compactMap { photo -> (slotStart: Date, photo: TravelAlbumOTGPhotoItem)? in
|
||||
|
||||
@ -0,0 +1,308 @@
|
||||
//
|
||||
// TravelAlbumAIEditResultStore.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import CoreImage
|
||||
import UIKit
|
||||
|
||||
/// AI 修图结果的内存数据源,在相册管理与照片预览之间共享本地演示结果。
|
||||
@MainActor
|
||||
final class TravelAlbumAIEditResultStore {
|
||||
/// 单张照片的修图记录。
|
||||
struct Record {
|
||||
var state: TravelAlbumAIEditResultState
|
||||
var editedImage: UIImage?
|
||||
var atmosphereImage: UIImage?
|
||||
var coverImage: UIImage?
|
||||
}
|
||||
|
||||
static let shared = TravelAlbumAIEditResultStore()
|
||||
static let didChangeNotification = Notification.Name("TravelAlbumAIEditResultStore.didChange")
|
||||
static let materialIDUserInfoKey = "materialID"
|
||||
|
||||
private var recordsByMaterialID: [Int: Record] = [:]
|
||||
|
||||
private init() {}
|
||||
|
||||
/// 获取指定照片的修图状态。
|
||||
func state(for materialID: Int) -> TravelAlbumAIEditResultState {
|
||||
recordsByMaterialID[materialID]?.state ?? TravelAlbumAIEditResultState()
|
||||
}
|
||||
|
||||
/// 获取指定照片最新的修图结果。
|
||||
func editedImage(for materialID: Int) -> UIImage? {
|
||||
recordsByMaterialID[materialID]?.editedImage
|
||||
}
|
||||
|
||||
/// 获取指定照片最新的氛围感修图结果。
|
||||
func atmosphereImage(for materialID: Int) -> UIImage? {
|
||||
recordsByMaterialID[materialID]?.atmosphereImage
|
||||
}
|
||||
|
||||
/// 获取指定照片最新的封面模板结果。
|
||||
func coverImage(for materialID: Int) -> UIImage? {
|
||||
recordsByMaterialID[materialID]?.coverImage
|
||||
}
|
||||
|
||||
/// 将照片标记为修图中,已有结果继续保留到新结果完成。
|
||||
func startProcessing(materialIDs: [Int]) {
|
||||
materialIDs.forEach { materialID in
|
||||
var record = recordsByMaterialID[materialID]
|
||||
?? Record(
|
||||
state: TravelAlbumAIEditResultState(),
|
||||
editedImage: nil,
|
||||
atmosphereImage: nil,
|
||||
coverImage: nil
|
||||
)
|
||||
record.state.startProcessing()
|
||||
recordsByMaterialID[materialID] = record
|
||||
notifyChange(materialID: materialID)
|
||||
}
|
||||
}
|
||||
|
||||
/// 保存最新结果并覆盖同一照片之前的修图结果。
|
||||
func complete(
|
||||
materialID: Int,
|
||||
presetID: String,
|
||||
atmosphereOptionID: String? = nil,
|
||||
coverTemplateID: String? = nil,
|
||||
editedImage: UIImage,
|
||||
atmosphereImage: UIImage? = nil,
|
||||
coverImage: UIImage? = nil
|
||||
) {
|
||||
var record = recordsByMaterialID[materialID]
|
||||
?? Record(
|
||||
state: TravelAlbumAIEditResultState(),
|
||||
editedImage: nil,
|
||||
atmosphereImage: nil,
|
||||
coverImage: nil
|
||||
)
|
||||
record.state.complete(
|
||||
presetID: presetID,
|
||||
atmosphereOptionID: atmosphereOptionID,
|
||||
coverTemplateID: coverTemplateID
|
||||
)
|
||||
record.editedImage = editedImage
|
||||
record.atmosphereImage = atmosphereImage
|
||||
record.coverImage = coverImage
|
||||
recordsByMaterialID[materialID] = record
|
||||
notifyChange(materialID: materialID)
|
||||
}
|
||||
|
||||
/// 修图失败时恢复按钮可用状态,并保留之前成功的结果。
|
||||
func failProcessing(materialID: Int) {
|
||||
guard var record = recordsByMaterialID[materialID] else { return }
|
||||
record.state.failProcessing()
|
||||
recordsByMaterialID[materialID] = record
|
||||
notifyChange(materialID: materialID)
|
||||
}
|
||||
|
||||
/// 还原为原图时清除该照片的本地修图结果。
|
||||
func restoreOriginal(materialID: Int) {
|
||||
guard var record = recordsByMaterialID[materialID] else { return }
|
||||
record.state.restoreOriginal()
|
||||
record.editedImage = nil
|
||||
record.atmosphereImage = nil
|
||||
record.coverImage = nil
|
||||
recordsByMaterialID[materialID] = record
|
||||
notifyChange(materialID: materialID)
|
||||
}
|
||||
|
||||
/// 切换指定照片当前展示的原图或修图后版本。
|
||||
func selectDisplayMode(_ mode: TravelAlbumAIEditResultState.DisplayMode, materialID: Int) {
|
||||
guard var record = recordsByMaterialID[materialID] else { return }
|
||||
record.state.selectDisplayMode(mode)
|
||||
recordsByMaterialID[materialID] = record
|
||||
notifyChange(materialID: materialID)
|
||||
}
|
||||
|
||||
/// 删除照片时同步清理其本地修图结果。
|
||||
func remove(materialID: Int) {
|
||||
recordsByMaterialID.removeValue(forKey: materialID)
|
||||
notifyChange(materialID: materialID)
|
||||
}
|
||||
|
||||
private func notifyChange(materialID: Int) {
|
||||
NotificationCenter.default.post(
|
||||
name: Self.didChangeNotification,
|
||||
object: self,
|
||||
userInfo: [Self.materialIDUserInfoKey: materialID]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// 本地 AI 修图效果生成器;后续接入服务端时可替换为结果图片下载。
|
||||
@MainActor
|
||||
enum TravelAlbumAIEditImageProcessor {
|
||||
private static let context = CIContext()
|
||||
|
||||
/// 根据预设生成演示用修图图片。
|
||||
static func render(
|
||||
effect: TravelAlbumEditPreset.Effect,
|
||||
source: UIImage
|
||||
) -> UIImage {
|
||||
guard effect != .original, let ciImage = CIImage(image: source) else { return source }
|
||||
let output: CIImage
|
||||
switch effect {
|
||||
case .original:
|
||||
output = ciImage
|
||||
case .portrait:
|
||||
output = ciImage.applyingFilter("CIColorControls", parameters: [
|
||||
kCIInputSaturationKey: 0.86,
|
||||
kCIInputBrightnessKey: 0.07,
|
||||
kCIInputContrastKey: 1.08,
|
||||
])
|
||||
case .vintage:
|
||||
output = ciImage.applyingFilter("CISepiaTone", parameters: [kCIInputIntensityKey: 0.45])
|
||||
case .brocade:
|
||||
output = ciImage.applyingFilter("CIColorControls", parameters: [
|
||||
kCIInputSaturationKey: 1.22,
|
||||
kCIInputBrightnessKey: 0.04,
|
||||
kCIInputContrastKey: 1.1,
|
||||
])
|
||||
case .distantMountain:
|
||||
output = ciImage.applyingFilter("CIColorControls", parameters: [
|
||||
kCIInputSaturationKey: 0.72,
|
||||
kCIInputBrightnessKey: 0.1,
|
||||
kCIInputContrastKey: 0.9,
|
||||
])
|
||||
case .mist:
|
||||
output = ciImage.applyingFilter("CIColorControls", parameters: [
|
||||
kCIInputSaturationKey: 0.7,
|
||||
kCIInputBrightnessKey: 0.14,
|
||||
kCIInputContrastKey: 0.82,
|
||||
])
|
||||
case .summer:
|
||||
output = ciImage.applyingFilter("CISepiaTone", parameters: [kCIInputIntensityKey: 0.24])
|
||||
case .rich:
|
||||
output = ciImage.applyingFilter("CIColorControls", parameters: [
|
||||
kCIInputSaturationKey: 1.38,
|
||||
kCIInputBrightnessKey: -0.02,
|
||||
kCIInputContrastKey: 1.2,
|
||||
])
|
||||
}
|
||||
guard let cgImage = context.createCGImage(output, from: output.extent) else { return source }
|
||||
return UIImage(cgImage: cgImage, scale: source.scale, orientation: source.imageOrientation)
|
||||
}
|
||||
}
|
||||
|
||||
/// 本地封面模板效果生成器,让封面结果在缩略图和预览页中与普通照片明显区分。
|
||||
@MainActor
|
||||
enum TravelAlbumCoverTemplateImageProcessor {
|
||||
/// 将照片渲染为指定封面排版;无原图时使用稳定的演示背景。
|
||||
static func render(
|
||||
template: TravelAlbumCoverTemplate,
|
||||
source: UIImage?,
|
||||
targetSize: CGSize = CGSize(width: 1200, height: 900)
|
||||
) -> UIImage {
|
||||
UIGraphicsImageRenderer(size: targetSize).image { context in
|
||||
let bounds = CGRect(origin: .zero, size: targetSize)
|
||||
UIColor(hex: 0xCAD8E8).setFill()
|
||||
context.cgContext.fill(bounds)
|
||||
if let source {
|
||||
source.draw(in: aspectFillRect(imageSize: source.size, bounds: bounds))
|
||||
}
|
||||
|
||||
let unit = min(targetSize.width / 232, targetSize.height / 208)
|
||||
switch template.previewStyle {
|
||||
case .travelMemoir:
|
||||
UIColor.black.withAlphaComponent(0.24).setFill()
|
||||
context.cgContext.fill(bounds)
|
||||
UIColor.white.setStroke()
|
||||
let oval = UIBezierPath(ovalIn: CGRect(
|
||||
x: bounds.midX - 50 * unit,
|
||||
y: 28 * unit,
|
||||
width: 100 * unit,
|
||||
height: 100 * unit
|
||||
))
|
||||
oval.lineWidth = 9 * unit
|
||||
oval.stroke()
|
||||
drawCaption(
|
||||
"TRAVEL\nMEMOIR",
|
||||
in: CGRect(x: 30 * unit, y: bounds.height - 62 * unit, width: bounds.width - 60 * unit, height: 46 * unit),
|
||||
alignment: .center,
|
||||
fontSize: 17 * unit
|
||||
)
|
||||
case .minimal:
|
||||
UIColor.white.withAlphaComponent(0.9).setFill()
|
||||
context.cgContext.fill(CGRect(x: bounds.width * 0.55, y: 0, width: bounds.width * 0.45, height: bounds.height))
|
||||
drawCaption(
|
||||
"LESS\nIS MORE",
|
||||
in: CGRect(x: bounds.width * 0.62, y: bounds.midY - 27 * unit, width: bounds.width * 0.3, height: 54 * unit),
|
||||
alignment: .left,
|
||||
color: .black,
|
||||
fontSize: 17 * unit
|
||||
)
|
||||
case .scenicStory:
|
||||
UIColor.black.withAlphaComponent(0.2).setFill()
|
||||
context.cgContext.fill(bounds)
|
||||
UIColor.white.setStroke()
|
||||
let inset = 20 * unit
|
||||
let frame = UIBezierPath(rect: bounds.insetBy(dx: inset, dy: inset))
|
||||
frame.lineWidth = 4 * unit
|
||||
frame.stroke()
|
||||
drawCaption(
|
||||
"SCENIC STORY",
|
||||
in: CGRect(x: 34 * unit, y: bounds.height - 58 * unit, width: bounds.width - 68 * unit, height: 24 * unit),
|
||||
alignment: .center,
|
||||
fontSize: 17 * unit
|
||||
)
|
||||
case .film:
|
||||
let stripHeight = 24 * unit
|
||||
UIColor.black.withAlphaComponent(0.72).setFill()
|
||||
context.cgContext.fill(CGRect(x: 0, y: 0, width: bounds.width, height: stripHeight))
|
||||
context.cgContext.fill(CGRect(x: 0, y: bounds.height - stripHeight, width: bounds.width, height: stripHeight))
|
||||
UIColor.white.withAlphaComponent(0.9).setFill()
|
||||
var x = 10 * unit
|
||||
while x <= bounds.width - 16 * unit {
|
||||
context.cgContext.fill(CGRect(x: x, y: 6 * unit, width: 14 * unit, height: 10 * unit))
|
||||
context.cgContext.fill(CGRect(
|
||||
x: x,
|
||||
y: bounds.height - 16 * unit,
|
||||
width: 14 * unit,
|
||||
height: 10 * unit
|
||||
))
|
||||
x += 30 * unit
|
||||
}
|
||||
drawCaption(
|
||||
"THE JOURNEY",
|
||||
in: CGRect(x: 28 * unit, y: bounds.height - 60 * unit, width: bounds.width - 56 * unit, height: 24 * unit),
|
||||
alignment: .center,
|
||||
fontSize: 17 * unit
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static func aspectFillRect(imageSize: CGSize, bounds: CGRect) -> CGRect {
|
||||
guard imageSize.width > 0, imageSize.height > 0 else { return bounds }
|
||||
let scale = max(bounds.width / imageSize.width, bounds.height / imageSize.height)
|
||||
let drawSize = CGSize(width: imageSize.width * scale, height: imageSize.height * scale)
|
||||
return CGRect(
|
||||
x: bounds.midX - drawSize.width / 2,
|
||||
y: bounds.midY - drawSize.height / 2,
|
||||
width: drawSize.width,
|
||||
height: drawSize.height
|
||||
)
|
||||
}
|
||||
|
||||
private static func drawCaption(
|
||||
_ text: String,
|
||||
in rect: CGRect,
|
||||
alignment: NSTextAlignment,
|
||||
color: UIColor = .white,
|
||||
fontSize: CGFloat
|
||||
) {
|
||||
let paragraph = NSMutableParagraphStyle()
|
||||
paragraph.alignment = alignment
|
||||
text.draw(
|
||||
in: rect,
|
||||
withAttributes: [
|
||||
.font: UIFont.systemFont(ofSize: fontSize, weight: .bold),
|
||||
.foregroundColor: color,
|
||||
.paragraphStyle: paragraph,
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -36,6 +36,7 @@ final class TravelAlbumDetailViewModel {
|
||||
private(set) var sortOption: SortOption = .createdDesc
|
||||
private(set) var isLoading = true
|
||||
private(set) var isRefreshing = false
|
||||
private(set) var isUsingPurchasedDemoData = false
|
||||
private(set) var isSelectionMode = false
|
||||
private(set) var selectedMaterialIds: Set<Int> = []
|
||||
|
||||
@ -126,6 +127,7 @@ final class TravelAlbumDetailViewModel {
|
||||
if reset {
|
||||
currentPage = 1
|
||||
canLoadMore = false
|
||||
isUsingPurchasedDemoData = false
|
||||
} else {
|
||||
guard canLoadMore, !isLoadingMore else { return }
|
||||
isLoadingMore = true
|
||||
@ -140,8 +142,15 @@ final class TravelAlbumDetailViewModel {
|
||||
orderBy: sortOption.rawValue,
|
||||
isPurchased: selectedTab == .purchased ? 1 : nil
|
||||
)
|
||||
materials = reset ? response.list : materials + response.list
|
||||
canLoadMore = materials.count < response.total
|
||||
if reset,
|
||||
selectedTab == .purchased,
|
||||
response.total == 0,
|
||||
response.list.isEmpty {
|
||||
applyPurchasedDemoMaterials()
|
||||
} else {
|
||||
materials = reset ? response.list : materials + response.list
|
||||
canLoadMore = materials.count < response.total
|
||||
}
|
||||
if selectedTab == .all {
|
||||
allPhotoCount = response.total
|
||||
}
|
||||
@ -154,6 +163,12 @@ final class TravelAlbumDetailViewModel {
|
||||
currentPage -= 1
|
||||
}
|
||||
isLoadingMore = false
|
||||
if reset, selectedTab == .purchased {
|
||||
// 已购接口暂不可用时继续提供稳定的本地演示数据,保证产品流程可演示。
|
||||
applyPurchasedDemoMaterials()
|
||||
notifyStateChange()
|
||||
return
|
||||
}
|
||||
onShowMessage?(error.localizedDescription)
|
||||
}
|
||||
}
|
||||
@ -225,6 +240,44 @@ final class TravelAlbumDetailViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
/// 已购照片接口无数据时生成稳定的本地素材;真实接口一旦返回数据即不再使用。
|
||||
private func applyPurchasedDemoMaterials() {
|
||||
let demoItems: [(fileName: String, fileSize: Int, assetName: String, createdAt: String)] = [
|
||||
("IMG_0724_0001.jpeg", 2_684_928, "purchased_alpine_lake", "2026-07-24 11:25:18"),
|
||||
("IMG_0724_0002.jpeg", 3_215_360, "purchased_forest_waterfall", "2026-07-24 11:27:46"),
|
||||
("IMG_0724_0003.jpeg", 2_936_832, "purchased_grassland_path", "2026-07-24 11:31:09"),
|
||||
("IMG_0724_0004.jpeg", 3_481_600, "purchased_lakeside_flowers", "2026-07-24 11:34:22"),
|
||||
]
|
||||
var materials = demoItems.enumerated().map { index, item in
|
||||
TravelAlbumMaterial(
|
||||
id: -((albumId * 10) + index + 1),
|
||||
userEquityTravelId: albumId,
|
||||
status: 2,
|
||||
fileName: item.fileName,
|
||||
fileType: 1,
|
||||
fileUrl: TravelAlbumMaterial.bundledImageURL(assetName: item.assetName),
|
||||
fileSize: item.fileSize,
|
||||
coverUrl: TravelAlbumMaterial.bundledImageURL(assetName: item.assetName),
|
||||
isPurchased: true,
|
||||
createdAt: item.createdAt,
|
||||
updatedAt: item.createdAt
|
||||
)
|
||||
}
|
||||
switch sortOption {
|
||||
case .createdAsc:
|
||||
materials.sort { $0.createdAt < $1.createdAt }
|
||||
case .createdDesc:
|
||||
materials.sort { $0.createdAt > $1.createdAt }
|
||||
case .fileNameAsc:
|
||||
materials.sort { $0.fileName.localizedStandardCompare($1.fileName) == .orderedAscending }
|
||||
case .fileNameDesc:
|
||||
materials.sort { $0.fileName.localizedStandardCompare($1.fileName) == .orderedDescending }
|
||||
}
|
||||
self.materials = materials
|
||||
canLoadMore = false
|
||||
isUsingPurchasedDemoData = true
|
||||
}
|
||||
|
||||
private func notifyStateChange() {
|
||||
onStateChange?()
|
||||
}
|
||||
|
||||
@ -94,6 +94,7 @@ final class WiredCameraTransferViewModel {
|
||||
albumTitle: String,
|
||||
headerPhone: String,
|
||||
scenicSpotLabel: String? = nil,
|
||||
initialTransferMode: TravelAlbumOTGTransferMode? = nil,
|
||||
connectionManager: (any WiredCameraConnectionManaging)? = nil,
|
||||
storage: TravelAlbumOTGPhotoStore = TravelAlbumOTGPhotoStore(),
|
||||
uploader: (any TravelAlbumOTGUploading)? = nil,
|
||||
@ -112,7 +113,11 @@ final class WiredCameraTransferViewModel {
|
||||
self.api = api ?? NetworkServices.shared.travelAlbumAPI
|
||||
self.appStore = appStore
|
||||
self.userDefaults = userDefaults
|
||||
self.transferMode = Self.persistedTransferMode(in: userDefaults)
|
||||
// 从相册管理选择模式进入时,以本次选择为准;其他旧入口继续沿用上次记录。
|
||||
self.transferMode = initialTransferMode ?? Self.persistedTransferMode(in: userDefaults)
|
||||
if let initialTransferMode {
|
||||
userDefaults.set(initialTransferMode.rawValue, forKey: Self.transferModeDefaultsKey)
|
||||
}
|
||||
}
|
||||
|
||||
/// 相机状态文案。
|
||||
|
||||
@ -11,6 +11,9 @@ import UIKit
|
||||
final class TravelAlbumDetailViewController: BaseViewController {
|
||||
private let viewModel: TravelAlbumDetailViewModel
|
||||
private let api: any TravelAlbumServing
|
||||
private let aiEditResultStore = TravelAlbumAIEditResultStore.shared
|
||||
private var pendingAIEditMaterialIDs: Set<Int> = []
|
||||
private var failedAIEditCount = 0
|
||||
|
||||
private let scrollContainer = UIView()
|
||||
private let infoCard = TravelAlbumInfoCard()
|
||||
@ -24,9 +27,9 @@ final class TravelAlbumDetailViewController: BaseViewController {
|
||||
private var dataSource: UICollectionViewDiffableDataSource<Int, TravelAlbumMaterial>!
|
||||
private let bottomBar = UIView()
|
||||
private let bottomActionStack = UIStackView()
|
||||
private let aiEditSelectedButton = UIButton(type: .system)
|
||||
private let deleteSelectedButton = UIButton(type: .system)
|
||||
private let uploadButton = UIButton(type: .system)
|
||||
private var isDeleteSelectedButtonVisible = false
|
||||
|
||||
init(albumId: Int, api: (any TravelAlbumServing)? = nil) {
|
||||
viewModel = TravelAlbumDetailViewModel(albumId: albumId)
|
||||
@ -41,6 +44,7 @@ final class TravelAlbumDetailViewController: BaseViewController {
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = "相册管理"
|
||||
navigationItem.backButtonDisplayMode = .minimal
|
||||
navigationItem.rightBarButtonItem = UIBarButtonItem(
|
||||
image: UIImage(systemName: "ellipsis"),
|
||||
menu: UIMenu(children: [
|
||||
@ -78,21 +82,39 @@ final class TravelAlbumDetailViewController: BaseViewController {
|
||||
withReuseIdentifier: TravelAlbumMaterialCell.reuseIdentifier,
|
||||
for: indexPath
|
||||
) as! TravelAlbumMaterialCell
|
||||
let aiEditState = self?.aiEditResultStore.state(for: material.id)
|
||||
?? TravelAlbumAIEditResultState()
|
||||
let resultImage = aiEditState.isCover
|
||||
? (self?.aiEditResultStore.coverImage(for: material.id)
|
||||
?? self?.aiEditResultStore.editedImage(for: material.id))
|
||||
: self?.aiEditResultStore.editedImage(for: material.id)
|
||||
cell.apply(
|
||||
material: material,
|
||||
selectionMode: self?.viewModel.isSelectionMode == true,
|
||||
selected: self?.viewModel.selectedMaterialIds.contains(material.id) == true
|
||||
selected: self?.viewModel.selectedMaterialIds.contains(material.id) == true,
|
||||
aiEditState: aiEditState,
|
||||
editedImage: resultImage
|
||||
)
|
||||
return cell
|
||||
}
|
||||
|
||||
bottomBar.backgroundColor = AppColor.pageBackground
|
||||
bottomActionStack.axis = .vertical
|
||||
bottomActionStack.spacing = 8
|
||||
configureBottomButton(deleteSelectedButton, title: "删除选中(0)", color: UIColor(hex: 0xE53935))
|
||||
bottomActionStack.axis = .horizontal
|
||||
bottomActionStack.spacing = 12
|
||||
bottomActionStack.distribution = .fillEqually
|
||||
configureSelectionActionButton(
|
||||
aiEditSelectedButton,
|
||||
title: "AI修图",
|
||||
image: UIImage(named: "travel_album_preview_ai_edit")?.withRenderingMode(.alwaysTemplate)
|
||||
)
|
||||
configureSelectionActionButton(
|
||||
deleteSelectedButton,
|
||||
title: "删除",
|
||||
image: UIImage(named: "travel_album_preview_delete")?.withRenderingMode(.alwaysTemplate)
|
||||
)
|
||||
configureBottomButton(uploadButton, title: "上传照片", color: AppColor.primary)
|
||||
aiEditSelectedButton.isHidden = true
|
||||
deleteSelectedButton.isHidden = true
|
||||
deleteSelectedButton.alpha = 0
|
||||
|
||||
view.addSubview(scrollContainer)
|
||||
scrollContainer.addSubview(infoCard)
|
||||
@ -105,6 +127,7 @@ final class TravelAlbumDetailViewController: BaseViewController {
|
||||
manageCard.addSubview(collectionView)
|
||||
view.addSubview(bottomBar)
|
||||
bottomBar.addSubview(bottomActionStack)
|
||||
bottomActionStack.addArrangedSubview(aiEditSelectedButton)
|
||||
bottomActionStack.addArrangedSubview(deleteSelectedButton)
|
||||
bottomActionStack.addArrangedSubview(uploadButton)
|
||||
}
|
||||
@ -118,11 +141,10 @@ final class TravelAlbumDetailViewController: BaseViewController {
|
||||
make.leading.trailing.equalToSuperview().inset(20)
|
||||
make.bottom.equalTo(view.safeAreaLayoutGuide).offset(-12)
|
||||
}
|
||||
deleteSelectedButton.snp.makeConstraints { make in
|
||||
make.height.equalTo(48).priority(.high)
|
||||
}
|
||||
uploadButton.snp.makeConstraints { make in
|
||||
make.height.equalTo(48).priority(.high)
|
||||
[aiEditSelectedButton, deleteSelectedButton, uploadButton].forEach { button in
|
||||
button.snp.makeConstraints { make in
|
||||
make.height.equalTo(58).priority(.high)
|
||||
}
|
||||
}
|
||||
scrollContainer.snp.makeConstraints { make in
|
||||
make.top.equalTo(view.safeAreaLayoutGuide).offset(12)
|
||||
@ -163,8 +185,15 @@ final class TravelAlbumDetailViewController: BaseViewController {
|
||||
purchasedTabButton.addTarget(self, action: #selector(purchasedTabTapped), for: .touchUpInside)
|
||||
sortButton.addTarget(self, action: #selector(sortTapped), for: .touchUpInside)
|
||||
selectButton.addTarget(self, action: #selector(selectTapped), for: .touchUpInside)
|
||||
aiEditSelectedButton.addTarget(self, action: #selector(aiEditSelectedTapped), for: .touchUpInside)
|
||||
deleteSelectedButton.addTarget(self, action: #selector(deleteSelectedTapped), for: .touchUpInside)
|
||||
uploadButton.addTarget(self, action: #selector(uploadTapped), for: .touchUpInside)
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(aiEditResultDidChange(_:)),
|
||||
name: TravelAlbumAIEditResultStore.didChangeNotification,
|
||||
object: aiEditResultStore
|
||||
)
|
||||
viewModel.onStateChange = { [weak self] in
|
||||
Task { @MainActor in self?.applyViewModel() }
|
||||
}
|
||||
@ -195,8 +224,7 @@ final class TravelAlbumDetailViewController: BaseViewController {
|
||||
selectButton.isHidden = viewModel.selectedTab != .all
|
||||
selectButton.setImage(UIImage(systemName: viewModel.isSelectionMode ? "checkmark.circle.fill" : "circle"), for: .normal)
|
||||
selectButton.tintColor = viewModel.isSelectionMode ? AppColor.primary : AppColor.textTertiary
|
||||
deleteSelectedButton.setTitle("删除选中(\(viewModel.selectedMaterialIds.count))", for: .normal)
|
||||
setDeleteSelectedButtonVisible(viewModel.isSelectionMode && !viewModel.selectedMaterialIds.isEmpty)
|
||||
updateBottomToolbar()
|
||||
|
||||
var snapshot = NSDiffableDataSourceSnapshot<Int, TravelAlbumMaterial>()
|
||||
snapshot.appendSections([0])
|
||||
@ -213,6 +241,28 @@ final class TravelAlbumDetailViewController: BaseViewController {
|
||||
}
|
||||
}
|
||||
|
||||
/// 根据选择数量和修图任务刷新底部操作栏。
|
||||
private func updateBottomToolbar() {
|
||||
let toolbarState = TravelAlbumSelectionToolbarState(
|
||||
isSelectionMode: viewModel.isSelectionMode,
|
||||
selectedCount: viewModel.selectedMaterialIds.count
|
||||
)
|
||||
uploadButton.isHidden = !toolbarState.showsUpload
|
||||
aiEditSelectedButton.isHidden = !toolbarState.showsSelectionActions
|
||||
deleteSelectedButton.isHidden = !toolbarState.showsSelectionActions
|
||||
let selectedContainsProcessingPhoto = viewModel.selectedMaterialIds.contains { materialID in
|
||||
aiEditResultStore.state(for: materialID).isProcessing
|
||||
}
|
||||
let canStartAIEditing = toolbarState.selectionActionsEnabled
|
||||
&& pendingAIEditMaterialIDs.isEmpty
|
||||
&& !selectedContainsProcessingPhoto
|
||||
aiEditSelectedButton.isEnabled = canStartAIEditing
|
||||
deleteSelectedButton.isEnabled = toolbarState.selectionActionsEnabled
|
||||
aiEditSelectedButton.alpha = canStartAIEditing ? 1 : 0.4
|
||||
deleteSelectedButton.alpha = toolbarState.selectionActionsEnabled ? 1 : 0.4
|
||||
bottomBar.backgroundColor = toolbarState.showsSelectionActions ? .white : AppColor.pageBackground
|
||||
}
|
||||
|
||||
private func configurePillButton(_ button: UIButton) {
|
||||
button.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
|
||||
button.layer.cornerRadius = 16
|
||||
@ -242,27 +292,20 @@ final class TravelAlbumDetailViewController: BaseViewController {
|
||||
button.layer.cornerRadius = 10
|
||||
}
|
||||
|
||||
private func setDeleteSelectedButtonVisible(_ visible: Bool) {
|
||||
guard visible != isDeleteSelectedButtonVisible else { return }
|
||||
isDeleteSelectedButtonVisible = visible
|
||||
|
||||
let changes = {
|
||||
self.deleteSelectedButton.isHidden = !visible
|
||||
self.deleteSelectedButton.alpha = visible ? 1 : 0
|
||||
self.view.layoutIfNeeded()
|
||||
/// 配置多选模式底部的图标操作按钮,图标复用照片预览页的 Iconfont 资源。
|
||||
private func configureSelectionActionButton(_ button: UIButton, title: String, image: UIImage?) {
|
||||
var configuration = UIButton.Configuration.plain()
|
||||
configuration.title = title
|
||||
configuration.image = image
|
||||
configuration.imagePlacement = .top
|
||||
configuration.imagePadding = 5
|
||||
configuration.baseForegroundColor = AppColor.textSecondary
|
||||
configuration.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in
|
||||
var attributes = attributes
|
||||
attributes.font = .systemFont(ofSize: 13, weight: .medium)
|
||||
return attributes
|
||||
}
|
||||
guard view.window != nil else {
|
||||
changes()
|
||||
return
|
||||
}
|
||||
|
||||
view.layoutIfNeeded()
|
||||
UIView.animate(
|
||||
withDuration: 0.25,
|
||||
delay: 0,
|
||||
options: [.curveEaseInOut, .beginFromCurrentState],
|
||||
animations: changes
|
||||
)
|
||||
button.configuration = configuration
|
||||
}
|
||||
|
||||
private func makeLayout() -> UICollectionViewCompositionalLayout {
|
||||
@ -319,6 +362,157 @@ final class TravelAlbumDetailViewController: BaseViewController {
|
||||
viewModel.toggleSelectionMode()
|
||||
}
|
||||
|
||||
@objc private func aiEditSelectedTapped() {
|
||||
let selectedMaterials = viewModel.materials.filter { viewModel.selectedMaterialIds.contains($0.id) }
|
||||
guard let firstMaterial = selectedMaterials.first else {
|
||||
showToast("请选择要修图的照片")
|
||||
return
|
||||
}
|
||||
let imageURLString = firstMaterial.coverUrl.isEmpty ? firstMaterial.fileUrl : firstMaterial.coverUrl
|
||||
guard let imageURL = URL(string: imageURLString), !imageURLString.isEmpty else {
|
||||
presentAIEditSheet(sourceImage: nil, selectedMaterials: selectedMaterials)
|
||||
return
|
||||
}
|
||||
KingfisherManager.shared.retrieveImage(with: imageURL) { [weak self] result in
|
||||
guard let self else { return }
|
||||
Task { @MainActor in
|
||||
let sourceImage: UIImage?
|
||||
if case let .success(value) = result {
|
||||
sourceImage = value.image
|
||||
} else {
|
||||
sourceImage = nil
|
||||
}
|
||||
self.presentAIEditSheet(sourceImage: sourceImage, selectedMaterials: selectedMaterials)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 复用单张照片预览页的 AI 修图预设弹窗完成批量选择演示。
|
||||
private func presentAIEditSheet(
|
||||
sourceImage: UIImage?,
|
||||
selectedMaterials: [TravelAlbumMaterial]
|
||||
) {
|
||||
let controller = TravelAlbumAIEditSheetViewController(
|
||||
sourceImage: sourceImage,
|
||||
selectedPhotoCount: selectedMaterials.count
|
||||
)
|
||||
controller.onConfirm = { [weak self] selection in
|
||||
self?.startBatchAIEditing(
|
||||
materials: selectedMaterials,
|
||||
selection: selection
|
||||
)
|
||||
}
|
||||
present(controller, animated: true)
|
||||
}
|
||||
|
||||
/// 启动批量本地演示修图,并在全部照片完成前禁用 AI 修图入口。
|
||||
private func startBatchAIEditing(
|
||||
materials: [TravelAlbumMaterial],
|
||||
selection: TravelAlbumAIEditSelection
|
||||
) {
|
||||
guard pendingAIEditMaterialIDs.isEmpty, !materials.isEmpty else { return }
|
||||
let materialIDs = materials.map(\.id)
|
||||
let coverMaterialID = selection.coverTemplate == nil ? nil : materials.first?.id
|
||||
pendingAIEditMaterialIDs = Set(materialIDs)
|
||||
failedAIEditCount = 0
|
||||
aiEditResultStore.startProcessing(materialIDs: materialIDs)
|
||||
applyViewModel()
|
||||
|
||||
materials.forEach { material in
|
||||
let imageURLString = material.fileUrl.isEmpty ? material.coverUrl : material.fileUrl
|
||||
guard let imageURL = URL(string: imageURLString), !imageURLString.isEmpty else {
|
||||
finishAIEditing(
|
||||
materialID: material.id,
|
||||
selection: selection,
|
||||
appliedCoverTemplate: material.id == coverMaterialID ? selection.coverTemplate : nil,
|
||||
sourceImage: nil
|
||||
)
|
||||
return
|
||||
}
|
||||
KingfisherManager.shared.retrieveImage(with: imageURL) { [weak self] result in
|
||||
guard let self else { return }
|
||||
Task { @MainActor in
|
||||
let sourceImage: UIImage?
|
||||
if case let .success(value) = result {
|
||||
sourceImage = value.image
|
||||
} else {
|
||||
sourceImage = nil
|
||||
}
|
||||
self.finishAIEditing(
|
||||
materialID: material.id,
|
||||
selection: selection,
|
||||
appliedCoverTemplate: material.id == coverMaterialID ? selection.coverTemplate : nil,
|
||||
sourceImage: sourceImage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 完成单张批量任务;最后一张结束后恢复入口并反馈整体结果。
|
||||
private func finishAIEditing(
|
||||
materialID: Int,
|
||||
selection: TravelAlbumAIEditSelection,
|
||||
appliedCoverTemplate: TravelAlbumCoverTemplate?,
|
||||
sourceImage: UIImage?
|
||||
) {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { [weak self] in
|
||||
guard let self else { return }
|
||||
if let sourceImage {
|
||||
let refinedImage = TravelAlbumAIEditImageProcessor.render(
|
||||
effect: selection.refinedPreset.effect,
|
||||
source: sourceImage
|
||||
)
|
||||
let atmosphereImage = selection.atmosphereOption.map { option in
|
||||
TravelAlbumAIEditImageProcessor.render(effect: option.effect, source: sourceImage)
|
||||
}
|
||||
let coverImage = appliedCoverTemplate.map { template in
|
||||
TravelAlbumCoverTemplateImageProcessor.render(
|
||||
template: template,
|
||||
source: refinedImage
|
||||
)
|
||||
}
|
||||
if selection.refinedPreset.effect == .original,
|
||||
selection.atmosphereOption == nil,
|
||||
appliedCoverTemplate == nil {
|
||||
self.aiEditResultStore.restoreOriginal(materialID: materialID)
|
||||
} else {
|
||||
self.aiEditResultStore.complete(
|
||||
materialID: materialID,
|
||||
presetID: selection.refinedPreset.id,
|
||||
atmosphereOptionID: selection.atmosphereOption?.id,
|
||||
coverTemplateID: appliedCoverTemplate?.id,
|
||||
editedImage: refinedImage,
|
||||
atmosphereImage: atmosphereImage,
|
||||
coverImage: coverImage
|
||||
)
|
||||
}
|
||||
} else {
|
||||
self.aiEditResultStore.failProcessing(materialID: materialID)
|
||||
self.failedAIEditCount += 1
|
||||
}
|
||||
self.pendingAIEditMaterialIDs.remove(materialID)
|
||||
self.applyViewModel()
|
||||
if self.pendingAIEditMaterialIDs.isEmpty {
|
||||
let successMessage: String
|
||||
if let coverTemplate = selection.coverTemplate,
|
||||
selection.atmosphereOption != nil {
|
||||
successMessage = "AI修图完成,每张生成 2 个结果,并生成「\(coverTemplate.title)」封面"
|
||||
} else if let coverTemplate = selection.coverTemplate {
|
||||
successMessage = "AI修图完成,已生成「\(coverTemplate.title)」封面"
|
||||
} else if selection.atmosphereOption != nil {
|
||||
successMessage = "AI修图完成,每张已生成 2 个结果"
|
||||
} else {
|
||||
successMessage = "AI修图完成"
|
||||
}
|
||||
let message = self.failedAIEditCount == 0
|
||||
? successMessage
|
||||
: "有 \(self.failedAIEditCount) 张照片修图失败,请重试"
|
||||
self.showToast(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func deleteSelectedTapped() {
|
||||
let count = viewModel.selectedMaterialIds.count
|
||||
let alert = UIAlertController(title: "删除素材", message: "确定删除选中的 \(count) 张素材吗?", preferredStyle: .alert)
|
||||
@ -331,22 +525,60 @@ final class TravelAlbumDetailViewController: BaseViewController {
|
||||
}
|
||||
|
||||
@objc private func uploadTapped() {
|
||||
let controller = TravelAlbumTransferModeSheetViewController()
|
||||
controller.onModeSelected = { [weak self] mode in
|
||||
self?.openWiredTransfer(mode: mode)
|
||||
}
|
||||
present(controller, animated: true)
|
||||
}
|
||||
|
||||
/// 根据本次选择进入对应传输模式,避免被历史缓存模式覆盖。
|
||||
private func openWiredTransfer(mode: TravelAlbumOTGTransferMode) {
|
||||
let album = viewModel.album
|
||||
let controller = WiredCameraTransferViewController(
|
||||
viewModel: WiredCameraTransferViewModel(
|
||||
albumId: album?.id ?? viewModel.albumId,
|
||||
albumTitle: album?.name ?? "",
|
||||
headerPhone: album?.displayPhone ?? ""
|
||||
headerPhone: album?.displayPhone ?? "",
|
||||
initialTransferMode: mode
|
||||
)
|
||||
)
|
||||
navigationController?.pushViewController(controller, animated: true)
|
||||
}
|
||||
|
||||
/// 仅刷新状态发生变化的缩略图,及时呈现修图结果和任务角标。
|
||||
@objc private func aiEditResultDidChange(_ notification: Notification) {
|
||||
guard let materialID = notification.userInfo?[TravelAlbumAIEditResultStore.materialIDUserInfoKey] as? Int,
|
||||
let material = dataSource.snapshot().itemIdentifiers.first(where: { $0.id == materialID }) else {
|
||||
return
|
||||
}
|
||||
var snapshot = dataSource.snapshot()
|
||||
snapshot.reconfigureItems([material])
|
||||
dataSource.apply(snapshot, animatingDifferences: true)
|
||||
updateBottomToolbar()
|
||||
}
|
||||
}
|
||||
|
||||
extension TravelAlbumDetailViewController: UICollectionViewDelegate {
|
||||
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
guard let material = dataSource.itemIdentifier(for: indexPath) else { return }
|
||||
viewModel.toggleMaterialSelection(material)
|
||||
if viewModel.isSelectionMode {
|
||||
viewModel.toggleMaterialSelection(material)
|
||||
} else {
|
||||
// 非多选状态进入预览,避免影响原有批量删除流程。
|
||||
let initialIndex = viewModel.materials.firstIndex(where: { $0.id == material.id }) ?? 0
|
||||
let controller = TravelAlbumPhotoPreviewViewController(
|
||||
materials: viewModel.materials,
|
||||
initialIndex: initialIndex,
|
||||
api: api
|
||||
)
|
||||
controller.onDeleted = { [weak self] in
|
||||
guard let self else { return }
|
||||
Task { await self.viewModel.refreshAll(api: self.api) }
|
||||
}
|
||||
// 照片与修图样式、封面模板统一走全屏预览,避免系统导航栏重复出现。
|
||||
present(controller, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||
@ -499,19 +731,70 @@ private final class TravelAlbumMaterialCell: UICollectionViewCell {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func apply(material: TravelAlbumMaterial, selectionMode: Bool, selected: Bool) {
|
||||
let urlString = material.coverUrl.isEmpty ? material.fileUrl : material.coverUrl
|
||||
if let url = URL(string: urlString), !urlString.isEmpty {
|
||||
imageView.kf.setImage(with: url, placeholder: UIImage(systemName: "photo"))
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
imageView.kf.cancelDownloadTask()
|
||||
imageView.image = nil
|
||||
}
|
||||
|
||||
func apply(
|
||||
material: TravelAlbumMaterial,
|
||||
selectionMode: Bool,
|
||||
selected: Bool,
|
||||
aiEditState: TravelAlbumAIEditResultState,
|
||||
editedImage: UIImage?
|
||||
) {
|
||||
imageView.backgroundColor = .clear
|
||||
imageView.tintColor = nil
|
||||
if aiEditState.hasEditedResult, let editedImage {
|
||||
imageView.kf.cancelDownloadTask()
|
||||
imageView.image = editedImage
|
||||
} else if let assetName = material.bundledImageAssetName,
|
||||
let bundledImage = UIImage(named: assetName) {
|
||||
imageView.kf.cancelDownloadTask()
|
||||
imageView.image = bundledImage
|
||||
} else {
|
||||
imageView.image = UIImage(systemName: "photo")
|
||||
imageView.tintColor = AppColor.primary
|
||||
imageView.backgroundColor = UIColor(hex: 0xEAF2FF)
|
||||
let urlString = material.coverUrl.isEmpty ? material.fileUrl : material.coverUrl
|
||||
if let url = URL(string: urlString), !urlString.isEmpty {
|
||||
imageView.kf.setImage(with: url, placeholder: UIImage(systemName: "photo"))
|
||||
} else {
|
||||
imageView.image = UIImage(systemName: "photo")
|
||||
imageView.tintColor = AppColor.primary
|
||||
imageView.backgroundColor = UIColor(hex: 0xEAF2FF)
|
||||
}
|
||||
}
|
||||
applyAIEditStatus(aiEditState.thumbnailStatus, isPurchased: material.isPurchased)
|
||||
checkImageView.isHidden = !selectionMode
|
||||
checkImageView.image = UIImage(systemName: selected ? "checkmark.circle.fill" : "circle")
|
||||
checkImageView.tintColor = selected ? AppColor.primary : .white
|
||||
nameLabel.text = material.fileName
|
||||
sizeLabel.text = TravelAlbumDisplayFormatter.fileSizeText(material.fileSize)
|
||||
}
|
||||
|
||||
/// 复用左上角状态位,让用户无需进入预览即可识别照片是否完成 AI 修图。
|
||||
private func applyAIEditStatus(
|
||||
_ status: TravelAlbumAIEditResultState.ThumbnailStatus,
|
||||
isPurchased: Bool
|
||||
) {
|
||||
let appearance: (title: String, color: UIColor, width: CGFloat)
|
||||
switch status {
|
||||
case .none:
|
||||
appearance = isPurchased
|
||||
? ("已购", AppColor.primary, 48)
|
||||
: ("已上传", UIColor(hex: 0x34C759), 48)
|
||||
case .processing:
|
||||
appearance = ("修图中", AppColor.primary, 48)
|
||||
case .edited:
|
||||
appearance = ("AI已修", UIColor(hex: 0x6750A4), 48)
|
||||
case .cover:
|
||||
appearance = ("AI封面", UIColor(hex: 0xF59E0B), 56)
|
||||
case .failed:
|
||||
appearance = ("修图失败", UIColor(hex: 0xE53935), 56)
|
||||
}
|
||||
statusLabel.text = appearance.title
|
||||
statusLabel.backgroundColor = appearance.color
|
||||
statusLabel.snp.updateConstraints { make in
|
||||
make.width.equalTo(appearance.width)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1351
suixinkan/UI/TravelAlbum/TravelAlbumPhotoPreviewViewController.swift
Normal file
@ -0,0 +1,171 @@
|
||||
//
|
||||
// TravelAlbumTransferModeSheetViewController.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 相册管理上传入口的传输模式选择弹窗。
|
||||
final class TravelAlbumTransferModeSheetViewController: UIViewController {
|
||||
/// 用户选择传输模式后的回调;弹窗关闭后触发。
|
||||
var onModeSelected: ((TravelAlbumOTGTransferMode) -> Void)?
|
||||
|
||||
private let titleLabel = UILabel()
|
||||
private let subtitleLabel = UILabel()
|
||||
private let optionsStack = UIStackView()
|
||||
private let cancelButton = UIButton(type: .system)
|
||||
|
||||
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
|
||||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
||||
modalPresentationStyle = .pageSheet
|
||||
if let sheetPresentationController {
|
||||
let identifier = UISheetPresentationController.Detent.Identifier("transferMode")
|
||||
sheetPresentationController.detents = [
|
||||
.custom(identifier: identifier) { context in
|
||||
min(356, context.maximumDetentValue)
|
||||
},
|
||||
]
|
||||
sheetPresentationController.selectedDetentIdentifier = identifier
|
||||
sheetPresentationController.prefersGrabberVisible = true
|
||||
sheetPresentationController.preferredCornerRadius = 22
|
||||
}
|
||||
}
|
||||
|
||||
@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 = .white
|
||||
|
||||
titleLabel.text = "选择传输模式"
|
||||
titleLabel.font = .systemFont(ofSize: 19, weight: .semibold)
|
||||
titleLabel.textColor = AppColor.textPrimary
|
||||
titleLabel.textAlignment = .center
|
||||
|
||||
subtitleLabel.text = "选择后进入对应的照片传输页面"
|
||||
subtitleLabel.font = .systemFont(ofSize: 13)
|
||||
subtitleLabel.textColor = AppColor.textSecondary
|
||||
subtitleLabel.textAlignment = .center
|
||||
|
||||
optionsStack.axis = .vertical
|
||||
optionsStack.spacing = 12
|
||||
TravelAlbumOTGTransferMode.allCases.enumerated().forEach { index, mode in
|
||||
optionsStack.addArrangedSubview(makeOptionView(mode: mode, index: index))
|
||||
}
|
||||
|
||||
cancelButton.setTitle("取消", for: .normal)
|
||||
cancelButton.setTitleColor(AppColor.textSecondary, for: .normal)
|
||||
cancelButton.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
|
||||
cancelButton.backgroundColor = UIColor(hex: 0xF4F5F7)
|
||||
cancelButton.layer.cornerRadius = 12
|
||||
cancelButton.addTarget(self, action: #selector(cancelTapped), for: .touchUpInside)
|
||||
|
||||
view.addSubview(titleLabel)
|
||||
view.addSubview(subtitleLabel)
|
||||
view.addSubview(optionsStack)
|
||||
view.addSubview(cancelButton)
|
||||
}
|
||||
|
||||
private func setupConstraints() {
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(view.safeAreaLayoutGuide).offset(14)
|
||||
make.leading.trailing.equalToSuperview().inset(20)
|
||||
}
|
||||
subtitleLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(titleLabel.snp.bottom).offset(7)
|
||||
make.leading.trailing.equalToSuperview().inset(20)
|
||||
}
|
||||
optionsStack.snp.makeConstraints { make in
|
||||
make.top.equalTo(subtitleLabel.snp.bottom).offset(18)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
}
|
||||
cancelButton.snp.makeConstraints { make in
|
||||
make.top.equalTo(optionsStack.snp.bottom).offset(14)
|
||||
make.leading.trailing.equalTo(optionsStack)
|
||||
make.height.equalTo(48)
|
||||
make.bottom.lessThanOrEqualTo(view.safeAreaLayoutGuide).offset(-10)
|
||||
}
|
||||
}
|
||||
|
||||
/// 创建无需二次确认的模式选项,点击后直接进入下一页。
|
||||
private func makeOptionView(mode: TravelAlbumOTGTransferMode, index: Int) -> UIView {
|
||||
let container = UIView()
|
||||
container.backgroundColor = UIColor(hex: 0xF7F9FC)
|
||||
container.layer.cornerRadius = 12
|
||||
container.layer.borderWidth = 1
|
||||
container.layer.borderColor = UIColor(hex: 0xE6ECF5).cgColor
|
||||
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.text = mode.title
|
||||
titleLabel.font = .systemFont(ofSize: 16, weight: .semibold)
|
||||
titleLabel.textColor = AppColor.textPrimary
|
||||
|
||||
let detailLabel = UILabel()
|
||||
detailLabel.text = mode.detailText
|
||||
detailLabel.font = .systemFont(ofSize: 12)
|
||||
detailLabel.textColor = AppColor.textSecondary
|
||||
detailLabel.numberOfLines = 2
|
||||
|
||||
let enterLabel = UILabel()
|
||||
enterLabel.text = "进入"
|
||||
enterLabel.font = .systemFont(ofSize: 13, weight: .medium)
|
||||
enterLabel.textColor = AppColor.primary
|
||||
enterLabel.textAlignment = .right
|
||||
|
||||
let button = UIButton(type: .custom)
|
||||
button.tag = index
|
||||
button.accessibilityLabel = "\(mode.title),\(mode.detailText)"
|
||||
button.addTarget(self, action: #selector(modeTapped(_:)), for: .touchUpInside)
|
||||
|
||||
container.addSubview(titleLabel)
|
||||
container.addSubview(detailLabel)
|
||||
container.addSubview(enterLabel)
|
||||
container.addSubview(button)
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(13)
|
||||
make.leading.equalToSuperview().offset(16)
|
||||
make.trailing.lessThanOrEqualTo(enterLabel.snp.leading).offset(-12)
|
||||
}
|
||||
detailLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(titleLabel.snp.bottom).offset(5)
|
||||
make.leading.equalTo(titleLabel)
|
||||
make.trailing.lessThanOrEqualTo(enterLabel.snp.leading).offset(-12)
|
||||
make.bottom.lessThanOrEqualToSuperview().offset(-12)
|
||||
}
|
||||
enterLabel.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().offset(-16)
|
||||
make.centerY.equalToSuperview()
|
||||
make.width.equalTo(34)
|
||||
}
|
||||
button.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
container.snp.makeConstraints { make in
|
||||
make.height.equalTo(78)
|
||||
}
|
||||
return container
|
||||
}
|
||||
|
||||
@objc private func modeTapped(_ sender: UIButton) {
|
||||
guard TravelAlbumOTGTransferMode.allCases.indices.contains(sender.tag) else { return }
|
||||
let mode = TravelAlbumOTGTransferMode.allCases[sender.tag]
|
||||
// 先保留回调,避免弹窗关闭释放后无法进入对应模式页面。
|
||||
let completion = onModeSelected
|
||||
dismiss(animated: true) {
|
||||
completion?(mode)
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func cancelTapped() {
|
||||
dismiss(animated: true)
|
||||
}
|
||||
}
|
||||
@ -788,14 +788,23 @@ final class WiredCameraTransferViewController: BaseViewController {
|
||||
}
|
||||
|
||||
private func presentPhotoPreview(_ item: TravelAlbumOTGPhotoItem) {
|
||||
guard let url = item.thumbnailURL else {
|
||||
// 使用当前筛选列表的实际展示顺序,让预览页可连续查看上一张和下一张。
|
||||
let displayedPhotos = dataSource.snapshot().itemIdentifiers
|
||||
guard let context = displayedPhotos.previewContext(startingWith: item.id) else {
|
||||
showToast("暂无可预览图片")
|
||||
return
|
||||
}
|
||||
let previewItem: MediaPreviewItem = url.isFileURL
|
||||
? .localImage(url: url)
|
||||
: MediaPreviewItem(source: .remoteImage(url))
|
||||
MediaPreviewViewController.present(from: self, items: [previewItem], startIndex: 0)
|
||||
let previewItems = context.photos.compactMap { photo -> MediaPreviewItem? in
|
||||
guard let url = photo.thumbnailURL else { return nil }
|
||||
return url.isFileURL
|
||||
? .localImage(url: url)
|
||||
: MediaPreviewItem(source: .remoteImage(url))
|
||||
}
|
||||
MediaPreviewViewController.present(
|
||||
from: self,
|
||||
items: previewItems,
|
||||
startIndex: context.initialIndex
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,6 +21,11 @@ final class WiredTransferSettingChipButton: UIButton {
|
||||
/// 当前展示的标题文案。
|
||||
private(set) var titleText: String = ""
|
||||
|
||||
/// 当前值的展示颜色,供状态测试确认不可交互时仍保持清晰。
|
||||
var displayedTitleColor: UIColor? {
|
||||
titleLabelView.textColor
|
||||
}
|
||||
|
||||
/// 创建设置 chip 按钮。
|
||||
/// - Parameter showsChevron: 是否展示下拉箭头,默认不展示。
|
||||
init(showsChevron: Bool = false) {
|
||||
@ -49,13 +54,14 @@ final class WiredTransferSettingChipButton: UIButton {
|
||||
layer.borderColor = AppColor.border.cgColor
|
||||
|
||||
titleLabelView.font = .systemFont(ofSize: 11)
|
||||
titleLabelView.textColor = AppColor.textTertiary
|
||||
// 当前设置值即使不可点击也代表已经生效,使用主文字色避免呈现为禁用状态。
|
||||
titleLabelView.textColor = AppColor.textPrimary
|
||||
titleLabelView.lineBreakMode = .byTruncatingTail
|
||||
titleLabelView.isUserInteractionEnabled = false
|
||||
|
||||
chevronView.image = UIImage(systemName: "chevron.down")?
|
||||
.withConfiguration(UIImage.SymbolConfiguration(pointSize: 13, weight: .semibold))
|
||||
chevronView.tintColor = AppColor.textTertiary
|
||||
chevronView.tintColor = AppColor.textSecondary
|
||||
chevronView.contentMode = .scaleAspectFit
|
||||
chevronView.isUserInteractionEnabled = false
|
||||
|
||||
|
||||