protected void AddToTotals(double?distanceQuantity, DistanceUom?distanceUom, double?timeQuantity, TimeUom?timeUom, UserDefaults userDefaults, int quantity, bool isRest) { double?repDistance = null; double?repTime = null; if (distanceQuantity.HasValue && distanceUom.HasValue) { repDistance = UnitConversions.ConvertDistance(distanceQuantity.Value, distanceUom.Value, userDefaults.DistanceUom) * quantity; } if (timeQuantity.HasValue && timeUom.HasValue) { repTime = UnitConversions.ConvertTime(timeQuantity.Value, timeUom.Value, userDefaults.TimeUom) * quantity; } if (repDistance.HasValue && repTime.HasValue) { TotalDistanceQuantity += repDistance.Value; TotalTimeQuantity += repTime.Value; } else if (repDistance.HasValue) { TotalDistanceQuantity += repDistance.Value; TotalTimeQuantity += (userDefaults.IsPaceDistancePerTime ? repDistance.Value / userDefaults.Pace : repDistance.Value * userDefaults.Pace); } else if (repTime.HasValue && !isRest) { TotalTimeQuantity += repTime.Value; TotalDistanceQuantity += (userDefaults.IsPaceDistancePerTime ? repTime.Value * userDefaults.Pace : repTime.Value / userDefaults.Pace); } else { return; // could not get reliable values from repetition } }