void SetWeightUnitsTapped() { var imperialPoundsAction = ActionSheetButton.CreateButton(WeightUnitEnum.ImperialPounds.ToSettingsName(), new DelegateCommand(() => { WeightUnitTypeSelected(WeightUnitEnum.ImperialPounds); })); var kilogramsAction = ActionSheetButton.CreateButton(WeightUnitEnum.Kilograms.ToSettingsName(), new DelegateCommand(() => { WeightUnitTypeSelected(WeightUnitEnum.Kilograms); })); var stonesPoundAction = ActionSheetButton.CreateButton(WeightUnitEnum.StonesAndPounds.ToSettingsName(), new DelegateCommand(() => { WeightUnitTypeSelected(WeightUnitEnum.StonesAndPounds); })); var cancelAction = ActionSheetButton.CreateCancelButton(Constants.Strings.Generic_Cancel, new DelegateCommand(() => { })); DialogService.DisplayActionSheetAsync(Constants.Strings.Settings_ChangeWeightUnitsActionSheet, imperialPoundsAction, kilogramsAction, stonesPoundAction, cancelAction); }
async void WeightUnitTypeSelected(WeightUnitEnum newUnits) { // already using this same setting, just return if (newUnits == SettingsService.WeightUnit) { return; } // see if there are existing weight entries not of this type IList <WeightEntry> allEntries = null; try { IncrementPendingRequestCount(); allEntries = await DataService.GetAllWeightEntries(); var weightsWithDifferentUnits = allEntries.Where(w => w.WeightUnit != newUnits); if (!weightsWithDifferentUnits.Any()) { var currentGoal = await DataService.GetGoal(); if (currentGoal == null) { SettingsService.WeightUnit = newUnits; // nothing to change, so just change the setting and return SetupMenu(); // refresh the menu to show the new setting return; } } } catch (Exception ex) { AnalyticsService.TrackFatalError($"{nameof(WeightUnitTypeSelected)} - an exception occurred getting all weights", ex); await DialogService.DisplayAlertAsync(Constants.Strings.Settings_ChangeWeightUnits_GetWeightsError_Title, Constants.Strings.Settings_ChangeWeightUnits_GetWeightsError_Message, Constants.Strings.Generic_OK); } finally { DecrementPendingRequestCount(); } // if they are switching between pounds and stones/pounds we don't need to ask them how to convert as the data is stored // the same either way (just changes how presented), so just go straight to the conversion in this case if ((newUnits == WeightUnitEnum.ImperialPounds && SettingsService.WeightUnit == WeightUnitEnum.StonesAndPounds) || (newUnits == WeightUnitEnum.StonesAndPounds && SettingsService.WeightUnit == WeightUnitEnum.ImperialPounds)) { UpdateWeightEntriesAndGoalUnits(newUnits, false); return; } // show warning of needing to convert these values var convertAction = ActionSheetButton.CreateButton(Constants.Strings.Settings_ChangeWeightUnits_ConvertWarning_ConvertWeightValues, new DelegateCommand(() => { UpdateWeightEntriesAndGoalUnits(newUnits, true); })); var changeUnitAction = ActionSheetButton.CreateButton(Constants.Strings.Settings_ChangeWeightUnits_ConvertWarning_ChangeUnits, new DelegateCommand(() => { UpdateWeightEntriesAndGoalUnits(newUnits, false); })); var cancelAction = ActionSheetButton.CreateCancelButton(Constants.Strings.Generic_Cancel, new DelegateCommand(() => { })); await DialogService.DisplayActionSheetAsync(Constants.Strings.Settings_ChangeWeightUnits_ConvertWarning, convertAction, changeUnitAction, cancelAction); }
private async void ExecuteMoreCommand() { try { IsBusy = true; var choice = await DialogService.DisplayActionSheetAsync("Menu", "Cancel", null, "Move", "Upload Screenshot"); switch (choice) { case "Upload Screenshot": Screenshot = Xamarin.Forms.DependencyService.Get <IScreenshotService>().Capture(); if (Screenshot != null) { using (Helper.Loading("Uploading Screenshot")) { var uploadUrl = $"{Api.ApiBaseUrl}{Api.Missions.Upload.Replace("{id}", Mission.Id.ToString())}"; var filename = $"mission-{Mission.Id}-screenshot-{Guid.NewGuid()}"; var token = await SecureStorage.GetAsync(SecureStorageProperties.AccessToken); var uploadResponse = await AppService.Api.Missions.Upload(Mission.Id, Screenshot); if (uploadResponse == null) { base.DisplayNoConnectionMessage(); return; } if (uploadResponse.Item2 != null) { base.DisplayErrorMessage(uploadResponse.Item2); return; } if (uploadResponse.Item1 != null) { Mission.Attachment = uploadResponse.Item1.AwsPublicUrl; AttachmentLink = Path.GetFileName(Mission.Attachment); Helper.Toast("Screenshot uploaded!", ToastType.Success); } } } break; case "Move": await NavigationService.NavigateAsync($"Navigation/NewMission?id={Mission.Id}", null, true); break; default: break; } } catch (Exception ex) { base.DisplayExceptionMessage(ex); } finally { IsBusy = false; } }