コード例 #1
0
        private SearchCountriesRequest CreateSearchRequest(string text)
        {
            SearchCountriesRequest request;

            if (!_searchResultsCache.TryGetValue(text, out request))
            {
                IList <Country> source;

                if (_lastSearchRequest != null &&
                    text.IndexOf(_lastSearchRequest.Text, StringComparison.OrdinalIgnoreCase) != -1)
                {
                    source = _lastSearchRequest.Source;
                }
                else
                {
                    _source = _source ?? CountryUtils.CountriesSource;

                    source = _source;
                }

                request = new SearchCountriesRequest(text, source);
            }
            return(request);
        }
コード例 #2
0
        private void SearchInternal(string text)
        {
            if (_lastSearchRequest != null)
            {
                _lastSearchRequest.Cancel();
            }

            if (string.IsNullOrEmpty(text))
            {
                LazySearchItems.Clear();
                SearchItems.Clear();

                foreach (var contact in _source)
                {
                    SearchItems.Add(contact);
                }

                return;
            }

            var nextSearchRequest = CreateSearchRequest(text);

            IsWorking = true;
            nextSearchRequest.ProcessAsync(results =>
                                           Execute.BeginOnUIThread(() =>
            {
                if (nextSearchRequest.IsCanceled)
                {
                    return;
                }

                SearchItems.Clear();
                LazySearchItems.Clear();

                for (var i = 0; i < results.Count; i++)
                {
                    if (i < 8)
                    {
                        SearchItems.Add(results[i]);
                    }
                    else
                    {
                        LazySearchItems.Add(results[i]);
                    }
                }

                IsWorking = false;
                Status    = Items.Count == 0 ? AppResources.NoResults : string.Empty;

                Telegram.Api.Helpers.Execute.BeginOnUIThread(() =>
                {
                    if (!String.Equals(text, Text, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    foreach (var lazySearchItem in LazySearchItems)
                    {
                        SearchItems.Add(lazySearchItem);
                    }
                    LazySearchItems.Clear();
                });
            }));

            _searchResultsCache[nextSearchRequest.Text] = nextSearchRequest;
            _lastSearchRequest = nextSearchRequest;
        }