| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | |
|
| | 4 | | internal class SectionSearchHandler : ISectionSearchHandler |
| | 5 | | { |
| | 6 | | public const string NAME_SORT_TYPE_ASC = "Alphabetic A-Z"; |
| | 7 | | public const string NAME_SORT_TYPE_DESC = "Alphabetic Z-A"; |
| | 8 | | public const string SIZE_SORT_TYPE_ASC = "Size Asc"; |
| | 9 | | public const string SIZE_SORT_TYPE_DESC = "Size Desc"; |
| | 10 | |
|
| 11 | 11 | | private readonly string[] scenesSortTypes = |
| | 12 | | { |
| | 13 | | NAME_SORT_TYPE_ASC, NAME_SORT_TYPE_DESC, |
| | 14 | | SIZE_SORT_TYPE_ASC, SIZE_SORT_TYPE_DESC |
| | 15 | | }; |
| | 16 | |
|
| | 17 | | public event Action OnUpdated; |
| | 18 | | public event Action<List<ISearchInfo>> OnResult; |
| | 19 | |
|
| | 20 | | private readonly SearchHandler<ISearchInfo> scenesSearchHandler; |
| | 21 | |
|
| | 22 | | private bool filterOwner = false; |
| | 23 | | private bool filterOperator = false; |
| | 24 | | private bool filterContributor = false; |
| | 25 | |
|
| 0 | 26 | | string[] ISectionSearchHandler.sortTypes => scenesSortTypes; |
| 0 | 27 | | string ISectionSearchHandler.searchString => scenesSearchHandler.currentSearchString; |
| 0 | 28 | | bool ISectionSearchHandler.filterOwner => filterOwner; |
| 0 | 29 | | bool ISectionSearchHandler.filterOperator => filterOperator; |
| 0 | 30 | | bool ISectionSearchHandler.filterContributor => filterContributor; |
| 0 | 31 | | string ISectionSearchHandler.sortType => scenesSearchHandler.currentSortingType; |
| 0 | 32 | | int ISectionSearchHandler.resultCount => scenesSearchHandler.resultCount; |
| | 33 | |
|
| 11 | 34 | | public SectionSearchHandler() |
| | 35 | | { |
| 11 | 36 | | scenesSearchHandler = new SearchHandler<ISearchInfo>(scenesSortTypes, (item) => |
| | 37 | | { |
| 20 | 38 | | bool result = true; |
| 20 | 39 | | if (filterContributor) |
| 0 | 40 | | result = item.isContributor; |
| 20 | 41 | | if (filterOperator && result) |
| 0 | 42 | | result = item.isOperator; |
| 20 | 43 | | if (filterOwner && result) |
| 0 | 44 | | result = item.isOwner; |
| 20 | 45 | | return result; |
| | 46 | | }); |
| | 47 | |
|
| 11 | 48 | | scenesSearchHandler.OnSearchChanged += list => |
| | 49 | | { |
| 13 | 50 | | OnUpdated?.Invoke(); |
| 13 | 51 | | OnResult?.Invoke(list); |
| 12 | 52 | | }; |
| 11 | 53 | | } |
| | 54 | |
|
| 24 | 55 | | void ISectionSearchHandler.SetSearchableList(List<ISearchInfo> list) { scenesSearchHandler.SetSearchableList(list); |
| | 56 | |
|
| 0 | 57 | | void ISectionSearchHandler.AddItem(ISearchInfo item) { scenesSearchHandler.AddItem(item); } |
| | 58 | |
|
| 0 | 59 | | void ISectionSearchHandler.RemoveItem(ISearchInfo item) { scenesSearchHandler.RemoveItem(item); } |
| | 60 | |
|
| | 61 | | void ISectionSearchHandler.SetFilter(bool isOwner, bool isOperator, bool isContributor) |
| | 62 | | { |
| 0 | 63 | | filterOwner = isOwner; |
| 0 | 64 | | filterOperator = isOperator; |
| 0 | 65 | | filterContributor = isContributor; |
| 0 | 66 | | scenesSearchHandler.NotifyFilterChanged(); |
| 0 | 67 | | } |
| | 68 | |
|
| 2 | 69 | | void ISectionSearchHandler.SetSortType(string sortType) { scenesSearchHandler.NotifySortTypeChanged(sortType); } |
| | 70 | |
|
| 0 | 71 | | void ISectionSearchHandler.SetSearchString(string searchText) { scenesSearchHandler.NotifySearchChanged(searchText); |
| | 72 | | } |