Esempio n. 1
0
        /// <summary>
        /// </summary>
        private static async void LocationByGeocoding()
        {
            var dialogResult = await XameteoDialogs.Prompt(Resx.Resources.Geolocation_Title, Resx.Resources.Geolocation_Message, string.Empty);

            if (dialogResult.Ok == false)
            {
                return;
            }

            var userChoice = dialogResult.Text.Trim();

            if (userChoice.Length > 0)
            {
                XameteoDialogs.ShowLoading();

                try
                {
                    var googleResponse = await XameteoApp.Instance.Geocoding.Get(userChoice);

                    if (googleResponse.Status != "OK")
                    {
                        throw new InvalidOperationException(string.Format(Resx.Resources.Geolocation_Error, googleResponse.Status));
                    }

                    var geocodingResults = googleResponse.Results;

                    if (geocodingResults.Count < 1)
                    {
                        throw new InvalidOperationException(Resx.Resources.Geolocation_Zero);
                    }

                    XameteoDialogs.HideLoading();

                    if (geocodingResults.Count == 1)
                    {
                        SaveLocation(new CoordinatesAdapter(googleResponse.Results[0].GeocodingGeometry.Location));
                    }
                    else
                    {
                        XameteoDialogs.ActionSheet(
                            geocodingResults.Select(it => new ActionSheetOption(it.Address, () => SaveLocation(new CoordinatesAdapter(it.GeocodingGeometry.Location)))).ToList(),
                            Resx.Resources.Geolocation_Multiple
                            );
                    }
                }
                catch (Exception exception)
                {
                    XameteoDialogs.HideLoading();
                    XameteoDialogs.Alert(exception);
                }
            }
            else
            {
                XameteoDialogs.Alert(Resx.Resources.Geolocation_Title, Resx.Resources.Prompt_Error);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="units"></param>
 /// <param name="generator"></param>
 /// <returns></returns>
 public static IDisposable SelectUnit <T>(T[] units, Action <T> generator) where T : Unit => XameteoDialogs.ActionSheet(
     units.Select(unit => new ActionSheetOption(unit.ToString(), () => generator(unit))).ToList(),
     string.Format(Resources.Settings_Units, units[0].Type)
     );
Esempio n. 3
0
 /// <summary>
 /// </summary>
 private static void LocationByAirport() => XameteoDialogs.ActionSheet(Airport.Instances.Select(
                                                                           airport => new ActionSheetOption(airport.ToString(), () => SaveLocation(new AirportAdapter(airport)))
                                                                           ).ToList(), Resx.Resources.Prompt_Airport);
Esempio n. 4
0
 /// <summary>
 /// </summary>
 public void InsertClicked(object sender, EventArgs ags)
 {
     XameteoDialogs.ActionSheet(_options, Resx.Resources.Prompt_Source);
 }