public StationInfoViewModel(RadioItem item, RadioPlugin plugin) { RadioItem = item; OpenItemCommand = new RelayCommand(async args => { SetResult(null); await plugin.OpenItemAsync(RadioItem); }); }
public RadioListViewModel(PanaceaServices core, RadioPlugin plugin, ILazyItemProvider provider) { Provider = provider; //LazyCustomButtons = new ObservableCollection<ServerItem> { _favoritesItem }; //LazyCustomCategories = plugin.Categories; ItemClickCommand = new RelayCommand((arg) => { if (plugin == null) { return; } if (arg is Category) { var c = (Category)arg; provider.SelectedCategory = c; //provider.GetItems(c); } else { var c = (RadioItem)arg; plugin.OpenItemAsync(c); } }); InfoClickCommand = new RelayCommand((arg) => { if (core.TryGetUiManager(out IUiManager ui)) { var rmp = new StationInfoViewModel(arg as RadioItem, plugin); var pop = ui.ShowPopup(rmp, "", PopupType.None); } }); IsFavoriteCommand = new RelayCommand((arg) => { }, (arg) => { var link = arg as RadioItem; if (plugin.Favorites == null) { return(false); } return(plugin.Favorites.Any(l => l.Id == link.Id)); }); FavoriteCommand = new RelayCommand(async(arg) => { try { if (core.TryGetUiManager(out IUiManager ui) && core.TryGetUserAccountManager(out IUserAccountManager user)) { var pluginName = "Radio"; if (core.UserService.User.Id == null) { if (await user.RequestLoginAsync(new Translator(pluginName).Translate("You need an account to add favorites"))) { ui.Navigate(this); } else { return; } } var link = arg as RadioItem; if (plugin.Favorites.Any(mm => mm.Id == link.Id)) { if (plugin.Favorites.Any(l => l.Id == link.Id)) { plugin.Favorites.Remove(plugin.Favorites.First(l => l.Id == link.Id)); } ui.Toast(new Translator(pluginName).Translate("This radio station has been removed from your favorites")); } else { plugin.Favorites.Add(link); ui.Toast(new Translator(pluginName).Translate("This radio station has been added to your favorites")); } core.WebSocket.Emit("set_cookie", new { pluginName = "Radio", user = core.UserService.User.Id, data = plugin.Favorites }); OnPropertyChanged("IsFavoriteCommand"); } } catch { } }); }