public void stop() { if (!subscription.IsNullOrEmpty()) { subscription.Dispose(); subscription = null; } }
public void OnStop() { ShowCountryProgress = false; if (!countryCancelation.IsNullOrEmpty()) { countryCancelation.Dispose(); countryCancelation = null; } ShowCityProgress = false; if (!cityCancelation.IsNullOrEmpty()) { cityCancelation.Dispose(); cityCancelation = null; } }
public void OnStart() { BusManager.Send(new SearchBarEvent() { isShow = true }); querySubscription = BusManager.Add((args) => { if (args is SearchBarEvent) { SearchBarEvent evt = args as SearchBarEvent; if (!evt.IsNullOrEmpty()) { if (evt.isQueryChange) { if (!queryCancel.IsNullOrEmpty()) { queryCancel.Dispose(); queryCancel = null; } queryCancel = Observable.Return( Regex.IsMatch(evt.queryText, @"([a-zA-Z0-9]{3,}[,\s]*)$", RegexOptions.IgnoreCase) ).Throttle(TimeSpan.FromMilliseconds(500)) .SelectMany(x => { if (x) { return(endpointClient.queryCustomers(evt.queryText)); } else { App.Current.Dispatcher.Invoke(() => { if (!Customers.IsNullOrEmpty()) { Customers.Clear(); } if (!CustomerFiles.IsNullOrEmpty()) { CustomerFiles.Clear(); } }); } return(Observable.Empty <HttpResponseMessage>()); }).ToResponse <List <CustomerEntity> >() .SubscribeOn(ThreadPoolScheduler.Instance) .ObserveOn(App.Current.Dispatcher) .Subscribe(x => { if (x.Code == ResponseCode.OK) { List <CustomerEntity> customers = x.Data; if (!customers.IsNullOrEmpty()) { if (Customers.IsNullOrEmpty()) { Customers = new CustomerEntities(); } else { Customers.Clear(); if (!CustomerFiles.IsNullOrEmpty()) { CustomerFiles.Clear(); } } customers.ForEach(y => Customers.Add(y)); } } else { x.PersistResponseError(); } }, error => { error.PersistException(); Debug.WriteLine("Error: " + error.StackTrace); }, () => { BusManager.Send(new SearchBarEvent() { isProgress = true }); }); } } } }); }