Repository Public License
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Camera9// File : App/Sources/Features/Library/AlbumsView.swift10// Description : Albums (create, open, delete without touching the items),11// the album picker and the duplicates review.12// Module : Features13// Repository : https://git.spboucher.ai/orix-camera14// Project Website : https://www.orixlab.dev15// Created : 2026-11-2116// Last Modified : 2026-11-2117//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author : Simon-Pierre Boucher23// Position : Professor of Finance24// Institution : Université du Québec en Outaouais (UQO)25// Department : Département des sciences administratives26// Organization : SP Boucher27//28// Website : https://spboucher.ai29// Git : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General : info@spboucher.ai36// Professional : contact@spboucher.ai37// Direct : simon@spboucher.ai38// Research : research@spboucher.ai39// Development : dev@spboucher.ai40// Support : support@spboucher.ai41// Security/Admin : admin@spboucher.ai42// Notifications : notifications@spboucher.ai43//44// Preferred Contact: support@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification : Public69// Distribution : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License : Proprietary, all rights reserved (see license file)83// License File : LICENSE84// Maintainer : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import ORIXDesign92import ORIXImaging93import SwiftUI9495struct AlbumsView: View {96 @Bindable var model: LibraryModel97 @Environment(\.dismiss) private var dismiss98 @State private var newName = ""99 @State private var doomed: MediaAlbum?100101 var body: some View {102 NavigationStack {103 List {104 Section {105 HStack {106 TextField("New album name", text: $newName).submitLabel(.done).onSubmit(create).accessibilityIdentifier("albums.name")107 Button("Create", action: create).disabled(newName.trimmingCharacters(in: .whitespaces).isEmpty).accessibilityIdentifier("albums.create")108 }109 }110 Section {111 if model.albums.isEmpty {112 Text("No albums yet. Albums group items without moving or copying files.").foregroundStyle(.secondary)113 }114 ForEach(model.albums, id: \.id) { album in115 Button { model.album = album; dismiss() } label: {116 HStack {117 Label(album.name, systemImage: "rectangle.stack").foregroundStyle(Color.primary)118 Spacer()119 Text("\(album.items.count)").foregroundStyle(Color.secondary).monospacedDigit()120 if model.album?.id == album.id { Image(systemName: "checkmark").foregroundStyle(.tint) }121 }122 }123 .accessibilityIdentifier("albums.row.\(album.name)")124 .swipeActions { Button("Delete", role: .destructive) { doomed = album } }125 }126 } header: { Text("Albums") } footer: {127 if !model.albums.isEmpty { Text("Swipe an album to delete it. Its photos and videos stay in the library.") }128 }129 if model.album != nil {130 Section { Button("Show all items") { model.album = nil; dismiss() } }131 }132 }133 .navigationTitle("Albums")134 .navigationBarTitleDisplayMode(.inline)135 .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() }.accessibilityIdentifier("albums.done") } }136 .confirmationDialog(Text("Delete the album “\(doomed?.name ?? "")”?"), isPresented: Binding(get: { doomed != nil }, set: { if !$0 { doomed = nil } }), titleVisibility: .visible) {137 Button("Delete Album", role: .destructive) { if let doomed { model.delete(doomed) }; doomed = nil }138 Button("Cancel", role: .cancel) { doomed = nil }139 } message: {140 Text("Only the album is deleted. Its items stay in the library.")141 }142 }143 .presentationDetents([.medium, .large])144 .presentationBackground(Color(.systemGroupedBackground))145 }146147 private func create() {148 if model.createAlbum(named: newName) != nil { newName = "" }149 }150}151152/// Adds items to an existing or a new album.153struct AlbumPicker: View {154 @Bindable var model: LibraryModel155 let items: [MediaItem]156 var done: () -> Void = {}157 @Environment(\.dismiss) private var dismiss158 @State private var newName = ""159160 var body: some View {161 NavigationStack {162 List {163 Section("New album") {164 HStack {165 TextField("Album name", text: $newName).submitLabel(.done)166 Button("Create and Add") {167 if let album = model.createAlbum(named: newName) { finish(album) }168 }169 .disabled(newName.trimmingCharacters(in: .whitespaces).isEmpty)170 }171 }172 if !model.albums.isEmpty {173 Section("Add to") {174 ForEach(model.albums, id: \.id) { album in175 Button { finish(album) } label: {176 HStack { Label(album.name, systemImage: "rectangle.stack").foregroundStyle(Color.primary); Spacer(); Text("\(album.items.count)").foregroundStyle(Color.secondary) }177 }178 }179 }180 }181 }182 .navigationTitle(items.count == 1 ? Text("Add 1 item") : Text("Add \(items.count) items"))183 .navigationBarTitleDisplayMode(.inline)184 .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Cancel") { dismiss() } } }185 }186 .presentationDetents([.medium])187 .presentationBackground(Color(.systemGroupedBackground))188 }189190 private func finish(_ album: MediaAlbum) {191 model.add(items, to: album)192 done()193 dismiss()194 }195}196197/// Groups of visually near-identical items. Nothing is deleted without the user choosing which copies go.198struct DuplicatesView: View {199 @Bindable var model: LibraryModel200 @Environment(\.dismiss) private var dismiss201 @State private var groups: [[MediaItem]] = []202 @State private var pending: [MediaItem] = []203 @State private var confirm = false204205 var body: some View {206 NavigationStack {207 Group {208 if groups.isEmpty {209 ORIXEmptyState(systemName: "square.on.square", title: "No duplicates found",210 message: "ORIX Camera compares a visual fingerprint of each capture in its own library. Nothing looks identical.")211 } else {212 List {213 ForEach(Array(groups.enumerated()), id: \.offset) { index, group in214 Section {215 ScrollView(.horizontal, showsIndicators: false) {216 HStack(spacing: 8) {217 ForEach(group, id: \.id) { item in218 VStack(spacing: 4) {219 MediaTile(item: model.snapshot(item), isFavorite: item.isFavorite).frame(width: 120).clipShape(RoundedRectangle(cornerRadius: 8))220 Text(MediaFormat.bytes(item.byteSize)).font(.caption2).foregroundStyle(.secondary)221 }222 }223 }224 }225 Button("Keep the first, delete \(group.count - 1)", role: .destructive) { pending = Array(group.dropFirst()); confirm = true }226 .accessibilityIdentifier("duplicates.resolve.\(index)")227 } header: { Text("\(group.count) similar items") }228 }229 }230 }231 }232 .navigationTitle("Duplicates")233 .navigationBarTitleDisplayMode(.inline)234 .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() }.accessibilityIdentifier("duplicates.done") } }235 .confirmationDialog(Text("Delete \(pending.count) items?"), isPresented: $confirm, titleVisibility: .visible) {236 Button("Delete from this device", role: .destructive) { model.delete(pending); pending = []; groups = model.duplicateGroups() }237 Button("Cancel", role: .cancel) { pending = [] }238 } message: {239 Text("The oldest capture of the group is kept. The others are removed from this device and cannot be recovered.")240 }241 .onAppear { groups = model.duplicateGroups() }242 }243 }244}245