Skip to content

Commit

Permalink
Ensure crop points are current
Browse files Browse the repository at this point in the history
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 googlearchive#47
  • Loading branch information
marcisme committed May 3, 2019
1 parent c020dc8 commit 13eeae1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
17 changes: 8 additions & 9 deletions ScienceJournal/UI/CropRangeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CropRangeViewController: UIViewController, EditTimestampViewControllerDele
weak var delegate: CropRangeViewControllerDelegate?

/// The crop range of the trial.
var trialCropRange: ChartAxis<Int64>?
private var trialCropRange: ChartAxis<Int64>?

private var alertPresentation: TimestampAlertPresentation?
private let trialRecordingRange: ChartAxis<Int64>
Expand All @@ -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<Int64>?, trialRecordingRange: ChartAxis<Int64>) {
self.trialCropRange = trialCropRange
init(trialRecordingRange: ChartAxis<Int64>) {
self.trialRecordingRange = trialRecordingRange
cropValidator = CropValidator(trialRecordingRange: trialRecordingRange)
super.init(nibName: nil, bundle: nil)
Expand All @@ -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<Int64>,
andCropMarkerType markerType: CropOverlayView.MarkerType) {
self.trialCropRange = trialCropRange

let editTimestampVC = EditTimestampViewController()
editTimestampVC.delegate = self
Expand Down
17 changes: 11 additions & 6 deletions ScienceJournal/UI/TrialDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -1128,8 +1127,6 @@ class TrialDetailViewController: MaterialHeaderViewController,
recordingRange: trial.recordingRange)
}
}

cropRangeController.trialCropRange = editingCropRange
}

private func endCropping() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 13eeae1

Please sign in to comment.