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
4 changes: 2 additions & 2 deletions Accelerometer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "\"Accelerometer/Preview Content\"";
DEVELOPMENT_TEAM = 3HG9ZBM8AV;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -974,7 +974,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "\"Accelerometer/Preview Content\"";
DEVELOPMENT_TEAM = 3HG9ZBM8AV;
ENABLE_PREVIEWS = YES;
Expand Down
100 changes: 100 additions & 0 deletions Accelerometer.xcodeproj/xcshareddata/xcschemes/Accelerometer.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "2600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B24EC0328621BBE00AD3EF1"
BuildableName = "Acc.elerometer.app"
BlueprintName = "Accelerometer"
ReferencedContainer = "container:Accelerometer.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B24EC1328621BC200AD3EF1"
BuildableName = "AccelerometerTests.xctest"
BlueprintName = "AccelerometerTests"
ReferencedContainer = "container:Accelerometer.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B24EC1D28621BC200AD3EF1"
BuildableName = "AccelerometerUITests.xctest"
BlueprintName = "AccelerometerUITests"
ReferencedContainer = "container:Accelerometer.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B24EC0328621BBE00AD3EF1"
BuildableName = "Acc.elerometer.app"
BlueprintName = "Accelerometer"
ReferencedContainer = "container:Accelerometer.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B24EC0328621BBE00AD3EF1"
BuildableName = "Acc.elerometer.app"
BlueprintName = "Accelerometer"
ReferencedContainer = "container:Accelerometer.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
1 change: 0 additions & 1 deletion Accelerometer/Other/PreviewUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,3 @@ struct PreviewUtils {
static let gravityTestRecording = recordingWithType(.gravity, duration: 60)
}
#endif

4 changes: 3 additions & 1 deletion Accelerometer/Recordings/Charts/RecordingBigChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ struct RecordingBigChartView: View {
measurementType: measurementType,
style: .big
)
.padding(.vertical)
.padding()
.navigationTitle(measurementType.name.capitalized)
.navigationBarTitleDisplayMode(.inline)
}
}

#if DEBUG
struct RecordingBigChartView_Previews: PreviewProvider {
static var previews: some View {
Group {
Expand All @@ -44,3 +45,4 @@ struct RecordingBigChartView_Previews: PreviewProvider {
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ struct RecordingChartContainerView: View {

// MARK: - Previews

#if DEBUG
struct RecordingChartContainerView_Previews: PreviewProvider {
static let recording = PreviewUtils.mediumRecording
static let type = measurementType(from: recording)
Expand Down Expand Up @@ -225,3 +226,4 @@ struct RecordingChartContainerView_Previews: PreviewProvider {
recording.sortedMeasurementTypes.first ?? .acceleration
}
}
#endif
2 changes: 2 additions & 0 deletions Accelerometer/Recordings/Charts/RecordingSmallChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct RecordingSmallChartView: View {

// MARK: - Previews

#if DEBUG
struct RecordingSmallChartView_Previews: PreviewProvider {

static var sampleRecordings: [Recording] = [
Expand Down Expand Up @@ -55,3 +56,4 @@ struct RecordingSmallChartView_Previews: PreviewProvider {
}
}
}
#endif
2 changes: 1 addition & 1 deletion Accelerometer/Recordings/NewRecordingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct NewRecordingView: View {
.controlSize(.large)
.tint(noneSelected ? .gray : .accentColor)
.disabled(noneSelected)
.padding(.horizontal)
.padding()
.animation(.easeInOut, value: noneSelected)
}
.navigationTitle("New recording")
Expand Down
45 changes: 45 additions & 0 deletions Accelerometer/Recordings/Recorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import DequeModule
import Combine
import SwiftUI
import AVFoundation

@MainActor
class Recorder: ObservableObject {
Expand All @@ -30,6 +31,8 @@ class Recorder: ObservableObject {
private let disableIdleTimer = true
private var subscriptions: [AnyCancellable] = []

private var audioPlayer: AVAudioPlayer?

init(measurer: Measurer, settings: Settings) {
self.measurer = measurer
self.settings = settings
Expand All @@ -40,6 +43,8 @@ class Recorder: ObservableObject {
Task {
await watchFreeSpace()
}

configureAudioSession()
}

var recordingInProgress: Bool {
Expand Down Expand Up @@ -69,6 +74,8 @@ class Recorder: ObservableObject {

objectWillChange.send()
}

startSilentAudioLoop()
}
}

Expand Down Expand Up @@ -107,6 +114,8 @@ class Recorder: ObservableObject {
subscriptions.removeAll()
objectWillChange.send()
}

stopSilentAudioLoop()
}
}

Expand Down Expand Up @@ -201,6 +210,42 @@ class Recorder: ObservableObject {
return hasEnoughMemory
}

// MARK: - Audio control

private func configureAudioSession() {
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(.playback, options: [.mixWithOthers])
try session.setMode(.default)
try session.setActive(true)
} catch {
print("Audio session setup failed:", error)
}
}


private func startSilentAudioLoop() {
guard audioPlayer == nil else { return }
if let url = Bundle.main.url(forResource: "silence", withExtension: "mp3") {
do {
let player = try AVAudioPlayer(contentsOf: url)
player.numberOfLoops = -1
player.volume = 0
player.play()
audioPlayer = player
} catch {
print("Failed to start silent audio:", error)
}
}
}

private func stopSilentAudioLoop() {
audioPlayer?.stop()
audioPlayer = nil
}

// MARK: - Debug

#if (DEBUG)
func createDebugSamples() {
Task {
Expand Down
6 changes: 4 additions & 2 deletions Accelerometer/Recordings/RecordingSummaryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct RecordingSummaryView: View {
.name
.capitalizingFirstLetter()
)
.font(.headline)
.font(.headline)
RecordingSmallChartView(
recording: recording,
measurementType: type
Expand Down Expand Up @@ -129,7 +129,7 @@ struct RecordingSummaryView: View {
isLoading = false
}
}

private func export(type: MeasurementType) {
guard !exportLoading, let recording = fullRecording else { return }
exportLoading = true
Expand Down Expand Up @@ -201,6 +201,7 @@ struct FileDocumentWrapper: FileDocument {

// MARK: - Previews

#if DEBUG
struct RecordingSummaryView_Previews: PreviewProvider {

static let settings = Settings()
Expand Down Expand Up @@ -251,3 +252,4 @@ struct RecordingSummaryView_Previews: PreviewProvider {
.preferredColorScheme(.dark)
}
}
#endif
2 changes: 2 additions & 0 deletions Accelerometer/Settings/AlwaysNotEnoughMemoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI

#if DEBUG
struct AlwaysNotEnoughMemoryView: View {

@EnvironmentObject var settings: Settings
Expand Down Expand Up @@ -34,3 +35,4 @@ struct AlwaysNotEnoughMemoryViewPreviews: PreviewProvider {
.environmentObject(Settings())
}
}
#endif
2 changes: 2 additions & 0 deletions Accelerometer/Settings/AnimationsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI

#if DEBUG
struct AnimationsView: View {

@EnvironmentObject var settings: Settings
Expand Down Expand Up @@ -38,3 +39,4 @@ struct AnimationsViewPreviews: PreviewProvider {
.environmentObject(Settings())
}
}
#endif
3 changes: 2 additions & 1 deletion Accelerometer/Settings/DebugSamplesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI

#if DEBUG
struct DebugSamplesView: View {

@EnvironmentObject var settings: Settings
Expand All @@ -33,4 +34,4 @@ struct DebugSamplesViewPreviews: PreviewProvider {
.environmentObject(Settings())
}
}

#endif
Loading