// CINEMAS' OTHER PLACES (cinemas-3.html): a series' seasons and episodes (the switch cross-fades and slides 24 pt in
// the season's direction, 260 ms), a row opened whole, Search as its own place, You (the TV, On this phone, his groups,
// the account's Delete), Your groups (make, rename, drag to order, delete; the films stay), and the one sheet for a
// title: what it is and which of his groups it is in, each changed at once. Every word is the core's or the line set's.
#if os(iOS)
import CottonKit
import SwiftUI
import UniformTypeIdentifiers
// MARK: - A series' seasons
struct CinemasSeasons: View {
let model: CinemasModel
let seasons: [CinemasTitle.Season]
let grow: Namespace.ID
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@State private var chosen: String?
@State private var season: CinemasRead?
/// +1 when the season chosen comes after the last, −1 before: the list slides that way.
@State private var direction: CGFloat = 1
private var current: CinemasTitle.Season? { seasons.first { $0.id == chosen } ?? seasons.first }
var body: some View {
VStack(alignment: .leading, spacing: 12) {
// Frame 4: the switch stands alone, full width, with no "Episodes" heading over it.
if seasons.count > 1 {
CinemasSegments(choices: seasons.map { CinemasSegments.Choice(id: $0.id, title: $0.title) }, chosen: current?.id) { id in
if let one = seasons.first(where: { $0.id == id }) { choose(one) }
}
// An element that contains its seasons, so its name does not stand in for theirs.
.accessibilityElement(children: .contain)
.accessibilityIdentifier("cinemas-season-switch")
} else if let current {
Text(current.title).font(CinemasType.rowTitle).foregroundStyle(CinemasInk.ink)
}
ZStack(alignment: .top) {
switch season {
case .read(let season)?:
LazyVStack(alignment: .leading, spacing: 0) {
if season.episodes.isEmpty {
CinemasLine(line: CinemasWords.line("stream.season_empty"))
}
ForEach(season.episodes) { episode in
CinemasEpisodeRow(model: model, episode: episode)
}
}
.id(season.season.id)
.transition(reduceMotion ? .opacity : .asymmetric(
insertion: .offset(x: CinemasMotion.seasonSlide * direction).combined(with: .opacity),
removal: .offset(x: -CinemasMotion.seasonSlide * direction).combined(with: .opacity)))
case .refused(let line)?: CinemasLine(line: line)
case nil:
VStack(spacing: 12) {
ForEach(0..<3, id: \.self) { _ in
HStack(spacing: 12) {
CinemasBlock().frame(width: 132, height: 74)
VStack(alignment: .leading, spacing: 6) {
CinemasBlock(corner: 3).frame(width: 140, height: 12)
CinemasBlock(corner: 3).frame(width: 80, height: 10)
}
Spacer(minLength: 0)
}
}
}
}
}
.padding(.horizontal, -CinemasInk.side)
}
.padding(.top, 8)
.task(id: "\(current?.id ?? "")/\(model.generation)") {
guard let id = current?.id else { return }
let read = await model.source.season(id)
withAnimation(CinemasMotion.or(CinemasMotion.seasonSwitch, reduced: reduceMotion)) { season = read }
}
}
private func choose(_ one: CinemasTitle.Season) {
direction = one.number >= (current?.number ?? 0) ? 1 : -1
chosen = one.id
}
}
/// The design's segmented switch: a dim track, the chosen one filled in ink.
struct CinemasSegments: View {
struct Choice: Identifiable, Equatable {
let id: String
let title: String
}
let choices: [Choice]
let chosen: String?
let choose: (String) -> Void
@Namespace private var mark
@Environment(\.accessibilityReduceMotion) private var reduceMotion
var body: some View {
// Up to four seasons share the width evenly; more scroll sideways.
if choices.count <= 4 {
track(full: true)
} else {
ScrollView(.horizontal) { track(full: false) }.scrollIndicators(.hidden)
}
}
private func track(full: Bool) -> some View {
HStack(spacing: 0) {
ForEach(choices) { choice in
let on = choice.id == chosen
Button {
withAnimation(CinemasMotion.or(CinemasMotion.seasonSwitch, reduced: reduceMotion)) { choose(choice.id) }
} label: {
Text(choice.title)
.font(CinemasType.chip)
.foregroundStyle(on ? CinemasInk.ground : CinemasInk.quiet)
.lineLimit(1)
.minimumScaleFactor(0.7)
.padding(.horizontal, 14)
.frame(maxWidth: full ? .infinity : nil, minHeight: 34)
.background {
if on { RoundedRectangle(cornerRadius: 8, style: .continuous).fill(CinemasInk.ink).matchedGeometryEffect(id: "on", in: mark) }
}
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityAddTraits(on ? [.isButton, .isSelected] : .isButton)
}
}
.padding(3)
.background(RoundedRectangle(cornerRadius: CinemasInk.buttonCorner, style: .continuous).fill(Color.white.opacity(0.07)))
}
}
/// An episode: its still with its states, "4. Its name", its length and what stands, and a tap plays it.
struct CinemasEpisodeRow: View {
let model: CinemasModel
let episode: CinemasSeason.Episode
/// The core's "2. Reeds"; from an older core, "4. Its name" in the line set's form.
private var numbered: String {
episode.label ?? CinemasWords.line("stream.episode_line", ["number": "\(episode.number)", "title": episode.title])
}
/// The core's words for where he is in it ("watched", "23 min left"); an older core's answer falls back to the
/// length.
private var line: String {
var parts: [String] = []
if let state = episode.stateLine {
parts.append(state)
} else if let minutes = episode.minutes {
parts.append(cinemasLength(minutes))
}
if episode.item.preparing { parts.append(CinemasWords.line("stream.poster_preparing")) }
return parts.joined(separator: " · ")
}
var body: some View {
// An episode still on the Mac opens its page, which says how far the Mac has got (`cinemas.preparing`).
Button { episode.item.preparing ? model.open(episode.item, from: "season") : model.play(episode.item) } label: {
HStack(alignment: .top, spacing: 12) {
ZStack {
CinemasPicture(key: episode.still ?? episode.item.backdrop, title: nil, seed: episode.item.id, art: episode.item.art)
CinemasStates(item: episode.item, wide: true)
}
.frame(width: 132, height: 74)
.clipShape(RoundedRectangle(cornerRadius: 6, style: .continuous))
VStack(alignment: .leading, spacing: 3) {
Text(numbered)
.font(CinemasFonts.sans(14, 700))
.foregroundStyle(CinemasInk.ink)
.lineLimit(2)
.multilineTextAlignment(.leading)
if !line.isEmpty { Text(line).font(CinemasType.small).foregroundStyle(CinemasInk.faint) }
if let synopsis = episode.synopsis {
Text(synopsis).font(CinemasType.small).foregroundStyle(CinemasInk.quiet).lineLimit(2).multilineTextAlignment(.leading)
}
if episode.item.onPhone == .kept {
Text(CinemasWords.line("stream.poster_kept")).font(CinemasType.small).foregroundStyle(CinemasInk.accent)
} else if episode.item.onPhone == .keeping {
Text(CinemasWords.line("stream.poster_keeping")).font(CinemasType.small).foregroundStyle(CinemasInk.accent)
}
}
Spacer(minLength: 0)
}
.padding(.horizontal, CinemasInk.side)
.padding(.vertical, 10)
.contentShape(Rectangle())
}
.buttonStyle(CinemasPress())
.onLongPressGesture(minimumDuration: CinemasMotion.liftAfter) {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
model.sheet = .item(episode.item)
}
.accessibilityElement(children: .ignore)
.accessibilityLabel(Text("\(numbered), \(cinemasLabel(episode.item))"))
.accessibilityAddTraits(.isButton)
.accessibilityAction(named: Text(CinemasWords.line("stream.group_sheet"))) { model.sheet = .item(episode.item) }
.accessibilityIdentifier("cinemas-episode-\(episode.id)")
}
}
// MARK: - A row opened whole
/// A big title in the design's display face, over a page that keeps the system's back button and edge swipe.
struct CinemasPageTitle: View {
let text: String
var size: CGFloat = 44
var body: some View {
Text(text.uppercased())
.font(CinemasType.title(size))
.foregroundStyle(CinemasInk.ink)
.lineLimit(3)
.minimumScaleFactor(0.6)
.accessibilityAddTraits(.isHeader)
}
}
/// Three across, at the row's poster size.
/// A grid's tile for a title: a web video keeps its 16:9 in the column, a film or series its 2:3.
private func cinemasTile(_ item: CinemasItem, _ size: CGSize) -> CGSize {
item.kind == .clip ? CGSize(width: size.width, height: (size.width * 9 / 16).rounded()) : size
}
private func cinemasGrid(_ width: CGFloat) -> (columns: [GridItem], size: CGSize) {
let across = 3
let side = ((width - 2 * CinemasInk.side - CGFloat(across - 1) * CinemasInk.gap) / CGFloat(across)).rounded(.down)
let size = CGSize(width: max(side, 60), height: (max(side, 60) * 1.5).rounded())
return (Array(repeating: GridItem(.fixed(size.width), spacing: CinemasInk.gap, alignment: .top), count: across), size)
}
/// A row's pages (`cinemas.row {id, after}`): the first page, then each `next` as the end comes into view. A title
/// met twice across pages is drawn once.
@MainActor @Observable
final class CinemasRowPages {
let id: String
/// The chip chosen; nil is All.
let filter: String?
private(set) var read: CinemasRead?
private(set) var items: [CinemasItem] = []
private(set) var next: String?
private var fetching = false
/// Read from inside Hidden: the core answers hidden titles too.
let hidden: Bool
init(id: String, filter: String? = nil, hidden: Bool = false) {
self.id = id
self.filter = filter
self.hidden = hidden
}
func first(_ source: any CinemasSource) async {
let answer = await source.row(id, after: nil, filter: filter, hidden: hidden)
read = answer
if case .read(let page) = answer {
items = Self.once(page.items)
next = page.next
}
}
/// The next page, once at a time; a refusal leaves what stands and stops asking.
func more(_ source: any CinemasSource) async {
guard let after = next, !fetching else { return }
fetching = true
defer { fetching = false }
switch await source.row(id, after: after, filter: filter, hidden: hidden) {
case .read(let page):
items = Self.once(items + page.items)
next = page.next == after ? nil : page.next
case .refused:
next = nil
}
}
/// After an act: the pages he has already loaded, asked again from the top, replacing what stands only once they
/// have come, so the grid keeps its length and the scroll its place.
func refresh(_ source: any CinemasSource) async {
guard !fetching else { return }
fetching = true
defer { fetching = false }
let had = items.count
var fresh: [CinemasItem] = []
var after: String?
repeat {
guard case .read(let page) = await source.row(id, after: after, filter: filter, hidden: hidden) else { return }
if fresh.isEmpty { read = .read(page) }
fresh = Self.once(fresh + page.items)
let moved = page.next != after
after = moved ? page.next : nil
} while after != nil && fresh.count < had
items = fresh
next = after
}
private static func once(_ items: [CinemasItem]) -> [CinemasItem] {
var seen = Set()
return items.filter { seen.insert($0.key).inserted }
}
}
struct CinemasRowScreen: View {
let model: CinemasModel
let id: String
let title: String
let grow: Namespace.ID
@State private var pages: CinemasRowPages?
private var width: CGFloat { model.width }
@State private var asked = 0
/// The chip chosen (frame 2); nil is All.
@State private var filter: String?
var body: some View {
let grid = cinemasGrid(width)
ScrollView {
VStack(alignment: .leading, spacing: 14) {
VStack(alignment: .leading, spacing: 4) {
CinemasPageTitle(text: title)
// How many it holds under its filter, as the core counts them.
if let count = pages?.read?.answer?.count {
Text(verbatim: "\(count)").font(CinemasType.small).foregroundStyle(CinemasInk.faint)
.accessibilityIdentifier("cinemas-row-count")
}
}
.padding(.horizontal, CinemasInk.side)
if let chips = pages?.read?.answer?.chips, !chips.isEmpty {
ScrollView(.horizontal) {
HStack(spacing: 8) {
ForEach(chips) { chip in
CinemasChip(label: chip.label, style: chip.on ? .on : .normal) {
guard !chip.on else { return }
UISelectionFeedbackGenerator().selectionChanged()
filter = chip.id == "all" ? nil : chip.id
}
.accessibilityAddTraits(chip.on ? .isSelected : [])
.accessibilityIdentifier("cinemas-row-chip-\(chip.id)")
}
}
.padding(.horizontal, CinemasInk.side)
}
.scrollIndicators(.hidden)
}
switch pages?.read {
case .read?:
let items = pages?.items ?? []
if items.isEmpty, id.hasPrefix("group:") {
CinemasButton(label: CinemasWords.line("stream.add_films"), icon: "plus", style: .outline) { model.tab = .search }
.padding(.horizontal, CinemasInk.side)
}
LazyVGrid(columns: grid.columns, spacing: 10) {
ForEach(Array(items.enumerated()), id: \.element.key) { at, item in
CinemasPoster(model: model, item: item, row: id, size: cinemasTile(item, grid.size), grow: grow, wide: item.kind == .clip)
.onAppear {
// The last few in view: the next page comes before the end does.
if at >= items.count - 6, let pages {
Task { await pages.more(model.source) }
}
}
}
}
.padding(.horizontal, CinemasInk.side)
case .refused(let line)?: CinemasRefused(line: line) { asked += 1 }
case nil:
LazyVGrid(columns: grid.columns, spacing: 10) {
ForEach(0..<9, id: \.self) { _ in CinemasBlock().frame(width: grid.size.width, height: grid.size.height) }
}
.padding(.horizontal, CinemasInk.side)
}
}
.padding(.bottom, 24)
}
.background(CinemasInk.ground.ignoresSafeArea())
.navigationBarTitleDisplayMode(.inline)
.toolbar { ToolbarItem(placement: .topBarTrailing) { CinemasRouteButton().frame(width: 32, height: 32) } }
.task(id: "\(asked)/\(filter ?? "all")") {
let fresh = CinemasRowPages(id: id, filter: filter, hidden: model.hiddenReads)
await fresh.first(model.source)
pages = fresh
}
.task(id: model.generation) {
// An act elsewhere (a group, the Bin, kept): what is loaded is asked again in place.
if let pages, case .read? = pages.read { await pages.refresh(model.source) }
}
.accessibilityIdentifier("cinemas-row-screen")
}
}
// MARK: - Search
struct CinemasSearchScreen: View {
let model: CinemasModel
let grow: Namespace.ID
@State private var q = ""
@State private var found: CinemasRead?
private var width: CGFloat { model.width }
@FocusState private var focused: Bool
var body: some View {
let grid = cinemasGrid(width)
ScrollView {
VStack(alignment: .leading, spacing: 18) {
Text(CinemasWords.line("stream.search").uppercased())
.font(CinemasType.heading)
.foregroundStyle(CinemasInk.ink)
.accessibilityAddTraits(.isHeader)
.padding(.top, 8)
field
if q.trimmingCharacters(in: .whitespaces).isEmpty {
Text(CinemasWords.line("stream.search_hint")).font(CinemasType.small).foregroundStyle(CinemasInk.faint)
.accessibilityIdentifier("cinemas-search-hint")
}
switch found {
case .read(let found)?:
if found.items.isEmpty && found.groups.isEmpty && !q.isEmpty {
CinemasLine(line: CinemasWords.line("stream.search_none", ["q": q]))
}
// Frame 6: the top result can be played, here or on the TV, without opening it; then the rest by
// what they are.
if let top = found.items.first {
CinemasTopResult(model: model, item: top, line: found.topLine)
}
let rest = Array(found.items.dropFirst())
let episodes = rest.filter { $0.kind == .episode }
let videos = rest.filter { $0.kind == .clip }
let titles = rest.filter { $0.kind != .episode && $0.kind != .clip }
if !episodes.isEmpty {
LazyVStack(alignment: .leading, spacing: 4) {
CinemasLabel(text: CinemasWords.line("stream.episodes"))
ForEach(episodes) { CinemasFoundRow(model: model, item: $0) }
}
}
if !found.people.isEmpty {
VStack(alignment: .leading, spacing: 4) {
CinemasLabel(text: CinemasWords.line("stream.search_people"))
ForEach(found.people) { person in
// Their titles are found by their name.
Button { q = person.name } label: {
HStack(spacing: 12) {
Image(systemName: person.kind == "channel" ? "play.rectangle" : "person.crop.circle")
.font(.system(size: 22)).foregroundStyle(CinemasInk.accent).frame(width: 36)
.accessibilityHidden(true)
VStack(alignment: .leading, spacing: 2) {
Text(person.name).font(CinemasType.list).foregroundStyle(CinemasInk.ink)
if let line = person.line { Text(line).font(CinemasType.small).foregroundStyle(CinemasInk.quiet) }
}
Spacer(minLength: 0)
}
.frame(minHeight: 52)
.contentShape(Rectangle())
}
.buttonStyle(CinemasPress())
.accessibilityElement(children: .combine)
.accessibilityIdentifier("cinemas-search-person-\(person.name)")
}
}
}
if !videos.isEmpty {
LazyVStack(alignment: .leading, spacing: 4) {
CinemasLabel(text: CinemasWords.line("home.videos"))
ForEach(videos) { CinemasFoundRow(model: model, item: $0) }
}
}
if !found.groups.isEmpty {
VStack(alignment: .leading, spacing: 8) {
CinemasLabel(text: CinemasWords.line("stream.search_groups"))
ForEach(found.groups) { group in
Button { model.push(.row(id: "group:\(group.id)", title: group.name)) } label: {
HStack {
Text(group.name).font(CinemasType.list).foregroundStyle(CinemasInk.ink)
CinemasYours()
Spacer()
Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).foregroundStyle(CinemasInk.faint)
}
.padding(.horizontal, 14)
.frame(minHeight: 48)
.background(RoundedRectangle(cornerRadius: 10, style: .continuous).fill(CinemasInk.raised))
}
.buttonStyle(CinemasPress())
.accessibilityIdentifier("cinemas-search-group-\(group.id)")
}
}
}
if !titles.isEmpty {
VStack(alignment: .leading, spacing: 8) {
CinemasLabel(text: CinemasWords.line("stream.search_titles"))
LazyVGrid(columns: grid.columns, spacing: 10) {
ForEach(titles) { item in
CinemasPoster(model: model, item: item, row: "search", size: cinemasTile(item, grid.size), grow: grow, wide: item.kind == .clip)
}
}
}
}
case .refused(let line)?: CinemasLine(line: line)
case nil: EmptyView()
}
}
.padding(.horizontal, CinemasInk.side)
.padding(.bottom, 24)
}
.scrollDismissesKeyboard(.immediately)
.background(CinemasInk.ground.ignoresSafeArea())
.toolbar(.hidden, for: .navigationBar)
.task(id: "\(q)/\(model.generation)") {
guard !q.trimmingCharacters(in: .whitespaces).isEmpty else {
found = nil
return
}
// A short pause while he types, so each letter does not ask again.
try? await Task.sleep(for: .milliseconds(180))
guard !Task.isCancelled else { return }
found = await model.source.search(q)
}
.onChange(of: model.tab) { _, now in
// Leaving Search puts the keyboard away; it never stands over Home or You.
guard now == .search else {
focused = false
return
}
if let ask = model.searchAsk {
q = ask
model.searchAsk = nil
} else {
focused = true
}
}
.accessibilityIdentifier("cinemas-search")
}
/// The field: 46 high, an amber ring and caret while it has the keyboard, ✕ to clear.
private var field: some View {
HStack(spacing: 10) {
Image(systemName: "magnifyingglass").foregroundStyle(CinemasInk.faint)
TextField(text: $q, prompt: Text(CinemasWords.line("stream.search_prompt")).foregroundStyle(CinemasInk.faint)) {
Text(CinemasWords.line("stream.search"))
}
.font(CinemasType.list)
.foregroundStyle(CinemasInk.ink)
.tint(CinemasInk.accent)
.focused($focused)
.submitLabel(.search)
.autocorrectionDisabled()
.accessibilityIdentifier("cinemas-search-field")
// Clear, in words: its spoken name is Clear, never Cancel.
if !q.isEmpty {
Button(CinemasWords.line("stream.search_clear")) { q = "" }
.font(CinemasFonts.sans(14, 600))
.foregroundStyle(CinemasInk.accent)
.frame(minWidth: 44, minHeight: 44)
.contentShape(Rectangle())
.accessibilityIdentifier("cinemas-search-clear")
}
}
.padding(.leading, 14)
.padding(.trailing, q.isEmpty ? 14 : 6)
.frame(minHeight: 46)
.background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(CinemasInk.field))
.overlay(RoundedRectangle(cornerRadius: 12, style: .continuous).strokeBorder(CinemasInk.accent, lineWidth: focused ? 1.5 : 0))
}
}
/// Search's top result: the picture, the title, what it is, and Play and On TV beside it.
struct CinemasTopResult: View {
let model: CinemasModel
let item: CinemasItem
/// The core's line for it; an older core's answer falls back to its caption or year.
var line: String?
@Environment(CinemasTV.self) private var tv
@Environment(\.dynamicTypeSize) private var typeSize
var body: some View {
VStack(alignment: .leading, spacing: 8) {
CinemasLabel(text: CinemasWords.line("stream.search_top"))
VStack(alignment: .leading, spacing: 12) {
Button { model.open(item, from: "search") } label: {
HStack(spacing: 12) {
CinemasPicture(key: item.poster, title: item.title, seed: item.id, art: item.art)
.frame(width: 60, height: 90)
.clipShape(RoundedRectangle(cornerRadius: 6, style: .continuous))
VStack(alignment: .leading, spacing: 4) {
Text(item.title).font(CinemasFonts.sans(17, 700)).foregroundStyle(CinemasInk.ink).multilineTextAlignment(.leading)
if let what = line ?? item.caption ?? item.year {
Text(what).font(CinemasType.small).foregroundStyle(CinemasInk.quiet).multilineTextAlignment(.leading)
}
}
Spacer(minLength: 0)
}
.contentShape(Rectangle())
}
.buttonStyle(CinemasPress())
.accessibilityIdentifier("cinemas-search-top")
if !item.preparing {
let layout = typeSize.isAccessibilitySize ? AnyLayout(VStackLayout(spacing: 10)) : AnyLayout(HStackLayout(spacing: 10))
layout {
CinemasButton(label: CinemasWords.line("home.play"), icon: "play.fill", height: 40) { model.play(item) }
.accessibilityIdentifier("cinemas-search-top-play")
CinemasButton(label: CinemasWords.line("stream.search_on_tv"), icon: "tv", style: .outline, height: 40) { tv.playOnTV(item, model: model) }
.accessibilityIdentifier("cinemas-search-top-tv")
}
}
}
.padding(12)
.background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(CinemasInk.raised))
}
}
}
/// An episode or a video found: a wide still, its name and what it is; a tap opens it.
struct CinemasFoundRow: View {
let model: CinemasModel
let item: CinemasItem
var body: some View {
Button { model.open(item, from: "search") } label: {
HStack(spacing: 12) {
CinemasPicture(key: item.backdrop ?? item.poster, title: nil, seed: item.id, art: item.art)
.frame(width: 96, height: 54)
.clipShape(RoundedRectangle(cornerRadius: 6, style: .continuous))
VStack(alignment: .leading, spacing: 3) {
Text(item.title).font(CinemasFonts.sans(14, 700)).foregroundStyle(CinemasInk.ink).multilineTextAlignment(.leading)
if let caption = item.caption { Text(caption).font(CinemasType.small).foregroundStyle(CinemasInk.quiet) }
}
Spacer(minLength: 0)
}
.frame(minHeight: 60)
.contentShape(Rectangle())
}
.buttonStyle(CinemasPress())
.accessibilityElement(children: .combine)
.accessibilityIdentifier("cinemas-search-\(item.id)")
}
}
// MARK: - You
struct CinemasYouScreen: View {
let model: CinemasModel
@Environment(CinemasTV.self) private var tv
@State private var keeper = FilmKeeper.shared
@State private var home = SettingsHome()
@State private var you: CinemasRead?
@Environment(\.dynamicTypeSize) private var typeSize
@State private var helpOpen = false
@State private var turning: String?
/// The subtitle languages the line set names, offered after this phone's own.
private static let languages = ["en", "hi", "te", "ta", "ml", "kn", "bn", "mr", "fr", "es", "de", "ja", "ko"]
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 18) {
Text(CinemasWords.line("stream.you").uppercased())
.font(CinemasType.heading)
.foregroundStyle(CinemasInk.ink)
.accessibilityAddTraits(.isHeader)
.padding(.top, 8)
// The account card (frame 12): the library he is signed in to, or Sign in, as every own-look app has it.
SettingsYouCard(home: home, core: model.core, look: .cinemas) { model.say($0) }
// Cinemas' own sections, as the core answers them (`cinemas.you`, frame 12).
switch you {
case .read(let you)?:
ForEach(you.sections) { section in
VStack(alignment: .leading, spacing: 6) {
CinemasLabel(text: section.title)
VStack(spacing: 0) {
ForEach(section.rows) { one in
youRow(one)
if one.id != section.rows.last?.id { Divider().overlay(CinemasInk.rule).padding(.leading, 52) }
}
}
.background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(CinemasInk.raised))
}
.accessibilityElement(children: .contain)
.accessibilityIdentifier("cinemas-you-section-\(section.id)")
}
case .refused(let line)?: CinemasRefused(line: line) { Task { await read() } }
case nil: ProgressView().tint(CinemasInk.accent).frame(maxWidth: .infinity)
}
// Adding films is the phone's own (Files), as Android's Plus is.
VStack(spacing: 0) {
row(ShellLines.line("cinemas", "add.title"), line: nil, icon: "plus.circle", id: "add") { model.push(.add) }
}
.background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(CinemasInk.raised))
// Storage, Help and feedback (a report) and About, as every own-look app has them.
SettingsParts(core: model.core, look: .cinemas, said: { model.say($0) })
VStack(alignment: .leading, spacing: 0) {
CinemasLabel(text: CinemasWords.line("stream.you_account"))
DeleteAccountPart(core: model.core, look: .cinemas, onDeleted: { model.tab = .home })
}
// Hidden (CONTRACT-2 HIDDEN): one plain row, last, with no count; it opens behind the phone's lock.
if model.hiddenReachable {
VStack(spacing: 0) {
row(CinemasWords.line("stream.hidden_place"), line: nil, icon: "eye.slash", id: "hidden") { Task { await model.openHidden() } }
}
.background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(CinemasInk.raised))
}
}
.padding(.horizontal, CinemasInk.side)
.padding(.bottom, 24)
}
.background(CinemasInk.ground.ignoresSafeArea())
.toolbar(.hidden, for: .navigationBar)
.task(id: model.generation) {
await home.read(model.core)
await read()
}
.accessibilityIdentifier("cinemas-you")
}
private func read() async {
you = await model.source.you(free: CinemasOnPhoneScreen.freeBytes())
}
private static func icon(_ id: String) -> String {
switch id {
case "tv": "airplayvideo"
case "mac": "desktopcomputer"
case "groups": "rectangle.stack"
case "autoplay_next": "forward.end"
case "downloads": "arrow.down.circle"
case "mobile_data": "antenna.radiowaves.left.and.right"
case "subtitles_on": "captions.bubble"
case "subtitle_language": "globe"
case "bin": "trash"
case "help_ready": "questionmark.circle"
default: "circle"
}
}
/// One of the core's rows: a switch it turns, the language menu, the help line in place, or a place it opens.
@ViewBuilder private func youRow(_ one: CinemasYou.Row) -> some View {
if let on = one.switch {
Toggle(isOn: Binding(get: { on }, set: { _ in turn(one) })) {
HStack(spacing: 14) {
Image(systemName: Self.icon(one.id)).font(.system(size: 18)).foregroundStyle(CinemasInk.accent).frame(width: 24)
.accessibilityHidden(true)
VStack(alignment: .leading, spacing: 2) {
Text(one.label).font(CinemasType.list).foregroundStyle(CinemasInk.ink)
if let sub = one.sub { Text(sub).font(CinemasType.small).foregroundStyle(CinemasInk.faint) }
}
}
}
.tint(CinemasInk.accent)
.disabled(turning != nil)
.padding(.horizontal, 14)
.frame(minHeight: 56)
.accessibilityIdentifier("cinemas-you-\(one.id)")
} else if one.id == "subtitle_language" {
Menu {
Button(CinemasWords.line("home.you_language_phone")) { language(nil, one) }
ForEach(Self.languages, id: \.self) { code in
Button(CinemasWords.line("home.lang_\(code)")) { language(code, one) }
}
} label: {
rowLabel(one.label, line: nil, value: one.value, icon: Self.icon(one.id))
}
.accessibilityIdentifier("cinemas-you-\(one.id)")
} else if one.act?.open == "help_ready" {
Button { withAnimation(CinemasMotion.standard(0.25)) { helpOpen.toggle() } } label: {
VStack(alignment: .leading, spacing: 6) {
rowLabel(one.label, line: one.value, value: nil, icon: Self.icon(one.id))
if helpOpen, let sub = one.sub {
Text(sub).font(CinemasType.small).foregroundStyle(CinemasInk.quiet)
.padding(.leading, 52).padding(.trailing, 14).padding(.bottom, 12)
}
}
}
.buttonStyle(CinemasPress())
.accessibilityIdentifier("cinemas-you-\(one.id)")
} else {
let line = one.id == "tv" ? (tv.device ?? CinemasWords.line("stream.you_tv_line")) : one.id == "downloads" ? (keeping ?? one.value) : nil
Button { open(one) } label: {
rowLabel(one.label, line: line, value: one.id == "downloads" || one.id == "tv" ? nil : one.value, icon: Self.icon(one.id))
}
.buttonStyle(CinemasPress())
.accessibilityIdentifier("cinemas-you-\(one.id)")
}
}
private func rowLabel(_ title: String, line: String?, value: String?, icon: String) -> some View {
HStack(spacing: 14) {
Image(systemName: icon).font(.system(size: 18)).foregroundStyle(CinemasInk.accent).frame(width: 24)
.accessibilityHidden(true)
// At the accessibility sizes the value goes under the name, so neither breaks mid-word.
let under = typeSize.isAccessibilitySize
VStack(alignment: .leading, spacing: 2) {
Text(title).font(CinemasType.list).foregroundStyle(CinemasInk.ink)
if let line { Text(line).font(CinemasType.small).foregroundStyle(CinemasInk.faint).lineLimit(under ? nil : 3) }
if under, let value { Text(value).font(CinemasType.small).foregroundStyle(CinemasInk.quiet) }
}
Spacer(minLength: 8)
if !under, let value { Text(value).font(CinemasType.small).foregroundStyle(CinemasInk.quiet).multilineTextAlignment(.trailing) }
Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).foregroundStyle(CinemasInk.faint)
.accessibilityHidden(true)
}
.padding(.horizontal, 14)
.frame(minHeight: 56)
.contentShape(Rectangle())
}
/// A row that opens a place: the TV picker, or the page its act reads.
private func open(_ one: CinemasYou.Row) {
if one.act?.open == "tv" { return tv.choose() }
switch one.act?.method {
case CottonMethod.cinemasRow?:
let id = one.act?.request?["id"]?.string ?? "getting_ready"
model.push(.row(id: id, title: one.label))
case CottonMethod.cinemasGroups?: model.push(.groups)
case CottonMethod.cinemasOnPhone?: model.push(.onPhone)
case CottonMethod.cinemasBin?: model.push(.bin)
default: break
}
}
/// A switch turned: the core's act (`cinemas.setting`, `films.keeping`), then You read again.
private func turn(_ one: CinemasYou.Row) {
guard let method = one.act?.method else { return }
turning = one.id
Task {
if case .refused(let line) = await model.source.youAct(method, one.act?.request) { model.say(line) }
await read()
turning = nil
}
}
private func language(_ code: String?, _ one: CinemasYou.Row) {
Task {
let ask: JSONValue = .object(["key": .string("subtitle_language"), "value": code.map { .string($0) } ?? .null])
if case .refused(let line) = await model.source.youAct(one.act?.method ?? CottonMethod.cinemasSetting, ask) { model.say(line) }
await read()
}
}
/// What is coming down now, as "Night Ferry · 42%".
private var keeping: String? {
guard let one = keeper.keeping.values.first else { return nil }
return CinemasWords.line("stream.keeping_line", ["title": one.title, "percent": "\(Int(one.fraction * 100))"])
}
private func row(_ title: String, line: String?, icon: String, id: String, tap: @escaping () -> Void) -> some View {
Button(action: tap) {
HStack(spacing: 14) {
Image(systemName: icon).font(.system(size: 18)).foregroundStyle(CinemasInk.accent).frame(width: 24)
VStack(alignment: .leading, spacing: 2) {
Text(title).font(CinemasType.list).foregroundStyle(CinemasInk.ink)
if let line { Text(line).font(CinemasType.small).foregroundStyle(CinemasInk.faint).lineLimit(2) }
}
Spacer()
Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).foregroundStyle(CinemasInk.faint)
}
.padding(.horizontal, 14)
.frame(minHeight: 56)
.contentShape(Rectangle())
}
.buttonStyle(CinemasPress())
.accessibilityIdentifier("cinemas-you-\(id)")
}
}
@MainActor
extension SettingsLook {
static var cinemas: SettingsLook {
var look = SettingsLook(
ink: CinemasInk.ink, quiet: CinemasInk.quiet, rule: CinemasInk.rule, ground: CinemasInk.ground,
body: CinemasType.list, small: CinemasType.small,
heading: { AnyView(CinemasLabel(text: $0)) },
act: { words, id, enabled, tap in
AnyView(Button(action: tap) {
Text(verbatim: words).font(CinemasType.button).foregroundStyle(CinemasInk.accent)
.frame(minHeight: 44, alignment: .leading).contentShape(Rectangle())
}
.buttonStyle(.plain).disabled(!enabled).opacity(enabled ? 1 : 0.45).accessibilityIdentifier(id))
},
choice: { words, on, id, enabled, tap in
AnyView(CinemasChip(label: words, style: on ? .on : .normal, action: tap).disabled(!enabled).accessibilityIdentifier(id))
}
)
look.danger = Color(red: 1, green: 0.54, blue: 0.5)
look.title = CinemasType.title(34)
return look
}
}
/// You › On this phone (frame 10), as `cinemas.onPhone` says it: the storage line, the flight card, Downloads with
/// the Mobile data switch (DECISIONS.md's standing rule, `films.keeping`), what is coming down (this phone's own
/// count, which the core does not hold) and what is kept.
struct CinemasOnPhoneScreen: View {
let model: CinemasModel
@State private var page: CinemasRead?
@State private var cellular: Bool?
@State private var keeper = FilmKeeper.shared
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 16) {
CinemasPageTitle(text: page?.answer?.title ?? CinemasWords.line("stream.you_on_phone"))
if let space = page?.answer?.space { Text(space).font(CinemasType.meta).foregroundStyle(CinemasInk.quiet) }
if let flight = page?.answer?.flight {
VStack(alignment: .leading, spacing: 4) {
Text(flight.line).font(CinemasFonts.sans(15, 700)).foregroundStyle(CinemasInk.accent)
Text(flight.what).font(CinemasType.small).foregroundStyle(CinemasInk.quiet)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(14)
.background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(CinemasInk.raised))
.accessibilityElement(children: .combine)
.accessibilityIdentifier("cinemas-flight")
}
ForEach(keeper.keeping.values.sorted { $0.title < $1.title }, id: \.key) { one in
VStack(alignment: .leading, spacing: 6) {
HStack {
Text(one.title).font(CinemasFonts.sans(14, 700)).foregroundStyle(CinemasInk.ink)
Spacer()
Text(CinemasWords.line("stream.keeping_percent", ["percent": "\(Int(one.fraction * 100))"])).font(CinemasType.small).foregroundStyle(CinemasInk.quiet).monospacedDigit()
}
GeometryReader { box in
ZStack(alignment: .leading) {
Capsule().fill(Color.white.opacity(0.15))
Capsule().fill(CinemasInk.accent).frame(width: (box.size.width * one.fraction).drawableOrZero)
.animation(CinemasMotion.keeping, value: one.fraction)
}
}
.frame(height: 3)
}
.padding(14)
.background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(CinemasInk.raised))
.accessibilityElement(children: .combine)
}
switch page {
case .read(let page)?:
if let empty = page.empty, keeper.keeping.isEmpty {
Text(empty).font(CinemasType.body).foregroundStyle(CinemasInk.quiet)
}
ForEach(page.items) { kept in
Button { model.open(kept.item, from: "on_phone") } label: {
HStack(spacing: 12) {
CinemasPicture(key: kept.item.poster, title: kept.item.title, seed: kept.item.id, art: kept.item.art)
.frame(width: 44, height: 66)
.clipShape(RoundedRectangle(cornerRadius: 4, style: .continuous))
VStack(alignment: .leading, spacing: 3) {
Text(kept.item.title).font(CinemasFonts.sans(15, 700)).foregroundStyle(CinemasInk.ink).lineLimit(2)
if let caption = kept.item.caption { Text(caption).font(CinemasType.small).foregroundStyle(CinemasInk.faint) }
Text(kept.line).font(CinemasType.small).foregroundStyle(CinemasInk.quiet)
}
Spacer(minLength: 0)
}
.contentShape(Rectangle())
}
.buttonStyle(CinemasPress())
.accessibilityElement(children: .combine)
.accessibilityIdentifier("cinemas-kept-\(kept.item.id)")
}
case .refused(let line)?: CinemasRefused(line: line) { model.changed() }
case nil: EmptyView()
}
// Downloads (frame 10): the Mobile data switch, DECISIONS.md's standing rule. Quality and Remove once
// watched wait for the core's knobs.
if let cellular {
VStack(alignment: .leading, spacing: 10) {
Text(CinemasWords.line("stream.downloads").uppercased())
.font(CinemasFonts.sans(11, 700)).tracking(1.2).foregroundStyle(CinemasInk.faint)
.accessibilityAddTraits(.isHeader)
Toggle(isOn: Binding(get: { cellular }, set: { turn($0) })) {
Text(CinemasWords.line("stream.mobile_data")).font(CinemasType.list).foregroundStyle(CinemasInk.ink)
}
.tint(CinemasInk.accent)
.padding(14)
.background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(CinemasInk.raised))
.accessibilityIdentifier("cinemas-mobile-data")
}
.padding(.top, 8)
}
}
.padding(.horizontal, CinemasInk.side)
.padding(.bottom, 24)
}
.background(CinemasInk.ground.ignoresSafeArea())
.navigationBarTitleDisplayMode(.inline)
.task(id: model.generation) {
page = await model.source.onPhone(free: Self.freeBytes())
cellular = await model.source.cellular().answer
}
.accessibilityIdentifier("cinemas-on-phone")
}
private func turn(_ on: Bool) {
cellular = on
Task {
switch await model.source.setCellular(on) {
case .read(let now):
cellular = now
model.say(ShellLines.line("cinemas", now ? "keep.cellular_on" : "keep.cellular_off", [:]))
case .refused(let line):
cellular = !on
UINotificationFeedbackGenerator().notificationOccurred(.warning)
model.say(line)
}
}
}
/// This phone's free space, as the system offers it for things the person asked to keep.
static func freeBytes() -> Int64? {
let home = URL(fileURLWithPath: NSHomeDirectory())
return try? home.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey]).volumeAvailableCapacityForImportantUsage
}
}
/// The titles kept on this phone, as the core's On this phone row reads them.
struct CinemasRowEmbed: View {
let model: CinemasModel
let id: String
@Namespace private var grow
@State private var page: CinemasRowPage?
private var width: CGFloat { model.width }
var body: some View {
let grid = cinemasGrid(width + 2 * CinemasInk.side)
LazyVGrid(columns: grid.columns, spacing: 10) {
ForEach(page?.items ?? []) { item in
CinemasPoster(model: model, item: item, row: id, size: grid.size, grow: grow)
}
}
.task(id: model.generation) { page = await model.source.row(id, after: nil).answer }
}
}
// MARK: - His groups
/// You › Your groups: each group a row on Home, in this order; drag to change it; rename or delete (the films stay).
struct CinemasGroupsScreen: View {
let model: CinemasModel
@State private var groups: CinemasRead?
@State private var asked = 0
var body: some View {
List {
Section {
VStack(alignment: .leading, spacing: 8) {
CinemasPageTitle(text: CinemasWords.line("stream.groups"))
Text(CinemasWords.line("stream.groups_lead")).font(CinemasType.small).foregroundStyle(CinemasInk.faint)
}
.listRowBackground(Color.clear)
.listRowInsets(EdgeInsets(top: 0, leading: CinemasInk.side, bottom: 8, trailing: CinemasInk.side))
}
switch groups {
case .read(let read)?:
if read.groups.isEmpty {
Text(CinemasWords.line("stream.groups_none")).font(CinemasType.body).foregroundStyle(CinemasInk.quiet)
.listRowBackground(Color.clear)
} else {
Section {
ForEach(Array(read.groups.enumerated()), id: \.element.id) { index, group in
groupRow(group, index: index, of: read.groups.count)
}
.onMove { from, to in move(read.groups, from: from, to: to) }
}
}
case .refused(let line)?:
CinemasRefused(line: line) { asked += 1 }.listRowBackground(Color.clear)
case nil:
EmptyView()
}
Section {
CinemasButton(label: CinemasWords.line("stream.group_new"), icon: "plus", style: .outline) { model.sheet = .newGroup }
.listRowBackground(Color.clear)
.listRowInsets(EdgeInsets(top: 8, leading: CinemasInk.side, bottom: 8, trailing: CinemasInk.side))
.accessibilityIdentifier("cinemas-groups-new")
}
}
.environment(\.editMode, .constant(.active))
.scrollContentBackground(.hidden)
.background(CinemasInk.ground.ignoresSafeArea())
.navigationBarTitleDisplayMode(.inline)
.task(id: "\(model.generation)/\(asked)") { groups = await model.source.groups() }
.accessibilityIdentifier("cinemas-groups")
}
private func groupRow(_ group: CinemasGroups.Group, index: Int, of count: Int) -> some View {
Button { model.sheet = .rename(id: group.id, name: group.name) } label: {
VStack(alignment: .leading, spacing: 2) {
Text(group.name).font(CinemasType.list).foregroundStyle(CinemasInk.ink)
if let n = group.count {
Text(CinemasWords.line(n == 1 ? "stream.group_films_one" : "stream.group_films_other", ["n": n.formatted()]))
.font(CinemasType.small).foregroundStyle(CinemasInk.faint)
}
}
.frame(maxWidth: .infinity, minHeight: 44, alignment: .leading)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.listRowBackground(CinemasInk.raised)
.accessibilityAction(named: Text(CinemasWords.line("stream.group_rename"))) { model.sheet = .rename(id: group.id, name: group.name) }
.accessibilityAction(named: Text(CinemasWords.line("stream.group_earlier"))) {
guard index > 0 else { return }
Task { model.act(await model.source.moveGroup(group.id, earlier: true)) }
}
.accessibilityAction(named: Text(CinemasWords.line("stream.group_later"))) {
guard index < count - 1 else { return }
Task { model.act(await model.source.moveGroup(group.id, earlier: false)) }
}
.accessibilityAction(named: Text(CinemasWords.line("stream.group_delete"))) {
Task { await model.deleteGroup(id: group.id, name: group.name) }
}
// Held: its menu, with Hide this category (CONTRACT-2 HIDDEN) once Hidden can be reached.
.contextMenu {
Button(CinemasWords.line("stream.group_rename"), systemImage: "pencil") { model.sheet = .rename(id: group.id, name: group.name) }
if model.hiddenReachable {
Button(CinemasWords.line("stream.hide_category"), systemImage: "eye.slash") { model.sheet = .hide(id: group.id, name: group.name) }
}
if model.core != nil {
Button(ShellLines.line("share", "open"), systemImage: "person.2") { model.sheet = .share(id: group.id) }
}
}
.accessibilityAction(named: Text(ShellLines.line("share", "open"))) { model.sheet = .share(id: group.id) }
.accessibilityIdentifier("cinemas-group-\(group.id)")
}
/// A drag: the group stands where it was let go at once, and the whole order goes to the core in one call
/// (`cinemas.groupsOrder`).
private func move(_ list: [CinemasGroups.Group], from: IndexSet, to: Int) {
guard let start = from.first else { return }
var now = list
now.move(fromOffsets: from, toOffset: to)
groups = .read(CinemasGroups(groups: now))
let end = to > start ? to - 1 : to
guard end != start else { return }
Task {
if case .refused(let line) = await model.source.orderGroups(now.map(\.id)) { model.say(line) }
model.changed()
}
}
}
// MARK: - The sheets
struct CinemasSheetPage: View {
let model: CinemasModel
let sheet: CinemasSheet
var body: some View {
switch sheet {
case .item(let item): CinemasItemSheet(model: model, item: item)
case .subtitles(let item): CinemasSubtitlesSheet(model: model, item: item)
case .send(let item): CinemasSendSheet(model: model, item: item)
case .hide(let id, let name): CinemasHideSheet(model: model, group: id, name: name)
case .share(let id):
if let core = model.core {
ShareSheetView(core: core, app: "cinemas", thing: .object(["kind": .string("list"), "id": .string(id)]), close: { model.sheet = nil })
}
case .newGroup:
CinemasNameSheet(model: model, title: CinemasWords.line("stream.group_new"), name: "", group: nil) { name in
await model.makeGroup(name, with: nil)
}
case .rename(let id, let name):
CinemasNameSheet(model: model, title: CinemasWords.line("stream.group_rename"), name: name, group: id) { now in
let done = await model.source.renameGroup(id, to: now)
model.act(done)
return done.answer != nil
}
}
}
}
/// The one sheet for a title (cinemas-3.html 9b): what it is (a film, a series, a video), and his groups, each a tick;
/// every change is made at once, with a tap of the phone and a toast; Done closes.
struct CinemasItemSheet: View {
let model: CinemasModel
let item: CinemasItem
@State private var groups: CinemasRead?
@State private var kind: CinemasItem.Kind
@State private var naming = false
@State private var name = ""
@FocusState private var focused: Bool
/// An episode (frame 9b): which series, season and episode, chosen in the same sheet.
@State private var episodeStep = false
@State private var seriesList: [CinemasItem] = []
@State private var series: String?
@State private var newSeries = ""
@State private var season = 1
@State private var episode = 1
@State private var moving = false
init(model: CinemasModel, item: CinemasItem) {
self.model = model
self.item = item
_kind = State(initialValue: item.kind)
}
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 14) {
HStack(spacing: 12) {
CinemasPicture(key: item.poster, title: item.title, seed: item.id, art: item.art)
.frame(width: 44, height: 66)
.clipShape(RoundedRectangle(cornerRadius: 4))
Text(item.title).font(CinemasFonts.sans(16, 700)).foregroundStyle(CinemasInk.ink).lineLimit(2)
}
.accessibilityElement(children: .combine)
if item.table == "film" {
CinemasLabel(text: CinemasWords.line("stream.it_is"))
FlowRow(spacing: 8) {
ForEach([CinemasItem.Kind.film, .series, .clip], id: \.self) { one in
let on = kind == one && !episodeStep
CinemasChip(label: CinemasWords.line("stream.kind_\(one.rawValue)"), icon: on ? "checkmark" : nil,
style: on ? .on : .normal) {
episodeStep = false
guard kind != one else { return }
let before = kind
kind = one
Task { if !(await model.kind(item, to: one)) { kind = before } }
}
.accessibilityIdentifier("cinemas-kind-\(one.rawValue)")
}
CinemasChip(label: CinemasWords.line("stream.kind_episode"), icon: episodeStep ? "checkmark" : nil,
style: episodeStep ? .on : .normal) {
withAnimation(CinemasMotion.sheet) { episodeStep = true }
}
.accessibilityIdentifier("cinemas-kind-episode")
}
if episodeStep { episodeChoice.transition(.opacity.combined(with: .move(edge: .top))) }
}
CinemasLabel(text: CinemasWords.line("stream.in_groups"))
VStack(spacing: 0) {
switch groups {
case .read(let read)?:
ForEach(read.groups) { group in tick(group) }
case .refused(let line)?:
Text(line).font(CinemasType.small).foregroundStyle(CinemasInk.quiet).padding(.vertical, 8)
case nil:
ForEach(0..<2, id: \.self) { _ in CinemasBlock(corner: 4).frame(height: 20).padding(.vertical, 10) }
}
if naming {
HStack(spacing: 10) {
TextField(text: $name, prompt: Text(CinemasWords.line("stream.group_name_hint")).foregroundStyle(CinemasInk.faint)) {
Text(CinemasWords.line("stream.group_name"))
}
.focused($focused)
.submitLabel(.done)
.onSubmit(make)
.font(CinemasType.list)
.foregroundStyle(CinemasInk.ink)
.tint(CinemasInk.accent)
.accessibilityIdentifier("cinemas-sheet-name")
Button(CinemasWords.line("stream.group_make"), action: make)
.font(CinemasType.button)
.foregroundStyle(CinemasInk.accent)
.disabled(name.trimmingCharacters(in: .whitespaces).isEmpty)
}
.frame(minHeight: 48)
.onAppear { focused = true }
} else {
Button { naming = true } label: {
Label(CinemasWords.line("stream.group_new"), systemImage: "plus")
.font(CinemasType.button)
.foregroundStyle(CinemasInk.accent)
.frame(maxWidth: .infinity, minHeight: 48, alignment: .leading)
.contentShape(Rectangle())
}
.buttonStyle(CinemasPress())
.accessibilityIdentifier("cinemas-sheet-new-group")
}
}
if item.table == "film" {
Text(CinemasWords.line("stream.kind_stays")).font(CinemasType.small).foregroundStyle(CinemasInk.faint)
}
CinemasButton(label: CinemasWords.line("stream.done")) { model.sheet = nil }
.accessibilityIdentifier("cinemas-sheet-done")
}
.padding(.horizontal, CinemasInk.side)
.padding(.top, 24)
.padding(.bottom, 20)
}
.scrollBounceBehavior(.basedOnSize)
.task(id: model.generation) { groups = await model.source.groups(holding: item, hidden: model.hiddenReads) }
.accessibilityIdentifier("cinemas-item-sheet")
}
/// Which series, which season, which episode; then Move it there (`cinemas.toEpisode`).
private var episodeChoice: some View {
let name = newSeries.trimmingCharacters(in: .whitespaces)
let ready = series != nil || !name.isEmpty
return VStack(alignment: .leading, spacing: 12) {
Text(CinemasWords.line("stream.episode_of_title", ["title": item.title]))
.font(CinemasFonts.sans(15, 700)).foregroundStyle(CinemasInk.ink)
Menu {
ForEach(seriesList) { one in
Button { series = one.id; newSeries = "" } label: {
if series == one.id { Label(one.title, systemImage: "checkmark") } else { Text(one.title) }
}
}
Button { series = nil } label: { Label(CinemasWords.line("stream.episode_series_new"), systemImage: "plus") }
} label: {
HStack {
Text(CinemasWords.line("stream.episode_series")).foregroundStyle(CinemasInk.quiet)
Spacer()
Text(seriesList.first { $0.id == series }?.title ?? CinemasWords.line("stream.episode_series_new"))
.foregroundStyle(CinemasInk.ink)
Image(systemName: "chevron.up.chevron.down").font(.system(size: 12)).foregroundStyle(CinemasInk.faint)
}
.font(CinemasType.list)
.frame(minHeight: 44)
}
.accessibilityIdentifier("cinemas-episode-series")
if series == nil {
TextField(text: $newSeries, prompt: Text(CinemasWords.line("stream.episode_series_name")).foregroundStyle(CinemasInk.faint)) {
Text(CinemasWords.line("stream.episode_series_name"))
}
.font(CinemasType.list).foregroundStyle(CinemasInk.ink).tint(CinemasInk.accent)
.frame(minHeight: 44)
.accessibilityIdentifier("cinemas-episode-new-series")
}
Stepper(value: $season, in: 1...99) {
Text(ShellLines.line("cinemas", "intake.season_title", ["number": "\(season)"])).font(CinemasType.list).foregroundStyle(CinemasInk.ink)
}
.accessibilityIdentifier("cinemas-episode-season")
Stepper(value: $episode, in: 1...999) {
Text(ShellLines.line("cinemas", "intake.episode_title", ["number": "\(episode)"])).font(CinemasType.list).foregroundStyle(CinemasInk.ink)
}
.accessibilityIdentifier("cinemas-episode-number")
CinemasButton(label: CinemasWords.line(moving ? "stream.episode_moving" : "stream.episode_make"), icon: "arrow.right.circle") {
moving = true
Task {
_ = await model.toEpisode(item, series: series, newSeries: series == nil ? name : nil, season: season, episode: episode)
moving = false
}
}
.disabled(!ready || moving)
.accessibilityIdentifier("cinemas-episode-make")
}
.padding(14)
.background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(CinemasInk.raised))
.task {
seriesList = await model.source.row("series", after: nil).answer?.items ?? []
if series == nil { series = seriesList.first?.id }
}
}
private func tick(_ group: CinemasGroups.Group) -> some View {
let holds = group.holds ?? false
return Button {
Task { _ = await model.group(group, item: item, in: !holds) }
} label: {
HStack(spacing: 12) {
Image(systemName: holds ? "checkmark.circle.fill" : "plus.circle")
.font(.system(size: 22))
.foregroundStyle(holds ? CinemasInk.accent : CinemasInk.faint)
.contentTransition(.symbolEffect(.replace))
Text(group.name).font(CinemasType.list).foregroundStyle(CinemasInk.ink)
Spacer()
}
.frame(minHeight: 44)
.contentShape(Rectangle())
}
.buttonStyle(CinemasPress())
.accessibilityAddTraits(holds ? [.isButton, .isSelected] : .isButton)
.accessibilityIdentifier("cinemas-sheet-group-\(group.id)")
}
private func make() {
let name = name.trimmingCharacters(in: .whitespaces)
guard !name.isEmpty else { return }
Task {
if await model.makeGroup(name, with: item) {
naming = false
self.name = ""
}
}
}
}
/// Name a group: the field, Cancel and Make; renaming also offers Delete group (the films stay).
struct CinemasNameSheet: View {
let model: CinemasModel
let title: String
@State var name: String
let group: String?
let done: (String) async -> Bool
@FocusState private var focused: Bool
var body: some View {
VStack(alignment: .leading, spacing: 16) {
Text(title).font(CinemasFonts.sans(16, 700)).foregroundStyle(CinemasInk.ink)
TextField(text: $name, prompt: Text(CinemasWords.line("stream.group_name_hint")).foregroundStyle(CinemasInk.faint)) {
Text(CinemasWords.line("stream.group_name"))
}
.focused($focused)
.submitLabel(.done)
.onSubmit(save)
.font(CinemasType.list)
.padding(.horizontal, 14)
.frame(minHeight: 46)
.background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(CinemasInk.field))
.foregroundStyle(CinemasInk.ink)
.tint(CinemasInk.accent)
.accessibilityIdentifier("cinemas-name-field")
HStack(spacing: 10) {
CinemasButton(label: CinemasWords.line("stream.group_cancel"), style: .plain) { model.sheet = nil }
CinemasButton(label: CinemasWords.line("stream.group_make"), disabled: name.trimmingCharacters(in: .whitespaces).isEmpty, action: save)
.accessibilityIdentifier("cinemas-name-make")
}
if let group {
Button(role: .destructive) {
model.sheet = nil
Task { await model.deleteGroup(id: group, name: name) }
} label: {
Text(CinemasWords.line("stream.group_delete")).font(CinemasType.button).foregroundStyle(Color(red: 1, green: 0.54, blue: 0.5))
.frame(maxWidth: .infinity, minHeight: 44)
}
.accessibilityIdentifier("cinemas-name-delete")
}
}
.padding(20)
.onAppear { focused = true }
}
private func save() {
let name = name.trimmingCharacters(in: .whitespaces)
guard !name.isEmpty else { return }
Task { if await done(name) { model.sheet = nil } }
}
}
/// Add films: Files' own picker, for films or for a whole folder of films and series; each is brought in where it
/// stands, copied once into the store, its names saying what it is (the intake reads a folder's films itself).
struct CinemasAddFilms: View {
let model: CinemasModel
let label: String
/// What Files is asked for: films, or one folder.
@State private var asking: [UTType]?
var body: some View {
VStack(spacing: 10) {
CinemasButton(label: label, icon: "plus") { asking = [.movie] }
.accessibilityIdentifier("cinemas-add-films")
CinemasButton(label: ShellLines.line("cinemas", "add.folder"), icon: "folder", style: .outline) { asking = [.folder] }
.accessibilityIdentifier("cinemas-add-folder")
}
.fileImporter(isPresented: Binding(get: { asking != nil }, set: { if !$0 { asking = nil } }),
allowedContentTypes: asking ?? [.movie], allowsMultipleSelection: asking != [.folder]) { result in
guard case .success(let urls) = result, !urls.isEmpty else { return }
model.say(ShellLines.line("cinemas", "add.adding"))
Task {
await model.shares?.films(inPlace: urls)
model.changed()
}
}
}
}
/// You › Add films: what can be added and how, then Files for films or a folder (Android's Plus).
struct CinemasAddScreen: View {
let model: CinemasModel
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 16) {
CinemasPageTitle(text: ShellLines.line("cinemas", "add.title"))
Text(ShellLines.line("cinemas", "add.lead")).font(CinemasType.body).foregroundStyle(CinemasInk.quiet)
CinemasAddFilms(model: model, label: ShellLines.line("cinemas", "add.files"))
.padding(.top, 8)
}
.padding(.horizontal, CinemasInk.side)
.padding(.bottom, 24)
}
.background(CinemasInk.ground.ignoresSafeArea())
.navigationBarTitleDisplayMode(.inline)
.accessibilityIdentifier("cinemas-add")
}
}
// MARK: - Subtitles
/// A title's subtitles (PUNCH Both 4, `cinemas.subtitles`): each track with where it came from and a tick on the one
/// chosen in the player; what the Mac is doing about them; and its acts: find them online, make them on the Mac, or
/// give his own .srt or .vtt file.
struct CinemasSubtitlesSheet: View {
let model: CinemasModel
let item: CinemasItem
@Environment(\.dismiss) private var dismiss
@State private var page: CinemasRead?
@State private var giving = false
@State private var busy: String?
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 18) {
HStack(alignment: .firstTextBaseline) {
Text(page?.answer?.title ?? CinemasWords.line("home.subtitles_title"))
.font(CinemasType.title(28)).foregroundStyle(CinemasInk.ink)
.accessibilityAddTraits(.isHeader)
Spacer()
Button(CinemasWords.line("stream.done")) { dismiss() }
.font(CinemasType.button).foregroundStyle(CinemasInk.accent)
.frame(minWidth: 44, minHeight: 44)
.contentShape(Rectangle())
.accessibilityIdentifier("cinemas-subtitles-done")
}
Text(item.title).font(CinemasType.meta).foregroundStyle(CinemasInk.quiet)
switch page {
case .read(let page)?:
if !page.tracks.isEmpty {
VStack(spacing: 0) {
ForEach(page.tracks) { track in
HStack(spacing: 12) {
VStack(alignment: .leading, spacing: 2) {
Text(track.name).font(CinemasFonts.sans(15, 600)).foregroundStyle(CinemasInk.ink)
if let from = track.from { Text(from).font(CinemasType.small).foregroundStyle(CinemasInk.quiet) }
}
Spacer(minLength: 8)
if track.chosen {
Image(systemName: "checkmark").font(.system(size: 15, weight: .bold)).foregroundStyle(CinemasInk.accent)
}
}
.padding(.vertical, 12)
.accessibilityElement(children: .combine)
.accessibilityAddTraits(track.chosen ? .isSelected : [])
.accessibilityIdentifier("cinemas-subtitle-\(track.id)")
if track.id != page.tracks.last?.id { Divider().overlay(CinemasInk.rule) }
}
}
.padding(.horizontal, 14)
.background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(CinemasInk.raised))
} else {
Text(page.line).font(CinemasType.body).foregroundStyle(CinemasInk.quiet)
}
if let working = page.working {
HStack(spacing: 10) {
ProgressView().tint(CinemasInk.accent)
Text(working).font(CinemasType.body).foregroundStyle(CinemasInk.ink)
}
.padding(14)
.frame(maxWidth: .infinity, alignment: .leading)
.overlay(RoundedRectangle(cornerRadius: 14, style: .continuous).strokeBorder(CinemasInk.accent.opacity(0.45), style: StrokeStyle(lineWidth: 1, dash: [5, 4])))
.accessibilityElement(children: .combine)
.accessibilityIdentifier("cinemas-subtitles-working")
}
VStack(spacing: 10) {
ForEach(page.acts) { act in
CinemasButton(label: act.label, icon: icon(act.id), style: act.id == page.acts.first?.id ? .primary : .outline) {
if act.id == "give" { giving = true } else { take(act.id, file: nil) }
}
.disabled(busy != nil)
.accessibilityIdentifier("cinemas-subtitles-\(act.id)")
}
}
case .refused(let line)?:
CinemasRefused(line: line) { Task { await read() } }
case nil:
ProgressView().tint(CinemasInk.accent).frame(maxWidth: .infinity)
}
}
.padding(CinemasInk.side)
.padding(.top, 8)
}
.task { await read() }
.fileImporter(isPresented: $giving, allowedContentTypes: Self.files) { result in
if case .success(let url) = result { give(url) }
}
.accessibilityIdentifier("cinemas-subtitles")
}
/// .srt and .vtt, whatever the system names them.
private static let files: [UTType] = ["srt", "vtt"].compactMap { UTType(filenameExtension: $0) }
private func icon(_ act: String) -> String {
switch act {
case "find": "magnifyingglass"
case "make": "desktopcomputer"
default: "doc.badge.plus"
}
}
private func read() async {
page = await model.source.subtitles(item)
}
/// His file, copied where the core can read it while it seals it into the film's folder.
private func give(_ picked: URL) {
let held = picked.startAccessingSecurityScopedResource()
defer { if held { picked.stopAccessingSecurityScopedResource() } }
let copy = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString).appendingPathExtension(picked.pathExtension)
do {
try FileManager.default.copyItem(at: picked, to: copy)
} catch {
model.say(CinemasWords.line("stream.could_not_load"))
return
}
take("give", file: copy)
}
private func take(_ act: String, file: URL?) {
busy = act
Task {
let done = await model.source.subtitlesAct(act, item: item, file: file)
if let file { try? FileManager.default.removeItem(at: file) }
busy = nil
switch done {
case .read(let said):
if let said { model.say(said) }
UINotificationFeedbackGenerator().notificationOccurred(.success)
await read()
model.changed()
case .refused(let line):
UINotificationFeedbackGenerator().notificationOccurred(.warning)
model.say(line)
}
}
}
}
// MARK: - Send to a friend
/// Send to a friend (PUNCH Both 5): the Send step every app has (`shell.opened {step: send}`): his people on Cotton,
/// what goes and its size; a tap sends it (`send.make`) and the receipt's toast offers Undo (`send.undo`). Someone
/// not yet added back is drawn but cannot be sent to, and says why.
struct CinemasSendSheet: View {
let model: CinemasModel
let item: CinemasItem
@Environment(\.dismiss) private var dismiss
@State private var step: CinemasRead?
@State private var sending: String?
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 16) {
HStack(alignment: .firstTextBaseline) {
Text(CinemasWords.line("stream.send_title", ["title": item.title]))
.font(CinemasFonts.sans(20, 700)).foregroundStyle(CinemasInk.ink)
.accessibilityAddTraits(.isHeader)
Spacer(minLength: 8)
Button(CinemasWords.line("stream.done")) { dismiss() }
.font(CinemasType.button).foregroundStyle(CinemasInk.accent)
.frame(minWidth: 44, minHeight: 44)
.contentShape(Rectangle())
.accessibilityIdentifier("cinemas-send-done")
}
switch step {
case .read(let step)?:
if let refused = step.refused {
CinemasLine(line: refused)
} else {
if let says = step.says { Text(says).font(CinemasType.small).foregroundStyle(CinemasInk.quiet) }
if step.rows.isEmpty {
CinemasLine(line: step.empty?.words ?? CinemasWords.line("stream.send_nobody"))
}
VStack(spacing: 0) {
ForEach(step.rows, id: \.value) { person in
row(person)
if person.value != step.rows.last?.value { Divider().overlay(CinemasInk.rule).padding(.leading, 60) }
}
}
.background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(CinemasInk.raised))
}
case .refused(let line)?:
CinemasLine(line: line)
case nil:
ProgressView().tint(CinemasInk.accent).frame(maxWidth: .infinity)
}
}
.padding(CinemasInk.side)
.padding(.top, 8)
}
.task { step = await model.source.sendStep(item) }
.accessibilityIdentifier("cinemas-send")
}
private func row(_ person: SendPerson) -> some View {
let waiting = person.waiting ?? false
return Button { send(to: person) } label: {
HStack(spacing: 12) {
Text(person.initials ?? String(person.words.prefix(1)))
.font(CinemasFonts.sans(15, 700)).foregroundStyle(CinemasInk.onAccent)
.frame(width: 36, height: 36)
.background(Circle().fill(waiting ? CinemasInk.faint : CinemasInk.accent))
.accessibilityHidden(true)
VStack(alignment: .leading, spacing: 2) {
Text(person.words).font(CinemasType.list).foregroundStyle(waiting ? CinemasInk.quiet : CinemasInk.ink)
if let detail = person.detail { Text(detail).font(CinemasType.small).foregroundStyle(CinemasInk.faint) }
}
Spacer(minLength: 8)
if sending == person.value {
ProgressView().tint(CinemasInk.accent)
} else if !waiting {
Image(systemName: "paperplane").foregroundStyle(CinemasInk.accent).accessibilityHidden(true)
}
}
.padding(.horizontal, 14)
.frame(minHeight: 60)
.contentShape(Rectangle())
}
.buttonStyle(CinemasPress())
.disabled(waiting || sending != nil)
.accessibilityElement(children: .combine)
.accessibilityIdentifier("cinemas-send-\(person.number)")
}
private func send(to person: SendPerson) {
sending = person.value
Task {
let made = await model.source.send(item, to: person)
sending = nil
switch made {
case .read(let sent):
dismiss()
UINotificationFeedbackGenerator().notificationOccurred(.success)
model.sent(sent)
case .refused(let line):
UINotificationFeedbackGenerator().notificationOccurred(.warning)
model.say(line)
}
}
}
}
// MARK: - The Bin
/// You › Bin (`cinemas.bin`), and inside Hidden its own Bin (`cinemas.bin {hidden: true}`, core 4: the hidden titles
/// alone, never counted or shown outside). What he moved there, newest first, each with Restore and Delete forever, and
/// Empty under them: the acts and their words as the core names them (Delete forever and Empty asked first).
struct CinemasBinScreen: View {
let model: CinemasModel
var hidden = false
@State private var page: CinemasRead?
@State private var busy: String?
@State private var asking: Asking?
/// Delete forever, for one title or the whole Bin, waiting on his yes.
private enum Asking: Identifiable, Equatable {
case one(CinemasItem)
case all
var id: String { if case .one(let item) = self { item.key } else { "all" } }
}
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 14) {
CinemasPageTitle(text: page?.answer?.title ?? CinemasWords.line("stream.you_bin"))
switch page {
case .read(let bin)?:
if let empty = bin.empty, bin.items.isEmpty { Text(empty).font(CinemasType.body).foregroundStyle(CinemasInk.quiet) }
ForEach(bin.items) { kept in row(kept, bin: bin) }
if let erase = bin.erase, !bin.items.isEmpty {
CinemasButton(label: CinemasWords.line("stream.bin_empty"), icon: "trash", style: .outline, disabled: busy != nil) {
asking = .all
}
.padding(.top, 10)
.accessibilityIdentifier("cinemas-bin-empty")
.accessibilityHint(Text(erase.label))
}
case .refused(let line)?: CinemasRefused(line: line) { model.changed() }
case nil: ProgressView().tint(CinemasInk.accent).frame(maxWidth: .infinity)
}
}
.padding(.horizontal, CinemasInk.side)
.padding(.bottom, 24)
}
.background(CinemasInk.ground.ignoresSafeArea())
.navigationBarTitleDisplayMode(.inline)
.task(id: model.generation) { page = await model.source.binned(hidden: hidden) }
.alert(askTitle, isPresented: Binding(get: { asking != nil }, set: { if !$0 { asking = nil } }), presenting: asking) { ask in
Button(page?.answer?.erase?.label ?? CinemasWords.line("stream.bin_empty"), role: .destructive) { erase(ask) }
.accessibilityIdentifier("cinemas-bin-erase-confirm")
Button(CinemasWords.line("stream.group_cancel"), role: .cancel) {}
}
.accessibilityIdentifier(hidden ? "cinemas-hidden-bin-page" : "cinemas-bin")
}
private var askTitle: String {
switch asking {
case .one(let item)?: CinemasWords.line("stream.bin_erase_ask", ["title": item.title])
case .all?: CinemasWords.line("stream.bin_empty_ask")
case nil: ""
}
}
private func row(_ kept: CinemasOnPhone.Kept, bin: CinemasBin) -> some View {
let restore = bin.restore?.label ?? CinemasWords.line("stream.put_back")
return VStack(alignment: .leading, spacing: 8) {
HStack(spacing: 12) {
CinemasPicture(key: kept.item.poster, title: kept.item.title, seed: kept.item.id, art: kept.item.art)
.frame(width: 44, height: 66)
.clipShape(RoundedRectangle(cornerRadius: 4, style: .continuous))
.accessibilityHidden(true)
VStack(alignment: .leading, spacing: 3) {
Text(kept.item.title).font(CinemasFonts.sans(15, 700)).foregroundStyle(CinemasInk.ink).lineLimit(3)
Text(kept.line).font(CinemasType.small).foregroundStyle(CinemasInk.quiet)
}
.accessibilityElement(children: .combine)
Spacer(minLength: 8)
}
ViewThatFits(in: .horizontal) {
HStack(spacing: 16) { acts(kept.item, restore: restore, erase: bin.erase) }
VStack(alignment: .leading, spacing: 4) { acts(kept.item, restore: restore, erase: bin.erase) }
}
.padding(.leading, 56)
}
.accessibilityElement(children: .contain)
.accessibilityIdentifier("cinemas-bin-\(kept.item.id)")
}
@ViewBuilder private func acts(_ item: CinemasItem, restore: String, erase: CinemasNamedAct?) -> some View {
Button(restore) { putBack(item) }
.font(CinemasFonts.sans(14, 600)).foregroundStyle(CinemasInk.accent)
.frame(minHeight: 44)
.contentShape(Rectangle())
.disabled(busy != nil)
.accessibilityLabel(Text("\(restore), \(item.title)"))
.accessibilityIdentifier("cinemas-bin-put-back-\(item.id)")
if let erase {
Button(erase.label, role: .destructive) { asking = .one(item) }
.font(CinemasFonts.sans(14, 600)).foregroundStyle(CinemasInk.quiet)
.frame(minHeight: 44)
.contentShape(Rectangle())
.disabled(busy != nil)
.accessibilityLabel(Text("\(erase.label), \(item.title)"))
.accessibilityIdentifier("cinemas-bin-erase-\(item.id)")
}
}
private func putBack(_ item: CinemasItem) {
busy = item.id
Task {
let done: CinemasRead
if let restore = page?.answer?.restore { done = await model.source.named(restore, id: item.id) } else { done = await model.source.restore(item) }
busy = nil
switch done {
case .read(let said):
UINotificationFeedbackGenerator().notificationOccurred(.success)
model.say(said ?? CinemasWords.line("home.restored"))
model.changed()
case .refused(let line):
UINotificationFeedbackGenerator().notificationOccurred(.warning)
model.say(line)
}
}
}
/// Delete forever (one title, its `id` added) or Empty (the act as named): what this Bin shows, and nothing else.
private func erase(_ ask: Asking) {
guard let act = page?.answer?.erase else { return }
busy = ask.id
Task {
let one: String? = if case .one(let item) = ask { item.id } else { nil }
let done = await model.source.named(act, id: one)
busy = nil
switch done {
case .read:
UINotificationFeedbackGenerator().notificationOccurred(.success)
model.say(CinemasWords.line(one == nil ? "stream.bin_emptied" : "stream.bin_erased"))
model.changed()
case .refused(let line):
UINotificationFeedbackGenerator().notificationOccurred(.warning)
model.say(line)
}
}
}
}
/// A row that opens a place (inside Hidden, its Bin): the name and how many, and a chevron.
struct CinemasPlaceRow: View {
let title: String
let count: Int
let open: () -> Void
var body: some View {
Button(action: open) {
HStack(alignment: .firstTextBaseline, spacing: 6) {
Text(title).font(CinemasType.rowTitle).foregroundStyle(CinemasInk.ink).multilineTextAlignment(.leading)
Text(count.formatted()).font(CinemasType.rowCount).foregroundStyle(CinemasInk.faint)
Spacer(minLength: 8)
Image(systemName: "chevron.right").font(.system(size: 14, weight: .semibold)).foregroundStyle(CinemasInk.quiet)
.accessibilityHidden(true)
}
.frame(minHeight: 44)
.contentShape(Rectangle())
}
.buttonStyle(CinemasPress())
.padding(.horizontal, CinemasInk.side)
.accessibilityLabel(Text(verbatim: "\(title), \(count.formatted())"))
}
}
#endif