public StationNamePage() { InitializeComponent(); String icon = "IconCheck.png"; BindingContext = this; if (StartPage.IsDeparture) { Title = "Выбор станции отправления"; } else { Title = "Выбор станции назначения"; } _stationService = new StationService(App.Database.sqlite); StationNamesList.ItemsSource = Stations; ToolbarItems.Add(new ToolbarItem { Icon = icon, Command = new Command(() => { Device.BeginInvokeOnMainThread(async() => { await Navigation.PopModalAsync(); }); }), }); StationNamesList.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => { if (StartPage.IsDeparture) { App.Request.DepartureStation = (Station)e.SelectedItem; } else { App.Request.ArrivalStation = (Station)e.SelectedItem; } Device.BeginInvokeOnMainThread(async() => { await Navigation.PopModalAsync(); }); }; Search.TextChanged += async(sender, e) => { if (e.NewTextValue.Length != 0) { Loader.IsVisible = true; var databaseStations = await _stationService.FindByName(e.NewTextValue.ToUpper()); if (databaseStations.Count == 0) { if (!DownloadCheker.IsStationDownloadedByName(e.NewTextValue)) { DataRetrievalHelper dataHelper = new DataRetrievalHelper(); await dataHelper.GetAndSaveStationsByName(e.NewTextValue[0]); databaseStations = await _stationService.FindByName(e.NewTextValue.ToUpper()); } } Stations.Clear(); foreach (var cargo in databaseStations) { Stations.Add(cargo); } Loader.IsVisible = false; StationNamesList.IsVisible = Stations.Count != 0; } else { StationNamesList.IsVisible = false; } }; }
public DataRetrievalHelper() { _stationService = new StationService(App.Database.sqlite); _cargoService = new CargoService(App.Database.sqlite); _observers = new List <IObserver <Message> >(); }