diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9c06ba..215cf7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,11 +1,14 @@ # ============================================================================= # BusTimeApp CI - 幅広いバージョンでのビルド&テスト # ============================================================================= -# macOS / Xcode の複数バージョンでビルドし、互換性を担保する +# 最低対応の iOS 27.0 と最新の iOS 27.x でビルド・テストし、互換性を担保する # # マトリクス構成: -# - macos-14/15 + Xcode 16 系 (iOS 18 SDK) -# - macos-26 + Xcode 26 系 (最新 SDK) +# - xcode-27 Runner + Xcode 27.0 (iOS 27.0 SDK / 最低対応 OS) +# - xcode-27 Runner + Xcode 27.2 (iOS 27.2 SDK / 最新) +# +# Deployment Target を iOS 27.0 にしているため、iOS 27 SDK を持たない +# macos-15 / macos-26 Runner(Xcode 16・26 系)ではビルドできません。 # ============================================================================= name: CI @@ -33,26 +36,19 @@ jobs: fail-fast: false matrix: include: - # ── macOS 14 + Xcode 16.2 (iOS 18.2 SDK / Simulator) ── - - name: "Xcode 16.2 / iOS 18.2" - runner: macos-14 - xcode: "16.2" - destination: "platform=iOS Simulator,name=iPhone 16,OS=18.2" - ios_version: "18.2-xcode16.2" - - # ── macOS 15 + Xcode 16.4 (iOS 18 SDK / 最新 16 系) ── - - name: "Xcode 16.4 / iOS 18" - runner: macos-15 - xcode: "16.4" - destination: "platform=iOS Simulator,name=iPhone 16,OS=18.5" - ios_version: "18.5" - - # ── macOS 26 + Xcode 26 (最新 SDK) ── - - name: "Xcode 26 / Latest iOS" - runner: macos-26 - xcode: "" - destination: "generic/platform=iOS Simulator" - ios_version: "latest" + # ── Xcode 27.0 (iOS 27.0 SDK / 最低対応 OS の Simulator) ── + - name: "Xcode 27.0 / iOS 27.0" + runner: xcode-27 + xcode: "27.0" + destination: "platform=iOS Simulator,name=iPhone 18 Pro,OS=27.0" + ios_version: "27.0" + + # ── Xcode 27.2 (iOS 27.2 SDK / 最新 27 系) ── + - name: "Xcode 27.2 / iOS 27.2" + runner: xcode-27 + xcode: "27.2" + destination: "platform=iOS Simulator,name=iPhone 18 Pro,OS=27.2" + ios_version: "27.2" steps: # ── チェックアウト ── @@ -225,7 +221,8 @@ jobs: # --------------------------------------------------------------------------- build-widget: name: "Build Widget Extension" - runs-on: macos-15 + # iOS 27 SDK が必要なため、Xcode 27 系を持つ Runner を使います。 + runs-on: xcode-27 timeout-minutes: 15 steps: @@ -270,7 +267,8 @@ jobs: # --------------------------------------------------------------------------- lint: name: "Lint & Static Analysis" - runs-on: macos-15 + # iOS 27 SDK が必要なため、Xcode 27 系を持つ Runner を使います。 + runs-on: xcode-27 timeout-minutes: 15 steps: diff --git a/BusTimeApp-Info.plist b/BusTimeApp-Info.plist index 37c1787..83e1ac2 100644 --- a/BusTimeApp-Info.plist +++ b/BusTimeApp-Info.plist @@ -16,7 +16,6 @@ CFBundleURLTypes - CFBundleURLName com.hara.BusTimeApp.route CFBundleURLSchemes diff --git a/BusTimeApp.xcodeproj/project.pbxproj b/BusTimeApp.xcodeproj/project.pbxproj index 0edb649..612030d 100644 --- a/BusTimeApp.xcodeproj/project.pbxproj +++ b/BusTimeApp.xcodeproj/project.pbxproj @@ -417,7 +417,7 @@ CODE_SIGN_ENTITLEMENTS = BusTimeWidgetExtension/BusTimeWidgetExtension.entitlements; GENERATE_INFOPLIST_FILE = NO; INFOPLIST_FILE = BusTimeWidgetExtension/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 16.1; + IPHONEOS_DEPLOYMENT_TARGET = 27.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -487,7 +487,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.2; + IPHONEOS_DEPLOYMENT_TARGET = 27.0; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; @@ -545,7 +545,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.2; + IPHONEOS_DEPLOYMENT_TARGET = 27.0; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; @@ -573,6 +573,7 @@ INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = UIInterfaceOrientationPortrait; + IPHONEOS_DEPLOYMENT_TARGET = 27.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -606,6 +607,7 @@ INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = UIInterfaceOrientationPortrait; + IPHONEOS_DEPLOYMENT_TARGET = 27.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -629,7 +631,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = FDKP7YY7G8; GENERATE_INFOPLIST_FILE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.2; + IPHONEOS_DEPLOYMENT_TARGET = 27.0; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.HR.BusTimeAppTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -650,7 +652,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = FDKP7YY7G8; GENERATE_INFOPLIST_FILE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.2; + IPHONEOS_DEPLOYMENT_TARGET = 27.0; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.HR.BusTimeAppTests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -711,7 +713,7 @@ CODE_SIGN_ENTITLEMENTS = BusTimeWidgetExtension/BusTimeWidgetExtension.entitlements; GENERATE_INFOPLIST_FILE = NO; INFOPLIST_FILE = BusTimeWidgetExtension/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 16.1; + IPHONEOS_DEPLOYMENT_TARGET = 27.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/BusTimeApp/BusTimetableViewModel.swift b/BusTimeApp/BusTimetableViewModel.swift index 2b1f06a..0ca8459 100644 --- a/BusTimeApp/BusTimetableViewModel.swift +++ b/BusTimeApp/BusTimetableViewModel.swift @@ -793,6 +793,9 @@ class HomeViewModel: NSObject, ObservableObject, CLLocationManagerDelegate { } else { searchResultDescription = L10n.Search.resultCount(searchResults.count, searchType.explanation) } + // 残り時間は便ごとに持っているため、結果が入れ替わったらすぐ数え直します。 + // 次の定期更新まで待つと、その間「計算中」のままになるためです。 + updateCountdown() send(.searchSucceeded(hasResults: !searchResults.isEmpty)) } @@ -1206,7 +1209,9 @@ class HomeViewModel: NSObject, ObservableObject, CLLocationManagerDelegate { lastActivityRemainingMinutes = activity.content.state.remainingMinutes } - func startLiveActivity(for bus: Bus) { + /// `routeName` を省略すると、いま画面で選んでいる経路の名前を使います。 + /// ショートカットのように、画面の経路とは別の経路の便を始めるときに指定します。 + func startLiveActivity(for bus: Bus, routeName: String? = nil) { restoreLiveActivity() if let trackedBusId, trackedBusId != bus.id { @@ -1249,7 +1254,7 @@ class HomeViewModel: NSObject, ObservableObject, CLLocationManagerDelegate { originName: bus.originName, destinationName: bus.destinationName, departureDate: departureDate, - routeName: selectedRoute.rawValue + routeName: routeName ?? selectedRoute.rawValue ) let remaining = max(0, Int(ceil(departureDate.timeIntervalSince(currentDate) / 60))) diff --git a/BusTimeApp/ContentView.swift b/BusTimeApp/ContentView.swift index 70efcce..f541a03 100644 --- a/BusTimeApp/ContentView.swift +++ b/BusTimeApp/ContentView.swift @@ -46,11 +46,11 @@ private struct SkyTabBar: View { tabButton(.home) tabButton(.timetable) } - .padding(5) + .padding(4) .background(Capsule().fill(sky.surface)) .overlay(Capsule().stroke(sky.surfaceBorder, lineWidth: SkyMetrics.borderWidth)) .padding(.horizontal, SkyMetrics.screenPadding) - .padding(.top, 6) + .padding(.top, 8) } private func tabButton(_ tab: MainTab) -> some View { @@ -62,7 +62,7 @@ private struct SkyTabBar: View { } } label: { Label(tab.title, systemImage: tab.systemName) - .dynamicFont(size: 14, relativeTo: .subheadline, weight: .bold, design: .rounded) + .dynamicFont(size: 14, relativeTo: .subheadline, weight: .semibold, design: .rounded) .foregroundStyle(isSelected ? sky.accentInk : sky.ink) .frame(maxWidth: .infinity, minHeight: SkyMetrics.minimumTapSize) .background(Capsule().fill(isSelected ? sky.accent : Color.clear)) @@ -82,6 +82,8 @@ struct ContentView: View { @StateObject private var notificationViewModel = NotificationViewModel() @StateObject private var skyClock = SkyClock() @StateObject private var weatherViewModel = WeatherViewModel() + /// ショートカットから預けられた依頼の受け渡し口です。 + @ObservedObject private var shortcutRequestCenter = ShortcutRequestCenter.shared @SceneStorage("selectedMainTab") private var selectedTab: MainTab = .home @Environment(\.scenePhase) private var scenePhase @Environment(\.colorScheme) private var systemColorScheme @@ -121,6 +123,8 @@ struct ContentView: View { viewModel.checkLocationAndSetOrigin() notificationViewModel.refresh() setAutomaticUpdatesActive(true) + // アプリが起動していないところへ届いた依頼は、画面が出てから受け取ります。 + handlePendingShortcutRequest() } .task { await viewModel.refreshTimetables() @@ -134,7 +138,7 @@ struct ContentView: View { // 検索結果はホームタブにあるので、そちらへ寄せます。 selectedTab = .home } - .onChange(of: scenePhase) { newPhase in + .onChange(of: scenePhase) { _, newPhase in if newPhase == .active { setAutomaticUpdatesActive(true) viewModel.refreshForAppActivation() @@ -144,24 +148,32 @@ struct ContentView: View { await viewModel.refreshTimetables() await weatherViewModel.refreshIfNeeded() } + handlePendingShortcutRequest() } else { setAutomaticUpdatesActive(false) } } + .onChange(of: shortcutRequestCenter.pendingRequest?.id) { _, _ in + handlePendingShortcutRequest() + } + // 説明画面などを閉じて通常のホームへ戻ったら、預かっていた依頼を実行します。 + .onChange(of: coordinator.state) { _, _ in + handlePendingShortcutRequest() + } // 経路・検索方法・時刻のいずれを変えても、その場で結果へ反映します。 // 実行ボタンを置かないぶん、変更が即座に画面へ出ることを保証します。 - .onChange(of: viewModel.selectedRoute) { _ in + .onChange(of: viewModel.selectedRoute) { _, _ in viewModel.performSearch() } - .onChange(of: viewModel.serviceDay) { _ in + .onChange(of: viewModel.serviceDay) { _, _ in viewModel.persistSearchPreferences() viewModel.performSearch() } - .onChange(of: viewModel.searchType) { _ in + .onChange(of: viewModel.searchType) { _, _ in viewModel.persistSearchPreferences() viewModel.performSearch() } - .onChange(of: viewModel.searchTime) { _ in + .onChange(of: viewModel.searchTime) { _, _ in viewModel.persistSearchPreferences() viewModel.performSearch() } @@ -266,7 +278,7 @@ struct ContentView: View { } message: { Text(coordinator.liveActivityErrorMessage ?? L10n.LiveActivity.genericError) } - .onChange(of: viewModel.liveActivityError) { errorMessage in + .onChange(of: viewModel.liveActivityError) { _, errorMessage in if let errorMessage { SkyHaptics.failure() coordinator.send(.liveActivityFailed(errorMessage)) @@ -382,7 +394,7 @@ struct ContentView: View { serviceFooter } .padding(.horizontal, horizontalPadding) - .padding(.top, 10) + .padding(.top, 8) .padding(.bottom, SkyMetrics.scrollBottomInset) // 横に広い画面では、1行が長くなりすぎないところで幅を止めて中央に置きます。 .frame(maxWidth: SkyMetrics.contentMaxWidth) @@ -434,7 +446,7 @@ struct ContentView: View { let followingBuses = Array(viewModel.searchResults.dropFirst()) if !followingBuses.isEmpty { - VStack(alignment: .leading, spacing: 10) { + VStack(alignment: .leading, spacing: 8) { SkySectionLabel(text: viewModel.followingSectionTitle) ForEach(followingBuses) { bus in @@ -470,7 +482,7 @@ struct ContentView: View { .fill(palette.positive) .frame(width: 6, height: 6) Text(L10n.Result.footer) - .dynamicFont(size: 11, relativeTo: .caption2, weight: .medium) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) .foregroundStyle(palette.inkSecondary) .fixedSize(horizontal: false, vertical: true) } @@ -505,6 +517,7 @@ struct ContentView: View { ?? settingsViewModel.shouldUseLiveActivity let liveActivityMessage = startLiveActivityIfNeeded( for: bus, + routeName: viewModel.selectedRoute.rawValue, shouldStart: shouldStartLiveActivity ) // 通知の登録は結果が文字でしか分からないので、成否を手応えでも返します。 @@ -523,7 +536,11 @@ struct ContentView: View { } } - private func startLiveActivityIfNeeded(for bus: Bus, shouldStart: Bool) -> String { + private func startLiveActivityIfNeeded( + for bus: Bus, + routeName: String, + shouldStart: Bool + ) -> String { guard shouldStart else { return "" } if viewModel.trackedBusId == bus.id { @@ -534,7 +551,7 @@ struct ContentView: View { return L10n.Notify.onlyNormalNotification } - viewModel.startLiveActivity(for: bus) + viewModel.startLiveActivity(for: bus, routeName: routeName) if viewModel.trackedBusId == bus.id { return L10n.Notify.liveActivityStarted } @@ -543,6 +560,111 @@ struct ContentView: View { viewModel.liveActivityError = nil return L10n.Notify.liveActivityFailed } + + // MARK: - ショートカットからの依頼 + + /// ショートカットから預かった依頼を、画面が受けられる状態のときに実行します。 + /// + /// Live Activityは前面でないと開始できず、説明画面やSheetの表示中に割り込むと + /// 表示中の内容を閉じてしまいます。そのため、通常のホームを見せられるようになるまで + /// 依頼は預かったままにします。 + private func handlePendingShortcutRequest() { + guard scenePhase == .active, + coordinator.state == .dashboard, + let request = shortcutRequestCenter.takePendingRequest() else { + return + } + + switch request.action { + case let .openRoute(route): + // ウィジェットのタップと同じく、選んだ経路をそのまま画面へ反映します。 + viewModel.selectRouteFromWidget(route) + selectedTab = .home + shortcutRequestCenter.finish(request.id, with: .succeeded(route.rawValue)) + + case let .startBusAlert(route, minutesBefore, startsLiveActivity): + scheduleBusAlertFromShortcut( + requestID: request.id, + route: route, + minutesBefore: minutesBefore, + startsLiveActivity: startsLiveActivity + ) + } + } + + /// 指定した経路の次の便に通知を設定し、結果をショートカットへ返します。 + /// + /// 登録やLive Activityの開始は、画面から操作したときと同じ処理を通します。 + /// 権限の拒否や過去になる通知などの扱いが、画面操作と食い違わないようにするためです。 + private func scheduleBusAlertFromShortcut( + requestID: UUID, + route: BusRoute, + minutesBefore: Int, + startsLiveActivity: Bool + ) { + let now = AppDate.now() + + let bus: Bus + switch ShortcutBusSelector.select(on: route, minutesBefore: minutesBefore, now: now) { + case let .success(selectedBus): + bus = selectedBus + case let .failure(failure): + SkyHaptics.failure() + coordinator.send(.notificationScheduled(failure.message)) + shortcutRequestCenter.finish(requestID, with: .failed(failure.message)) + return + } + + notificationViewModel.scheduleNotification( + for: bus, + routeName: route.rawValue, + minutesBefore: minutesBefore, + now: now + ) { result in + switch result { + case let .success(item): + // 画面の選択を変えずに済むよう、Live Activityには指定の経路名を渡します。 + let liveActivityMessage = startLiveActivityIfNeeded( + for: bus, + routeName: route.rawValue, + shouldStart: startsLiveActivity + ) + SkyHaptics.success() + coordinator.send(.notificationScheduled( + L10n.Notify.scheduledMessage( + item.busDescription, + item.notificationDescription, + liveActivityMessage + ) + )) + shortcutRequestCenter.finish( + requestID, + with: .succeeded(shortcutSuccessMessage( + route: route, + bus: bus, + minutesBefore: minutesBefore, + liveActivityMessage: liveActivityMessage + )) + ) + case let .failure(error): + SkyHaptics.failure() + coordinator.send(.notificationScheduled(error.localizedDescription)) + shortcutRequestCenter.finish(requestID, with: .failed(error.localizedDescription)) + } + } + } + + /// ショートカットが返す文です。画面の完了表示より短くまとめます。 + private func shortcutSuccessMessage( + route: BusRoute, + bus: Bus, + minutesBefore: Int, + liveActivityMessage: String + ) -> String { + let scheduled = L10n.Shortcut.alertScheduled(route.rawValue, bus.departure, minutesBefore) + let liveActivity = liveActivityMessage.trimmingCharacters(in: .whitespacesAndNewlines) + return liveActivity.isEmpty ? scheduled : "\(scheduled)\n\(liveActivity)" + } } struct ContentView_Previews: PreviewProvider { diff --git a/BusTimeApp/DesignSystem/SkyComponents.swift b/BusTimeApp/DesignSystem/SkyComponents.swift index 02f8706..60c3f0d 100644 --- a/BusTimeApp/DesignSystem/SkyComponents.swift +++ b/BusTimeApp/DesignSystem/SkyComponents.swift @@ -3,9 +3,13 @@ import SwiftUI /// 画面全体で共有する寸法です。値をここに集約し、画面ごとの数値のばらつきを防ぎます。 enum SkyMetrics { /// カードの角丸半径です。 - static let cardRadius: CGFloat = 22 - /// カード内側の余白です。 - static let cardPadding: CGFloat = 18 + static let cardRadius: CGFloat = 20 + /// カード内側の余白です。背景のピクセルと同じ4pt格子に乗せます。 + static let cardPadding: CGFloat = 20 + /// カードの中に敷く面(説明の帯や選択の溝)の角丸半径です。 + static let innerRadius: CGFloat = 12 + /// ボタンや入力欄など、操作部品の角丸半径です。 + static let controlRadius: CGFloat = 8 /// 画面左右の余白です。 static let screenPadding: CGFloat = 20 /// アクセシビリティ文字サイズ時の画面左右の余白です。 @@ -187,14 +191,14 @@ struct SkyPrimaryButton: View { let action: () -> Void /// ボタンの角丸半径です。 - private let radius: CGFloat = 14 + private let radius: CGFloat = SkyMetrics.innerRadius var body: some View { Button(action: action) { Label(title, systemImage: systemImage) - .dynamicFont(size: 15, relativeTo: .subheadline, weight: .bold, design: .rounded) + .dynamicFont(size: 15, relativeTo: .subheadline, weight: .semibold, design: .rounded) .foregroundStyle(sky.accentInk) - .padding(.horizontal, 18) + .padding(.horizontal, 20) .frame(minHeight: SkyMetrics.minimumTapSize) .background( RoundedRectangle(cornerRadius: radius, style: .continuous) @@ -216,14 +220,14 @@ struct SkySecondaryButton: View { let action: () -> Void /// ボタンの角丸半径です。 - private let radius: CGFloat = 14 + private let radius: CGFloat = SkyMetrics.innerRadius var body: some View { Button(action: action) { Label(title, systemImage: systemImage) - .dynamicFont(size: 15, relativeTo: .subheadline, weight: .bold, design: .rounded) + .dynamicFont(size: 15, relativeTo: .subheadline, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) - .padding(.horizontal, 18) + .padding(.horizontal, 20) .frame(minHeight: SkyMetrics.minimumTapSize) .background( RoundedRectangle(cornerRadius: radius, style: .continuous) @@ -251,7 +255,7 @@ struct SkyIconButton: View { var body: some View { Button(action: action) { Image(systemName: systemImage) - .dynamicFont(size: 16, relativeTo: .body, weight: .semibold) + .dynamicFont(size: 16, relativeTo: .body, weight: .medium) .foregroundStyle(isHighlighted ? sky.accentInk : sky.ink) .scaledTapTarget() // 風景の上に直接置くので、カードと同じ地を敷いて見え方を揃えます。 @@ -274,7 +278,13 @@ struct SkyIconButton: View { } } -/// 2択以上の選択に使う、小さなチップです。 +/// 2択以上の選択に使う、溝の中の1区画です。 +/// +/// 選んでいる区画は、色で塗りつぶさずに一段持ち上げた面と輪郭で示します。 +/// 強調色は「この便を通知する」のような主要な操作のために取っておき、 +/// 条件の選択が画面でいちばん目立つことを避けるためです。 +/// 形の違いで選択が分かるので、「カラー以外で区別」がオンでも同じ見た目で伝わります。 +/// 並べるときは `skySegmentTrack()` で溝を敷きます。 struct SkyChip: View { @Environment(\.sky) private var sky /// iPhoneの「ボタンの形」設定です。 @@ -284,56 +294,105 @@ struct SkyChip: View { let isSelected: Bool let action: () -> Void + /// 区画の角丸半径です。溝の角丸から溝の内側の余白を引いた値にして、角を揃えます。 + private let radius: CGFloat = SkyMetrics.innerRadius - SkySegmentTrackMetrics.inset + /// 選んだ区画を持ち上げる面の濃さです。文字色を薄く重ね、昼夜どちらでも一段明暗が変わるようにします。 + private let selectedFillOpacity: Double = 0.14 + /// 選んだ区画の輪郭の濃さです。 + private let selectedOutlineOpacity: Double = 0.36 + + private var shape: RoundedRectangle { + RoundedRectangle(cornerRadius: radius, style: .continuous) + } + var body: some View { Button(action: action) { Text(title) - .dynamicFont(size: 14, relativeTo: .subheadline, weight: .bold, design: .rounded) - .foregroundStyle(isSelected ? sky.accentInk : sky.ink) + .dynamicFont( + size: 14, + relativeTo: .subheadline, + weight: isSelected ? .semibold : .medium, + design: .rounded + ) + .foregroundStyle(sky.ink) .frame(maxWidth: .infinity) .frame(minHeight: SkyMetrics.minimumTapSize) - .background(chipBackground) - .overlay( - Capsule().stroke( - isSelected - ? Color.clear - : sky.ink.opacity(SkyButtonOutline.opacity(showButtonShapes: showButtonShapes)), - lineWidth: SkyMetrics.borderWidth - ) - ) + .background(shape.fill(isSelected ? sky.ink.opacity(selectedFillOpacity) : Color.clear)) + .overlay(shape.stroke(outlineColor, lineWidth: SkyMetrics.borderWidth)) + .contentShape(shape) } .buttonStyle(SkyPressStyle()) .accessibilityAddTraits(isSelected ? .isSelected : []) } - /// チップの地です。 + /// 区画の輪郭の色です。 /// - /// 選んでいない側にも地を敷きます。地がないとカードごしに風景が透け、 - /// うしろの明るさによって文字の読みやすさが変わってしまうためです。 - @ViewBuilder - private var chipBackground: some View { + /// 選んでいない区画にはふだん輪郭を引きませんが、「ボタンの形」がオンのときは + /// 押せる範囲が分かるよう、選んでいない区画にも輪郭を引きます。 + private var outlineColor: Color { if isSelected { - Capsule().fill(sky.accent) - } else { - Color.clear.skyCardFill(Capsule(), isDense: true) + return sky.ink.opacity(selectedOutlineOpacity) } + return showButtonShapes + ? sky.ink.opacity(SkyButtonOutline.emphasized) + : Color.clear + } +} + +/// 選択の溝の寸法です。 +enum SkySegmentTrackMetrics { + /// 溝の内側の余白です。 + static let inset: CGFloat = 4 +} + +/// チップを並べる溝を敷く修飾子です。 +private struct SkySegmentTrackModifier: ViewModifier { + @Environment(\.sky) private var sky + /// iPhoneの「ボタンの形」設定です。 + @Environment(\.accessibilityShowButtonShapes) private var showButtonShapes + + private var shape: RoundedRectangle { + RoundedRectangle(cornerRadius: SkyMetrics.innerRadius, style: .continuous) + } + + func body(content: Content) -> some View { + content + .padding(SkySegmentTrackMetrics.inset) + // 溝にも地を敷きます。地がないとカードごしに風景が透け、 + // うしろの明るさによって文字の読みやすさが変わってしまうためです。 + .skyCardFill(shape, isDense: true) + .overlay( + shape.stroke( + sky.ink.opacity(SkyButtonOutline.opacity(showButtonShapes: showButtonShapes)), + lineWidth: SkyMetrics.borderWidth + ) + ) + } +} + +extension View { + /// `SkyChip` を並べる溝を敷きます。 + func skySegmentTrack() -> some View { + modifier(SkySegmentTrackModifier()) } } // MARK: - 文字とレイアウトの部品 -/// セクションの上に置く、字間を広げた小さな見出しです。 +/// セクションの上に置く、小さな見出しです。 +/// +/// 字間は広げず、太さも中程度に留めます。見出しの役割は大きさと位置で示し、 +/// その下にある時刻や停留所名より目立たないようにするためです。 struct SkySectionLabel: View { @Environment(\.sky) private var sky - @ScaledMetric(relativeTo: .caption) private var letterSpacing: CGFloat = 1.2 let text: String var body: some View { Text(text) // 標準のテキストスタイルを直接使い、Dynamic Type監査でも追従を判定できるようにします。 - .font(.system(.caption, design: .rounded, weight: .heavy)) - .tracking(letterSpacing) - .foregroundStyle(sky.ink) + .font(.system(.footnote, design: .rounded, weight: .semibold)) + .foregroundStyle(sky.inkSecondary) .accessibilityAddTraits(.isHeader) } } @@ -361,10 +420,10 @@ struct SkyNoticeRow: View { var body: some View { DynamicTypeStack(verticalAlignment: .top, spacing: 8) { Image(systemName: systemImage) - .font(.caption.weight(.bold)) + .font(.caption.weight(.medium)) .foregroundStyle(isWarning ? sky.warning : sky.inkSecondary) Text(message) - .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) // 注意状態はアイコンの形と文面で伝え、本文は常に高コントラスト色にします。 .foregroundStyle(isWarning ? sky.ink : sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) diff --git a/BusTimeApp/Features/Home/HomeViews.swift b/BusTimeApp/Features/Home/HomeViews.swift index 3278800..4f1fd7c 100644 --- a/BusTimeApp/Features/Home/HomeViews.swift +++ b/BusTimeApp/Features/Home/HomeViews.swift @@ -28,20 +28,20 @@ struct HomeHeaderBar: View { } private var brand: some View { - DynamicTypeStack(spacing: 10) { + DynamicTypeStack(spacing: 8) { Image(systemName: "bus.fill") - .dynamicFont(size: 17, relativeTo: .headline, weight: .bold) + .dynamicFont(size: 16, relativeTo: .headline, weight: .medium) .foregroundStyle(sky.accentReadable) VStack(alignment: .leading, spacing: 2) { Text(L10n.Home.brandName) - .dynamicFont(size: 16, relativeTo: .headline, weight: .bold, design: .rounded) + .dynamicFont(size: 16, relativeTo: .headline, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) .lineLimit(1) .minimumScaleFactor(0.8) Text(L10n.Home.serviceName) - .font(.caption2.weight(.semibold)) - .foregroundStyle(sky.ink) + .font(.caption2.weight(.medium)) + .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) } } @@ -97,12 +97,12 @@ struct NextDepartureHero: View { /// 残り時間の数字の基準サイズです。 private let countdownNumberSize: CGFloat = 76 /// 残り時間の単位の基準サイズです。 - private let countdownUnitSize: CGFloat = 25 + private let countdownUnitSize: CGFloat = 24 /// 1時間を分に直した値です。 private let minutesPerHour = 60 var body: some View { - VStack(alignment: .leading, spacing: 18) { + VStack(alignment: .leading, spacing: 16) { SkySectionLabel(text: sectionTitle) countdown @@ -111,28 +111,20 @@ struct NextDepartureHero: View { SkyDivider() - VStack(alignment: .leading, spacing: 6) { + VStack(alignment: .leading, spacing: 4) { timeRow // 停留所名は固有名詞なので、そのまま並べます。 + // 経路は上のカードでも選んでいるので、ここでは確認用の控えめな一行にします。 Text(verbatim: "\(bus.originName) → \(bus.destinationName)") - .dynamicFont(size: 13, relativeTo: .footnote, weight: .bold) - .foregroundStyle(sky.ink) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .regular) + .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) - .padding(.horizontal, 8) - .padding(.vertical, 5) - .background( - RoundedRectangle(cornerRadius: 8, style: .continuous) - .fill(sky.surfaceOpaque) - ) if let note = bus.note { Text(note) - .dynamicFont(size: 11, relativeTo: .caption2, weight: .bold, design: .rounded) + .dynamicFont(size: 12, relativeTo: .caption, weight: .medium, design: .rounded) .foregroundStyle(sky.accentReadable) - .padding(.horizontal, 9) - .padding(.vertical, 5) - .background(Capsule().fill(sky.accentSoft)) - .padding(.top, 2) + .fixedSize(horizontal: false, vertical: true) } } @@ -186,7 +178,7 @@ struct NextDepartureHero: View { private var countdownPrefix: some View { Text(L10n.Result.remainingPrefix) - .dynamicFont(size: 15, relativeTo: .subheadline, weight: .bold, design: .rounded) + .dynamicFont(size: 16, relativeTo: .subheadline, weight: .medium, design: .rounded) .foregroundStyle(sky.inkSecondary) } @@ -201,7 +193,7 @@ struct NextDepartureHero: View { .dynamicFont( size: countdownNumberSize, relativeTo: .largeTitle, - weight: .bold, + weight: .semibold, design: .rounded ) .monospacedDigit() @@ -215,7 +207,7 @@ struct NextDepartureHero: View { .dynamicFont( size: countdownUnitSize, relativeTo: .title2, - weight: .bold, + weight: .medium, design: .rounded ) .foregroundStyle(sky.ink) @@ -224,7 +216,7 @@ struct NextDepartureHero: View { /// 数字を伴わない状態を、大きすぎない文字で表します。 private func countdownPhrase(_ text: String) -> some View { Text(text) - .dynamicFont(size: 34, relativeTo: .largeTitle, weight: .bold, design: .rounded) + .dynamicFont(size: 32, relativeTo: .largeTitle, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) .lineLimit(1) .minimumScaleFactor(0.6) @@ -258,25 +250,25 @@ struct NextDepartureHero: View { private var timeRow: some View { DynamicTypeStack(verticalAlignment: .lastTextBaseline, spacing: 8) { Text(bus.departure) - .dynamicFont(size: 27, relativeTo: .title, weight: .bold, design: .rounded) + .dynamicFont(size: 28, relativeTo: .title, weight: .semibold, design: .rounded) .monospacedDigit() .foregroundStyle(sky.ink) .minimumScaleFactor(0.7) Text(L10n.Result.departureSuffix) - .dynamicFont(size: 12, relativeTo: .caption, weight: .bold) + .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) .foregroundStyle(sky.inkSecondary) Image(systemName: "arrow.right") - .font(.caption.weight(.bold)) + .font(.caption.weight(.medium)) .foregroundStyle(sky.inkFaint) Text(bus.arrival) - .dynamicFont(size: 21, relativeTo: .title3, weight: .bold, design: .rounded) + .dynamicFont(size: 20, relativeTo: .title3, weight: .medium, design: .rounded) .monospacedDigit() .foregroundStyle(sky.inkSecondary) .minimumScaleFactor(0.7) Text(L10n.Result.arrivalSuffix) - .dynamicFont(size: 12, relativeTo: .caption, weight: .bold) + .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) .foregroundStyle(sky.inkSecondary) } .accessibilityElement(children: .combine) @@ -324,23 +316,23 @@ struct UpcomingDepartureRow: View { Button(action: action) { DynamicTypeStack(verticalAlignment: .center, spacing: 12) { VStack(alignment: .leading, spacing: 4) { - HStack(alignment: .lastTextBaseline, spacing: 6) { + HStack(alignment: .lastTextBaseline, spacing: 8) { Text(bus.departure) - .dynamicFont(size: 20, relativeTo: .title3, weight: .bold, design: .rounded) + .dynamicFont(size: 20, relativeTo: .title3, weight: .semibold, design: .rounded) .monospacedDigit() .foregroundStyle(sky.ink) Image(systemName: "arrow.right") - .font(.caption2.weight(.bold)) + .font(.caption2.weight(.medium)) .foregroundStyle(sky.inkFaint) Text(bus.arrival) - .dynamicFont(size: 16, relativeTo: .body, weight: .semibold, design: .rounded) + .dynamicFont(size: 16, relativeTo: .body, weight: .medium, design: .rounded) .monospacedDigit() .foregroundStyle(sky.inkSecondary) } if let note = bus.note { Text(note) - .dynamicFont(size: 11, relativeTo: .caption2, weight: .medium) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) .foregroundStyle(sky.inkSecondary) } } @@ -348,13 +340,14 @@ struct UpcomingDepartureRow: View { if let countdown { Text(countdown) - .dynamicFont(size: 12, relativeTo: .caption, weight: .bold, design: .rounded) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium, design: .rounded) + .monospacedDigit() .foregroundStyle(sky.inkSecondary) } if canSchedule { Image(systemName: isNotificationScheduled ? "bell.fill" : "bell") - .dynamicFont(size: 14, relativeTo: .body, weight: .semibold) + .dynamicFont(size: 16, relativeTo: .body, weight: .medium) .foregroundStyle(isNotificationScheduled ? sky.accent : sky.inkSecondary) .scaledTapTarget() } @@ -387,18 +380,18 @@ struct NoticeCard: View { let isWarning: Bool var body: some View { - DynamicTypeStack(verticalAlignment: .top, spacing: 14) { + DynamicTypeStack(verticalAlignment: .top, spacing: 12) { Image(systemName: systemImage) - .dynamicFont(size: 24, relativeTo: .title3, weight: .semibold) + .dynamicFont(size: 20, relativeTo: .title3, weight: .medium) .foregroundStyle(isWarning ? sky.warning : sky.inkSecondary) - VStack(alignment: .leading, spacing: 6) { + VStack(alignment: .leading, spacing: 4) { Text(title) - .dynamicFont(size: 17, relativeTo: .headline, weight: .bold, design: .rounded) + .dynamicFont(size: 17, relativeTo: .headline, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) .fixedSize(horizontal: false, vertical: true) Text(message) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) } diff --git a/BusTimeApp/Features/Home/SearchPanel.swift b/BusTimeApp/Features/Home/SearchPanel.swift index 7a1f1d7..fa2a193 100644 --- a/BusTimeApp/Features/Home/SearchPanel.swift +++ b/BusTimeApp/Features/Home/SearchPanel.swift @@ -13,6 +13,8 @@ import SwiftUI struct RouteHeaderCard: View { @Environment(\.sky) private var sky @Environment(\.dynamicTypeSize) private var dynamicTypeSize + /// iPhoneの「ボタンの形」設定です。 + @Environment(\.accessibilityShowButtonShapes) private var showButtonShapes @ObservedObject var viewModel: HomeViewModel let locationAction: () -> Void @@ -40,14 +42,14 @@ struct RouteHeaderCard: View { } if viewModel.isLocationPermissionDenied { - VStack(alignment: .leading, spacing: 6) { + VStack(alignment: .leading, spacing: 4) { SkyNoticeRow( message: L10n.Route.locationPermissionDenied, systemImage: "location.slash.fill", isWarning: true ) Button(L10n.Route.openLocationSettings, action: viewModel.openAppSettings) - .dynamicFont(size: 12, relativeTo: .caption, weight: .bold, design: .rounded) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium, design: .rounded) .foregroundStyle(sky.accentReadable) .frame(minHeight: SkyMetrics.minimumTapSize, alignment: .leading) } @@ -65,16 +67,16 @@ struct RouteHeaderCard: View { @ViewBuilder private var routeRow: some View { if dynamicTypeSize.isAccessibilitySize { - VStack(alignment: .leading, spacing: 6) { - HStack(spacing: 6) { + VStack(alignment: .leading, spacing: 8) { + HStack(spacing: 8) { originMenu Spacer(minLength: 0) swapButton } - HStack(spacing: 6) { + HStack(spacing: 8) { Image(systemName: "arrow.turn.down.right") - .font(.caption.weight(.bold)) + .font(.caption.weight(.medium)) .foregroundStyle(sky.inkSecondary) destinationMenu } @@ -94,7 +96,7 @@ struct RouteHeaderCard: View { private var arrowIcon: some View { Image(systemName: "arrow.right") - .dynamicFont(size: 13, relativeTo: .headline, weight: .bold) + .dynamicFont(size: 13, relativeTo: .headline, weight: .medium) .foregroundStyle(sky.inkSecondary) .accessibilityHidden(true) } @@ -137,7 +139,7 @@ struct RouteHeaderCard: View { } } } label: { - HStack(spacing: 3) { + HStack(spacing: 4) { ZStack(alignment: .leading) { // 最も長い停留所名を見えない下敷きとして重ね、枠の幅を固定します。 // 選んでいる名前の長さで幅が決まると、入れ替えたときに @@ -152,7 +154,7 @@ struct RouteHeaderCard: View { .accessibilityHidden(true) Image(systemName: "chevron.down") - .font(.caption2.weight(.bold)) + .font(.caption2.weight(.medium)) .foregroundStyle(sky.inkSecondary) } .frame(minHeight: SkyMetrics.minimumTapSize) @@ -168,7 +170,7 @@ struct RouteHeaderCard: View { .dynamicFont( size: stopNameSize, relativeTo: .headline, - weight: .bold, + weight: .semibold, design: .rounded ) .foregroundStyle(sky.ink) @@ -183,8 +185,9 @@ struct RouteHeaderCard: View { viewModel.swapEndpoints() } label: { Image(systemName: "arrow.left.arrow.right") - .dynamicFont(size: 14, relativeTo: .body, weight: .bold) - .foregroundStyle(viewModel.canSwapEndpoints ? sky.accent : sky.inkFaint) + .dynamicFont(size: 16, relativeTo: .body, weight: .medium) + // 強調色は主要な操作のために取っておき、入れ替えは文字と同じ色で示します。 + .foregroundStyle(viewModel.canSwapEndpoints ? sky.inkSecondary : sky.inkFaint) .scaledTapTarget() } .buttonStyle(SkyPressStyle()) @@ -201,14 +204,14 @@ struct RouteHeaderCard: View { /// 現在地へ合わせ直す操作を添えます。 private var decisionRow: some View { DynamicTypeStack(verticalAlignment: .center, spacing: 8) { - HStack(spacing: 6) { + HStack(spacing: 8) { Image(systemName: viewModel.routeDecision.systemName) - .font(.caption2.weight(.bold)) - .foregroundStyle(sky.ink) + .font(.caption.weight(.medium)) + .foregroundStyle(sky.inkSecondary) Text(viewModel.routeDecisionDescription) - .dynamicFont(size: 12, relativeTo: .caption, weight: .bold) - .foregroundStyle(sky.ink) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) + .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) } .frame(maxWidth: .infinity, alignment: .leading) @@ -217,10 +220,10 @@ struct RouteHeaderCard: View { locationButton } } - .padding(.horizontal, 10) + .padding(.horizontal, 12) .padding(.vertical, 8) .background( - RoundedRectangle(cornerRadius: 10, style: .continuous) + RoundedRectangle(cornerRadius: SkyMetrics.controlRadius, style: .continuous) .fill(sky.surfaceOpaque) ) } @@ -230,13 +233,17 @@ struct RouteHeaderCard: View { SkyHaptics.tap() locationAction() } label: { - Label(L10n.Route.useCurrentLocation, systemImage: "location.fill") - .dynamicFont(size: 12, relativeTo: .caption, weight: .bold, design: .rounded) - .foregroundStyle(sky.accentReadable) + Label(L10n.Route.useCurrentLocation, systemImage: "location") + .dynamicFont(size: 12, relativeTo: .caption, weight: .medium, design: .rounded) + .foregroundStyle(sky.ink) .padding(.horizontal, 12) .frame(minHeight: SkyMetrics.minimumTapSize) .background( - Capsule().stroke(sky.accent.opacity(0.4), lineWidth: SkyMetrics.borderWidth) + RoundedRectangle(cornerRadius: SkyMetrics.controlRadius, style: .continuous) + .stroke( + sky.ink.opacity(SkyButtonOutline.opacity(showButtonShapes: showButtonShapes)), + lineWidth: SkyMetrics.borderWidth + ) ) } .buttonStyle(SkyPressStyle()) @@ -256,6 +263,8 @@ struct ServiceDayTimeCard: View { @Environment(\.sky) private var sky @Environment(\.dynamicTypeSize) private var dynamicTypeSize @Environment(\.accessibilityReduceMotion) private var reduceMotion + /// iPhoneの「ボタンの形」設定です。 + @Environment(\.accessibilityShowButtonShapes) private var showButtonShapes @ObservedObject var viewModel: HomeViewModel @@ -275,7 +284,7 @@ struct ServiceDayTimeCard: View { /// 運行日の選択です。平日ダイヤが1本しかないため、 /// 日付そのものではなく運行日の単位で選びます。 private var serviceDayChips: some View { - DynamicTypeStack(spacing: 8) { + DynamicTypeStack(spacing: SkySegmentTrackMetrics.inset) { ForEach(HomeViewModel.ServiceDay.allCases) { day in SkyChip( title: viewModel.serviceDayDisplayName(for: day), @@ -287,10 +296,11 @@ struct ServiceDayTimeCard: View { } } } + .skySegmentTrack() } private var searchTypeChips: some View { - DynamicTypeStack(spacing: 8) { + DynamicTypeStack(spacing: SkySegmentTrackMetrics.inset) { SkyChip( title: HomeViewModel.SearchType.departure.shortTitle, isSelected: viewModel.searchType == .departure @@ -308,6 +318,7 @@ struct ServiceDayTimeCard: View { } } } + .skySegmentTrack() } @ViewBuilder @@ -316,7 +327,7 @@ struct ServiceDayTimeCard: View { if !viewModel.isViewingToday { timePicker } else if dynamicTypeSize.isAccessibilitySize { - VStack(alignment: .leading, spacing: 10) { + VStack(alignment: .leading, spacing: 12) { timePicker currentTimeButton .frame(maxWidth: .infinity, alignment: .trailing) @@ -333,7 +344,7 @@ struct ServiceDayTimeCard: View { private var timePicker: some View { VStack(alignment: .leading, spacing: 4) { Text(viewModel.searchType.timeTitle) - .dynamicFont(size: 11, relativeTo: .caption2, weight: .bold) + .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) @@ -348,7 +359,10 @@ struct ServiceDayTimeCard: View { .foregroundStyle(sky.ink) .padding(.horizontal, 12) .frame(minHeight: SkyMetrics.minimumTapSize) - .background(RoundedRectangle(cornerRadius: 10).fill(sky.surfaceOpaque)) + .background( + RoundedRectangle(cornerRadius: SkyMetrics.controlRadius, style: .continuous) + .fill(sky.surfaceOpaque) + ) } .buttonStyle(SkyPressStyle()) .accessibilityLabel(viewModel.searchType.timeTitle) @@ -383,12 +397,16 @@ struct ServiceDayTimeCard: View { viewModel.setSearchToCurrentTime() } label: { Label(L10n.When.currentTime, systemImage: "clock.arrow.circlepath") - .dynamicFont(size: 13, relativeTo: .footnote, weight: .bold, design: .rounded) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium, design: .rounded) .foregroundStyle(sky.ink) - .padding(.horizontal, 14) + .padding(.horizontal, 12) .frame(minHeight: SkyMetrics.minimumTapSize) .background( - Capsule().stroke(sky.ink.opacity(0.24), lineWidth: SkyMetrics.borderWidth) + RoundedRectangle(cornerRadius: SkyMetrics.controlRadius, style: .continuous) + .stroke( + sky.ink.opacity(SkyButtonOutline.opacity(showButtonShapes: showButtonShapes)), + lineWidth: SkyMetrics.borderWidth + ) ) } .buttonStyle(SkyPressStyle()) @@ -398,25 +416,32 @@ struct ServiceDayTimeCard: View { /// 何件見つかったかを、条件を変えた手元に出します。 /// 結果カードはこのすぐ下にありますが、条件を変えた瞬間の手応えを /// 同じ場所で返すための行です。 + /// + /// 見つかったときは件数と並び順だけを短く出し、印は付けません。 + /// 見つからなかったときだけ注意の印を添え、ふだんとの違いを形でも示します。 private var resultSummary: some View { - HStack(alignment: .firstTextBaseline, spacing: 6) { - Image(systemName: viewModel.searchResults.isEmpty ? "exclamationmark.circle.fill" : "checkmark.circle.fill") - // 状態はアイコンの形で区別できるため、文字と同じ高コントラスト色を使います。 - // カード背景が時刻・天候で変わっても説明全体を読みやすく保てます。 - .foregroundStyle(sky.ink) - .accessibilityHidden(true) + HStack(alignment: .firstTextBaseline, spacing: 8) { + if viewModel.searchResults.isEmpty { + Image(systemName: "exclamationmark.circle") + // 状態はアイコンの形で区別できるため、文字と同じ高コントラスト色を使います。 + // カード背景が時刻・天候で変わっても説明全体を読みやすく保てます。 + .font(.caption.weight(.medium)) + .foregroundStyle(sky.ink) + .accessibilityHidden(true) + } Text(viewModel.searchResultDescription) - .dynamicFont(size: 12, relativeTo: .caption, weight: .bold, design: .rounded) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .regular, design: .rounded) + .monospacedDigit() .foregroundStyle(sky.ink) .fixedSize(horizontal: false, vertical: true) } - .padding(.horizontal, 10) + .padding(.horizontal, 12) .padding(.vertical, 8) .frame(maxWidth: .infinity, alignment: .leading) // 背景アニメーションの明暗が文字の直下へ透けないようにし、 // どの時刻・天候でも検索結果の説明を同じコントラストで表示します。 .background( - RoundedRectangle(cornerRadius: 10, style: .continuous) + RoundedRectangle(cornerRadius: SkyMetrics.controlRadius, style: .continuous) .fill(sky.surfaceOpaque) ) } diff --git a/BusTimeApp/Features/Notifications/NotificationManagementView.swift b/BusTimeApp/Features/Notifications/NotificationManagementView.swift index 9399fa1..224c17e 100644 --- a/BusTimeApp/Features/Notifications/NotificationManagementView.swift +++ b/BusTimeApp/Features/Notifications/NotificationManagementView.swift @@ -18,7 +18,7 @@ struct NotificationManagementView: View { } .padding(.horizontal, SkyMetrics.screenPadding) .padding(.top, 16) - .padding(.bottom, 30) + .padding(.bottom, 32) } .background(SkyBackground()) .navigationTitle(L10n.Manage.title) @@ -26,7 +26,7 @@ struct NotificationManagementView: View { .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button(L10n.Common.close) { dismiss() } - .fontWeight(.bold) + .fontWeight(.semibold) .foregroundStyle(sky.accentReadable) } } @@ -40,23 +40,23 @@ struct NotificationManagementView: View { private var permissionCard: some View { DynamicTypeStack(verticalAlignment: .top, spacing: 12) { Image(systemName: isAuthorized ? "checkmark.circle.fill" : "bell.slash.fill") - .dynamicFont(size: 20, relativeTo: .title3, weight: .semibold) + .dynamicFont(size: 20, relativeTo: .title3, weight: .medium) .foregroundStyle(isAuthorized ? sky.positive : sky.warning) - VStack(alignment: .leading, spacing: 6) { + VStack(alignment: .leading, spacing: 4) { Text(viewModel.permissionStatus.title) - .dynamicFont(size: 15, relativeTo: .subheadline, weight: .bold, design: .rounded) + .dynamicFont(size: 15, relativeTo: .subheadline, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) .fixedSize(horizontal: false, vertical: true) Text(L10n.Manage.permissionMessage) - .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) if viewModel.permissionStatus == .denied { Button(L10n.Manage.openNotificationSettings, action: viewModel.openNotificationSettings) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .bold, design: .rounded) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium, design: .rounded) .foregroundStyle(sky.accentReadable) .frame(minHeight: SkyMetrics.minimumTapSize, alignment: .leading) } @@ -68,22 +68,22 @@ struct NotificationManagementView: View { } private var liveActivityCard: some View { - VStack(alignment: .leading, spacing: 10) { + VStack(alignment: .leading, spacing: 12) { SkySectionLabel(text: "Live Activity") if liveActivityBusID != nil { Text(L10n.Manage.liveActivityShowing) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) Button(L10n.Manage.endLiveActivity, action: onEndLiveActivity) - .dynamicFont(size: 14, relativeTo: .subheadline, weight: .bold, design: .rounded) + .dynamicFont(size: 14, relativeTo: .subheadline, weight: .medium, design: .rounded) .foregroundStyle(sky.ink) .frame(minHeight: SkyMetrics.minimumTapSize, alignment: .leading) } else { Text(L10n.Manage.noLiveActivity) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) } @@ -101,16 +101,16 @@ struct NotificationManagementView: View { Button(L10n.Manage.clearAll) { viewModel.cancelAllNotifications() } - .dynamicFont(size: 12, relativeTo: .caption, weight: .bold, design: .rounded) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium, design: .rounded) .foregroundStyle(sky.ink) } } if viewModel.scheduledNotifications.isEmpty { Text(L10n.Manage.empty) - .dynamicFont(size: 14, relativeTo: .subheadline, weight: .medium) + .dynamicFont(size: 14, relativeTo: .subheadline, weight: .regular) .foregroundStyle(sky.inkSecondary) - .padding(.vertical, 10) + .padding(.vertical, 8) } else { ForEach(viewModel.scheduledNotifications) { item in notificationRow(for: item) @@ -121,21 +121,21 @@ struct NotificationManagementView: View { private func notificationRow(for item: ScheduledBusNotification) -> some View { DynamicTypeStack(verticalAlignment: .top, spacing: 12) { - Image(systemName: "bell.badge.fill") - .dynamicFont(size: 14, relativeTo: .body, weight: .semibold) + Image(systemName: "bell.fill") + .dynamicFont(size: 16, relativeTo: .body, weight: .medium) .foregroundStyle(sky.accentReadable) VStack(alignment: .leading, spacing: 4) { Text(item.busDescription) - .dynamicFont(size: 14, relativeTo: .subheadline, weight: .bold, design: .rounded) + .dynamicFont(size: 15, relativeTo: .subheadline, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) .fixedSize(horizontal: false, vertical: true) Text(L10n.Manage.notificationRow(item.notificationDescription)) - .dynamicFont(size: 12, relativeTo: .caption, weight: .bold) - .foregroundStyle(sky.accentReadable) + .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) + .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) Text(item.routeName) - .dynamicFont(size: 11, relativeTo: .caption2, weight: .medium) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) } @@ -145,13 +145,13 @@ struct NotificationManagementView: View { viewModel.cancelNotification(for: item) } label: { Image(systemName: "trash") - .dynamicFont(size: 14, relativeTo: .body, weight: .semibold) + .dynamicFont(size: 16, relativeTo: .body, weight: .regular) .foregroundStyle(sky.warning) .scaledTapTarget() } .buttonStyle(SkyPressStyle()) .accessibilityLabel(L10n.Manage.cancelOne) } - .skyCard(radius: 16, padding: 14) + .skyCard(radius: 16, padding: 16) } } diff --git a/BusTimeApp/Features/Notifications/NotificationOptionsView.swift b/BusTimeApp/Features/Notifications/NotificationOptionsView.swift index d23dfcc..ecf996f 100644 --- a/BusTimeApp/Features/Notifications/NotificationOptionsView.swift +++ b/BusTimeApp/Features/Notifications/NotificationOptionsView.swift @@ -18,6 +18,14 @@ struct NotificationOptionsView: View { /// 選べる通知タイミングです。 private let reminderMinutes = [5, 10, 15] + /// 通知タイミングの行の角丸半径です。 + private let rowRadius: CGFloat = 16 + /// 通知タイミングの行の内側の余白です。 + private let rowPadding: CGFloat = 16 + /// 押せない部品の中身の濃さです。 + private let disabledContentOpacity: Double = 0.48 + /// 大きなボタンの高さです。 + private let largeButtonHeight: CGFloat = 48 var body: some View { NavigationStack { @@ -29,7 +37,7 @@ struct NotificationOptionsView: View { } .padding(.horizontal, SkyMetrics.screenPadding) .padding(.top, 16) - .padding(.bottom, 30) + .padding(.bottom, 32) } .background(SkyBackground()) .navigationTitle(L10n.Options.title) @@ -37,7 +45,7 @@ struct NotificationOptionsView: View { .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button(L10n.Common.close) { dismiss() } - .fontWeight(.bold) + .fontWeight(.semibold) .foregroundStyle(sky.accentReadable) } } @@ -47,21 +55,21 @@ struct NotificationOptionsView: View { // MARK: - 対象の便 private var busSummary: some View { - VStack(alignment: .leading, spacing: 10) { + VStack(alignment: .leading, spacing: 8) { SkySectionLabel(text: L10n.Options.targetSection) - HStack(alignment: .lastTextBaseline, spacing: 6) { + HStack(alignment: .lastTextBaseline, spacing: 4) { Text(bus.departure) - .dynamicFont(size: 30, relativeTo: .title, weight: .bold, design: .rounded) + .dynamicFont(size: 32, relativeTo: .title, weight: .semibold, design: .rounded) .monospacedDigit() .foregroundStyle(sky.ink) Text(L10n.Result.departureSuffix) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .bold) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium) .foregroundStyle(sky.inkSecondary) } Text(bus.stopSummary) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) @@ -74,10 +82,14 @@ struct NotificationOptionsView: View { ) } - Text(routeName) - .dynamicFont(size: 11, relativeTo: .caption2, weight: .medium) - .foregroundStyle(sky.inkSecondary) - .fixedSize(horizontal: false, vertical: true) + // 便の停留所の並びと選んでいる経路が同じなら、同じ文を2回並べません。 + // 経由便のように両者が違うときだけ、どの経路の便かを添えます。 + if routeName != bus.stopSummary { + Text(routeName) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) + .foregroundStyle(sky.inkSecondary) + .fixedSize(horizontal: false, vertical: true) + } } .frame(maxWidth: .infinity, alignment: .leading) .skyCard() @@ -91,11 +103,11 @@ struct NotificationOptionsView: View { if let scheduledNotification { Text(L10n.Options.currentSetting(scheduledNotification.notificationDescription)) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .bold) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium) .foregroundStyle(sky.accentReadable) .fixedSize(horizontal: false, vertical: true) Text(L10n.Options.onlyOnePerBus) - .dynamicFont(size: 11, relativeTo: .caption2, weight: .medium) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) } @@ -105,14 +117,14 @@ struct NotificationOptionsView: View { } if permissionStatus == .denied { - VStack(alignment: .leading, spacing: 6) { + VStack(alignment: .leading, spacing: 4) { SkyNoticeRow( message: L10n.Options.notPermitted, systemImage: "exclamationmark.circle.fill", isWarning: true ) Button(L10n.Options.allowInSettings, action: onOpenNotificationSettings) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .bold, design: .rounded) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium, design: .rounded) .foregroundStyle(sky.accentReadable) .frame(minHeight: SkyMetrics.minimumTapSize, alignment: .leading) } @@ -136,13 +148,13 @@ struct NotificationOptionsView: View { onSchedule(minutes) } label: { DynamicTypeStack(spacing: 12) { - Image(systemName: "bell.badge.fill") - .dynamicFont(size: 16, relativeTo: .body, weight: .semibold) - .foregroundStyle(sky.accentReadable) + Image(systemName: "bell") + .dynamicFont(size: 16, relativeTo: .body, weight: .medium) + .foregroundStyle(sky.inkSecondary) - VStack(alignment: .leading, spacing: 3) { + VStack(alignment: .leading, spacing: 4) { Text(L10n.Options.minutesBefore(minutes)) - .dynamicFont(size: 15, relativeTo: .subheadline, weight: .bold, design: .rounded) + .dynamicFont(size: 15, relativeTo: .subheadline, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) Text( schedule.map { @@ -151,21 +163,23 @@ struct NotificationOptionsView: View { ) } ?? L10n.Options.notAvailable ) - .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) } .frame(maxWidth: .infinity, alignment: .leading) Image(systemName: "chevron.right") - .font(.caption.weight(.bold)) + .font(.caption.weight(.medium)) .foregroundStyle(sky.inkSecondary) } - .skyCard(radius: 16, padding: 14) + // 設定できない行は中身だけを淡くし、カードの地は残します。 + // 行ごと淡くすると地まで透けて、うしろの風景が文字に重なるためです。 + .opacity(schedule == nil ? disabledContentOpacity : 1) + .skyCard(radius: rowRadius, padding: rowPadding) } .buttonStyle(SkyPressStyle()) .disabled(schedule == nil) - .opacity(schedule == nil ? 0.48 : 1) } // MARK: - Live Activity @@ -175,7 +189,7 @@ struct NotificationOptionsView: View { SkySectionLabel(text: "Live Activity") Text(L10n.Options.liveActivityDescription) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) @@ -198,7 +212,7 @@ struct NotificationOptionsView: View { SkyNoticeRow(message: L10n.Options.autoStartOff) } else if let scheduledNotification { Text(L10n.Options.existingAlertKept(scheduledNotification.minutesBefore)) - .dynamicFont(size: 12, relativeTo: .caption, weight: .bold) + .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) .foregroundStyle(sky.accentReadable) .fixedSize(horizontal: false, vertical: true) } else { @@ -213,12 +227,12 @@ struct NotificationOptionsView: View { private var liveActivityControl: some View { if liveActivityBusID == bus.id { Button(action: onEndLiveActivity) { - Label(L10n.Options.endThisDisplay, systemImage: "stop.circle.fill") - .dynamicFont(size: 15, relativeTo: .subheadline, weight: .bold, design: .rounded) + Label(L10n.Options.endThisDisplay, systemImage: "stop.circle") + .dynamicFont(size: 15, relativeTo: .subheadline, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) - .frame(maxWidth: .infinity, minHeight: 50) + .frame(maxWidth: .infinity, minHeight: largeButtonHeight) .background( - RoundedRectangle(cornerRadius: 16, style: .continuous) + RoundedRectangle(cornerRadius: SkyMetrics.innerRadius, style: .continuous) .stroke(sky.warning.opacity(0.5), lineWidth: SkyMetrics.borderWidth) ) } @@ -231,17 +245,17 @@ struct NotificationOptionsView: View { : L10n.Options.startKeepingAlert, systemImage: "lock.rectangle.on.rectangle" ) - .dynamicFont(size: 15, relativeTo: .subheadline, weight: .bold, design: .rounded) + .dynamicFont(size: 15, relativeTo: .subheadline, weight: .semibold, design: .rounded) .foregroundStyle(sky.accentInk) - .frame(maxWidth: .infinity, minHeight: 50) + .frame(maxWidth: .infinity, minHeight: largeButtonHeight) .background( - RoundedRectangle(cornerRadius: 16, style: .continuous) + RoundedRectangle(cornerRadius: SkyMetrics.innerRadius, style: .continuous) .fill(sky.accent) ) } .buttonStyle(SkyPressStyle()) .disabled(!isLiveActivityAvailable) - .opacity(isLiveActivityAvailable ? 1 : 0.48) + .opacity(isLiveActivityAvailable ? 1 : disabledContentOpacity) } else { SkyNoticeRow(message: L10n.Options.otherBusShowing) } diff --git a/BusTimeApp/Features/Settings/SettingsView.swift b/BusTimeApp/Features/Settings/SettingsView.swift index d941872..36bdd1a 100644 --- a/BusTimeApp/Features/Settings/SettingsView.swift +++ b/BusTimeApp/Features/Settings/SettingsView.swift @@ -13,6 +13,7 @@ struct SettingsView: View { appearanceCard cardOpacityCard liveActivityCard + legalCard } .padding(.horizontal, SkyMetrics.screenPadding) .padding(.top, 16) @@ -24,7 +25,7 @@ struct SettingsView: View { .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button(L10n.Common.done) { dismiss() } - .fontWeight(.bold) + .fontWeight(.semibold) .foregroundStyle(sky.accentReadable) } } @@ -42,12 +43,12 @@ struct SettingsView: View { SkySectionLabel(text: L10n.Settings.appearanceSection) Text(L10n.Settings.appearanceTitle) - .dynamicFont(size: 18, relativeTo: .title3, weight: .bold, design: .rounded) + .dynamicFont(size: 18, relativeTo: .title3, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) .fixedSize(horizontal: false, vertical: true) Text(L10n.Settings.appearanceDescription) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) @@ -73,7 +74,7 @@ struct SettingsView: View { ) Text(L10n.Settings.weatherNotice) - .dynamicFont(size: 11, relativeTo: .caption2, weight: .medium) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) } @@ -112,15 +113,15 @@ struct SettingsView: View { return HStack(spacing: 8) { ForEach(previewHours, id: \.hour) { item in - VStack(spacing: 6) { + VStack(spacing: 8) { // 日付は背景本体と同じものを使い、今日の背景と同じ空の移り変わりを見せます。 SkyCanvas() .environment(\.sky, SkyPalette.at(hour: item.hour, day: sky.day)) - .frame(height: 78) - .clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous)) + .frame(height: 80) + .clipShape(RoundedRectangle(cornerRadius: SkyMetrics.controlRadius, style: .continuous)) Text(item.label) - .dynamicFont(size: 11, relativeTo: .caption2, weight: .bold) + .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) .foregroundStyle(sky.inkSecondary) } } @@ -135,13 +136,13 @@ struct SettingsView: View { SkySectionLabel(text: L10n.Settings.cardOpacitySection) Text(L10n.Settings.cardOpacityDescription) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) HStack(spacing: 12) { Text(L10n.Settings.cardOpacityLight) - .dynamicFont(size: 11, relativeTo: .caption2, weight: .bold) + .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) .foregroundStyle(sky.inkSecondary) Slider( @@ -155,7 +156,7 @@ struct SettingsView: View { .accessibilityLabel(L10n.Settings.cardOpacitySection) Text(L10n.Settings.cardOpacityDense) - .dynamicFont(size: 11, relativeTo: .caption2, weight: .bold) + .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) .foregroundStyle(sky.inkSecondary) } @@ -165,6 +166,29 @@ struct SettingsView: View { .skyCard() } + private var legalCard: some View { + VStack(alignment: .leading, spacing: 12) { + SkySectionLabel(text: L10n.Settings.legalSection) + Link(destination: URL(string: "https://hr0101.dev/apps/bustimeapp/privacy/")!) { + Label(L10n.Settings.privacyPolicy, systemImage: "arrow.up.right.square") + .frame(maxWidth: .infinity, alignment: .leading) + .padding(.vertical, 8) + } + Link(destination: URL(string: "https://hr0101.dev/apps/bustimeapp/terms/")!) { + Label(L10n.Settings.termsOfUse, systemImage: "arrow.up.right.square") + .frame(maxWidth: .infinity, alignment: .leading) + .padding(.vertical, 8) + } + Text(L10n.Settings.legalWebsiteNotice) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) + .foregroundStyle(sky.inkSecondary) + .fixedSize(horizontal: false, vertical: true) + } + .tint(sky.accentReadable) + .frame(maxWidth: .infinity, alignment: .leading) + .skyCard() + } + private var liveActivityCard: some View { VStack(alignment: .leading, spacing: 12) { SkySectionLabel(text: L10n.Settings.notificationsSection) @@ -177,10 +201,10 @@ struct SettingsView: View { ) { VStack(alignment: .leading, spacing: 4) { Text(L10n.Settings.liveActivityToggle) - .dynamicFont(size: 15, relativeTo: .subheadline, weight: .bold, design: .rounded) + .dynamicFont(size: 15, relativeTo: .subheadline, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) Text(L10n.Settings.liveActivityDescription) - .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) + .dynamicFont(size: 12, relativeTo: .caption, weight: .regular) .foregroundStyle(sky.inkSecondary) .fixedSize(horizontal: false, vertical: true) } diff --git a/BusTimeApp/Features/Shortcuts/NextBusIntent.swift b/BusTimeApp/Features/Shortcuts/NextBusIntent.swift index b26ce52..4e587b5 100644 --- a/BusTimeApp/Features/Shortcuts/NextBusIntent.swift +++ b/BusTimeApp/Features/Shortcuts/NextBusIntent.swift @@ -4,8 +4,10 @@ import Foundation /// 「次のバスは?」に答えるショートカットです。 /// /// アプリを開いて画面を見るまでもない場面のために、声だけで答えられるようにします。 -/// 経路の決め方はアプリと同じで、自分で選んだ経路があればそれを、 +/// 経路を指定しなければ、アプリと同じ判断で決めます。自分で選んだ経路があればそれを、 /// なければ時間帯と前回の行き先から決めます。 +/// +/// 出発日時を値として返すので、ショートカットの後続のアクションへ渡せます。 @available(iOS 16.0, *) struct NextBusIntent: AppIntent { static var title: LocalizedStringResource { "shortcut.nextBusTitle" } @@ -16,9 +18,15 @@ struct NextBusIntent: AppIntent { /// 答えるだけなのでアプリは開きません。 static var openAppWhenRun: Bool { false } + @Parameter(title: "shortcut.routeParameter", description: "shortcut.routeAutoDescription") + var route: BusRouteOption? + @MainActor - func perform() async throws -> some IntentResult & ProvidesDialog { - .result(dialog: IntentDialog(stringLiteral: NextBusAnswer.text(at: Date()))) + func perform() async throws -> some IntentResult & ProvidesDialog & ReturnsValue { + guard let answer = NextBusAnswer.answer(for: route?.route, at: Date()) else { + throw ShortcutActionError.failed(L10n.Shortcut.noService) + } + return .result(value: answer.departureDate, dialog: IntentDialog(stringLiteral: answer.text)) } } @@ -26,27 +34,37 @@ struct NextBusIntent: AppIntent { /// /// 声で聞く人には画面がないので、経路・出発・到着・残り時間を1文にまとめます。 enum NextBusAnswer { - static func text(at now: Date) -> String { - let route = SharedAppData.manualRoute ?? BusSchedule.recommendedRoute( - at: now, - location: nil, - preferredPartner: SharedAppData.preferredPartnerStop - ) + /// 答えの文と、次の便の出発日時です。 + struct Answer: Equatable { + let text: String + let departureDate: Date + } + + /// 指定した経路の次の便について答えます。経路を指定しなければアプリと同じ判断で決めます。 + /// どの経路にも次の便がなければnilを返します。 + static func answer(for route: BusRoute?, at now: Date) -> Answer? { + let route = route ?? ShortcutRouteResolver.automaticRoute(at: now) guard let next = BusSchedule.upcomingDepartures( on: route, from: now, limit: 1 ).first else { - return L10n.Shortcut.noService + return nil } - return L10n.Shortcut.answer( + let text = L10n.Shortcut.answer( route.rawValue, next.departure, next.arrival, BusRemainingTimeFormatter.string(until: next.departureDate, now: now) ) + return Answer(text: text, departureDate: next.departureDate) + } + + /// 経路を指定せずに答える文です。 + static func text(at now: Date) -> String { + answer(for: nil, at: now)?.text ?? L10n.Shortcut.noService } } @@ -67,5 +85,25 @@ struct BusTimeAppShortcuts: AppShortcutsProvider { shortTitle: "shortcut.nextBusTitle", systemImageName: "bus.fill" ) + + AppShortcut( + intent: OpenRouteIntent(), + phrases: [ + "\(.applicationName)で経路を開く", + "Open a route in \(.applicationName)" + ], + shortTitle: "shortcut.openRouteTitle", + systemImageName: "map.fill" + ) + + AppShortcut( + intent: StartBusAlertIntent(), + phrases: [ + "\(.applicationName)で次のバスの通知を設定", + "Set a bus alert in \(.applicationName)" + ], + shortTitle: "shortcut.startAlertTitle", + systemImageName: "bell.badge.fill" + ) } } diff --git a/BusTimeApp/Features/Shortcuts/OpenRouteIntent.swift b/BusTimeApp/Features/Shortcuts/OpenRouteIntent.swift new file mode 100644 index 0000000..e3e2da7 --- /dev/null +++ b/BusTimeApp/Features/Shortcuts/OpenRouteIntent.swift @@ -0,0 +1,28 @@ +import AppIntents +import Foundation + +/// 指定した経路のホームをアプリで開くショートカットです。 +/// +/// ウィジェットをタップしたときと同じく、選んだ経路を「自分で選んだ経路」として +/// 扱います。位置情報が後から届いても、この経路は上書きされません。 +@available(iOS 16.0, *) +struct OpenRouteIntent: AppIntent { + static var title: LocalizedStringResource { "shortcut.openRouteTitle" } + static var description: IntentDescription { + IntentDescription(LocalizedStringResource("shortcut.openRouteDescription")) + } + + /// 画面を見せるのが目的なので、アプリを開きます。 + static var openAppWhenRun: Bool { true } + + @Parameter(title: "shortcut.routeParameter") + var route: BusRouteOption + + @MainActor + func perform() async throws -> some IntentResult { + let outcome = await ShortcutRequestCenter.shared.submit(.openRoute(route.route)) + // 開けなかったときは、成功を装わずショートカットを失敗として終えます。 + _ = try outcome.requireSuccessMessage() + return .result() + } +} diff --git a/BusTimeApp/Features/Shortcuts/ShortcutOptions.swift b/BusTimeApp/Features/Shortcuts/ShortcutOptions.swift new file mode 100644 index 0000000..4ccdcc7 --- /dev/null +++ b/BusTimeApp/Features/Shortcuts/ShortcutOptions.swift @@ -0,0 +1,118 @@ +import AppIntents +import Foundation + +/// ショートカットで選べる経路です。 +/// +/// `BusRoute` の生の値は日本語の表示名なので、そのまま保存すると表示名を直したときに +/// 利用者が作ったショートカットが壊れます。そのため保存される値は変わらない識別子にして、 +/// 表示名とは切り離しています。 +@available(iOS 16.0, *) +enum BusRouteOption: String, CaseIterable, AppEnum { + case mansionToStation + case stationToMansion + case mansionToYokado + case stationToYokado + case yokadoToMansion + + static var typeDisplayRepresentation: TypeDisplayRepresentation { + TypeDisplayRepresentation(name: "shortcut.routeParameter") + } + + static var caseDisplayRepresentations: [BusRouteOption: DisplayRepresentation] { + [ + .mansionToStation: DisplayRepresentation(title: "shortcut.routeMansionToStation"), + .stationToMansion: DisplayRepresentation(title: "shortcut.routeStationToMansion"), + .mansionToYokado: DisplayRepresentation(title: "shortcut.routeMansionToYokado"), + .stationToYokado: DisplayRepresentation(title: "shortcut.routeStationToYokado"), + .yokadoToMansion: DisplayRepresentation(title: "shortcut.routeYokadoToMansion") + ] + } + + /// アプリ本体で使う経路です。 + var route: BusRoute { + switch self { + case .mansionToStation: + return .mansionToStation + case .stationToMansion: + return .stationToMansion + case .mansionToYokado: + return .mansionToYokado + case .stationToYokado: + return .stationToYokado + case .yokadoToMansion: + return .yokadoToMansion + } + } + + init(route: BusRoute) { + switch route { + case .mansionToStation: + self = .mansionToStation + case .stationToMansion: + self = .stationToMansion + case .mansionToYokado: + self = .mansionToYokado + case .stationToYokado: + self = .stationToYokado + case .yokadoToMansion: + self = .yokadoToMansion + } + } +} + +/// ショートカットで選べる、出発の何分前に知らせるかです。 +/// +/// アプリの通知画面と同じ3つに限り、登録ミスを減らします。 +@available(iOS 16.0, *) +enum BusAlertLeadTime: String, CaseIterable, AppEnum { + case fiveMinutes + case tenMinutes + case fifteenMinutes + + static var typeDisplayRepresentation: TypeDisplayRepresentation { + TypeDisplayRepresentation(name: "shortcut.leadTimeParameter") + } + + static var caseDisplayRepresentations: [BusAlertLeadTime: DisplayRepresentation] { + [ + .fiveMinutes: DisplayRepresentation(title: "shortcut.leadTimeFiveMinutes"), + .tenMinutes: DisplayRepresentation(title: "shortcut.leadTimeTenMinutes"), + .fifteenMinutes: DisplayRepresentation(title: "shortcut.leadTimeFifteenMinutes") + ] + } + + /// 出発の何分前に知らせるかです。 + var minutes: Int { + switch self { + case .fiveMinutes: + return 5 + case .tenMinutes: + return 10 + case .fifteenMinutes: + return 15 + } + } +} + +/// ショートカットで経路が指定されなかったときの決め方です。 +enum ShortcutRouteResolver { + /// 経路の指定があればそれを、なければアプリと同じ判断で決めます。 + /// + /// 自分で選んだ経路があればそれを、なければ時間帯と前回の行き先から決めます。 + @available(iOS 16.0, *) + static func route(for option: BusRouteOption?, at now: Date) -> BusRoute { + if let option { + return option.route + } + return automaticRoute(at: now) + } + + /// アプリと同じ判断で決めた経路です。 + static func automaticRoute(at now: Date) -> BusRoute { + SharedAppData.manualRoute ?? BusSchedule.recommendedRoute( + at: now, + location: nil, + preferredPartner: SharedAppData.preferredPartnerStop + ) + } +} diff --git a/BusTimeApp/Features/Shortcuts/ShortcutRequestCenter.swift b/BusTimeApp/Features/Shortcuts/ShortcutRequestCenter.swift new file mode 100644 index 0000000..7e8fd6d --- /dev/null +++ b/BusTimeApp/Features/Shortcuts/ShortcutRequestCenter.swift @@ -0,0 +1,120 @@ +import Combine +import Foundation + +/// ショートカットからアプリ本体へ頼む操作です。 +enum ShortcutAction: Equatable { + /// 指定した経路のホームを開きます。 + case openRoute(BusRoute) + /// 指定した経路の次の便に通知を設定し、必要ならLive Activityも開始します。 + case startBusAlert(route: BusRoute, minutesBefore: Int, startsLiveActivity: Bool) +} + +/// 預けられた1件の依頼です。 +struct ShortcutRequest: Equatable, Identifiable { + let id: UUID + let action: ShortcutAction +} + +/// 依頼を処理した結果です。 +enum ShortcutOutcome: Equatable { + /// 成功です。ショートカットが返す文を持ちます。 + case succeeded(String) + /// 失敗です。利用者へ伝える理由を持ちます。 + case failed(String) + /// 画面が一定時間内に処理しませんでした。 + case noResponse +} + +/// ショートカットの実行を失敗として終えるときのエラーです。 +/// +/// 自動化の途中で失敗に気づけるよう、成功を装った文を返さずエラーとして投げます。 +enum ShortcutActionError: Error, CustomLocalizedStringResourceConvertible { + case failed(String) + + var localizedStringResource: LocalizedStringResource { + switch self { + case let .failed(message): + // 文はすでに端末の言語へ翻訳済みなので、そのまま表示します。 + return LocalizedStringResource(stringLiteral: message) + } + } +} + +extension ShortcutOutcome { + /// 成功なら文を返し、失敗や無応答ならエラーとして投げます。 + func requireSuccessMessage() throws -> String { + switch self { + case let .succeeded(message): + return message + case let .failed(message): + throw ShortcutActionError.failed(message) + case .noResponse: + throw ShortcutActionError.failed(L10n.Shortcut.noResponse) + } + } +} + +/// ショートカットとアプリの画面のあいだで、依頼を受け渡します。 +/// +/// 通知やLive Activityの状態は、画面が持つViewModelの中にあります。 +/// ショートカットが別の入れ物を作って同じ保存領域へ書くと、起動中のViewModelが +/// 古い内容で上書きして、OS側の通知と記録がずれてしまいます。 +/// そこで、ショートカットは依頼をここへ預け、画面が既存の処理で実行して結果を返します。 +@MainActor +final class ShortcutRequestCenter: ObservableObject { + static let shared = ShortcutRequestCenter() + + /// 画面が依頼を処理するまで待つ時間の既定値です。 + nonisolated static let defaultResponseTimeout: Duration = .seconds(15) + + /// 画面がまだ受け取っていない依頼です。 + @Published private(set) var pendingRequest: ShortcutRequest? + + private let responseTimeout: Duration + private var continuations: [UUID: CheckedContinuation] = [:] + private var timeoutTasks: [UUID: Task] = [:] + + init(responseTimeout: Duration = ShortcutRequestCenter.defaultResponseTimeout) { + self.responseTimeout = responseTimeout + } + + /// 依頼を預け、画面が処理を終えるまで待って結果を返します。 + func submit(_ action: ShortcutAction) async -> ShortcutOutcome { + // まだ受け取られていない前の依頼は、この依頼に置き換えます。 + if let stale = pendingRequest { + finish(stale.id, with: .noResponse) + } + + let request = ShortcutRequest(id: UUID(), action: action) + let timeout = responseTimeout + + return await withCheckedContinuation { continuation in + continuations[request.id] = continuation + pendingRequest = request + // 画面が受け取れない状態が続いても、ショートカットが待ち続けないようにします。 + timeoutTasks[request.id] = Task { [weak self] in + try? await Task.sleep(for: timeout) + guard !Task.isCancelled else { return } + self?.finish(request.id, with: .noResponse) + } + } + } + + /// 画面が依頼を受け取ります。受け取った依頼は、預かり中ではなくなります。 + func takePendingRequest() -> ShortcutRequest? { + guard let request = pendingRequest else { return nil } + pendingRequest = nil + return request + } + + /// 依頼の結果を伝え、待っているショートカットを再開します。 + /// + /// 同じ依頼に何度呼ばれても、再開は一度だけです。 + func finish(_ id: UUID, with outcome: ShortcutOutcome) { + timeoutTasks.removeValue(forKey: id)?.cancel() + if pendingRequest?.id == id { + pendingRequest = nil + } + continuations.removeValue(forKey: id)?.resume(returning: outcome) + } +} diff --git a/BusTimeApp/Features/Shortcuts/StartBusAlertIntent.swift b/BusTimeApp/Features/Shortcuts/StartBusAlertIntent.swift new file mode 100644 index 0000000..7e032fb --- /dev/null +++ b/BusTimeApp/Features/Shortcuts/StartBusAlertIntent.swift @@ -0,0 +1,125 @@ +import AppIntents +import Foundation + +/// 指定した経路の次の便に通知を設定し、必要ならLive Activityも開始するショートカットです。 +/// +/// Live Activityはアプリが前面にいないと開始できません。また、通知の保存内容は +/// 画面のViewModelが持っているため、依頼をアプリへ渡して既存の処理で実行します。 +/// そのため、このショートカットはアプリを開きます。 +@available(iOS 16.0, *) +struct StartBusAlertIntent: AppIntent { + static var title: LocalizedStringResource { "shortcut.startAlertTitle" } + static var description: IntentDescription { + IntentDescription(LocalizedStringResource("shortcut.startAlertDescription")) + } + + static var openAppWhenRun: Bool { true } + + @Parameter(title: "shortcut.routeParameter", description: "shortcut.routeAutoDescription") + var route: BusRouteOption? + + @Parameter(title: "shortcut.leadTimeParameter", default: .fiveMinutes) + var leadTime: BusAlertLeadTime + + @Parameter(title: "shortcut.liveActivityParameter", default: true) + var startsLiveActivity: Bool + + @MainActor + func perform() async throws -> some IntentResult & ProvidesDialog { + let targetRoute = ShortcutRouteResolver.route(for: route, at: AppDate.now()) + let outcome = await ShortcutRequestCenter.shared.submit( + .startBusAlert( + route: targetRoute, + minutesBefore: leadTime.minutes, + startsLiveActivity: startsLiveActivity + ) + ) + let message = try outcome.requireSuccessMessage() + return .result(dialog: IntentDialog(stringLiteral: message)) + } +} + +/// 通知を設定する対象の便を選びます。 +/// +/// アプリの画面と同じく、運休日や別の運行日の便には通知を設定しません。 +/// 「次の便」であっても、通知の時刻がすでに過ぎている便は飛ばし、 +/// 通知が間に合う最初の便を選びます。 +enum ShortcutBusSelector { + enum Failure: Error, Equatable { + /// 今日は運休日です。 + case noService + /// 今日これから通知を設定できる便がありません。 + case noBusAvailable + + /// 利用者へ伝える理由です。 + var message: String { + switch self { + case .noService: + return L10n.Notify.unavailableSuspended + case .noBusAvailable: + return L10n.Shortcut.noBusToAlert + } + } + } + + static func select( + on route: BusRoute, + minutesBefore: Int, + now: Date, + calendar: Calendar = AppCalendar.japan + ) -> Result { + guard + let serviceDayStart = BusNotificationTimeCalculator.serviceDayStart( + for: now, + calendar: calendar + ), BusServiceCalendar.isServiceDay(serviceDayStart, calendar: calendar) + else { + return .failure(.noService) + } + + let candidates = BusSchedule.timetable(for: route).compactMap { bus in + notificationCandidate( + for: bus, + minutesBefore: minutesBefore, + now: now, + calendar: calendar + ) + } + + guard let earliest = candidates.min(by: { $0.departureDate < $1.departureDate }) else { + return .failure(.noBusAvailable) + } + return .success(earliest.bus) + } + + private static func notificationCandidate( + for bus: Bus, + minutesBefore: Int, + now: Date, + calendar: Calendar + ) -> (bus: Bus, departureDate: Date)? { + guard + let dates = BusNotificationTimeCalculator.notificationDate( + for: bus.departure, + minutesBefore: minutesBefore, + from: now, + calendar: calendar + ) + else { + return nil + } + + // 今日の便が出尽くすと、次の運行日の便へ繰り越されます。 + // 画面では他の運行日の通知を扱わないため、ここでも対象にしません。 + guard + BusNotificationTimeCalculator.departureDateForCurrentServiceDay( + for: bus.departure, + from: now, + calendar: calendar + ) == dates.departureDate + else { + return nil + } + return (bus, dates.departureDate) + } +} diff --git a/BusTimeApp/Features/Timetable/TimetableSyncBanner.swift b/BusTimeApp/Features/Timetable/TimetableSyncBanner.swift index d8e3edb..78e860d 100644 --- a/BusTimeApp/Features/Timetable/TimetableSyncBanner.swift +++ b/BusTimeApp/Features/Timetable/TimetableSyncBanner.swift @@ -46,7 +46,7 @@ struct TimetableSyncBanner: View { Task { await viewModel.refreshTimetables() } } label: { Image(systemName: "arrow.clockwise") - .frame(minWidth: 44, minHeight: 44) + .frame(minWidth: SkyMetrics.minimumTapSize, minHeight: SkyMetrics.minimumTapSize) } .accessibilityLabel(L10n.Sync.refresh) .disabled(info.connection == .syncing) @@ -55,7 +55,7 @@ struct TimetableSyncBanner: View { .foregroundStyle(sky.ink) .fixedSize(horizontal: false, vertical: true) .frame(maxWidth: .infinity, alignment: .leading) - .skyCard(padding: 14) + .skyCard(padding: 16) } } } diff --git a/BusTimeApp/Features/Timetable/TimetableTabView.swift b/BusTimeApp/Features/Timetable/TimetableTabView.swift index e6307ae..639ba5a 100644 --- a/BusTimeApp/Features/Timetable/TimetableTabView.swift +++ b/BusTimeApp/Features/Timetable/TimetableTabView.swift @@ -26,6 +26,8 @@ struct TimetableTabView: View { /// iPhoneの「色を使わず区別」設定です。 /// オンのときは、色だけで示していた状態に形の手がかりを足します。 @Environment(\.accessibilityDifferentiateWithoutColor) private var differentiateWithoutColor + /// iPhoneの「ボタンの形」設定です。 + @Environment(\.accessibilityShowButtonShapes) private var showButtonShapes @State private var didScrollInitially = false @ObservedObject var viewModel: HomeViewModel @@ -38,20 +40,22 @@ struct TimetableTabView: View { /// 時のラベルの幅です。2桁の時が折り返さない幅を確保します。 private let hourLabelWidth: CGFloat = 24 /// 時のラベルと分のマスのあいだの間隔です。 - private let hourLabelSpacing: CGFloat = 6 + private let hourLabelSpacing: CGFloat = 8 /// マス同士の間隔です。 private let cellSpacing: CGFloat = 2 /// 行の左右の余白です。 - private let rowPadding: CGFloat = 6 + private let rowPadding: CGFloat = 8 + /// 行の上下の余白です。 + private let rowVerticalPadding: CGFloat = 4 /// マスの角丸半径です。 - private let cellRadius: CGFloat = 10 + private let cellRadius: CGFloat = SkyMetrics.controlRadius /// 備考のある便に添える点の直径です。 /// 小さく淡いと見落とすため、時刻の文字と同じ濃さでしっかり置きます。 - private let noteMarkerSize: CGFloat = 5 + private let noteMarkerSize: CGFloat = 4 /// 画面左右の余白です。マスの幅を稼ぐため、他の画面より狭くしています。 private var horizontalPadding: CGFloat { - dynamicTypeSize.isAccessibilitySize ? SkyMetrics.compactScreenPadding : 14 + dynamicTypeSize.isAccessibilitySize ? SkyMetrics.compactScreenPadding : 16 } /// 1行に並べる分のマスの数です。 @@ -83,17 +87,12 @@ struct TimetableTabView: View { isWarning: false ) } else { - // 通知をまだ使っていない間だけ、操作の仕方を大きく案内します。 - // 運休日は通知を設定できないため、案内も出しません。 - if scheduledBusIDs.isEmpty, !viewModel.isServiceSuspended { - notificationHint - } timetableGrid legend } } .padding(.horizontal, horizontalPadding) - .padding(.top, 10) + .padding(.top, 8) .padding(.bottom, SkyMetrics.scrollBottomInset) // 横に広い画面では、1行が長くなりすぎないところで幅を止めて中央に置きます。 .frame(maxWidth: SkyMetrics.contentMaxWidth) @@ -111,55 +110,50 @@ struct TimetableTabView: View { // MARK: - 見出し private var header: some View { - VStack(alignment: .leading, spacing: 10) { + VStack(alignment: .leading, spacing: 8) { SkySectionLabel(text: L10n.Timetable.title) - DynamicTypeStack(verticalAlignment: .firstTextBaseline, spacing: 10) { + DynamicTypeStack(verticalAlignment: .firstTextBaseline, spacing: 12) { Text(viewModel.selectedRoute.rawValue) - .dynamicFont(size: 19, relativeTo: .title3, weight: .bold, design: .rounded) + .dynamicFont(size: 20, relativeTo: .title3, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) .fixedSize(horizontal: false, vertical: true) .frame(maxWidth: .infinity, alignment: .leading) Text(L10n.Timetable.serviceCount(viewModel.currentFullTimetable.count)) - .dynamicFont(size: 13, relativeTo: .footnote, weight: .bold, design: .rounded) + .dynamicFont(size: 13, relativeTo: .footnote, weight: .medium, design: .rounded) .monospacedDigit() - .foregroundStyle(sky.accentReadable) + .foregroundStyle(sky.inkSecondary) } - SkyNoticeRow( - message: L10n.Timetable.routeHint, - systemImage: "arrow.left.arrow.right" - ) - } - .frame(maxWidth: .infinity, alignment: .leading) - .skyCard() - } - - /// 通知を一度も設定していない人へ、操作の仕方を伝える案内です。 - /// 1件でも設定されていれば表示しません。 - private var notificationHint: some View { - DynamicTypeStack(verticalAlignment: .top, spacing: 12) { - Image(systemName: "bell.badge") - .dynamicFont(size: 20, relativeTo: .title3, weight: .semibold) - .foregroundStyle(sky.accentReadable) - - VStack(alignment: .leading, spacing: 5) { - Text(L10n.Timetable.notificationHintTitle) - .dynamicFont(size: 15, relativeTo: .subheadline, weight: .bold, design: .rounded) - .foregroundStyle(sky.ink) - .fixedSize(horizontal: false, vertical: true) + VStack(alignment: .leading, spacing: 4) { + SkyNoticeRow( + message: L10n.Timetable.routeHint, + systemImage: "arrow.left.arrow.right" + ) - Text(L10n.Timetable.notificationHintBody) - .dynamicFont(size: 12, relativeTo: .caption, weight: .medium) - .foregroundStyle(sky.inkSecondary) - .fixedSize(horizontal: false, vertical: true) + // 通知をまだ使っていない間だけ、操作の仕方を一行で添えます。 + // 表そのものを押し下げないよう、別のカードにはしません。 + // 運休日は通知を設定できないため、案内も出しません。 + if showsNotificationHint { + SkyNoticeRow( + message: L10n.Timetable.notificationHintTitle, + systemImage: "bell" + ) + } } - .frame(maxWidth: .infinity, alignment: .leading) + .padding(.top, 4) } .frame(maxWidth: .infinity, alignment: .leading) .skyCard() - .accessibilityElement(children: .combine) + } + + /// 通知の操作の仕方を案内するかどうかです。 + /// 1件でも設定されていれば、もう操作を知っているので表示しません。 + private var showsNotificationHint: Bool { + !viewModel.currentFullTimetable.isEmpty + && scheduledBusIDs.isEmpty + && !viewModel.isServiceSuspended } // MARK: - 時刻表 @@ -186,9 +180,9 @@ struct TimetableTabView: View { return HStack(alignment: .top, spacing: hourLabelSpacing) { // 時刻の数字そのものです。翻訳の対象ではないので verbatim で渡します。 Text(verbatim: "\(group.hour)") - .dynamicFont(size: 17, relativeTo: .body, weight: .bold, design: .rounded) + .dynamicFont(size: 16, relativeTo: .body, weight: .semibold, design: .rounded) .monospacedDigit() - .foregroundStyle(isCurrentHour ? sky.accent : sky.inkSecondary) + .foregroundStyle(isCurrentHour ? sky.accentReadable : sky.inkSecondary) .lineLimit(1) .minimumScaleFactor(0.7) .frame(width: hourLabelWidth, alignment: .trailing) @@ -210,7 +204,7 @@ struct TimetableTabView: View { .frame(maxWidth: .infinity, alignment: .leading) } .padding(.horizontal, rowPadding) - .padding(.vertical, 5) + .padding(.vertical, rowVerticalPadding) .frame(maxWidth: .infinity, alignment: .leading) .background(isCurrentHour ? sky.accentSoft : Color.clear) .accessibilityElement(children: .contain) @@ -228,7 +222,7 @@ struct TimetableTabView: View { } label: { VStack(spacing: 0) { Text(minuteText(for: bus)) - .dynamicFont(size: 16, relativeTo: .body, weight: .bold, design: .rounded) + .dynamicFont(size: 16, relativeTo: .body, weight: .medium, design: .rounded) .monospacedDigit() .foregroundStyle(isScheduled ? sky.accentInk : sky.ink) @@ -249,7 +243,7 @@ struct TimetableTabView: View { .overlay( RoundedRectangle(cornerRadius: cellRadius, style: .continuous) .stroke( - isRecommended && !isScheduled ? sky.accent : sky.ink.opacity(0.26), + cellStrokeColor(isRecommended: isRecommended && !isScheduled), style: cellStrokeStyle(isRecommended: isRecommended && !isScheduled) ) ) @@ -257,7 +251,7 @@ struct TimetableTabView: View { .overlay(alignment: .topTrailing) { if differentiateWithoutColor, isScheduled { Image(systemName: "bell.fill") - .dynamicFont(size: 9, relativeTo: .caption2, weight: .bold) + .dynamicFont(size: 9, relativeTo: .caption2, weight: .medium) .foregroundStyle(sky.accentInk) .padding(4) } @@ -277,7 +271,7 @@ struct TimetableTabView: View { } private var legend: some View { - VStack(alignment: .leading, spacing: 6) { + VStack(alignment: .leading, spacing: 8) { // 色を使わず区別する設定では、色ではなく形の説明に切り替えます。 SkyNoticeRow( message: differentiateWithoutColor @@ -300,6 +294,20 @@ struct TimetableTabView: View { } } + /// マスの枠線の色です。 + /// + /// 駅の時刻表と同じく、ふだんの分は枠で囲まずに数字だけを並べます。 + /// 枠を引くのは検索条件に合う便だけにして、表の中で目立つものを絞ります。 + /// 「ボタンの形」がオンのときは、押せる範囲が分かるようすべてのマスに枠を引きます。 + private func cellStrokeColor(isRecommended: Bool) -> Color { + if isRecommended { + return sky.accent + } + return showButtonShapes + ? sky.ink.opacity(SkyButtonOutline.emphasized) + : Color.clear + } + /// マスの枠線です。 /// 色を使わず区別する設定では、検索条件に合う便を破線で示します。 private func cellStrokeStyle(isRecommended: Bool) -> StrokeStyle { diff --git a/BusTimeApp/Features/Tutorial/TutorialView.swift b/BusTimeApp/Features/Tutorial/TutorialView.swift index 900b450..f19dbdd 100644 --- a/BusTimeApp/Features/Tutorial/TutorialView.swift +++ b/BusTimeApp/Features/Tutorial/TutorialView.swift @@ -43,7 +43,7 @@ struct TutorialView: View { } } .padding(.horizontal, SkyMetrics.screenPadding) - .padding(.top, 18) + .padding(.top, 16) } private var advanceButton: some View { @@ -60,18 +60,18 @@ struct TutorialView: View { Spacer() Image(systemName: viewModel.isLastPage ? "checkmark" : "arrow.right") } - .dynamicFont(size: 15, relativeTo: .subheadline, weight: .bold, design: .rounded) + .dynamicFont(size: 15, relativeTo: .subheadline, weight: .semibold, design: .rounded) .foregroundStyle(sky.accentInk) .padding(.horizontal, 20) .frame(maxWidth: .infinity, minHeight: 52) .background( - RoundedRectangle(cornerRadius: 16, style: .continuous) + RoundedRectangle(cornerRadius: SkyMetrics.innerRadius, style: .continuous) .fill(sky.accent) ) } .buttonStyle(SkyPressStyle()) .padding(.horizontal, SkyMetrics.screenPadding) - .padding(.bottom, 22) + .padding(.bottom, 24) } } @@ -90,7 +90,7 @@ struct TutorialPage: View { var body: some View { ScrollView(showsIndicators: false) { - VStack(spacing: dynamicTypeSize.isAccessibilitySize ? 18 : 24) { + VStack(spacing: dynamicTypeSize.isAccessibilitySize ? 16 : 24) { Spacer(minLength: dynamicTypeSize.isAccessibilitySize ? 12 : 48) Image(systemName: systemName) @@ -98,13 +98,13 @@ struct TutorialPage: View { .foregroundStyle(sky.accentReadable) Text(title) - .dynamicFont(size: 26, relativeTo: .title, weight: .bold, design: .rounded) + .dynamicFont(size: 28, relativeTo: .title, weight: .semibold, design: .rounded) .foregroundStyle(sky.ink) .multilineTextAlignment(.center) .fixedSize(horizontal: false, vertical: true) Text(description) - .dynamicFont(size: 14, relativeTo: .subheadline, weight: .medium) + .dynamicFont(size: 15, relativeTo: .subheadline, weight: .regular) .foregroundStyle(sky.inkSecondary) .multilineTextAlignment(.center) .fixedSize(horizontal: false, vertical: true) diff --git a/BusTimeApp/Localization/L10n.swift b/BusTimeApp/Localization/L10n.swift index 8d3dece..4689318 100644 --- a/BusTimeApp/Localization/L10n.swift +++ b/BusTimeApp/Localization/L10n.swift @@ -26,6 +26,46 @@ public enum L10n { } /// 次に出るバスが見つかりませんでした。 public static var noService: String { String(localized: "shortcut.noService") } + /// 経路 + public static var routeParameter: String { String(localized: "shortcut.routeParameter") } + /// 指定しないときは、アプリと同じ判断(自分で選んだ経路、なければ時間帯と前回の行き先)で決めます。 + public static var routeAutoDescription: String { String(localized: "shortcut.routeAutoDescription") } + /// コロンブスシティ → 海浜幕張駅 + public static var routeMansionToStation: String { String(localized: "shortcut.routeMansionToStation") } + /// 海浜幕張駅 → コロンブスシティ + public static var routeStationToMansion: String { String(localized: "shortcut.routeStationToMansion") } + /// コロンブスシティ → ヨーカドー前 + public static var routeMansionToYokado: String { String(localized: "shortcut.routeMansionToYokado") } + /// 海浜幕張駅 → ヨーカドー前 + public static var routeStationToYokado: String { String(localized: "shortcut.routeStationToYokado") } + /// ヨーカドー前 → コロンブスシティ + public static var routeYokadoToMansion: String { String(localized: "shortcut.routeYokadoToMansion") } + /// 通知のタイミング + public static var leadTimeParameter: String { String(localized: "shortcut.leadTimeParameter") } + /// 5分前 + public static var leadTimeFiveMinutes: String { String(localized: "shortcut.leadTimeFiveMinutes") } + /// 10分前 + public static var leadTimeTenMinutes: String { String(localized: "shortcut.leadTimeTenMinutes") } + /// 15分前 + public static var leadTimeFifteenMinutes: String { String(localized: "shortcut.leadTimeFifteenMinutes") } + /// Live Activityも開始 + public static var liveActivityParameter: String { String(localized: "shortcut.liveActivityParameter") } + /// 経路を指定して開く + public static var openRouteTitle: String { String(localized: "shortcut.openRouteTitle") } + /// 選んだ経路のホームをアプリで開きます。 + public static var openRouteDescription: String { String(localized: "shortcut.openRouteDescription") } + /// 次の便の通知を設定 + public static var startAlertTitle: String { String(localized: "shortcut.startAlertTitle") } + /// 選んだ経路の次の便に通知を設定します。Live Activityも一緒に開始できます。 + public static var startAlertDescription: String { String(localized: "shortcut.startAlertDescription") } + /// %1$@の%2$@発の便に、%3$lld分前の通知を設定しました。 + public static func alertScheduled(_ arg0: String, _ arg1: String, _ arg2: Int) -> String { + String.localizedStringWithFormat(String(localized: "shortcut.alertScheduled"), arg0, arg1, arg2) + } + /// この経路には、今日これから通知を設定できる便がありません。 + public static var noBusToAlert: String { String(localized: "shortcut.noBusToAlert") } + /// アプリでの処理が完了しませんでした。アプリを開いて確認してください。 + public static var noResponse: String { String(localized: "shortcut.noResponse") } } public enum Common { @@ -129,9 +169,9 @@ public enum L10n { public static var departureTimeTitle: String { String(localized: "when.departureTimeTitle") } /// この時刻までに到着 public static var arrivalTimeTitle: String { String(localized: "when.arrivalTimeTitle") } - /// 指定した時刻以降に出発する便を、早い順に表示します + /// 出発の早い順 public static var departureExplanation: String { String(localized: "when.departureExplanation") } - /// 指定した時刻までに目的地へ着く便を、到着時刻が近い順に表示します + /// 到着が指定時刻に近い順 public static var arrivalExplanation: String { String(localized: "when.arrivalExplanation") } /// 現在時刻 public static var currentTime: String { String(localized: "when.currentTime") } @@ -231,11 +271,11 @@ public enum L10n { public static var resultInitial: String { String(localized: "search.resultInitial") } /// 条件に合う便がありません。時刻または目的地を変更してください public static var noResults: String { String(localized: "search.noResults") } - /// %lld便見つかりました。運休日のため平日ダイヤの時刻です + /// 平日ダイヤの%lld便・本日は運休 public static func resultCountSuspended(_ arg0: Int) -> String { String.localizedStringWithFormat(String(localized: "search.resultCountSuspended"), arg0) } - /// %1$lld便見つかりました。%2$@ + /// %1$lld便・%2$@ public static func resultCount(_ arg0: Int, _ arg1: String) -> String { String.localizedStringWithFormat(String(localized: "search.resultCount"), arg0, arg1) } @@ -472,12 +512,10 @@ public enum L10n { public static func serviceCount(_ arg0: Int) -> String { String.localizedStringWithFormat(String(localized: "timetable.serviceCount"), arg0) } - /// 経路を変えるときは、ホームタブで出発地と目的地を選んでください + /// 経路はホームで変更できます public static var routeHint: String { String(localized: "timetable.routeHint") } /// 時刻をタップすると通知できます public static var notificationHintTitle: String { String(localized: "timetable.notificationHintTitle") } - /// 選んだ便が出発する前にお知らせします。設定した時刻は色が変わります。 - public static var notificationHintBody: String { String(localized: "timetable.notificationHintBody") } /// %lld時台 public static func hourAccessibility(_ arg0: Int) -> String { String.localizedStringWithFormat(String(localized: "timetable.hourAccessibility"), arg0) @@ -503,6 +541,14 @@ public enum L10n { } public enum Settings { + /// プライバシー・利用規約 + public static var legalSection: String { String(localized: "settings.legalSection") } + /// プライバシーポリシー + public static var privacyPolicy: String { String(localized: "settings.privacyPolicy") } + /// 利用規約 + public static var termsOfUse: String { String(localized: "settings.termsOfUse") } + /// ブラウザで開発者のWebサイトを開きます。本文は日本語で掲載しています。 + public static var legalWebsiteNotice: String { String(localized: "settings.legalWebsiteNotice") } /// 設定 public static var title: String { String(localized: "settings.title") } /// 画面の色 diff --git a/BusTimeApp/Localization/Localizable.xcstrings b/BusTimeApp/Localization/Localizable.xcstrings index 0df345b..9842aa7 100644 --- a/BusTimeApp/Localization/Localizable.xcstrings +++ b/BusTimeApp/Localization/Localizable.xcstrings @@ -3480,13 +3480,13 @@ "one": { "stringUnit": { "state": "translated", - "value": "Found %1$lld service. %2$@" + "value": "%1$lld service · %2$@" } }, "other": { "stringUnit": { "state": "translated", - "value": "Found %1$lld services. %2$@" + "value": "%1$lld services · %2$@" } } } @@ -3495,13 +3495,13 @@ "ja": { "stringUnit": { "state": "translated", - "value": "%1$lld便見つかりました。%2$@" + "value": "%1$lld便・%2$@" } }, "zh-Hans": { "stringUnit": { "state": "translated", - "value": "找到%1$lld个班次。%2$@" + "value": "%1$lld个班次 · %2$@" } } } @@ -3515,13 +3515,13 @@ "one": { "stringUnit": { "state": "translated", - "value": "Found %lld service. There is no service today, so these are weekday times." + "value": "%lld weekday service · no service today" } }, "other": { "stringUnit": { "state": "translated", - "value": "Found %lld services. There is no service today, so these are weekday times." + "value": "%lld weekday services · no service today" } } } @@ -3530,13 +3530,13 @@ "ja": { "stringUnit": { "state": "translated", - "value": "%lld便見つかりました。運休日のため平日ダイヤの時刻です" + "value": "平日ダイヤの%lld便・本日は運休" } }, "zh-Hans": { "stringUnit": { "state": "translated", - "value": "找到%lld个班次。今日停运,显示的是工作日时刻。" + "value": "工作日时刻的%lld个班次 · 今日停运" } } } @@ -3886,6 +3886,52 @@ } } }, + "settings.legalSection": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Privacy & Terms" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "プライバシー・利用規約" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "隐私与条款" + } + } + } + }, + "settings.legalWebsiteNotice": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Opens the developer’s website in your browser. Documents are available in Japanese." + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "ブラウザで開発者のWebサイトを開きます。本文は日本語で掲載しています。" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "将在浏览器中打开开发者的网站。文档以日语提供。" + } + } + } + }, "settings.liveActivityAvailable": { "extractionState": "manual", "localizations": { @@ -4093,6 +4139,52 @@ } } }, + "settings.privacyPolicy": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Privacy Policy" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "プライバシーポリシー" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "隐私政策" + } + } + } + }, + "settings.termsOfUse": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Terms of Use" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "利用規約" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "使用条款" + } + } + } + }, "settings.title": { "extractionState": "manual", "localizations": { @@ -4208,6 +4300,29 @@ } } }, + "shortcut.alertScheduled": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Alert set for the %2$@ bus on %1$@, %3$lld minutes before it leaves." + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "%1$@の%2$@発の便に、%3$lld分前の通知を設定しました。" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "已为%1$@ %2$@出发的班次设置提前%3$lld分钟的提醒。" + } + } + } + }, "shortcut.answer": { "extractionState": "manual", "localizations": { @@ -4231,6 +4346,121 @@ } } }, + "shortcut.leadTimeFifteenMinutes": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "15 minutes before" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "15分前" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "提前15分钟" + } + } + } + }, + "shortcut.leadTimeFiveMinutes": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "5 minutes before" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "5分前" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "提前5分钟" + } + } + } + }, + "shortcut.leadTimeParameter": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Alert timing" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "通知のタイミング" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "提醒时间" + } + } + } + }, + "shortcut.leadTimeTenMinutes": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "10 minutes before" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "10分前" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "提前10分钟" + } + } + } + }, + "shortcut.liveActivityParameter": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Also start a Live Activity" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "Live Activityも開始" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "同时启动实时活动" + } + } + } + }, "shortcut.nextBusDescription": { "extractionState": "manual", "localizations": { @@ -4277,6 +4507,52 @@ } } }, + "shortcut.noBusToAlert": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "There is no bus left today on this route that an alert can be set for." + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "この経路には、今日これから通知を設定できる便がありません。" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "今天该路线已没有可以设置提醒的班次。" + } + } + } + }, + "shortcut.noResponse": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "The app did not finish in time. Please open the app and check." + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "アプリでの処理が完了しませんでした。アプリを開いて確認してください。" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "应用未能及时完成处理。请打开应用确认。" + } + } + } + }, "shortcut.noService": { "extractionState": "manual", "localizations": { @@ -4300,6 +4576,52 @@ } } }, + "shortcut.openRouteDescription": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Opens the app on the home screen for the route you choose." + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "選んだ経路のホームをアプリで開きます。" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "在应用中打开所选路线的主页。" + } + } + } + }, + "shortcut.openRouteTitle": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Open a route" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "経路を指定して開く" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "打开指定路线" + } + } + } + }, "shortcut.phrase": { "extractionState": "manual", "localizations": { @@ -4323,6 +4645,213 @@ } } }, + "shortcut.routeAutoDescription": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "If left empty, the route is chosen the way the app does it: your own choice first, otherwise by time of day and your last destination." + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "指定しないときは、アプリと同じ判断(自分で選んだ経路、なければ時間帯と前回の行き先)で決めます。" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "不指定时,将与应用采用相同的判断(优先使用您自己选择的路线,否则按时间段和上次的目的地决定)。" + } + } + } + }, + "shortcut.routeMansionToStation": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "コロンブスシティ → 海浜幕張駅" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "コロンブスシティ → 海浜幕張駅" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "コロンブスシティ → 海浜幕張駅" + } + } + } + }, + "shortcut.routeMansionToYokado": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "コロンブスシティ → ヨーカドー前" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "コロンブスシティ → ヨーカドー前" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "コロンブスシティ → ヨーカドー前" + } + } + } + }, + "shortcut.routeParameter": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Route" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "経路" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "路线" + } + } + } + }, + "shortcut.routeStationToMansion": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "海浜幕張駅 → コロンブスシティ" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "海浜幕張駅 → コロンブスシティ" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "海浜幕張駅 → コロンブスシティ" + } + } + } + }, + "shortcut.routeStationToYokado": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "海浜幕張駅 → ヨーカドー前" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "海浜幕張駅 → ヨーカドー前" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "海浜幕張駅 → ヨーカドー前" + } + } + } + }, + "shortcut.routeYokadoToMansion": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "ヨーカドー前 → コロンブスシティ" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "ヨーカドー前 → コロンブスシティ" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "ヨーカドー前 → コロンブスシティ" + } + } + } + }, + "shortcut.startAlertDescription": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Sets an alert for the next bus on the route you choose. It can also start a Live Activity." + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "選んだ経路の次の便に通知を設定します。Live Activityも一緒に開始できます。" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "为所选路线的下一班车设置提醒,也可以同时启动实时活动。" + } + } + } + }, + "shortcut.startAlertTitle": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Set an alert for the next bus" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "次の便の通知を設定" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "为下一班车设置提醒" + } + } + } + }, "sync.bundledTimetable": { "extractionState": "manual", "localizations": { @@ -4875,29 +5404,6 @@ } } }, - "timetable.notificationHintBody": { - "extractionState": "manual", - "localizations": { - "en": { - "stringUnit": { - "state": "translated", - "value": "You will be alerted before the service departs. Times with an alert change colour." - } - }, - "ja": { - "stringUnit": { - "state": "translated", - "value": "選んだ便が出発する前にお知らせします。設定した時刻は色が変わります。" - } - }, - "zh-Hans": { - "stringUnit": { - "state": "translated", - "value": "将在所选班次出发前通知您。已设置的时刻会变色。" - } - } - } - }, "timetable.notificationHintTitle": { "extractionState": "manual", "localizations": { @@ -4927,19 +5433,19 @@ "en": { "stringUnit": { "state": "translated", - "value": "To change the route, choose the stops on the Home tab" + "value": "Change the route on Home" } }, "ja": { "stringUnit": { "state": "translated", - "value": "経路を変えるときは、ホームタブで出発地と目的地を選んでください" + "value": "経路はホームで変更できます" } }, "zh-Hans": { "stringUnit": { "state": "translated", - "value": "要更改路线,请在首页标签页选择出发地和目的地" + "value": "可在首页更改路线" } } } @@ -5330,19 +5836,19 @@ "en": { "stringUnit": { "state": "translated", - "value": "Shows services arriving by the time you set, closest arrival first" + "value": "closest to your arrival time first" } }, "ja": { "stringUnit": { "state": "translated", - "value": "指定した時刻までに目的地へ着く便を、到着時刻が近い順に表示します" + "value": "到着が指定時刻に近い順" } }, "zh-Hans": { "stringUnit": { "state": "translated", - "value": "按到达时间由近及远显示能在指定时间前抵达的班次" + "value": "按到达时间由近及远" } } } @@ -5422,19 +5928,19 @@ "en": { "stringUnit": { "state": "translated", - "value": "Shows services departing after the time you set, earliest first" + "value": "earliest first" } }, "ja": { "stringUnit": { "state": "translated", - "value": "指定した時刻以降に出発する便を、早い順に表示します" + "value": "出発の早い順" } }, "zh-Hans": { "stringUnit": { "state": "translated", - "value": "按最早顺序显示在指定时间之后出发的班次" + "value": "按出发先后" } } } diff --git a/BusTimeAppTests/BusTimeAppTests.swift b/BusTimeAppTests/BusTimeAppTests.swift index 9b108a3..732fea4 100644 --- a/BusTimeAppTests/BusTimeAppTests.swift +++ b/BusTimeAppTests/BusTimeAppTests.swift @@ -1274,6 +1274,32 @@ struct BusTimeAppTests { #expect(viewModel.followingSectionTitle == "このあとの便") } + @Test @MainActor + func searchCalculatesRemainingMinutesWithoutWaitingForTimer() { + let viewModel = HomeViewModel( + nowProvider: { makeTestDate(hour: 8) }, + defaults: makeIsolatedDefaults() + ) + viewModel.performSearch() + + // 経路や検索方法を変えると別の便が並びます。 + // 定期更新を待たずに、新しい便の残り時間が入っていることを確かめます。 + viewModel.selectOrigin(.mansion) + viewModel.performSearch() + #expect(!viewModel.searchResults.isEmpty) + for bus in viewModel.searchResults { + #expect(viewModel.remainingMinutes[bus.id] != nil, "\(bus.departure)発の残り時間がありません") + } + + viewModel.searchType = .arrival + viewModel.searchTime = makeTestDate(hour: 9) + viewModel.performSearch() + #expect(!viewModel.searchResults.isEmpty) + for bus in viewModel.searchResults { + #expect(viewModel.remainingMinutes[bus.id] != nil, "\(bus.departure)発の残り時間がありません") + } + } + // MARK: - 深夜の検索 @Test @MainActor @@ -2132,6 +2158,238 @@ struct BusTimeAppTests { #expect(answer != L10n.Shortcut.noService) } + // MARK: - ショートカット(経路を指定するアクション) + + @Test + func shortcutAnswerForAnExplicitRouteUsesThatRoute() { + // 経路を指定したときは、アプリの自動判断ではなくその経路の次の便を答えます。 + let answer = NextBusAnswer.answer(for: .stationToYokado, at: makeTestDate(hour: 10)) + + #expect(answer?.text.contains("海浜幕張駅 → ヨーカドー前") == true) + // 買い物便は海浜幕張駅を毎時38分に出るので、10時の次は10:38です。 + #expect(answer?.departureDate == makeTestDate(hour: 10, minute: 38)) + } + + @Test + func shortcutRouteOptionsCoverEveryRouteOfTheApp() { + // 経路が増えたときにショートカットの選択肢へ入れ忘れると、ここで気づけます。 + #expect(BusRouteOption.allCases.count == BusRoute.allCases.count) + for route in BusRoute.allCases { + #expect(BusRouteOption(route: route).route == route) + } + } + + @Test + func shortcutOptionsKeepTheirStoredIdentifiers() { + // 利用者のショートカットに保存される値です。変えると作成済みのショートカットが壊れます。 + #expect(BusRouteOption.allCases.map(\.rawValue) == [ + "mansionToStation", + "stationToMansion", + "mansionToYokado", + "stationToYokado", + "yokadoToMansion" + ]) + #expect(BusAlertLeadTime.allCases.map(\.rawValue) == [ + "fiveMinutes", + "tenMinutes", + "fifteenMinutes" + ]) + } + + @Test + func shortcutLeadTimesAreTheSameChoicesAsTheAppsAlerts() { + #expect(BusAlertLeadTime.allCases.map(\.minutes) == [5, 10, 15]) + } + + @Test + func busAlertSelectionPicksTheNextBusOnTheRoute() { + let result = ShortcutBusSelector.select( + on: .stationToYokado, + minutesBefore: 5, + now: makeTestDate(hour: 10) + ) + + guard case let .success(bus) = result else { + Issue.record("次の便が選ばれませんでした") + return + } + #expect(bus.departure == "10:38") + } + + @Test + func busAlertSelectionSkipsABusWhoseAlertTimeHasPassed() { + // 10:25の時点で15分前の通知は、10:38発なら10:23で過ぎています。 + // 通知が間に合う次の便(11:38発)を選びます。 + let result = ShortcutBusSelector.select( + on: .stationToYokado, + minutesBefore: 15, + now: makeTestDate(hour: 10, minute: 25) + ) + + guard case let .success(bus) = result else { + Issue.record("通知が間に合う便が選ばれませんでした") + return + } + #expect(bus.departure == "11:38") + } + + @Test + func busAlertSelectionKeepsMinutePrecisionAtTheAlertBoundary() throws { + let alertTime = makeTestDate(hour: 10, minute: 23) + let withinAlertMinute = try ShortcutBusSelector.select( + on: .stationToYokado, + minutesBefore: 15, + now: alertTime.addingTimeInterval(59) + ).get() + let afterAlertMinute = try ShortcutBusSelector.select( + on: .stationToYokado, + minutesBefore: 15, + now: alertTime.addingTimeInterval(60) + ).get() + + #expect(withinAlertMinute.departure == "10:38") + #expect(afterAlertMinute.departure == "11:38") + } + + @Test + func busAlertSelectionUsesThePreviousServiceDayForLateNightBuses() throws { + // 土曜0時台でも、金曜の運行日に属する最終便は通知の対象です。 + let bus = try ShortcutBusSelector.select( + on: .stationToMansion, + minutesBefore: 5, + now: makeTestDate(day: 15, hour: 0) + ).get() + + #expect(bus.departure == "0:13") + } + + @Test + func busAlertSelectionDoesNotCarryOverAfterTheLastLateNightBus() { + let result = ShortcutBusSelector.select( + on: .stationToMansion, + minutesBefore: 5, + now: makeTestDate(day: 15, hour: 0, minute: 14) + ) + + guard case let .failure(failure) = result else { + Issue.record("最終便の後に、別の運行日の便が選ばれました") + return + } + #expect(failure == .noBusAvailable) + } + + @Test + func busAlertSelectionRefusesANonServiceDay() { + // 2026年8月15日は土曜日で、運休日です。 + let result = ShortcutBusSelector.select( + on: .mansionToStation, + minutesBefore: 5, + now: makeTestDate(day: 15, hour: 10) + ) + + guard case let .failure(failure) = result else { + Issue.record("運休日なのに便が選ばれました") + return + } + #expect(failure == .noService) + } + + @Test + func busAlertSelectionDoesNotCarryOverToTheNextServiceDay() { + // ヨーカドー前行きは16:30発が最終です。17時には翌運行日の便へ繰り越さず断ります。 + // 画面でも、他の運行日の便には通知を設定できないためです。 + let result = ShortcutBusSelector.select( + on: .mansionToYokado, + minutesBefore: 5, + now: makeTestDate(hour: 17) + ) + + guard case let .failure(failure) = result else { + Issue.record("今日の便がないのに、別の運行日の便が選ばれました") + return + } + #expect(failure == .noBusAvailable) + } + + @Test + func shortcutOutcomeThrowsInsteadOfPretendingToSucceed() throws { + // 自動化の途中で失敗に気づけるよう、失敗は成功の文ではなくエラーにします。 + #expect(try ShortcutOutcome.succeeded("設定しました").requireSuccessMessage() == "設定しました") + #expect(throws: ShortcutActionError.self) { + try ShortcutOutcome.failed("理由").requireSuccessMessage() + } + #expect(throws: ShortcutActionError.self) { + try ShortcutOutcome.noResponse.requireSuccessMessage() + } + } + + @Test @MainActor + func shortcutRequestIsHandedToTheAppAndTheResultReturnsToTheShortcut() async { + let center = ShortcutRequestCenter() + let waiting = Task { @MainActor in + await center.submit(.openRoute(.mansionToStation)) + } + await waitUntilPending(center) + + let request = center.takePendingRequest() + #expect(request?.action == .openRoute(.mansionToStation)) + // 受け取った依頼は、預かり中ではなくなります。 + #expect(center.pendingRequest == nil) + #expect(center.takePendingRequest() == nil) + + if let request { + center.finish(request.id, with: .succeeded("開きました")) + // 同じ依頼に再度結果を返しても、再開は一度だけです。 + center.finish(request.id, with: .failed("二度目")) + } + #expect(await waiting.value == .succeeded("開きました")) + } + + @Test @MainActor + func shortcutRequestTimesOutWhenTheAppNeverAnswers() async { + let center = ShortcutRequestCenter(responseTimeout: .milliseconds(50)) + + let outcome = await center.submit(.openRoute(.mansionToStation)) + + #expect(outcome == .noResponse) + #expect(center.pendingRequest == nil) + } + + @Test @MainActor + func aNewShortcutRequestReplacesOneTheAppHasNotTakenYet() async { + let center = ShortcutRequestCenter() + let first = Task { @MainActor in + await center.submit(.openRoute(.mansionToStation)) + } + await waitUntilPending(center) + + let second = Task { @MainActor in + await center.submit(.openRoute(.stationToMansion)) + } + // 受け取られないまま置き換えられた依頼は、待たせ続けずに返します。 + #expect(await first.value == .noResponse) + + await waitUntilPending(center) + let request = center.takePendingRequest() + #expect(request?.action == .openRoute(.stationToMansion)) + + if let request { + center.finish(request.id, with: .succeeded("開きました")) + } + #expect(await second.value == .succeeded("開きました")) + } + + /// 依頼が預けられるまで、他の処理へ実行を譲って待ちます。 + @MainActor + private func waitUntilPending(_ center: ShortcutRequestCenter) async { + let maximumYields = 1_000 + var yields = 0 + while center.pendingRequest == nil && yields < maximumYields { + await Task.yield() + yields += 1 + } + } + // MARK: - ウィジェットのタップ先 @Test @@ -2310,9 +2568,12 @@ struct BusTimeAppTests { @Test @MainActor func weekendKeepsTheNoticeAndStillShowsWeekdayTimes() { let saturday = makeTestDate(day: 15, hour: 8) + // 同梱ダイヤの運休判定を確かめるため、端末に保存されたAPIの時刻表は使いません。 + // 保存済みの時刻表があると、運休の理由が「運行ダイヤの設定」に変わってしまいます。 let viewModel = HomeViewModel( nowProvider: { saturday }, - defaults: makeIsolatedDefaults() + defaults: makeIsolatedDefaults(), + timetableRepository: nil ) viewModel.searchTime = saturday viewModel.performSearch() diff --git a/BusTimeAppUITests/BusTimeAppUITests.swift b/BusTimeAppUITests/BusTimeAppUITests.swift index 0f802b4..837cdc7 100644 --- a/BusTimeAppUITests/BusTimeAppUITests.swift +++ b/BusTimeAppUITests/BusTimeAppUITests.swift @@ -75,7 +75,7 @@ final class BusTimeAppUITests: XCTestCase { timetableTab.tap() // 時刻表タブだけに出る案内文で、画面が切り替わったことを確かめます。 - let timetableGuidance = app.staticTexts["経路を変えるときは、ホームタブで出発地と目的地を選んでください"] + let timetableGuidance = app.staticTexts["経路はホームで変更できます"] XCTAssertTrue(timetableGuidance.waitForExistence(timeout: 5)) app.buttons["ホームタブ"].tap() @@ -297,19 +297,19 @@ final class BusTimeAppUITests: XCTestCase { language: "ja", locale: "ja_JP", timetableTab: "時刻表タブ", - timetableHint: "経路を変えるときは、ホームタブで出発地と目的地を選んでください" + timetableHint: "経路はホームで変更できます" ), ( language: "en", locale: "en_US", timetableTab: "Timetable tab", - timetableHint: "To change the route, choose the stops on the Home tab" + timetableHint: "Change the route on Home" ), ( language: "zh-Hans", locale: "zh_CN", timetableTab: "时刻表标签页", - timetableHint: "要更改路线,请在首页标签页选择出发地和目的地" + timetableHint: "可在首页更改路线" ) ] diff --git a/README.md b/README.md index acdee86..57019ff 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,12 @@ ## 対応環境 - iPhone専用 -- iOS 16.2以降 +- iOS 27.0以降 - SwiftUI - アプリ本体、単体テスト、UIテスト、Widget Extensionの4ターゲット - 外部パッケージ依存なし -ホーム画面ウィジェットとLive Activityを同梱しています。ウィジェット拡張自体のDeployment TargetはiOS 16.1です。 +ホーム画面ウィジェットとLive Activityを同梱しています。アプリ本体、ウィジェット拡張、テストのDeployment TargetはすべてiOS 27.0です。 ## 対応する停留所と経路 @@ -110,7 +110,7 @@ - 通知一覧では個別削除と全件削除ができ、期限切れの保存データは起動時に整理します。 - 通知の保存形式にはバージョンを持たせ、旧形式からの移行を実装しています。壊れた保存データを無理に上書きしません。 - Live Activityはロック画面とDynamic Islandの展開・コンパクト・最小表示に対応し、経路、出発/到着、残り時間、出発済み状態を表示します。 -- 残り時間はシステムが時刻に合わせて数え進める表示を使い、アプリが停止していても減っていきます。iOS 18以降は秒を出さない時間・分表記、iOS 16.2〜17は秒を含むタイマーで表示します。 +- 残り時間はシステムが時刻に合わせて数え進める表示を使い、アプリが停止していても減っていきます。秒を出さない時間・分表記で表示します。 - 出発時刻をActivityの期限(`staleDate`)として開始時と更新時の両方で渡し、アプリから更新が届かなくても出発後は「出発済み」に切り替えます。アプリからの更新は残り分が変わったときだけ送り、過剰な更新を避けます。 - 実行中のLive Activityは再起動後に復元できます。別便が表示中、機能が許可されていない、すでに出発済みなどの失敗理由も案内します。 - 対応端末ではLive Activityを初期状態で有効にし、設定画面のToggleでいつでも変更・保存できます。 @@ -124,7 +124,11 @@ - ウィジェットは許可済みの場合だけ位置情報を1回取得し、キャッシュがあれば待たずに利用します。手動経路がある場合は位置情報より優先します。 - アプリとウィジェットはApp Groupで前回の行き先と手動経路を共有します。共有領域が利用できない場合もアプリ単体は標準の保存領域へフォールバックします。 - ウィジェットをタップすると独自URLで表示中の経路を渡し、アプリのホームを同じ経路で開きます。URLには日本語ではなく安定した停留所IDを使います。 -- App Intent「次のバス」を日本語・英語の呼びかけで登録しています。アプリを開かず、経路、出発、到着、残り時間を1文で返します。 +- 「ショートカット」アプリのアクションとして、次の3つを登録しています。Siriは日本語・英語の呼びかけで起動できます。 + - 「次のバスを調べる」:アプリを開かず、経路、出発、到着、残り時間を1文で返します。経路は省略でき、省略時はアプリと同じ判断で決めます。出発日時を値として返すので、後続のアクションへ渡せます。 + - 「経路を指定して開く」:指定した経路のホームを開きます。ウィジェットのタップと同じく「自分で選んだ経路」として扱い、位置情報で上書きしません。 + - 「次の便の通知を設定」:指定した経路の次の便に、5・10・15分前の通知を設定します。Live Activityも同時に開始できます。運休日や今日これから通知できる便がないときは、別の運行日へ繰り越さず失敗として終えます。 +- 状態を変える後ろの2つは、アプリを開いて既存の通知・Live Activity処理で実行します。通知の保存内容は画面のViewModelが持ち、Live Activityは前面でないと開始できないためです。依頼は`ShortcutRequestCenter`が受け渡し、15秒以内に処理されなければショートカットを失敗として終えます。 ### 7. 時刻・季節・実際の天気で変わるピクセルアート @@ -180,7 +184,7 @@ - 夕暮れの途中で文字色だけが灰色へ溶けないよう、文字とカード面を同じしきい値で一括切り替えします。 - 背景との相対輝度からアクセント上の文字色を白/黒で選びます。1日24時間×四季について、本文、アクセント、警告・成功色のコントラストを単体テストしています。 - 未選択のチップにも背景を持たせ、景色の明暗に左右されにくくしています。 -- iOS 26以降ではシステムのLiquid Glassに沿うタブを使い、それ以前では同じ世界観のカプセル型タブバーを表示します。 +- システムのLiquid Glassに沿うタブを使います。iOS 26より前のためのカプセル型タブバーはコードに残っていますが、iOS 27.0以上を対象にしているため使われません。 - 画面の本文幅は最大520 ptに抑え、大きいiPhoneでも視線移動が広がりすぎないようにしています。 - ハプティクスはタップ、成功、失敗という明示的な操作結果だけに使い、自動更新では鳴らしません。 @@ -255,7 +259,7 @@ Open-Meteo ─> 天気キャッシュ ─> 時刻・季節連動のピクセル | `Features/Settings` / `Tutorial` | 表示・カード・Live Activity設定と初回ガイド | | `DesignSystem` | 時刻・季節配色、ピクセル背景、カード、ボタン、Dynamic Type、ハプティクス | | `BusTimeWidgetExtension` | ホーム/ロック画面ウィジェット、Live Activity、Dynamic Island | -| `Features/Shortcuts` | App IntentとSiri向けの次便回答 | +| `Features/Shortcuts` | App Intent3種(次便回答、経路を開く、通知・Live Activity開始)と、アプリ画面への依頼の受け渡し | | `Localization` / `Scripts` | 3言語のString Catalogと型付きAPIの生成 | UIへ状態を公開するサービスの多くは`@MainActor`へ寄せ、天気取得はプロトコル、時刻はProvider、保存先は`UserDefaults`注入にして、通信・時計・保存状態をテストから差し替えられるようにしています。SwiftのStrict Concurrency Checkingは`targeted`、コンパイラ警告はエラーとして扱います。 @@ -294,7 +298,7 @@ UIへ状態を公開するサービスの多くは`@MainActor`へ寄せ、天気 | Medium Widget | 経路、次便とその次の便、残り時間 | 同上 | Smallより詳細な便情報を表示 | | Accessory Rectangular | ロック画面向けの次便概要 | 同上 | 表示領域に合わせ情報量を制限 | | Live Activity | 経路、出発・到着、残り分、出発済み状態 | アプリ側から開始・終了 | ロック画面、Dynamic Islandの展開・コンパクト・最小表示に対応 | -| Siri/ショートカット | 経路、出発、到着、残り時間を一文で回答 | 「次のバス」Intentを実行 | UIを開かず共有ダイヤから計算 | +| Siri/ショートカット | 経路、出発、到着、残り時間を一文で回答。通知設定の結果も一文で回答 | 「次のバスを調べる」「経路を指定して開く」「次の便の通知を設定」を実行 | 次便回答はUIを開かず共有ダイヤから計算。後ろの2つはアプリを開き、画面と同じ処理で実行 | ### 検索条件と結果の意味 @@ -471,7 +475,7 @@ Deep Linkは`bustimeapp://route/-`形式です。停留所 | 項目 | アプリ本体 | Widget Extension | | --- | --- | --- | | Bundle ID | `com.hara.BusTimeApp` | `com.hara.BusTimeApp.BusTimeWidgetExtension` | -| Deployment Target | iOS 16.2 | iOS 16.1 | +| Deployment Target | iOS 27.0 | iOS 27.0 | | Device Family | iPhoneのみ | 親アプリに同梱 | | Orientation | Portraitのみ | Widgetの各Familyに従う | | App Group | `group.com.hara.BusTimeApp` | 同左 | @@ -515,7 +519,11 @@ Deep Linkは`bustimeapp://route/-`形式です。停留所 | `Features/Weather/WeatherModels.swift` | 天気状態、雨量段階、WMO解釈、Service Error | | `Features/Weather/WeatherService.swift` | Open-Meteo通信、Response decode、Debug Stub | | `Features/Weather/WeatherViewModel.swift` | 15分更新、1分監視、Cache、Backoff、lifecycle | -| `Features/Shortcuts/NextBusIntent.swift` | App Intent、Siri回答、Shortcut Phrase | +| `Features/Shortcuts/NextBusIntent.swift` | 次便回答のApp Intent、Siri回答、Shortcut Phraseの登録 | +| `Features/Shortcuts/OpenRouteIntent.swift` | 指定経路のホームを開くApp Intent | +| `Features/Shortcuts/StartBusAlertIntent.swift` | 次の便の通知・Live Activityを開始するApp Intentと、対象便の選択 | +| `Features/Shortcuts/ShortcutOptions.swift` | ショートカットで選べる経路・通知タイミング(`AppEnum`)と経路の自動判断 | +| `Features/Shortcuts/ShortcutRequestCenter.swift` | ショートカットから画面への依頼の受け渡し、結果の返却、タイムアウト | ### Shared・Design System・Localization @@ -534,7 +542,7 @@ Deep Linkは`bustimeapp://route/-`形式です。停留所 | `DesignSystem/DynamicTypeSupport.swift` | Scaled font、Bold Text、文字サイズに応じたLayout helper | | `DesignSystem/SkyHaptics.swift` | タップ・成功・失敗のHaptic境界 | | `Localization/L10n.swift` | 生成された型付きLocalization API。直接編集しない | -| `Localization/Localizable.xcstrings` | 235件の画面・通知・Widget・Siri文言を持つ生成済みString Catalog | +| `Localization/Localizable.xcstrings` | 272件の画面・通知・Widget・Siri文言を持つ生成済みString Catalog | | `Localization/InfoPlist.xcstrings` | 位置情報の使用理由を日本語・英語・簡体字中国語で表示するString Catalog | ### Widget、テスト、設定、生成ツール @@ -548,7 +556,7 @@ Deep Linkは`bustimeapp://route/-`形式です。停留所 | `BusTimeAppTests/BusTimeAppTests.swift` | Swift Testingによるドメイン・状態・表示計算のテスト | | `BusTimeAppUITests/BusTimeAppUITests.swift` | XCTest UI操作、Dynamic Type、言語、RTL、Accessibility Audit | | `BusTimeAppUITests/BusTimeAppUITestsLaunchTests.swift` | 起動確認とScreenshot Attachment | -| `Scripts/localization_strings.py` | 235件の翻訳対訳を持つ唯一の原本 | +| `Scripts/localization_strings.py` | 272件の翻訳対訳を持つ唯一の原本 | | `Scripts/generate_l10n.py` | String Catalogと`L10n.swift`の生成・差分検査 | | `.github/workflows/ci.yml` | Xcode Matrix、Test、Widget、Lint、Artifact、Summary | | `BusTimeApp-Info.plist` | URL Scheme定義 | @@ -757,7 +765,7 @@ WidgetKitのTimeline再要求時刻はシステムが最終決定します。現 - Small、Medium、Accessory Rectangularを別レイアウトにし、Smallの主時刻は`ScaledMetric`へ追従させます。 - タップ時は表示中の経路をDeep Linkでアプリへ渡すため、Widgetとアプリの文脈が途切れません。 -Live Activity側では、ロック画面とDynamic Islandに同じ`BusActivityAttributes`を使います。Live Activityは描いた内容を保存して表示するため、`TimelineView`では残り時間が進みません。iOS 18以降は`Text(.currentDate, format: .timer(...))`に1分単位の精度を指定し、システムに秒を含まない残り時間を数え進めさせます。iOS 16.2〜17では同じ役割の`Text(timerInterval:)`を使います。出発時刻は`staleDate`として毎回渡し、アプリが停止したまま出発しても期限切れをきっかけに「出発済み」へ描き直されます。アプリからのActivity更新は残り分が変わったときだけ送り、秒単位の無意味な更新を避けています。 +Live Activity側では、ロック画面とDynamic Islandに同じ`BusActivityAttributes`を使います。Live Activityは描いた内容を保存して表示するため、`TimelineView`では残り時間が進みません。`Text(.currentDate, format: .timer(...))`に1分単位の精度を指定し、システムに秒を含まない残り時間を数え進めさせます。iOS 18より前のための`Text(timerInterval:)`の分岐はコードに残っていますが、iOS 27.0以上では使われません。出発時刻は`staleDate`として毎回渡し、アプリが停止したまま出発しても期限切れをきっかけに「出発済み」へ描き直されます。アプリからのActivity更新は残り分が変わったときだけ送り、秒単位の無意味な更新を避けています。 #### トレードオフ @@ -835,7 +843,7 @@ Canvas生成によりアセット数を抑え、条件の組み合わせを表 #### 設計と実装 -- `Scripts/localization_strings.py`を235件の文言の唯一の原本にしています。 +- `Scripts/localization_strings.py`を272件の文言の唯一の原本にしています。 - Pythonスクリプトが日本語・英語・簡体字中国語のString Catalogと、`L10n.Result.nextBus`のような型付きSwift APIを同時生成します。 - キーの重複を生成前に検出します。 - 引数の型からSwift関数を生成し、言語規則が必要な文言はString Catalogのplural variationと`localizedStringWithFormat`を使います。 @@ -892,7 +900,7 @@ Canvas生成によりアセット数を抑え、条件の組み合わせを表 - UIテストでは`-UITestNow`で時刻、`-forceWeather clear`で天気、`-SkyBackgroundStill`で背景、`-UITestResetState`で保存状態を固定します。 - 単体テストは80件あり、運行日、経路推薦、状態遷移、通知、天気、配色、月相、Widget Deep Link、多言語日付を対象にしています。 - UIテストは8件あり、主要導線、最大文字サイズ、アクセシビリティ監査、3言語、RTL、起動を対象にしています。 -- CIはXcode 16.2、16.4、26の複数環境でDebug/Releaseをビルドし、安定版2環境でテストとcoverageを記録します。 +- CIはXcode 27.0と27.2の2環境でDebug/Releaseをビルドし、両方でテストとcoverageを記録します。 - Widget Extensionは別Schemeでビルドし、本体だけ通って拡張が壊れる状態を検出します。 - `SWIFT_TREAT_WARNINGS_AS_ERRORS=YES`をプロジェクトとCIの両方で指定し、ローカル設定差で警告が見逃されないようにしています。 - 静的解析、翻訳生成物、TODO/FIXME、警告件数、失敗ログ、xcresultを別々の証拠として残します。 @@ -1002,7 +1010,7 @@ xcodebuild build \ xcodebuild test \ -project BusTimeApp.xcodeproj \ -scheme BusTimeApp \ - -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.5' \ + -destination 'platform=iOS Simulator,name=iPhone 18 Pro,OS=27.2' \ -testLanguage ja \ -testRegion JP \ -enableCodeCoverage YES @@ -1212,6 +1220,10 @@ UIテストでは、ホーム/時刻表の遷移、最大Dynamic Typeでの主 #### Widget・Siri・Deep Link - `shortcutAnswerNamesTheRouteAndTheNextDeparture`: Siri回答の経路・次便内容 +- `shortcutAnswerForAnExplicitRouteUsesThatRoute`: 経路を指定した回答と、値として返す出発日時 +- `shortcutRouteOptionsCoverEveryRouteOfTheApp`、`shortcutOptionsKeepTheirStoredIdentifiers`: 経路の増減への追従と、保存される識別子の固定 +- `busAlertSelectionPicksTheNextBusOnTheRoute`、`busAlertSelectionSkipsABusWhoseAlertTimeHasPassed`、`busAlertSelectionRefusesANonServiceDay`、`busAlertSelectionDoesNotCarryOverToTheNextServiceDay`: 通知対象の便の選択 +- `shortcutRequestIsHandedToTheAppAndTheResultReturnsToTheShortcut`、`shortcutRequestTimesOutWhenTheAppNeverAnswers`、`aNewShortcutRequestReplacesOneTheAppHasNotTakenYet`: 画面への依頼の受け渡し - `widgetLinkCarriesTheRouteBothWays`: Deep Linkの往復変換 - `widgetLinkIgnoresOtherURLs`: 他scheme/hostを拒否 - `openingFromTheWidgetSwitchesTheRoute`: Widgetからアプリの経路切替 @@ -1236,7 +1248,7 @@ UIテストでは、ホーム/時刻表の遷移、最大Dynamic Typeでの主 GitHub Actionsでは次を実行します。 -- Xcode 16.2/iOS 18.2、Xcode 16.4/iOS 18.5、Xcode 26/最新SDKのビルドマトリクス +- Xcode 27.0/iOS 27.0、Xcode 27.2/iOS 27.2のビルドマトリクス - Debug/Releaseビルド - 安定版2環境での単体・UIテストとコードカバレッジ記録 - Widget Extensionの独立ビルド @@ -1268,25 +1280,24 @@ CIの目的は、単に一つの環境で`xcodebuild`を成功させることで 同じブランチへ短時間に複数回pushした場合は、`concurrency`のgroupをworkflow名とGit refで作り、古い実行を`cancel-in-progress`で中止します。すでに古くなったcommitへmacOS Runnerを使い続けず、最新commitへ結果を早く返すためです。別ブランチのCIは異なるgroupなので互いに中断しません。 -#### 3種類のXcodeマトリクス +#### 2種類のXcodeマトリクス | 環境 | この環境で確認したいこと | テスト方針 | | --- | --- | --- | -| Xcode 16.2/iOS 18.2 | 現在の互換性基準となるXcode 16系でコンパイル・実行できること | Debug/Release、単体・UIテスト | -| Xcode 16.4/iOS 18.5 | Xcode 16系の後期コンパイラとSDKでも警告や挙動が変わらないこと | Debug/Release、単体・UIテスト | -| Xcode 26/最新SDK | `#available(iOS 26, *)`を含むコードが最新コンパイラで成立すること | Debug/Releaseのビルドのみ | +| Xcode 27.0/iOS 27.0 | 最低対応OSのSDKとSimulatorでコンパイル・実行できること | Debug/Release、単体・UIテスト | +| Xcode 27.2/iOS 27.2 | Xcode 27系の最新コンパイラとSDKでも警告や挙動が変わらないこと | Debug/Release、単体・UIテスト | -1環境だけでは、ローカルで選ばれているXcodeには通るが別コンパイラでは警告がエラーになる、古いAPIのavailability指定が不足する、といった問題を見逃します。Xcode 16.2と16.4を両方残し、さらに最新Xcodeを先行してビルドすることで、現在の互換性と将来の互換性を別々に見ています。 +Deployment TargetをiOS 27.0にしているため、iOS 27 SDKを持たないXcode 16・26系ではビルドできません。どちらの環境も、Xcode 27系を載せたGitHub-hosted Runner(`xcode-27`、現在はPreview)で実行します。 -`strategy.fail-fast`は`false`です。例えばXcode 16.2だけが失敗しても16.4と26を最後まで実行し、特定バージョンの問題か全環境の問題かを1回のCIで判別するためです。所要時間を最短にするより、失敗分布を一度に得ることを優先しています。 +1環境だけでは、ローカルで選ばれているXcodeには通るが別コンパイラでは警告がエラーになる、といった問題を見逃します。最低対応OSと同じXcode 27.0と、最新のXcode 27.2を両方残し、最低対応OSでの動作と最新環境での互換性を別々に見ています。 -最新SDKの行は`generic/platform=iOS Simulator`を使います。これはビルド専用Destinationであり、アプリを起動してテストできません。そのため`matrix.ios_version != 'latest'`の条件でテストとcoverageを除外しています。最新環境はRunner上の具体的なSimulator名やOS版が変わりやすいため、まずコンパイラ・SDK互換性を安定して確認する役割に限定しています。 +`strategy.fail-fast`は`false`です。例えばXcode 27.0だけが失敗しても27.2を最後まで実行し、特定バージョンの問題か全環境の問題かを1回のCIで判別するためです。所要時間を最短にするより、失敗分布を一度に得ることを優先しています。 -なお、このマトリクスが確認するのはXcode/SDKの互換性です。アプリのDeployment TargetはiOS 16.2ですが、CIの実行先はiOS 18.2と18.5なので、「iOS 16.2実機上のランタイム互換性」までは証明していません。最低対応OS固有の動作まで保証するには、利用可能な旧Simulatorまたは実機テストを別途追加する必要があります。 +Xcode 27.0の行はiOS 27.0のSimulatorで実行するため、最低対応OSでの振る舞いまで確認できます。実機固有の動作(Live Activityの開始、位置情報など)は実機で確認します。 #### Xcode選択にフォールバックを持たせる理由 -Xcode 16.2/16.4は`xcode-select`で明示的に選びます。GitHub-hosted Runnerのイメージ更新で指定minor版が一時的に消えた場合は、同じmajor版の最新Xcodeを探すフォールバックを持たせています。 +Xcode 27.0/27.2は`xcode-select`で明示的に選びます。GitHub-hosted Runnerのイメージ更新で指定minor版が一時的に消えた場合は、同じmajor版の最新Xcodeを探すフォールバックを持たせています。 これはRunner更新だけでCI全体が止まることを避けるためですが、厳密なminor版再現性は弱くなります。ログへ実際の`xcodebuild -version`、macOS、Swift、Simulator Runtimeを出すことで、「指定版ではなくフォールバックで動いた」事実を追えるようにしています。リリース認証のように完全な再現性を優先する段階では、フォールバックせず指定Xcode不在を失敗にする判断も必要です。 @@ -1324,7 +1335,7 @@ Simulator向けCIなので、`CODE_SIGN_IDENTITY=""`、`CODE_SIGNING_REQUIRED=NO `lint`ジョブは次の役割を持ちます。 -- `generate_l10n.py --check`で、235件の対訳原本とString Catalog/`L10n.swift`の生成結果が一致するか確認する +- `generate_l10n.py --check`で、272件の対訳原本とString Catalog/`L10n.swift`の生成結果が一致するか確認する - `xcodebuild analyze`で、通常ビルドだけでは検出しにくい問題を静的解析する - Swiftファイル一覧をSummaryへ出し、どのコードが解析対象か確認できるようにする - TODO、FIXME、HACK、XXXを一覧化し、未完事項を見えないままにしない @@ -1360,8 +1371,6 @@ CIの説明では「cacheがあるから高速」と断定せず、設定先が | 未実施の項目 | 現在の判断 | 追加するなら | | --- | --- | --- | -| iOS 16.2 Runtimeテスト | Runnerで安定して使えるiOS 18系を優先 | 旧Simulatorまたは実機Farmを追加 | -| 最新XcodeでのUIテスト | generic Destinationでコンパイル互換性に限定 | Runner上のRuntimeを動的に解決して実行 | | coverage下限 | 境界条件の振る舞いテストを優先 | モジュール別・差分coverage Gate | | Release Archive/署名 | 証明書を持たないSimulator CIと分離 | 保護EnvironmentとApp Store Connect APIを使うRelease Workflow | | TestFlight自動配布 | 手動Archiveで配布判断を残す | tagまたは`release/**`から承認付きUpload | @@ -1375,10 +1384,9 @@ CIの説明では「cacheがあるから高速」と断定せず、設定先が | 失敗した場所 | 最初に確認するArtifact/出力 | 疑う範囲 | | --- | --- | --- | -| Xcode 16.2だけ | `build-logs-18.2-xcode16.2` | 古いCompiler/SDKとの互換性、availability、警告差 | -| Xcode 16.4だけ | `build-logs-18.5` | Xcode 16後期で変わった警告・Simulator挙動 | -| Xcode 26だけ | `build-logs-latest` | 最新SDK、iOS 26条件分岐、将来のCompiler警告 | -| 安定版2環境のTest | 各`test-results-...`の`xcresult` | 単体・UIのAssertion、Screenshot、Accessibility Audit、時刻固定 | +| Xcode 27.0だけ | `build-logs-27.0` | 最低対応OSのSDK・Simulatorとの互換性、availability、警告差 | +| Xcode 27.2だけ | `build-logs-27.2` | Xcode 27後期で変わった警告・Simulator挙動 | +| 2環境のTest | 各`test-results-...`の`xcresult` | 単体・UIのAssertion、Screenshot、Accessibility Audit、時刻固定 | | Widgetだけ | `widget-build-logs` | Extension Info.plist、Entitlements、Target Membership、WidgetKit/ActivityKit | | 翻訳検査 | `Lint & Static Analysis` log | 対訳原本変更後の生成忘れ、生成物の直接編集 | | Analyzeだけ | `Lint & Static Analysis` log | 静的解析、Concurrency、未使用・到達不能などのCompiler診断 | @@ -1424,6 +1432,7 @@ CIの説明では「cacheがあるから高速」と断定せず、設定先が 3. `BusSchedule.timetables`へ便を登録し、現在地推薦、相手停留所保存、最終便後Fallbackを確認します。 4. Deep LinkのIdentifierを一度公開したら変更しません。変更が必要なら旧URLもdecodeできるMigrationを用意します。 5. Widgetの各Family、Siri回答、検索Menu、経路Swap、VoiceOver Label、多言語文言を確認します。 +6. ショートカット3種は実機の「ショートカット」アプリで確認します。特に「次の便の通知を設定」のLive Activity開始は、前面でないと開始できないためシミュレータだけでは不十分です。 6. App Groupへ保存済みの旧raw valueを読んだときのFallbackをTestします。 ### 祝日データを更新する @@ -1490,6 +1499,14 @@ CIの説明では「cacheがあるから高速」と断定せず、設定先が ## プライバシー概要 +プライバシーポリシー・利用規約の本文はポートフォリオサイトで管理し、アプリの設定画面から外部ブラウザで開きます。 + +- プライバシーポリシー: https://hr0101.dev/apps/bustimeapp/privacy/ +- 利用規約: https://hr0101.dev/apps/bustimeapp/terms/ +- ページのソース: `/Users/Rhara/portfolio_site/src/app/apps/bustimeapp/{privacy,terms}/page.tsx` + +公開時は `portfolio_site` の静的ビルドを既存のS3・CloudFrontへ反映し、両URLがHTTP 200で本文を表示することを確認してください。App Store ConnectのプライバシーポリシーURLにも同じURLを設定します。 + | 項目 | 扱い | | --- | --- | | トラッキング | なし | diff --git a/Scripts/localization_strings.py b/Scripts/localization_strings.py index 42f83c1..28adb14 100644 --- a/Scripts/localization_strings.py +++ b/Scripts/localization_strings.py @@ -34,6 +34,47 @@ '%1$@的下一班车%2$@出发,%3$@到达。%4$@。', ['String', 'String', 'String', 'String']), ('shortcut.noService', '次に出るバスが見つかりませんでした。', 'I could not find the next bus.', '未能找到下一班车。', []), + ('shortcut.routeParameter', '経路', 'Route', '路线', []), + ('shortcut.routeAutoDescription', + '指定しないときは、アプリと同じ判断(自分で選んだ経路、なければ時間帯と前回の行き先)で決めます。', + 'If left empty, the route is chosen the way the app does it: your own choice first, otherwise by time of day and your last destination.', + '不指定时,将与应用采用相同的判断(优先使用您自己选择的路线,否则按时间段和上次的目的地决定)。', []), + # 停留所名は現地の案内に合わせ、どの言語でも日本語表記のままにします。 + ('shortcut.routeMansionToStation', 'コロンブスシティ → 海浜幕張駅', + 'コロンブスシティ → 海浜幕張駅', 'コロンブスシティ → 海浜幕張駅', []), + ('shortcut.routeStationToMansion', '海浜幕張駅 → コロンブスシティ', + '海浜幕張駅 → コロンブスシティ', '海浜幕張駅 → コロンブスシティ', []), + ('shortcut.routeMansionToYokado', 'コロンブスシティ → ヨーカドー前', + 'コロンブスシティ → ヨーカドー前', 'コロンブスシティ → ヨーカドー前', []), + ('shortcut.routeStationToYokado', '海浜幕張駅 → ヨーカドー前', + '海浜幕張駅 → ヨーカドー前', '海浜幕張駅 → ヨーカドー前', []), + ('shortcut.routeYokadoToMansion', 'ヨーカドー前 → コロンブスシティ', + 'ヨーカドー前 → コロンブスシティ', 'ヨーカドー前 → コロンブスシティ', []), + ('shortcut.leadTimeParameter', '通知のタイミング', 'Alert timing', '提醒时间', []), + ('shortcut.leadTimeFiveMinutes', '5分前', '5 minutes before', '提前5分钟', []), + ('shortcut.leadTimeTenMinutes', '10分前', '10 minutes before', '提前10分钟', []), + ('shortcut.leadTimeFifteenMinutes', '15分前', '15 minutes before', '提前15分钟', []), + ('shortcut.liveActivityParameter', 'Live Activityも開始', 'Also start a Live Activity', + '同时启动实时活动', []), + ('shortcut.openRouteTitle', '経路を指定して開く', 'Open a route', '打开指定路线', []), + ('shortcut.openRouteDescription', '選んだ経路のホームをアプリで開きます。', + 'Opens the app on the home screen for the route you choose.', + '在应用中打开所选路线的主页。', []), + ('shortcut.startAlertTitle', '次の便の通知を設定', 'Set an alert for the next bus', + '为下一班车设置提醒', []), + ('shortcut.startAlertDescription', + '選んだ経路の次の便に通知を設定します。Live Activityも一緒に開始できます。', + 'Sets an alert for the next bus on the route you choose. It can also start a Live Activity.', + '为所选路线的下一班车设置提醒,也可以同时启动实时活动。', []), + ('shortcut.alertScheduled', '%1$@の%2$@発の便に、%3$lld分前の通知を設定しました。', + 'Alert set for the %2$@ bus on %1$@, %3$lld minutes before it leaves.', + '已为%1$@ %2$@出发的班次设置提前%3$lld分钟的提醒。', ['String', 'String', 'Int']), + ('shortcut.noBusToAlert', 'この経路には、今日これから通知を設定できる便がありません。', + 'There is no bus left today on this route that an alert can be set for.', + '今天该路线已没有可以设置提醒的班次。', []), + ('shortcut.noResponse', 'アプリでの処理が完了しませんでした。アプリを開いて確認してください。', + 'The app did not finish in time. Please open the app and check.', + '应用未能及时完成处理。请打开应用确认。', []), # ---- 共通 ---- ('common.close', '閉じる', 'Close', '关闭', []), @@ -84,8 +125,8 @@ ('when.searchTypeArrivalFull', '到着したい時刻から探す', 'Search by arrival time', '按到达时间查找', []), ('when.departureTimeTitle', 'この時刻以降に出発', 'Departing after', '在此时间之后出发', []), ('when.arrivalTimeTitle', 'この時刻までに到着', 'Arriving by', '在此时间之前到达', []), - ('when.departureExplanation', '指定した時刻以降に出発する便を、早い順に表示します', 'Shows services departing after the time you set, earliest first', '按最早顺序显示在指定时间之后出发的班次', []), - ('when.arrivalExplanation', '指定した時刻までに目的地へ着く便を、到着時刻が近い順に表示します', 'Shows services arriving by the time you set, closest arrival first', '按到达时间由近及远显示能在指定时间前抵达的班次', []), + ('when.departureExplanation', '出発の早い順', 'earliest first', '按出发先后', []), + ('when.arrivalExplanation', '到着が指定時刻に近い順', 'closest to your arrival time first', '按到达时间由近及远', []), ('when.currentTime', '現在時刻', 'Now', '当前时间', []), ('when.currentTimeHint', '選択中の検索方法を変えずに現在時刻を入力します', 'Fills in the current time without changing the search type', '在不更改搜索方式的情况下填入当前时间', []), @@ -133,13 +174,13 @@ ('search.criteriaInitial', '検索条件: まだ検索されていません', 'Search: not run yet', '搜索条件:尚未搜索', []), ('search.resultInitial', '出発地・目的地と時刻を選んでください', 'Choose the stops and the time', '请选择站点和时间', []), ('search.noResults', '条件に合う便がありません。時刻または目的地を変更してください', 'No services match. Change the time or the destination.', '没有符合条件的班次。请更改时间或目的地。', []), - ('search.resultCountSuspended', '%lld便見つかりました。運休日のため平日ダイヤの時刻です', - {'one': 'Found %lld service. There is no service today, so these are weekday times.', - 'other': 'Found %lld services. There is no service today, so these are weekday times.'}, - '找到%lld个班次。今日停运,显示的是工作日时刻。', ['Int']), - ('search.resultCount', '%1$lld便見つかりました。%2$@', - {'one': 'Found %1$lld service. %2$@', 'other': 'Found %1$lld services. %2$@'}, - '找到%1$lld个班次。%2$@', ['Int', 'String']), + ('search.resultCountSuspended', '平日ダイヤの%lld便・本日は運休', + {'one': '%lld weekday service · no service today', + 'other': '%lld weekday services · no service today'}, + '工作日时刻的%lld个班次 · 今日停运', ['Int']), + ('search.resultCount', '%1$lld便・%2$@', + {'one': '%1$lld service · %2$@', 'other': '%1$lld services · %2$@'}, + '%1$lld个班次 · %2$@', ['Int', 'String']), ('search.criteriaArrival', '%1$@ → %2$@|%3$@までに到着', '%1$@ → %2$@ | arriving by %3$@', '%1$@ → %2$@|%3$@前到达', ['String', 'String', 'String']), ('search.adjustedToCurrentTime', '過去の指定時刻を現在時刻に合わせました', 'The past requested time was adjusted to the current time.', '过去的指定时间已调整为当前时间。', []), ('search.criteriaDeparture', '%1$@ → %2$@|%3$@以降に出発', '%1$@ → %2$@ | departing after %3$@', '%1$@ → %2$@|%3$@后出发', ['String', 'String', 'String']), @@ -248,9 +289,8 @@ ('timetable.serviceCount', '%lld便', {'one': '%lld service', 'other': '%lld services'}, '%lld个班次', ['Int']), - ('timetable.routeHint', '経路を変えるときは、ホームタブで出発地と目的地を選んでください', 'To change the route, choose the stops on the Home tab', '要更改路线,请在首页标签页选择出发地和目的地', []), + ('timetable.routeHint', '経路はホームで変更できます', 'Change the route on Home', '可在首页更改路线', []), ('timetable.notificationHintTitle', '時刻をタップすると通知できます', 'Tap a time to set an alert', '轻点时刻即可设置提醒', []), - ('timetable.notificationHintBody', '選んだ便が出発する前にお知らせします。設定した時刻は色が変わります。', 'You will be alerted before the service departs. Times with an alert change colour.', '将在所选班次出发前通知您。已设置的时刻会变色。', []), ('timetable.hourAccessibility', '%lld時台', "%lld o'clock", '%lld点时段', ['Int']), ('timetable.legendScheduled', '色のついた時刻は通知を設定済みです', 'Coloured times have an alert set', '带颜色的时刻已设置提醒', []), ('timetable.legendNote', '点の付いた便はお買い物便や経由便です', 'A dot marks a shopping service or a service with a detour', '带点的班次为购物班次或经由班次', []), @@ -259,6 +299,10 @@ ('timetable.cellDeparted', '、出発済み', ', departed', ',已出发', []), # ---- 設定画面 ---- + ('settings.legalSection', 'プライバシー・利用規約', 'Privacy & Terms', '隐私与条款', []), + ('settings.privacyPolicy', 'プライバシーポリシー', 'Privacy Policy', '隐私政策', []), + ('settings.termsOfUse', '利用規約', 'Terms of Use', '使用条款', []), + ('settings.legalWebsiteNotice', 'ブラウザで開発者のWebサイトを開きます。本文は日本語で掲載しています。', 'Opens the developer’s website in your browser. Documents are available in Japanese.', '将在浏览器中打开开发者的网站。文档以日语提供。', []), ('settings.title', '設定', 'Settings', '设置', []), ('settings.appearanceSection', '画面の色', 'Appearance', '界面颜色', []), ('settings.appearanceTitle', '時刻に合わせて変わります', 'Changes with the time of day', '随时间变化', []),