Actualización sin cambiar de app: Share Extension "Quick Update" + clipboard auto-advance

El dolor: para actualizar cada source hay que saltar a la app del banco, copiar/
memorizar el valor y volver. iOS no permite ventanas flotantes editables (PiP es
solo vídeo), así que se resuelve con las dos vías sancionadas:

Share Extension (target nuevo PortfolioJournalQuickUpdate):
- Al compartir texto desde CUALQUIER app aparece "Portfolio Journal": mini-form
  sobre la app anfitriona con el importe pre-parseado del texto compartido y la
  siguiente source pendiente del mes preseleccionada. Guardar → sigues en el banco.
- Sin Core Data en la extensión: la app publica un espejo de sources activas en el
  App Group (SharedQuickUpdateSync.refreshMirror) y la extensión encola
  PendingQuickUpdate; la app los convierte en Snapshots reales al activarse
  (ingestPending). ExtSharedBridge duplica el contrato (keep-in-sync comentado).
- Parser de importes tolerante a locales (12.345,67 € / $1,234.56 / 1234,5).
- UI localizada en los 7 idiomas (lproj propios de la extensión).
- pbxproj: target app-extension completo (sync group, embed, dependency, configs)
  replicando el patrón del widget. Entitlements solo con App Group.

Clipboard auto-advance en Quick Update:
- Al volver a la app con un importe copiado: banner de un tap "Pegar X en <source>"
  que rellena la siguiente source vacía y avanza el foco a la siguiente.
- Badge NEXT en la fila activa; no repite sugerencias del mismo clipboard.

Script de upload: -allowProvisioningUpdates + API key también en el archive para
que el bundle id nuevo de la extensión se registre automáticamente.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015qUZrBusG82T37R7PeokqJ
This commit is contained in:
alexandrev-tibco
2026-07-03 23:21:55 +02:00
parent f7d4fdbe2d
commit 386f4ff265
24 changed files with 836 additions and 3 deletions
@@ -1,9 +1,11 @@
import SwiftUI
import CoreData
import UIKit
struct QuickUpdateView: View {
@Environment(\.dismiss) private var dismiss
@Environment(\.managedObjectContext) private var context
@Environment(\.scenePhase) private var scenePhase
@FetchRequest(
sortDescriptors: [NSSortDescriptor(keyPath: \InvestmentSource.name, ascending: true)],
predicate: NSPredicate(format: "isActive == YES"),
@@ -15,6 +17,19 @@ struct QuickUpdateView: View {
@State private var isSaving = false
@State private var saveError: String?
// Clipboard round-trip: copy a value in your bank app, come back, one tap fills
// the next pending source and the focus advances no retyping, no memorizing.
@FocusState private var focusedSource: NSManagedObjectID?
@State private var clipboardAmount: Decimal?
@State private var lastSuggestedRaw: String?
/// First source (list order) still without a value the "active" one.
private var nextEmptySource: InvestmentSource? {
sources.first { source in
(values[source.objectID] ?? "").trimmingCharacters(in: .whitespaces).isEmpty
}
}
var body: some View {
NavigationStack {
ZStack {
@@ -28,6 +43,29 @@ struct QuickUpdateView: View {
)
} else {
List {
if let amount = clipboardAmount, let target = nextEmptySource {
Section {
Button {
applyClipboard(amount, to: target)
} label: {
HStack(spacing: 8) {
Image(systemName: "doc.on.clipboard.fill")
Text(String(
format: String(localized: "quick_update_paste_suggestion"),
amount.currencyString, target.name
))
.multilineTextAlignment(.leading)
Spacer()
Image(systemName: "arrow.down.circle.fill")
}
.font(.subheadline.weight(.semibold))
.foregroundColor(.white)
.padding(.vertical, 2)
}
.listRowBackground(Color.appPrimary)
}
}
Section {
ForEach(sources) { source in
sourceRow(source)
@@ -63,7 +101,13 @@ struct QuickUpdateView: View {
} message: {
Text(saveError ?? "")
}
.onAppear { prefillContributions() }
.onAppear {
prefillContributions()
checkClipboard()
}
.onChange(of: scenePhase) { _, phase in
if phase == .active { checkClipboard() }
}
}
}
@@ -72,8 +116,19 @@ struct QuickUpdateView: View {
VStack(spacing: 6) {
HStack {
VStack(alignment: .leading, spacing: 2) {
Text(source.name)
.font(.subheadline.weight(.medium))
HStack(spacing: 6) {
Text(source.name)
.font(.subheadline.weight(.medium))
if source.objectID == nextEmptySource?.objectID {
Text(String(localized: "quick_update_next_badge"))
.font(.caption2.weight(.bold))
.padding(.horizontal, 6)
.padding(.vertical, 1)
.background(Color.appSecondary.opacity(0.15))
.foregroundColor(.appSecondary)
.clipShape(Capsule())
}
}
if source.latestValue != .zero {
Text(source.latestValue.currencyString)
.font(.caption)
@@ -89,6 +144,7 @@ struct QuickUpdateView: View {
.multilineTextAlignment(.trailing)
.frame(width: 120)
.font(.subheadline)
.focused($focusedSource, equals: source.objectID)
}
if contributions[source.objectID] != nil {
@@ -129,6 +185,29 @@ struct QuickUpdateView: View {
)
}
/// Reads the pasteboard and offers the parsed amount for the next pending source.
/// Skips values already suggested (or already typed) so returning to the app
/// with the same clipboard doesn't nag.
private func checkClipboard() {
guard let raw = UIPasteboard.general.string, raw != lastSuggestedRaw,
let parsed = CurrencyFormatter.parseUserInput(raw), parsed > 0,
nextEmptySource != nil else {
return
}
lastSuggestedRaw = raw
clipboardAmount = parsed
}
private func applyClipboard(_ amount: Decimal, to source: InvestmentSource) {
values[source.objectID] = String(format: "%.2f", NSDecimalNumber(decimal: amount).doubleValue)
clipboardAmount = nil
// Advance focus to the next source still pending, so the user can keep going
// (type directly or hop to the next bank app and come back).
if let next = nextEmptySource {
focusedSource = next.objectID
}
}
private func prefillContributions() {
for source in sources {
if let amount = MonthlyContributionStore.contribution(for: source.id) {
@@ -165,6 +244,8 @@ struct QuickUpdateView: View {
for source in sources where values[source.objectID].map({ !$0.isEmpty }) == true {
NotificationService.shared.scheduleReminder(for: source)
}
// Keep the share-extension mirror in sync with what was just saved
SharedQuickUpdateSync.refreshMirror()
dismiss()
} catch {
saveError = error.localizedDescription