private async void GetResults(string searchParameter) { if (!string.IsNullOrWhiteSpace(SearchParameter as string)) { try { SearchResult = await SearchResult.SearchByTitleAsync(searchParameter.ToString(), CurrentPage); MoviesView = new ListCollectionView(SearchResult.Search.ToList()); Sorting(SortMethod); await LocalStorageDAL.SaveLastSearch(searchParameter.ToString()); SetPageStaus(PageStatus, SearchResult.TotalResults); } catch (Exception xcp) { if (SearchResult != null) { bool response = SearchResult.Response; string error = SearchResult.Error; messageService.ShowNotification(error); } else { messageService.ShowNotification(xcp.Message); } } } }
public WatchedViewModel(Mediator _mediator, IMessageBoxService _messageSerivce) { messageService = _messageSerivce; ProgressVisibility = "Hidden"; mediator = _mediator; IsClosed = true; OpenDetailsCommand = new RelayCommand(OpenDetailsExecute, CanOpenDetails); ImportCommand = new RelayCommand(ImportWithProgress, CanImport); DownloadPosterCommand = new RelayCommand(DownloadPosterExecute, CanDownload); CurrentPath = LocalStorageDAL.GetLastPath(); mediator.Register("Closing3", DetailsClosed); }
//Removes movie from favorite list public async void RemoveFavoriteExecute(object selectedMovie) { if (selectedMovie != null) { Movie movie = selectedMovie as Movie; List <string> idList = await ReadFavorites(); idList.Remove((selectedMovie as Movie).ImdbID); LocalStorageDAL.WriteFavorite(idList); GetMovies(); } }
public async Task ImportExecute(object path) { //Sets the progress bar BadFolders = new List<string>(); IEnumerable<string> folders = LocalStorageDAL.ReadMoviesFromFolder(path.ToString()); await LocalStorageDAL.SaveLastPath(path.ToString()); List<Movie> movieList = new List<Movie>(); StringBuilder sb = new StringBuilder(); foreach (string folder in folders) { sb = new StringBuilder(); //Checks movie pattern Match match = Regex.Match(folder, @".+\s?\([0-9]+\)"); if (match.Success) { IEnumerable<char> charArray = folder.TakeWhile(c => c != '('); foreach (char c in charArray) { sb.Append(c); } Movie movie = await Movie.GetMovieByTitle(sb.ToString().Trim()); //Added to demonstrate loading as the loading time is mostly too short await Task.Delay(750); if (movie.ImdbID != null) { movieList.Add(movie); } } else { BadFolders.Add(folder); } } if (BadFolders.Count > 0) { sb = new StringBuilder(); foreach (string folder in BadFolders) { sb.AppendLine(folder); } messageService.ShowNotification("Following movies could not be parsed\n" + sb.ToString()); } MovieCollection = new ListCollectionView(movieList); }
public MoviesViewModel(Mediator _mediator, IMessageBoxService _messageService) { messageService = _messageService; IsClosed = true; mediator = _mediator; SortMethod = "sortbyyear"; PageBackCommand = new RelayCommand(PageBackExecute, CanPageBack); PageForwardCommand = new RelayCommand(PageForwardExecute, CanPageForward); SearchCommand = new RelayCommand(SearchExecute, CanSearch); SortCommand = new RelayCommand(SortExecute, CanSort); FavoriteCommand = new RelayCommand(FavoriteExecute, CanFavorite); SearchParameter = LocalStorageDAL.GetLastSearch(); CurrentPage = 1; SearchExecute(SearchParameter); PropertyChanged += MoviesViewModel_PropertyChanged; mediator.Register("Closing", DetailsClosed); }
//Adds new favorite private async void Favorite(object input) { if (input != null) { string favoritedMovie = (input as Movie).ImdbID; List <string> idList = await ReadFavorites(); if (!idList.Contains(favoritedMovie)) { idList.Add(favoritedMovie); } else { messageService.ShowNotification("Selected movie is already in favorites"); } LocalStorageDAL.WriteFavorite(idList); GetMovies(); } }
//Reads favorites from Json file and return an ID list private async Task <List <string> > ReadFavorites() { List <string> ids = new List <string>(); try { if (File.Exists("Favorites.txt")) { string jsonString = File.ReadAllText("Favorites.txt"); if (!string.IsNullOrWhiteSpace(jsonString)) { ids = await LocalStorageDAL.ReadFavorite(); return(ids); } return(ids); } return(ids); } catch (Exception) { return(null); } }