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);
}