From 13eeae1c4b3acd258aa5e695db2cbd31b50125ad Mon Sep 17 00:00:00 2001 From: Marc Schwieterman Date: Fri, 3 May 2019 11:27:41 -0700 Subject: [PATCH 1/2] Ensure crop points are current Previously setting the crop points via the text entry dialog would update the sliders, but moving the sliders would not update the pre-populated values in the text entry dialog. This was due to the text field being populated with the `Trial` values, which aren't updated until the crop changes are saved. This change uses the crop values from the current playback view controller, which is the same value that the sliders present and modify. Fixes #47 --- ScienceJournal/UI/CropRangeViewController.swift | 17 ++++++++--------- .../UI/TrialDetailViewController.swift | 17 +++++++++++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/ScienceJournal/UI/CropRangeViewController.swift b/ScienceJournal/UI/CropRangeViewController.swift index 7f1a053..1b0bc69 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 + /// - trialCropRange: The trial's crop range. + /// - markerType: A crop marker type. + func showTimestampEditAlert(forTrialCropRange trialCropRange: ChartAxis, + andCropMarkerType markerType: CropOverlayView.MarkerType) { + self.trialCropRange = trialCropRange let editTimestampVC = EditTimestampViewController() editTimestampVC.delegate = self diff --git a/ScienceJournal/UI/TrialDetailViewController.swift b/ScienceJournal/UI/TrialDetailViewController.swift index f5c46a4..86f46f8 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(forTrialCropRange: trialCropRange, + andCropMarkerType: cropMarkerType) + } + /// Creates trial data for export. /// /// - Parameter completion: Called when complete with a Bool indicating success, and the trial From 3b591c572010d841bcecf10042eaf586a0587854 Mon Sep 17 00:00:00 2001 From: Marc Schwieterman Date: Fri, 3 May 2019 14:25:38 -0700 Subject: [PATCH 2/2] Rename method params --- ScienceJournal/UI/CropRangeViewController.swift | 6 +++--- ScienceJournal/UI/TrialDetailViewController.swift | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ScienceJournal/UI/CropRangeViewController.swift b/ScienceJournal/UI/CropRangeViewController.swift index 1b0bc69..98f7885 100644 --- a/ScienceJournal/UI/CropRangeViewController.swift +++ b/ScienceJournal/UI/CropRangeViewController.swift @@ -61,10 +61,10 @@ class CropRangeViewController: UIViewController, EditTimestampViewControllerDele /// Shows an alert that allows the user to manually input a timestamp for the given crop marker. /// /// - Parameters - /// - trialCropRange: The trial's crop range. /// - markerType: A crop marker type. - func showTimestampEditAlert(forTrialCropRange trialCropRange: ChartAxis, - andCropMarkerType markerType: CropOverlayView.MarkerType) { + /// - trialCropRange: The trial's crop range. + func showTimestampEditAlert(for markerType: CropOverlayView.MarkerType, + trialCropRange: ChartAxis) { self.trialCropRange = trialCropRange let editTimestampVC = EditTimestampViewController() diff --git a/ScienceJournal/UI/TrialDetailViewController.swift b/ScienceJournal/UI/TrialDetailViewController.swift index 86f46f8..df41c50 100644 --- a/ScienceJournal/UI/TrialDetailViewController.swift +++ b/ScienceJournal/UI/TrialDetailViewController.swift @@ -1308,8 +1308,8 @@ class TrialDetailViewController: MaterialHeaderViewController, guard let trialCropRange = self.currentPlaybackViewController?.1.cropRange else { return } - self.cropRangeController.showTimestampEditAlert(forTrialCropRange: trialCropRange, - andCropMarkerType: cropMarkerType) + self.cropRangeController.showTimestampEditAlert(for: cropMarkerType, + trialCropRange: trialCropRange) } /// Creates trial data for export.