public CargoCodePage() { InitializeComponent(); String icon = "IconCheck.png"; BindingContext = this; _cargoService = new CargoService(App.Database.sqlite); CargoNamesList.ItemsSource = CargoList; ToolbarItems.Add(new ToolbarItem { Icon = icon, Command = new Command(() => { Device.BeginInvokeOnMainThread(async() => { await Navigation.PopModalAsync(); }); }), }); CargoNamesList.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => { App.Request.Cargo = (Cargo)e.SelectedItem; Device.BeginInvokeOnMainThread(async() => { await Navigation.PopModalAsync(); }); }; Search.TextChanged += async(sender, e) => { if (e.NewTextValue.Length != 0) { Loader.IsVisible = true; var databaseCargo = await _cargoService.FindByCode(e.NewTextValue); if (databaseCargo.Count == 0) { if (!DownloadCheker.IsCargoDownloadedByCode(e.NewTextValue)) { DataRetrievalHelper dataHelper = new DataRetrievalHelper(); await dataHelper.GetAndSaveCargoByCode(e.NewTextValue[0]); databaseCargo = await _cargoService.FindByCode(e.NewTextValue); } } CargoList.Clear(); foreach (var cargo in databaseCargo) { CargoList.Add(cargo); } Loader.IsVisible = false; CargoNamesList.IsVisible = CargoList.Count != 0; } else { CargoNamesList.IsVisible = false; } }; }
public DataRetrievalHelper() { _stationService = new StationService(App.Database.sqlite); _cargoService = new CargoService(App.Database.sqlite); _observers = new List <IObserver <Message> >(); }