Skip to content

Commit

Permalink
v7.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
flparrot committed Jun 29, 2023
1 parent b418448 commit fe9ca49
Show file tree
Hide file tree
Showing 29 changed files with 312 additions and 139 deletions.
68 changes: 36 additions & 32 deletions OpenFlight/OpenFlight.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct TouchAndFlyActivationModel: MissionActivationModel {

public func stopMissionIfNeeded() {
_ = Services.hub.connectedDroneHolder.drone?.getPilotingItf(PilotingItfs.pointOfInterest)?.deactivate()
_ = Services.hub.connectedDroneHolder.drone?.getPilotingItf(PilotingItfs.guided)?.deactivate()
_ = Services.hub.connectedDroneHolder.drone?.getPilotingItf(PilotingItfs.pointAndFly)?.deactivate()
}

/// Whether the mission can be stop.
Expand All @@ -66,9 +66,9 @@ public struct TouchAndFlyActivationModel: MissionActivationModel {

public func isActive() -> Bool {
let poi = Services.hub.connectedDroneHolder.drone?.getPilotingItf(PilotingItfs.pointOfInterest)
let guided = Services.hub.connectedDroneHolder.drone?.getPilotingItf(PilotingItfs.guided)
guard let poi = poi, let guided = guided else { return false }
return poi.state == .active || guided.state == .active
let pointAndFly = Services.hub.connectedDroneHolder.drone?.getPilotingItf(PilotingItfs.pointAndFly)
guard let poi = poi, let pointAndFly = pointAndFly else { return false }
return poi.state == .active || pointAndFly.state == .active
}

public func getPriority() -> MissionPriority {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ private extension SettingValuesChoiceTableViewCell {
}
}
button.cornerRadiusedWith(backgroundColor: backgroundColor,
radius: Style.largeCornerRadius,
borderWidth: Style.largeBorderWidth)
radius: Style.largeCornerRadius)
button.addShadow()
button.isSelected = isSelected
button.tintColor = button.isSelected ? .white : ColorName.defaultTextColor.color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ private extension ProjectManagerViewController {
} else {
// Cancel the view tap gesture subscriber.
tapAroundKeyboardSubscriber?.cancel()
handleProjectNameModification()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ extension GalleryViewModel {
start(action: .delete)

try await mediaListService.delete(medias: medias)
deselectAll()
stop(action: .delete)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ final class SettingsGeoFenceCell: MainTableViewCell, NibReusable {
private enum Constants {
static let altitudeIndex: Int = 1
static let distanceIndex: Int = 2
static let distanceMinRange: Float = 10
static let distanceMaxRange: Float = 1000
static let distanceHighlightedRangePercent: Float = 0.6
}

// MARK: - Override Funcs
Expand All @@ -62,7 +65,14 @@ final class SettingsGeoFenceCell: MainTableViewCell, NibReusable {
guard let viewModel = viewModel as? SettingsGeofenceViewModel else { return }
self.viewModel = viewModel

viewModel.notifyChangePublisher
viewModel.isGeofenceActivatedPublisher
.removeDuplicates()
.combineLatest(viewModel.minDistancePublisher.removeDuplicates(),
viewModel.distancePublisher.removeDuplicates(),
viewModel.maxDistancePublisher.removeDuplicates())
.combineLatest(viewModel.minAltitudePublisher.removeDuplicates(),
viewModel.altitudePublisher.removeDuplicates(),
viewModel.isUpdatingPublisher.removeDuplicates())
.sink { [weak self] _ in
guard let self = self else { return }
self.updateView()
Expand Down Expand Up @@ -114,9 +124,14 @@ private extension SettingsGeoFenceCell {
/// Configures the distance slider cell.
func configureDistanceSliderCell() {
let settingSegmentedEntry = viewModel.geoFenceDistanceEntry
let min = Float((settingSegmentedEntry.setting as? SliderSetting)?.min) ?? Constants.distanceMinRange
let max = settingSegmentedEntry.settingStepperSlider?.limitIntervalChange ?? Constants.distanceMaxRange
distanceSliderCell.configureCell(settingEntry: settingSegmentedEntry,
atIndexPath: IndexPath(row: Constants.distanceIndex, section: 0),
shouldShowBackground: false)
shouldShowBackground: false,
highlightedRange: SliderHighlightedRange(min: min,
max: max,
percent: Constants.distanceHighlightedRangePercent))
distanceSliderCell.enabledMargins = []
}

Expand All @@ -137,12 +152,12 @@ extension SettingsGeoFenceCell: SettingsSliderCellDelegate {

switch indexPath.row {
case Constants.altitudeIndex:
if let setting = viewModel.geoFenceAltitudeEntry.setting as? DoubleSetting {
if let setting = viewModel.geoFenceAltitudeEntry.setting as? SliderSetting {
setting.value = convertedValue
viewModel.saveGeofenceAltitude(convertedValue)
}
case Constants.distanceIndex:
if let setting = viewModel.geoFenceDistanceEntry.setting as? DoubleSetting {
if let setting = viewModel.geoFenceDistanceEntry.setting as? SliderSetting {
setting.value = convertedValue
viewModel.saveGeofenceDistance(convertedValue)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ final class SettingsSliderCell: MainTableViewCell, NibReusable {
private var sliderOverLimitValue: Float?
private var sliderDefaultValue: Float?
private var currentValueIntervalStep: Float = 0.05
private var currentValueStepped: Float = 0.0
private var currentValueStepped: Float?
private var indexPath: IndexPath!
private var highlightedRange: SliderHighlightedRange?
private var isEnabled: Bool = true {
didSet {
slider.isEnabled = isEnabled
Expand All @@ -79,7 +80,7 @@ final class SettingsSliderCell: MainTableViewCell, NibReusable {
case .percent?:
return currentUnit?.value(withFloat: slider.value.percentValue(min: slider.minimumValue, max: slider.maximumValue)) ?? ""
default:
return currentUnit?.value(withFloat: slider.value) ?? ""
return currentUnit?.value(withFloat: currentValueStepped ?? slider.value) ?? ""
}
}

Expand Down Expand Up @@ -107,13 +108,16 @@ final class SettingsSliderCell: MainTableViewCell, NibReusable {
/// - settingEntry: cell setting entry
/// - indexPath: indexPath
/// - shouldShowBackground: tells if we must show the background
/// - highlightedRange: specific slider range to highlight
func configureCell(settingEntry: SettingEntry,
atIndexPath indexPath: IndexPath,
shouldShowBackground: Bool = true) {
shouldShowBackground: Bool = true,
highlightedRange: SliderHighlightedRange? = nil) {
setupBackground(shouldShow: shouldShowBackground)

self.settingEntry = settingEntry
self.indexPath = indexPath
self.highlightedRange = highlightedRange
titleLabel.text = settingEntry.title
currentUnit = settingEntry.unit ?? UnitType.none

Expand All @@ -126,27 +130,29 @@ final class SettingsSliderCell: MainTableViewCell, NibReusable {
if let setting = settingEntry.setting as? DoubleSetting {
slider.maximumValue = Float(setting.max)
slider.minimumValue = Float(setting.min)
slider.value = settingEntry.savedValue ?? Float(setting.value)
slider.value = settingEntry.savedValue ?? rangeToSliderValue(value: Float(setting.value)) ?? Float(setting.value)
}

isEnabled = settingEntry.isEnabled
updateSliderView()
}
}

// MARK: - Private Funcs
private extension SettingsSliderCell {

/// Add A range to slider
///
/// - Parameters:
/// - settingStepperSlider: setting stepper to add
func actionStepperSlider(_ settingStepperSlider: SettingStepperSlider) {
let minValueSlider = slider.minimumValue
let maxValueSlider = slider.maximumValue
var currentValueSlider = sliderToRangeValue() ?? slider.value

let limitIntervalChange = settingStepperSlider.limitIntervalChange
let leftIntervalStep = settingStepperSlider.leftIntervalStep
let rightIntervalStep = settingStepperSlider.rightIntervalStep
var currentValueSlider = slider.value

if (minValueSlider...limitIntervalChange).contains(currentValueSlider) {
currentValueIntervalStep = leftIntervalStep
} else {
Expand Down Expand Up @@ -214,6 +220,56 @@ private extension SettingsSliderCell {
? ColorName.white.color
: .clear
}

/// Switch the slider value to its proportional within a highlighted range of values
/// - Returns: the newly created slider value.
func sliderToRangeValue() -> Float? {
guard let highlightedRange = self.highlightedRange else { return nil }

let minValueSlider = slider.minimumValue
let maxValueSlider = slider.maximumValue
let currentValueSlider = slider.value
let targetMinValue: Float = highlightedRange.min
let targetMaxValue: Float = highlightedRange.max

let progressPercentage = (slider.value - minValueSlider) / (maxValueSlider - minValueSlider)

if progressPercentage < highlightedRange.percent {
let rangeMinValue: Float = minValueSlider
let rangeMaxValue: Float = minValueSlider + (maxValueSlider - minValueSlider) * highlightedRange.percent
let rangePercentage = (currentValueSlider - rangeMinValue) / (rangeMaxValue - rangeMinValue)
return targetMinValue + (rangePercentage * (targetMaxValue - targetMinValue))
} else {
let rangeMinValue: Float = minValueSlider + (maxValueSlider - minValueSlider) * highlightedRange.percent
let rangeMaxValue: Float = maxValueSlider
let rangePercentage = (currentValueSlider - rangeMinValue) / (rangeMaxValue - rangeMinValue)
return targetMaxValue + (rangePercentage * (maxValueSlider - targetMaxValue))
}
}

/// Switch a previously computed proportional value back to an original slider value
/// - Returns: the newly created slider value.
func rangeToSliderValue(value: Float) -> Float? {
guard let highlightedRange = self.highlightedRange else { return nil }

let minValueSlider = slider.minimumValue
let maxValueSlider = slider.maximumValue
let currentValueSlider = value
let targetMinValue: Float = highlightedRange.min
let targetMaxValue: Float = highlightedRange.max

if currentValueSlider <= targetMaxValue {
let receivedPercentage = (currentValueSlider - targetMinValue) / (targetMaxValue - targetMinValue)
let rangeMinValue: Float = minValueSlider
let rangeMaxValue: Float = minValueSlider + (maxValueSlider - minValueSlider) * highlightedRange.percent
return rangeMinValue + (receivedPercentage * (rangeMaxValue - rangeMinValue))
} else {
let rangeMinValue: Float = minValueSlider + (maxValueSlider - minValueSlider) * highlightedRange.percent
let rangeMaxValue: Float = maxValueSlider
let receivedPercentage = (currentValueSlider - targetMaxValue) / (maxValueSlider - targetMaxValue)
return rangeMinValue + (receivedPercentage * (rangeMaxValue - rangeMinValue))
}
}
}

// MARK: - Actions
Expand All @@ -226,10 +282,9 @@ private extension SettingsSliderCell {
@IBAction func didFinishEditing(_ sender: AnyObject) {
if (settingEntry?.settingStepperSlider) != nil {
guard let unwSettingStepperSlider = sender as? UISlider else { return }
unwSettingStepperSlider.setValue(currentValueStepped, animated: true)
unwSettingStepperSlider.setValue(currentValueStepped ?? slider.value, animated: false)
}

delegate?.settingsSliderCellSliderDidFinishEditing(value: slider.value,
delegate?.settingsSliderCellSliderDidFinishEditing(value: currentValueStepped ?? slider.value,
atIndexPath: indexPath)

LogEvent.log(.button(item: settingEntry?.itemLogKey ?? "" + SettingsBehavioursMode.current.logKey ,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2023 Parrot Drones SAS
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the Parrot Company nor the names
// of its contributors may be used to endorse or promote products
// derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// PARROT COMPANY BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.

import Foundation

class SliderHighlightedRange {
var min: Float
var max: Float
var percent: Float

init(min: Float, max: Float, percent: Float) {
self.min = min
self.max = max
self.percent = percent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extension QuickSettingsViewModel {
imageDisabled: Asset.Settings.Quick.icStopAudio.image,
itemLogKey: LogEvent.LogKeyQuickSettings.audio),
SettingEntry(setting: SettingsGeofenceViewModel.geofenceModeModel(geofence: geofence),
title: L10n.settingsAdvancedCategoryGeofence,
title: L10n.settingsQuickCategoryGeofence,
itemLogKey: LogEvent.LogKeyQuickSettings.geofence),
SettingEntry(setting: newZoomModel,
title: L10n.settingsCameraLossyZoom,
Expand Down
Loading

0 comments on commit fe9ca49

Please sign in to comment.