Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 10 additions & 33 deletions AutoRoutes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@
isa = PBXNativeTarget;
buildConfigurationList = 6D47A5332FCAD20800E6C7B7 /* Build configuration list for PBXNativeTarget "AutoRoutes" */;
buildPhases = (
CE7B1A04118E4AE8A2FC7114 /* Increment Build Number */,
6D47A50C2FCAD20600E6C7B7 /* Sources */,
6D47A50D2FCAD20600E6C7B7 /* Frameworks */,
6D47A50E2FCAD20600E6C7B7 /* Resources */,
Expand Down Expand Up @@ -336,28 +335,6 @@
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
CE7B1A04118E4AE8A2FC7114 /* Increment Build Number */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Increment Build Number";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "agvtool next-version -all\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXTargetDependency section */
6D47A5212FCAD20800E6C7B7 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
Expand All @@ -380,7 +357,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
VERSIONING_SYSTEM = "apple-generic";
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
Expand Down Expand Up @@ -441,14 +417,14 @@
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
VERSIONING_SYSTEM = "apple-generic";
};
name = Debug;
};
6D47A5322FCAD20800E6C7B7 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
VERSIONING_SYSTEM = "apple-generic";
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
Expand Down Expand Up @@ -502,6 +478,7 @@
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
};
Expand All @@ -512,10 +489,10 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 4U6275HKV3;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = AutoRoutes/Info.plist;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.travel";
Expand Down Expand Up @@ -555,10 +532,10 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 4U6275HKV3;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = AutoRoutes/Info.plist;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.travel";
Expand Down Expand Up @@ -596,7 +573,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 7;
DEVELOPMENT_TEAM = 4U6275HKV3;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.5;
Expand All @@ -622,7 +599,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 7;
DEVELOPMENT_TEAM = 4U6275HKV3;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.5;
Expand All @@ -647,7 +624,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 7;
DEVELOPMENT_TEAM = 4U6275HKV3;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
Expand All @@ -672,7 +649,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 7;
DEVELOPMENT_TEAM = 4U6275HKV3;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
Expand Down
2 changes: 1 addition & 1 deletion AutoRoutes.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"testTargets" : [
{
"target" : {
"containerPath" : "container:AutoRoute.xcodeproj",
"containerPath" : "container:AutoRoutes.xcodeproj",
"identifier" : "6D47A51E2FCAD20800E6C7B7",
"name" : "AutoRoutesTests"
}
Expand Down
118 changes: 76 additions & 42 deletions AutoRoutes/UI/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ struct HomeView: View {

@Environment(\.modelContext) private var modelContext
@Environment(RouteService.self) private var routeService

@Query(sort: \Route.startedAt, order: .reverse) private var routes: [Route]

@State private var viewModel = HomeViewModel()
@State private var showingRecordingScreen = false
@State private var showingMergeSheet = false
@State private var routesToMerge: [Route] = []

// MARK: - Body

Expand All @@ -36,40 +35,13 @@ struct HomeView: View {
} else {
viewModel.update(with: routes)
}
showingRecordingScreen = isRecording
viewModel.showingRecordingScreen = isRecording
}
}
.fullScreenCover(isPresented: $showingRecordingScreen) {
RecordingView(routeService: routeService)
}
.alert(
String(localized: "Delete Routes", comment: "Delete confirmation alert title"),
isPresented: $viewModel.showingDeleteConfirmation
) {
Button.delete {
let selected = viewModel.selectedRoutes(from: viewModel.sections)
viewModel.exitSelectMode()
viewModel.deleteRoutes(selected, using: modelContext)
}
Button.cancel()
} message: {
Text(viewModel.deleteConfirmationMessage)
}
.alert(
String(localized: "Couldn't Start Recording", comment: "Start route failure alert title"),
isPresented: $viewModel.showingStartRouteError
) {
Button(String(localized: "OK", comment: "Dismiss start route error alert"), role: .cancel) { }
} message: {
Text(viewModel.startRouteErrorMessage ?? "")
}
.sheet(isPresented: $showingMergeSheet) {
if routesToMerge.count == 2 {
MergeRoutesView(routes: routesToMerge) { orderedRoutes, mergedName in
viewModel.mergeRoutes(orderedRoutes: orderedRoutes, mergedName: mergedName, using: modelContext)
}
}
}
.modifier(RecordingScreenModifier(routeService: routeService, viewModel: viewModel))
.modifier(DeleteRoutesAlertModifier(viewModel: viewModel, modelContext: modelContext))
.modifier(StartRouteErrorAlertModifier(viewModel: viewModel))
.modifier(MergeRoutesSheetModifier(viewModel: viewModel, modelContext: modelContext))
}

