diff --git a/ScienceJournal/UI/CropRangeViewController.swift b/ScienceJournal/UI/CropRangeViewController.swift index 7f1a053..98f7885 100644 --- a/ScienceJournal/UI/CropRangeViewController.swift +++ b/ScienceJournal/UI/CropRangeViewController.swift @@ -37,7 +37,7 @@ class CropRangeViewController: UIViewController, EditTimestampViewControllerDele weak var delegate: CropRangeViewControllerDelegate? /// The crop range of the trial. - var trialCropRange: ChartAxis? + private var trialCropRange: ChartAxis? private var alertPresentation: TimestampAlertPresentation? private let trialRecordingRange: ChartAxis @@ -47,10 +47,8 @@ class CropRangeViewController: UIViewController, EditTimestampViewControllerDele /// Designated initializer /// /// - Parameters: - /// - trialCropRange: The trial's crop range. /// - trialRecordingRange: The trial's recording range. - init(trialCropRange: ChartAxis?, trialRecordingRange: ChartAxis) { - self.trialCropRange = trialCropRange + init(trialRecordingRange: ChartAxis) { self.trialRecordingRange = trialRecordingRange cropValidator = CropValidator(trialRecordingRange: trialRecordingRange) super.init(nibName: nil, bundle: nil) @@ -62,11 +60,12 @@ class CropRangeViewController: UIViewController, EditTimestampViewControllerDele /// Shows an alert that allows the user to manually input a timestamp for the given crop marker. /// - /// - Parameter marker: A crop marker type. - func showTimestampEditAlert(forCropMarkerType markerType: CropOverlayView.MarkerType) { - guard let trialCropRange = trialCropRange else { - return - } + /// - Parameters + /// - markerType: A crop marker type. + /// - trialCropRange: The trial's crop range. + func showTimestampEditAlert(for markerType: CropOverlayView.MarkerType, + trialCropRange: ChartAxis) { + self.trialCropRange = trialCropRange let editTimestampVC = EditTimestampViewController() editTimestampVC.delegate = self diff --git a/ScienceJournal/UI/TrialDetailViewController.swift b/ScienceJournal/UI/TrialDetailViewController.swift index f5c46a4..df41c50 100644 --- a/ScienceJournal/UI/TrialDetailViewController.swift +++ b/ScienceJournal/UI/TrialDetailViewController.swift @@ -260,8 +260,7 @@ class TrialDetailViewController: MaterialHeaderViewController, self.preferenceManager = preferenceManager self.sensorDataManager = sensorDataManager cropValidator = CropValidator(trialRecordingRange: trial.recordingRange) - cropRangeController = CropRangeViewController(trialCropRange: trial.cropRange, - trialRecordingRange: trial.recordingRange) + cropRangeController = CropRangeViewController(trialRecordingRange: trial.recordingRange) // MDCCollectionViewFlowLayout currently has a bug that breaks sectionHeadersPinToVisibleBounds // so we need to use a UICollectionViewFlowLayout instead until it's fixed. See issue: @@ -1128,8 +1127,6 @@ class TrialDetailViewController: MaterialHeaderViewController, recordingRange: trial.recordingRange) } } - - cropRangeController.trialCropRange = editingCropRange } private func endCropping() { @@ -1296,17 +1293,25 @@ class TrialDetailViewController: MaterialHeaderViewController, // Edit start time. actions.append(PopUpMenuAction(title: String.editCropStartTime, isEnabled: true) { _ in - self.cropRangeController.showTimestampEditAlert(forCropMarkerType: .start) + self.showTimestampEditAlert(for: .start) }) // Edit end time. actions.append(PopUpMenuAction(title: String.editCropEndTime, isEnabled: true) { _ in - self.cropRangeController.showTimestampEditAlert(forCropMarkerType: .end) + self.showTimestampEditAlert(for: .end) }) return actions } + private func showTimestampEditAlert(for cropMarkerType: CropOverlayView.MarkerType) { + guard let trialCropRange = self.currentPlaybackViewController?.1.cropRange else { + return + } + self.cropRangeController.showTimestampEditAlert(for: cropMarkerType, + trialCropRange: trialCropRange) + } + /// Creates trial data for export. /// /// - Parameter completion: Called when complete with a Bool indicating success, and the trial