public static IRepeatDuration Create(IRepeatDuration.RepeatDurationType type, RepeatStep parent) { IRepeatDuration newDuration; switch (type) { case IRepeatDuration.RepeatDurationType.RepeatCount: { newDuration = new RepeatCountDuration(parent); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilTime: { newDuration = new RepeatUntilTimeDuration(parent); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilDistance: { newDuration = new RepeatUntilDistanceDuration(parent); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilHeartRateAbove: { newDuration = new RepeatUntilHeartRateAboveDuration(parent); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilHeartRateBelow: { newDuration = new RepeatUntilHeartRateBelowDuration(parent); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilCalories: { newDuration = new RepeatUntilCaloriesDuration(parent); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilPowerAbove: { newDuration = new RepeatUntilPowerAboveDuration(parent); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilPowerBelow: { newDuration = new RepeatUntilPowerBelowDuration(parent); break; } default: { Debug.Assert(false); newDuration = null; break; } } parent.Duration = newDuration; return newDuration; }
void OnRepeatDurationChanged(RepeatStep modifiedStep, IRepeatDuration durationChanged, PropertyChangedEventArgs changedProperty) { if (ConcreteWorkout.StepRepeatDurationChanged != null) { ConcreteWorkout.StepRepeatDurationChanged(this, modifiedStep, durationChanged, changedProperty); } }
public static string FormatRepeatDurationDescription(IRepeatDuration duration) { string result; string baseString; IRepeatDuration.RepeatDurationType type = duration.Type; FieldInfo fieldInfo = type.GetType().GetField(Enum.GetName(type.GetType(), type)); StepDescriptionStringProviderAttribute providerAttribute = (StepDescriptionStringProviderAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(StepDescriptionStringProviderAttribute)); baseString = GarminFitnessView.GetLocalizedString(providerAttribute.StringName); switch (type) { case IRepeatDuration.RepeatDurationType.RepeatCount: { RepeatCountDuration concreteDuration = duration as RepeatCountDuration; result = String.Format(baseString, concreteDuration.RepetitionCount); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilDistance: { RepeatUntilDistanceDuration concreteDuration = duration as RepeatUntilDistanceDuration; result = String.Format(baseString, concreteDuration.GetDistanceInBaseUnit(), Length.LabelAbbr(concreteDuration.BaseUnit)); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilTime: { RepeatUntilTimeDuration concreteDuration = duration as RepeatUntilTimeDuration; result = String.Format(baseString, concreteDuration.Hours, concreteDuration.Minutes, concreteDuration.Seconds); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilHeartRateAbove: { RepeatUntilHeartRateAboveDuration concreteDuration = duration as RepeatUntilHeartRateAboveDuration; string unitsString; if (concreteDuration.IsPercentageMaxHeartRate) { unitsString = CommonResources.Text.LabelPercentOfMax; } else { unitsString = CommonResources.Text.LabelBPM; } result = String.Format(baseString, concreteDuration.MaxHeartRate, unitsString); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilHeartRateBelow: { RepeatUntilHeartRateBelowDuration concreteDuration = duration as RepeatUntilHeartRateBelowDuration; string unitsString; if (concreteDuration.IsPercentageMaxHeartRate) { unitsString = CommonResources.Text.LabelPercentOfMax; } else { unitsString = CommonResources.Text.LabelBPM; } result = String.Format(baseString, concreteDuration.MinHeartRate, unitsString); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilCalories: { RepeatUntilCaloriesDuration concreteDuration = duration as RepeatUntilCaloriesDuration; result = String.Format(baseString, concreteDuration.CaloriesToSpend); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilPowerAbove: { RepeatUntilPowerAboveDuration concreteDuration = duration as RepeatUntilPowerAboveDuration; string unitsString; if (concreteDuration.IsPercentFTP) { unitsString = GarminFitnessView.GetLocalizedString("PercentFTPText"); } else { unitsString = CommonResources.Text.LabelWatts; } result = String.Format(baseString, concreteDuration.MaxPower, unitsString); break; } case IRepeatDuration.RepeatDurationType.RepeatUntilPowerBelow: { RepeatUntilPowerBelowDuration concreteDuration = duration as RepeatUntilPowerBelowDuration; string unitsString; if (concreteDuration.IsPercentFTP) { unitsString = GarminFitnessView.GetLocalizedString("PercentFTPText"); } else { unitsString = CommonResources.Text.LabelWatts; } result = String.Format(baseString, concreteDuration.MinPower, unitsString); break; } default: { Debug.Assert(false); result = String.Empty; break; } } return result; }
private void OnDurationChanged(IRepeatDuration modifiedDuration, PropertyChangedEventArgs changedProperty) { TriggerDurationChangedEvent(modifiedDuration, changedProperty); }
protected void TriggerDurationChangedEvent(IRepeatDuration duration, PropertyChangedEventArgs args) { if (DurationChanged != null) { DurationChanged(this, duration, args); } }
void OnWorkoutStepRepeatDurationChanged(IWorkout modifiedWorkout, RepeatStep modifiedStep, IRepeatDuration modifiedDuration, PropertyChangedEventArgs changedProperty) { if (InvokeRequired) { Invoke(new WorkoutStepRepeatDurationChangedDelegate(OnWorkoutStepRepeatDurationChanged), new object[] { modifiedWorkout, modifiedStep, modifiedDuration, changedProperty }); } else { if (SelectedWorkout == modifiedWorkout) { // Refresh the steps list so it updates the name/description StepsList.Invalidate(); if (modifiedStep == SelectedStep) { UpdateUIFromDuration(); } } } }