public HomeLocationEditorViewModel( ISchedulerProvider schedulerProvider, INavigationService navigationService, IPlacesProvider placesProvider, IEmptyAutocompleteResultProvider autocompleteResultProvider, ISettingsProvider settingsProvider, IGeocodingProvider geocodingProvider) : base(schedulerProvider, placesProvider, geocodingProvider, navigationService) { _autocompleteResultProvider = autocompleteResultProvider; SelectedAutoCompleteResultModelObservable .Subscribe(async result => { var address = await geocodingProvider.ReverseGeocodingFromPlaceId(result.PlaceId); settingsProvider.SetHomeAddress(address); navigationService.GoBack(); }); this.Changed(() => SelectedSearchResult) .Where(r => r is SetLocationOnMapResultModel) .Subscribe(result => { navigationService.NavigateTo <ChooseHomeAddressOnMapViewModel>(); }); }
protected BaseLocationEditorViewModel( ISchedulerProvider schedulerProvider, IPlacesProvider placesProvider, IGeocodingProvider geocodingProvider, INavigationService navigationService) { _geocodingProvider = geocodingProvider; _navigationService = navigationService; this.Changed(() => SearchText) .Where(text => !string.IsNullOrEmpty(text)) .Throttle(TimeSpan.FromMilliseconds(300), schedulerProvider.DefaultScheduler) .ObserveOn(schedulerProvider.SynchronizationContextScheduler) .Subscribe(async searchText => { IsSearching = true; SearchResults = await placesProvider.GetAutoCompleteResponse(searchText); IsSearching = false; }); this.Changed(() => SearchText) .Where(string.IsNullOrEmpty) .Subscribe(_ => SearchResults = GetEmptyAutocompleteResult()); this.Changed(() => SelectedSearchResult) .Where(result => result is EmptyAutocompleteResultModel) .Cast <EmptyAutocompleteResultModel>() .ObserveOn(schedulerProvider.SynchronizationContextScheduler) .Subscribe(selectedResult => { if (selectedResult.Address == null) { NavigateToLocationEditorViewModel(selectedResult); } else { SelectedAddress = selectedResult.Address; _navigationService.GoBack(); } }); SelectedAutoCompleteResultModelObservable.Subscribe(async result => { await SetAutoCompleteResultModel(result.PlaceId); }); }