MonoMobile.Views.DialogViewController.PerformFilter C# (CSharp) Method

PerformFilter() public method

public PerformFilter ( string text ) : void
text string
return void
		public void PerformFilter(string text)
		{
			if (_OriginalSections == null)
				return;
			
			var progress = new ProgressHud() { TitleText = string.Format("Searching for {0}", text) , GraceTime = 0.5f };
			progress.ShowWhileExecuting(()=>
			{
				var index = 0;
				foreach(var section in _OriginalSections.Values)
				{
					section.DataContext = _OriginalDataContext[index++] as IList;
				}
				
				OnSearchTextChanged(text);
				
				var newSections = new Dictionary<int, Section>();
				
				var searchable = TableView.Source as ISearchBar;
				if (searchable != null)
				{
					if (searchable.SearchCommand == null)
					{
						index = 0;
						foreach(var section in _OriginalSections.Values)
						{
							if (TableView.Source is ListSource)
							{
								var newList = new List<object>();
								var list = section.DataContext as IEnumerable;
								if (list != null)
								{
									foreach(var item in list)
									{
										var caption = item as ICaption;
										var searchableItem = item as ISearchable;
										if ((searchableItem != null && searchableItem.Matches(text)) || 
											(caption != null && !string.IsNullOrEmpty(caption.Caption)) || 
											item.ToString().ToLower().Contains(text.ToLower()))
										{
											newList.Add(item);
	
											if (!newSections.ContainsKey(index))
											{
												newSections.Add(index, section);
											}
										}
									}
								}
	
								section.DataContext = newList;
							}
	
							index++;
						}
					}
					else
					{
						newSections = searchable.SearchCommand.Execute(_OriginalSections, text);
					}
				}
				
				((BaseDialogViewSource)TableView.Source).Sections = newSections;
	
				InvokeOnMainThread(()=>ReloadData());
			}, true);
		}

Usage Example

Exemplo n.º 1
0
//		public override void OnEditingStopped(UISearchBar searchbar)
//		{
//			var searchable = _Container.Root as ISearchBar;
//			if (searchable != null && searchable.IncrementalSearch)
//			{
//		//		searchbar.ShowsCancelButton = false;
//		//		_Container.FinishSearch(false);
//			}
//		}

        public override void TextChanged(UISearchBar searchbar, string searchText)
        {
            var searchable = _Container.TableView.Source as ISearchBar;

            if (searchable != null && searchable.IncrementalSearch)
            {
                _Container.PerformFilter(searchText ?? "");
            }
        }