// MARK: - Private Views
Expand All @@ -96,7 +68,7 @@ struct HomeView: View {
List {
if routeService.isRecording {
RecordingBannerSection(triggerDisplayName: routeService.route?.trigger.displayName) {
showingRecordingScreen = true
viewModel.showingRecordingScreen = true
}
}

Expand Down Expand Up @@ -153,9 +125,7 @@ struct HomeView: View {
canDelete: viewModel.canDelete,
selectionCountText: viewModel.selectionCountText
) {
let routes = viewModel.selectedRoutes(from: viewModel.sections)
routesToMerge = routes.sorted { $0.startedAt < $1.startedAt }
showingMergeSheet = true
viewModel.triggerMerge()
} onDelete: {
viewModel.showingDeleteConfirmation = true
}
Expand All @@ -182,7 +152,7 @@ struct HomeView: View {
if !viewModel.isSelectMode {
Button {
if routeService.isRecording {
showingRecordingScreen = true
viewModel.showingRecordingScreen = true
} else {
viewModel.startRoute(using: routeService)
}
Expand All @@ -204,14 +174,78 @@ struct HomeView: View {
.buttonStyle(.plain)
.accessibilityLabel(
routeService.isRecording
? String(localized: "Currently recording — open recording screen", comment: "Record button when recording")
: String(localized: "Start a new route", comment: "Record button when idle")
? String(localized: "Currently recording — open recording screen", comment: "Record button when recording")
: String(localized: "Start a new route", comment: "Record button when idle")
)
}
}
}
}

// MARK: - Presentation Modifiers

private struct RecordingScreenModifier: ViewModifier {
let routeService: RouteService
@Bindable var viewModel: HomeViewModel

func body(content: Content) -> some View {
content.fullScreenCover(isPresented: $viewModel.showingRecordingScreen) {
RecordingView(routeService: routeService)
}
}
}

private struct DeleteRoutesAlertModifier: ViewModifier {
@Bindable var viewModel: HomeViewModel
let modelContext: ModelContext

func body(content: Content) -> some View {
content.alert(
String(localized: "Delete Routes", comment: "Delete confirmation alert title"),
isPresented: $viewModel.showingDeleteConfirmation
) {
Button.delete {
let selected = viewModel.selectedRoutes(from: viewModel.sections)
viewModel.exitSelectMode()
viewModel.deleteRoutes(selected, using: modelContext)
}
Button.cancel()
} message: {
Text(viewModel.deleteConfirmationMessage)
}
}
}

private struct StartRouteErrorAlertModifier: ViewModifier {
@Bindable var viewModel: HomeViewModel

func body(content: Content) -> some View {
content.alert(
String(localized: "Couldn't Start Recording", comment: "Start route failure alert title"),
isPresented: $viewModel.showingStartRouteError
) {
Button(String(localized: "OK", comment: "Dismiss start route error alert"), role: .cancel) { }
} message: {
Text(viewModel.startRouteErrorMessage ?? "")
}
}
}

private struct MergeRoutesSheetModifier: ViewModifier {
@Bindable var viewModel: HomeViewModel
let modelContext: ModelContext

func body(content: Content) -> some View {
content.sheet(isPresented: $viewModel.showingMergeSheet) {
if viewModel.routesToMerge.count == 2 {
MergeRoutesView(routes: viewModel.routesToMerge) { orderedRoutes, mergedName in
viewModel.mergeRoutes(orderedRoutes: orderedRoutes, mergedName: mergedName, using: modelContext)
}
}
}
}
}

// MARK: - Preview

#Preview {
Expand Down
11 changes: 10 additions & 1 deletion AutoRoutes/UI/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ final class HomeViewModel {
private(set) var summaryLine: String?
private(set) var isSelectMode: Bool = false
private(set) var selectedRouteIDs: Set<UUID> = []
private(set) var startRouteErrorMessage: String?
private(set) var routesToMerge: [Route] = []

var showingDeleteConfirmation: Bool = false
var showingStartRouteError: Bool = false
private(set) var startRouteErrorMessage: String?
var showingRecordingScreen: Bool = false
var showingMergeSheet: Bool = false

// MARK: - Computed Properties

Expand Down Expand Up @@ -87,6 +91,11 @@ final class HomeViewModel {
selectedRouteIDs = []
}

func triggerMerge() {
routesToMerge = selectedRoutes(from: sections).sorted { $0.startedAt < $1.startedAt }
showingMergeSheet = true
}

func toggleSelection(for id: UUID) {
if selectedRouteIDs.contains(id) {
selectedRouteIDs.remove(id)
Expand Down
Loading