Exemplo n.º 1
0
        protected override void SearchCommandExecute()
        {
            if (DelayCTS != null && !DelayCTS.IsCancellationRequested)
            {
                DelayCTS.Cancel();
                DelayCTS = new CancellationTokenSource();
            }

            if (HintsCTS != null && !HintsCTS.IsCancellationRequested)
            {
                HintsCTS.Cancel();
            }

            Task.Run(async() =>
            {
                await VmService.SaveSearchRequestInHistory(SearchText);
                await LoadContent();
            });

            ContentVm.SearchCommand.Execute(null);

            InvokeOnMainThread(() =>
            {
                HintsItems       = new ObservableCollection <IHintItemVM>();
                AutocomleteItems = new ObservableCollection <IAutocompleteItemVM>();

                HintsVisible   = false;
                HistoryVisible = false;

                RaisePropertyChanged(() => ContentVisible);
            });
        }
Exemplo n.º 2
0
        private void StartSearch(IContentSearchItemVM item)
        {
            if (DelayCTS != null && !DelayCTS.IsCancellationRequested)
            {
                DelayCTS.Cancel();
                DelayCTS = new CancellationTokenSource();
            }

            if (HintsCTS != null && !HintsCTS.IsCancellationRequested)
            {
                HintsCTS.Cancel();
            }

            SetProperty(ref _searchText, item.SearchText, "SearchText");

            ContentVm.SearchText = SearchText;

            SearchCommand.Execute(null);

            InvokeOnMainThread(() =>
            {
                HistoryVisible = false;
                HintsVisible   = false;

                RaisePropertyChanged(() => ContentVisible);
            });
        }
Exemplo n.º 3
0
        protected override void OnSearchTextChanged(string searchText)
        {
            ContentVm.SearchText = searchText;

            if (DelayCTS != null && !DelayCTS.IsCancellationRequested)
            {
                DelayCTS.Cancel();
                DelayCTS = new CancellationTokenSource();
            }

            if (HintsCTS != null && !HintsCTS.IsCancellationRequested)
            {
                HintsCTS.Cancel();
                HintsCTS = null;
            }

            if (ContentVm.SearchText.IsNullOrEmtpy())
            {
                InvokeOnMainThread(() =>
                {
                    HintsItems       = new ObservableCollection <IHintItemVM>();
                    AutocomleteItems = new ObservableCollection <IAutocompleteItemVM>();

                    HintsVisible   = false;
                    HistoryVisible = true;

                    RaisePropertyChanged(() => ContentVisible);
                });

                return;
            }

            try
            {
                DelayCTS = new CancellationTokenSource();
                Task.Run(async() =>
                {
                    try
                    {
                        await Task.Delay(300, DelayCTS.Token);
                        await LoadHintsContent();
                    }
                    catch (OperationCanceledException)
                    {
                    }
                }, DelayCTS.Token);
            }
            catch (OperationCanceledException)
            {
            }
        }