Beispiel #1
0
        /// <summary>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void SelectClicked(object sender, EventArgs args)
        {
            try
            {
                var dateTime     = DateTime.Now;
                var dialogResult = await XameteoDialogs.DatePicker(dateTime.AddDays(-30), dateTime.AddDays(-1));

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

                XameteoDialogs.ShowLoading();
                _selected = dialogResult.SelectedDate;
                OnPropertyChanged(nameof(Selected));

                var parsed  = _selected.Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
                var history = (await XameteoApp.Instance.Apixu.History(_adapter, parsed)).Forecast.Days;

                if (history.Count > 0)
                {
                    HistoryView.Content = new HistoryView(history[0]);
                }

                XameteoDialogs.HideLoading();
            }
            catch (Exception exception)
            {
                XameteoDialogs.HideLoading();
                XameteoDialogs.Alert(exception);
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
 /// <summary>
 /// </summary>
 /// <param name="apixuPlace"></param>
 public LocationView(ApixuPlace apixuPlace)
 {
     try
     {
         _place = apixuPlace;
         InitializeView(apixuPlace.Forecast);
         ToolbarItems.Add(new ToolbarItem(Resx.Resources.Button_Refresh, "icon_refresh.png", RefreshPlace));
     }
     catch (Exception exception)
     {
         XameteoDialogs.Alert(exception);
     }
 }
Beispiel #4
0
 /// <summary>
 /// </summary>
 private static async void LocationByDevice()
 {
     try
     {
         XameteoDialogs.ShowLoading();
         SaveLocation(new CoordinatesAdapter(await XameteoApp.Instance.DeviceLocation()));
         XameteoDialogs.HideLoading();
     }
     catch (Exception exception)
     {
         XameteoDialogs.HideLoading();
         XameteoDialogs.Alert(exception);
     }
 }
Beispiel #5
0
 /// <summary>
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs args)
 {
     try
     {
         if (args.SelectedItem is MainModel item)
         {
             IsPresented = false;
             Detail      = new NavigationPage(item.ViewModel == null ? (Page)Activator.CreateInstance(item.TargetType) : new LocationView(item.ViewModel));
         }
     }
     catch (Exception exception)
     {
         XameteoDialogs.Alert(exception);
     }
 }
Beispiel #6
0
        /// <summary>
        /// </summary>
        /// <param name="previousIndex"></param>
        /// <returns></returns>
        public MainModel RefreshView(int previousIndex)
        {
            try
            {
                MenuItems.Clear();
                MenuItems.Add(_homePage);
                MenuItems.Add(_settingsPage);
                XameteoApp.Instance.Places.ForEach(InsertLocation);
            }
            catch (Exception exception)
            {
                XameteoDialogs.Alert(exception);
            }

            return(MenuItems[previousIndex]);
        }
Beispiel #7
0
        /// <summary>
        /// </summary>
        private async void InitializeView()
        {
            try
            {
                MenuItems.Add(_homePage);
                MenuItems.Add(_settingsPage);
                XameteoDialogs.ShowLoading();
                await XameteoApp.Instance.RefreshPlaces(0);

                XameteoDialogs.HideLoading();
            }
            catch (Exception exception)
            {
                XameteoDialogs.HideLoading();
                XameteoDialogs.Alert(exception);
            }
        }
Beispiel #8
0
        /// <summary>
        /// </summary>
        /// <param name="source"></param>
        private static async void UpdateApixuKey(SettingsModel source)
        {
            var dialogResult = await XameteoDialogs.Prompt(Resources.ApixuKey_Title, Resources.ApixuKey_Message, XameteoApp.Instance.ApixuKey);

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

            var userChoice = dialogResult.Text.Trim();

            if (userChoice.Length > 0)
            {
                source.Value = userChoice;
                XameteoApp.Instance.ApixuKey = userChoice;
            }
            else if (dialogResult.Ok)
            {
                XameteoDialogs.Alert(Resources.ApixuKey_Title, Resources.Prompt_Error);
            }
        }
Beispiel #9
0
        /// <summary>
        /// </summary>
        /// <param name="apixuAdapter"></param>
        private static async void SaveLocation(ApixuAdapter apixuAdapter)
        {
            try
            {
                XameteoDialogs.ShowLoading();

                if (await XameteoApp.Instance.InsertPlace(apixuAdapter) == false)
                {
                    XameteoDialogs.HideLoading();
                    XameteoDialogs.Alert(Resx.Resources.Exists_Title, Resx.Resources.Exists_Message);
                }
                else
                {
                    XameteoDialogs.HideLoading();
                }
            }
            catch (Exception exception)
            {
                XameteoDialogs.HideLoading();
                XameteoDialogs.Alert(exception);
            }
        }
Beispiel #10
0
        /// <summary>
        /// </summary>
        public async void RefreshPlace()
        {
            XameteoDialogs.ShowLoading();

            try
            {
                var place = await XameteoApp.Instance.RefreshPlace(_place);

                if (place != null)
                {
                    Children.Clear();
                    _place = place;
                    InitializeView(place.Forecast);
                }

                XameteoDialogs.HideLoading();
            }
            catch (Exception exception)
            {
                XameteoDialogs.HideLoading();
                XameteoDialogs.Alert(exception);
            }
        }