diff --git a/apps/ios/ItemAtlas.xcodeproj/project.pbxproj b/apps/ios/ItemAtlas.xcodeproj/project.pbxproj index 880a00b..2e53591 100644 --- a/apps/ios/ItemAtlas.xcodeproj/project.pbxproj +++ b/apps/ios/ItemAtlas.xcodeproj/project.pbxproj @@ -117,7 +117,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 20; + CURRENT_PROJECT_VERSION = 21; GENERATE_INFOPLIST_FILE = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ATLAS_API_BASE_URL = "https://api-atlas.tutudog.com"; @@ -138,7 +138,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 20; + CURRENT_PROJECT_VERSION = 21; GENERATE_INFOPLIST_FILE = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ATLAS_API_BASE_URL = "https://api-atlas.tutudog.com"; diff --git a/apps/ios/ItemAtlas/IntakeView.swift b/apps/ios/ItemAtlas/IntakeView.swift index fcdeae3..1281d8e 100644 --- a/apps/ios/ItemAtlas/IntakeView.swift +++ b/apps/ios/ItemAtlas/IntakeView.swift @@ -14,6 +14,7 @@ struct IntakeView: View { @State private var selections: [Int: UUID] = [:] @State private var operation: Operation? @State private var busy = false + @State private var supplementing = false @State private var showingAdd = false @State private var error: String? @State private var showingHelp = false @@ -43,6 +44,8 @@ struct IntakeView: View { !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } + private var canReview: Bool { draft?.candidates.contains { $0.action != "SKIP" } == true } + var body: some View { if let onReturnToChooser { if showingAdd { @@ -69,11 +72,12 @@ struct IntakeView: View { .font(.subheadline).foregroundStyle(.secondary) .accessibilityLabel("默认位置," + initialLocation.path) } - smartCard - manualEntry - if voice.phase == .idle && operation == nil { - inputCard - if let draft { reviewCard(draft).id(draft.id) } + if operation == nil { + inputCard.id("intake.original") + if let draft, !supplementing, voice.phase == .idle { + reviewCard(draft).id(draft.id) + } + if voice.phase == .idle && !supplementing { manualEntry } } if let operation { operationCard(operation) } if let error { Text(error).font(.callout).foregroundStyle(.red) } @@ -83,11 +87,16 @@ struct IntakeView: View { .frame(maxWidth: .infinity) } .onChange(of: draft?.id) { _, id in - if let id { withAnimation { scroll.scrollTo(id, anchor: .top) } } + if let id { withAnimation { scroll.scrollTo(id) } } + } + .onChange(of: supplementing) { _, active in + if active { withAnimation { scroll.scrollTo("intake.original", anchor: .top) } } } } .background(Color(uiColor: .systemGroupedBackground)) - .scrollDismissesKeyboard(.interactively) + .safeAreaInset(edge: .bottom, spacing: 0) { + if !typing && operation == nil { bottomBar } + } .dismissibleKeyboard(active: typing) { typing = false } .navigationTitle("录入物品") .navigationBarTitleDisplayMode(.inline) @@ -97,9 +106,18 @@ struct IntakeView: View { if let onReturnToChooser { onReturnToChooser() } else { dismiss() } } - .disabled(busy) + .disabled(busy || voice.phase != .idle) } - ToolbarItem(placement: .topBarTrailing) { + ToolbarItemGroup(placement: .topBarTrailing) { + Menu { + Picker("录音方式", selection: $recordingMode) { + Text("点按开始,再点结束").tag(RecordingMode.tap) + Text("按住说,松手结束").tag(RecordingMode.hold) + } + } label: { + Label("录音设置", systemImage: "slider.horizontal.3") + } + .disabled(voice.phase != .idle) Button { showingHelp = true } label: { Label("录入说明", systemImage: "questionmark.circle") } .disabled(voice.phase != .idle) } @@ -114,47 +132,37 @@ struct IntakeView: View { if operation == nil && draft?.originalText != updated { draft = nil selections = [:] + supplementing = false } } .sheet(isPresented: $showingHelp) { help } } - private var smartCard: some View { - VStack(alignment: .leading, spacing: 12) { - HStack(alignment: .firstTextBaseline) { - Text("智能录入").font(.title3.weight(.semibold)) - .accessibilityAddTraits(.isHeader) - Spacer() - Menu { - Picker("录音方式", selection: $recordingMode) { - Text("点按开始,再点结束").tag(RecordingMode.tap) - Text("按住录音,松手结束").tag(RecordingMode.hold) - } - } label: { - Label(recordingMode == .hold ? "按住说" : "点按录音", systemImage: "chevron.up.chevron.down") - .font(.subheadline.weight(.medium)) - } - .accessibilityLabel("录音方式") - .accessibilityValue(recordingMode == .hold ? "按住说" : "点按录音") - .disabled(voice.phase != .idle) - } - Text("说出要记的物品,例如「记录两根数据线」。") - .font(.subheadline).foregroundStyle(.secondary) - voiceButton + private var bottomBar: some View { + VStack(spacing: 8) { if voice.phase == .recording || voice.phase == .finishing { ProgressView(value: Double(voice.elapsedSeconds), total: Double(VoiceCapture.maximumDuration)) { Text("\(voice.elapsedSeconds) / \(VoiceCapture.maximumDuration) 秒") .font(.caption.monospacedDigit()) } } - if !voice.transcript.isEmpty { - Text(voice.transcript).font(.callout) - .frame(maxWidth: .infinity, alignment: .leading) + if let draft, canReview, !supplementing, voice.phase == .idle { + Button { Task { await submit(draft) } } label: { + primaryLabel(busy ? "正在保存" : "保存物品", symbol: "checkmark", + color: .atlasBlue, enabled: !busy) + } + .buttonStyle(.plain) + .disabled(busy) + } else { + voiceButton } - if let error = voice.error { Text(error).font(.footnote).foregroundStyle(.secondary) } } - .padding(16) - .background(Color.atlasBlue.opacity(0.10), in: .rect(cornerRadius: 20)) + .frame(maxWidth: 560) + .padding(.horizontal, 16) + .padding(.vertical, 10) + .frame(maxWidth: .infinity) + .background(.bar) + .overlay(alignment: .top) { Divider() } } private var manualEntry: some View { @@ -186,19 +194,39 @@ struct IntakeView: View { private var inputCard: some View { VStack(alignment: .leading, spacing: 10) { - Text("物品描述").font(.headline).accessibilityAddTraits(.isHeader) - TextField("录音文字会显示在这里,也可以直接输入", text: $text, axis: .vertical) - .lineLimit(3...7) - .focused($typing) - .accessibilityLabel("物品描述") - .disabled(busy) + HStack { + Text("物品描述").font(.headline).accessibilityAddTraits(.isHeader) + Spacer() + if supplementing { + Button("取消补录") { supplementing = false } + .disabled(voice.phase != .idle) + } else if draft != nil { + Button("再说一句", action: supplement) + .disabled(busy || typing) + } + } + .font(.subheadline) + if voice.phase == .idle { + TextField("例如:把两根数据线放在书房抽屉", text: $text, axis: .vertical) + .lineLimit(3...7) + .focused($typing) + .accessibilityLabel("物品描述") + .disabled(busy) + } else { + let original = [text, voice.transcript].filter { !$0.isEmpty }.joined(separator: "\n") + Text(original.isEmpty ? "听到的文字会显示在这里。" : original) + .foregroundStyle(original.isEmpty ? Color.secondary : Color.primary) + .lineLimit(3...) + .frame(maxWidth: .infinity, alignment: .leading) + } if text.utf16.count > 4000 { Text("最多 4,000 字,可以分开整理。").font(.footnote).foregroundStyle(.secondary) } - if !text.isEmpty && draft == nil { + if !text.isEmpty && draft == nil && !supplementing && voice.phase == .idle { Button("整理成物品草稿") { typing = false; Task { await parse() } }.disabled(!canParse) } - if busy && draft == nil { ProgressView("正在整理") } + if let error = voice.error { Text(error).font(.footnote).foregroundStyle(.secondary) } + if busy && !canReview { ProgressView("正在整理") } } .padding(16) .background(Color(uiColor: .secondarySystemGroupedBackground), in: .rect(cornerRadius: 16)) @@ -233,14 +261,6 @@ struct IntakeView: View { .background(Color(uiColor: .systemGroupedBackground), in: .rect(cornerRadius: 12)) } } - if draft.candidates.contains(where: { $0.action != "SKIP" }) { - Button { typing = false; Task { await submit(draft) } } label: { - Text("保存物品").frame(maxWidth: .infinity).padding(.vertical, 4) - } - .buttonStyle(.borderedProminent) - .disabled(busy) - } - if busy { ProgressView(draft.candidates.isEmpty ? "正在整理" : "正在保存") } } .padding(16) .background(Color(uiColor: .secondarySystemGroupedBackground), in: .rect(cornerRadius: 16)) @@ -270,10 +290,10 @@ struct IntakeView: View { NavigationStack { List { Section("智能录入") { - Text("1. 点按开始录音,或者选择按住录音。") + Text("1. 在屏幕底部开始录音。右上角可以切换录音方式。") Text("2. 看到录音状态再说。一次最多 25 秒,可以停顿。") Text("3. 说完松手或再次点按。可以修改转写,也可以直接打字。") - Text("4. 核对物品后保存。位置可以调整、清除或留空。") + Text("4. 可以再说一句,也可以核对物品后在底部保存。位置可以调整、清除或留空。") } Section("手动添加") { Text("填写名称就能录入单件物品。需要时再加位置、照片或备注。") @@ -308,7 +328,9 @@ struct IntakeView: View { private var recordingTitle: String { switch voice.phase { - case .idle: recordingMode == .hold ? "按住说" : "开始录音" + case .idle: + if recordingMode == .hold { "按住说" } + else { supplementing ? "开始补录" : "开始录音" } case .preparing: "麦克风准备中" case .recording: recordingMode == .hold ? "松手结束" : "结束录音" case .finishing: "正在转写" @@ -316,13 +338,17 @@ struct IntakeView: View { } private var recordingLabel: some View { - Label(recordingTitle, systemImage: voice.phase == .recording ? "waveform" : "mic.fill") + primaryLabel(recordingTitle, symbol: voice.phase == .recording ? "waveform" : "mic.fill", + color: voice.phase == .recording ? .atlasNavy : .atlasBlue, enabled: voiceEnabled) + } + + private func primaryLabel(_ title: String, symbol: String, color: Color, enabled: Bool) -> some View { + Label(title, systemImage: symbol) .font(.headline) .frame(maxWidth: .infinity, minHeight: 54) .foregroundStyle(.white) - .background(voice.phase == .recording ? Color.atlasNavy : Color.atlasBlue, - in: .rect(cornerRadius: 14)) - .opacity(voiceEnabled ? 1 : 0.55) + .background(color, in: .rect(cornerRadius: 14)) + .opacity(enabled ? 1 : 0.55) .contentShape(Rectangle()) } @@ -330,16 +356,40 @@ struct IntakeView: View { if voice.phase == .idle { beginRecording() } else { voice.stop() } } + private func supplement() { + supplementing = true + if recordingMode == .tap { beginRecording() } + } + private func beginRecording() { guard voiceEnabled, voice.phase == .idle else { return } typing = false voice.start(context: store.locations.map(\.name)) { phrase, complete in - let previous = text.trimmingCharacters(in: .whitespacesAndNewlines) - text = previous.isEmpty ? phrase : previous + "\n" + phrase + text = transcript(appending: phrase) + supplementing = false if complete { Task { await parse() } } } } + private func transcript(appending phrase: String) -> String { + let previous = text.trimmingCharacters(in: .whitespacesAndNewlines) + guard !previous.isEmpty else { return phrase } + guard !phrase.isEmpty else { return previous } + + if supplementing, let draft, draft.candidates.count <= 1, draft.candidates.first?.location == nil, + let verb = ["放在", "放到", "放进", "收进", "放"].first(where: { phrase.hasPrefix($0) }) { + let hint = String(phrase.dropFirst(verb.count)).trimmingCharacters(in: .whitespacesAndNewlines) + let subject = previous.trimmingCharacters(in: CharacterSet(charactersIn: "。.!!")) + // Keep a standalone location with its item so it can still use the single-sentence parser. + if !subject.isEmpty && !hint.isEmpty && + (verb != "放" || IntakeLocationMatcher.match(hint, locations: store.locations, + defaultID: initialLocation?.id) != nil) { + return subject + (verb == "放" ? "放在" : verb) + hint + } + } + return previous + "\n" + phrase + } + private func parse(source: String = "VOICE") async { guard canParse else { return } let original = text diff --git a/docs/product/ios-experience.md b/docs/product/ios-experience.md index 90d1da7..2a41335 100644 --- a/docs/product/ios-experience.md +++ b/docs/product/ios-experience.md @@ -8,9 +8,9 @@ 底栏是「找物」「位置」「社区」「我的」。中间的蓝色加号略高于栏面,点开进入「录入物品」,关闭后回到刚才的页面。「找物」空页里的「添加物品」进入同一页。房间和子位置的「在这里录入」会带上当前位置。 -「智能录入」支持说话或输入文字。录音方式可选点按开始、再点结束,或者按住说、松手结束。看到录音状态再说,每次最多 25 秒,停顿前后的文字会留在同一段。 +录音按钮固定在屏幕底部。右上角「录音设置」可切换点按开始、再点结束,或按住说、松手结束。录音用时显示在按钮上方,每次最多 25 秒。边说边看到转写,结束后可以在同一处修改文字。用键盘输入时,底部只显示「收起键盘」。 -例如说「记录两根数据线」,草稿可以只有名称和数量。提到的位置会尝试匹配现有路径。原话没有提位置时,可以使用进入录入时带来的当前位置。路径无法确定时留空。位置旁的叉号可以清除,点位置可以改选。核对后才会保存。 +例如说「记录两根数据线」,草稿可以只有名称和数量。可以点「再说一句」补充「放在书房抽屉」,文字和草稿会一起更新。提到的位置会尝试匹配现有路径。原话没有提位置时,可以使用进入录入时带来的当前位置。路径无法确定时留空。位置旁的叉号可以清除,点位置可以改选。核对后点底部「保存物品」才会入库。 在「手动添加」可以填写名称、数量、照片和备注。位置是可选项。暂时没放好的物品也能在「找物」里搜到,之后可到详情设置位置。 diff --git a/docs/testing/cases.md b/docs/testing/cases.md index b8a3980..50de2be 100644 --- a/docs/testing/cases.md +++ b/docs/testing/cases.md @@ -49,5 +49,6 @@ R01–R10 对应[需求与验收](../product/requirements.md)。实现和当前 | TC-43 导航栏与删除位置 | R02 | 在 iPhone 打开房间详情并滑到列表末尾,再检查四个底栏入口的选中状态。 | 删除位置可完整显示和点击。四个图标的视觉大小一致,当前选中项为实心,中央加号仍进入录入页。 | | TC-44 购入总额和记录数 | R03 | 同一所有者在两个空间并发录入,修改一件物品的数量和单价,发布、撤回并删除物品,再删除其所在空间。用另一账号查自己的概览。 | 每步统计与物品状态一致,已删除物品从金额扣除,超上限单价被拒绝,查询只读取当前账号的汇总。 | | TC-45 社区资料和评价 | R08、R10 | 从帖子和评论点进不同作者主页,查公开物品。从已公开物品的详情进入社区评价,改星并发表评论。 | 公开主页只显示昵称、头像和公开物品及数量。个人短评和购入总额仅当前账号可见。 | +| TC-46 iOS 底部录音与补录 | R06 | 单手点底部录音,说「记录两根数据线」,等草稿出现。点「再说一句」补充「放在书房抽屉」。切换按住说再试一次,并测试取消补录、用键盘修改原话。 | 两种录音方式的按钮都在底部,计时位于其上方。转写和修改使用同一区域,补录更新草稿,取消补录保留已有草稿。键盘打开时可收起键盘,核对时底部可保存。 | [测试与演示计划](plan.md)