| | 1 | | using System.Collections.Generic; |
| | 2 | |
|
| | 3 | | public class FavoritesController |
| | 4 | | { |
| 32 | 5 | | private List<CatalogItem> favoritesCatalogItems = new List<CatalogItem>(); |
| | 6 | |
|
| | 7 | | public CatalogGroupListView catalogGroupListView; |
| | 8 | |
|
| 32 | 9 | | public FavoritesController(CatalogGroupListView catalogGroupListView) |
| | 10 | | { |
| 32 | 11 | | if (catalogGroupListView == null) |
| 30 | 12 | | return; |
| | 13 | |
|
| 2 | 14 | | catalogGroupListView.OnCatalogItemFavorite += ToggleFavoriteState; |
| 2 | 15 | | } |
| | 16 | |
|
| | 17 | | public void Dispose() |
| | 18 | | { |
| 30 | 19 | | if (catalogGroupListView != null) |
| 0 | 20 | | catalogGroupListView.OnCatalogItemFavorite -= ToggleFavoriteState; |
| 30 | 21 | | } |
| | 22 | |
|
| 0 | 23 | | public List<CatalogItem> GetFavorites() { return favoritesCatalogItems; } |
| | 24 | |
|
| | 25 | | public void ToggleFavoriteState(CatalogItem catalogItem, CatalogItemAdapter adapter) |
| | 26 | | { |
| 2 | 27 | | if (!favoritesCatalogItems.Contains(catalogItem)) |
| | 28 | | { |
| 1 | 29 | | favoritesCatalogItems.Add(catalogItem); |
| 1 | 30 | | catalogItem.SetFavorite(true); |
| 1 | 31 | | BIWAnalytics.FavoriteAdded(catalogItem); |
| 1 | 32 | | } |
| | 33 | | else |
| | 34 | | { |
| 1 | 35 | | favoritesCatalogItems.Remove(catalogItem); |
| 1 | 36 | | catalogItem.SetFavorite(false); |
| | 37 | | } |
| | 38 | |
|
| 2 | 39 | | adapter?.SetFavorite(catalogItem.IsFavorite()); |
| 2 | 40 | | } |
| | 41 | | } |