Пример #1
0
 public static async Task TryExecuteAsync <T>(this IMvxAsyncCommand <T> self, T parameter)
 {
     if (self.CanExecute(parameter))
     {
         await self.ExecuteAsync(parameter);
     }
 }
Пример #2
0
 public static async Task TryExecuteAsync(this IMvxAsyncCommand self)
 {
     if (self.CanExecute())
     {
         await self.ExecuteAsync();
     }
 }
        public static IDisposable SubscribeSearchText <TParameter, TResult>(this MvxViewModel <TParameter, TResult> viewModel, string propertyName, IMvxAsyncCommand searchCommand, Func <bool> canExecute)
        {
            var propertyChanged = Observable.FromEventPattern <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                h => viewModel.PropertyChanged += h, h => viewModel.PropertyChanged -= h);

            var autoCompleteSuggest = propertyChanged
                                      .Where(property => property.EventArgs.PropertyName.Equals(propertyName))
                                      .Select(property =>
                                              property.Sender.GetType().GetProperty(propertyName).GetValue(property.Sender) as string)
                                      .Where(_ => canExecute())
                                      .Throttle(TimeSpan.FromMilliseconds(250))
                                      .DistinctUntilChanged();

            IObservable <Unit> GetSuggestions() =>
            Observable.FromAsync(() => searchCommand.ExecuteAsync());

            var results = from searchText in autoCompleteSuggest
                          from suggestResult in GetSuggestions()
                          .TakeUntil(autoCompleteSuggest)
                          select suggestResult;

            return(results.ObserveOn(SynchronizationContext.Current).Subscribe(
                       unit => { },
                       exception => { }
                       ));
        }
        public static IDisposable SubscribeOnScrollEnd(this MvxRecyclerView recyclerView, IMvxAsyncCommand loadElements, Func <bool> canExecute)
        {
            var propertyChanged = Observable.FromEventPattern <EventHandler <View.ScrollChangeEventArgs>, View.ScrollChangeEventArgs>(
                h => recyclerView.ScrollChange += h, h => recyclerView.ScrollChange -= h);

            return(propertyChanged
                   .Select(_ => recyclerView.GetLayoutManager() as LinearLayoutManager ??
                           recyclerView.GetLayoutManager() as GridLayoutManager)
                   .Where(lm => lm != null && canExecute() &&
                          (lm.StackFromEnd
                                 ? lm.FindFirstVisibleItemPosition() <= 10
                                 : lm.FindFirstVisibleItemPosition() + lm.ChildCount >= lm.ItemCount - 10))
                   .Throttle(TimeSpan.FromMilliseconds(100))
                   .ObserveOn(Application.SynchronizationContext)
                   .Subscribe(
                       async _ => await loadElements.ExecuteAsync(),
                       exception =>
                       Mvx.Resolve <IToastSerivce>().ShowByResourceId(exception.Message)));
        }
Пример #5
0
 private async void HandlePolylineClick(object sender, GoogleMap.PolylineClickEventArgs poly)
 {
     int id = int.Parse(poly.Polyline.Id.Trim(new Char[] { 'p', 'l' }));
     await _command.ExecuteAsync(id);
 }