Ejemplo n.º 1
0
        public AlbumViewModel(MusicLibrary library, Album album)
        {
            this.Album = album;
            this.library = library;
            library.PropertyChanged += library_PropertyChanged;

            if (library.Songs != null) LoadSongs();
        }
Ejemplo n.º 2
0
        public ArtistViewModel(MusicLibrary library, string name)
        {
            this.Name = name;
            this.library = library;
            library.PropertyChanged += library_PropertyChanged;

            if (library.Songs != null) LoadSongs();
            if (library.Albums != null) LoadAlbums();
        }
Ejemplo n.º 3
0
        public GenreViewModel(MusicLibrary library, Genre genre)
        {
            this.Name = genre.Name;
            this.genre = genre;
            this._filters = new FilterViewModel[0];
            this.library = library;
            library.PropertyChanged += library_PropertyChanged;

            if (library.Songs != null) LoadFilters();
        }
Ejemplo n.º 4
0
        public SaveNewPlaylistViewModel(MusicLibrary musicLibrary)
        {
            var resourceLoader = ResourceLoader.GetForViewIndependentUse();
            
            this.SaveCommand = new RelayCommandWithParameter(async o => {
                var commandAfter = o as ICommand;

                if (this.Name == null || this.Name.Trim() == "")
                    await new MessageDialog(resourceLoader.GetString("SaveNewPlaylistNameEmpty")).ShowAsync();
                else
                {
                    var lowerName = this.Name.ToLower();
                    var playlistWithSameName = (musicLibrary.SavedPlaylists).Where(p => p.Name.ToLower() == lowerName).ToArray();
                    if (playlistWithSameName.Any())
                    {
                        var messageDialog = new MessageDialog(resourceLoader.GetString("SaveNewPlaylistNameExists"));
                        messageDialog.Commands.Add(new UICommand(resourceLoader.GetString("MessageDialogNo")));
                        messageDialog.Commands.Add(new UICommand(resourceLoader.GetString("MessageDialogYes"), async c =>
                        {
                            foreach (var playlist in playlistWithSameName)
                                await musicLibrary.PlaylistManager.DeleteFromLibrary(musicLibrary, playlist);

                            await musicLibrary.PlaylistManager.SaveToLibrary(musicLibrary, this.Name);
                            if (commandAfter != null)
                                commandAfter.Execute(null);
                        }));
                        messageDialog.DefaultCommandIndex = 1;
                        messageDialog.CancelCommandIndex = 0;
                        await messageDialog.ShowAsync();
                    }
                    else
                    {
                        await musicLibrary.PlaylistManager.SaveToLibrary(musicLibrary, this.Name);
                        if (commandAfter != null)
                            commandAfter.Execute(null);
                    }
                }
            });
        }
Ejemplo n.º 5
0
 public abstract void LoadData(MusicLibrary library);
Ejemplo n.º 6
0
 public override void LoadData(MusicLibrary library)
 {
     this.musicLibrary = library;
     StartSearchAsync(_searchString);
 }
Ejemplo n.º 7
0
        public static async Task<MusicLibrary> Open(LocalLibrarySource localLibrarySource, params PropertyChangedEventHandler[] propertyChangedEventHandlers)
        {
            MusicLibrary library = new MusicLibrary(localLibrarySource);

            if (propertyChangedEventHandlers != null)
                foreach (var handler in propertyChangedEventHandlers)
                    library.PropertyChanged += handler;
            library.databaseConnection = await ConnectToDatabase();
            library.PlaylistManager = new ListPlaylistManager(library.databaseConnection);
            library.Songs = new ObservableCollection<Song>(await library.databaseConnection.Table<Song>().ToListAsync());
            library.Artists = new ObservableCollection<string>(library.Songs.Select(p => p.AlbumArtist).Where(p => p.Trim() != "").Distinct(StringComparer.CurrentCultureIgnoreCase));
            library.Albums = new ObservableCollection<Album>(library.Songs.Select(p => new Album(p.Album, p.AlbumArtist, library)).Where(p => p.Name.Trim() != "").Distinct());
            library.SavedPlaylists = new ObservableCollection<SavedPlaylist>(await library.databaseConnection.Table<SavedPlaylist>().ToListAsync());
            library.Genres = new ObservableCollection<Genre>(await library.databaseConnection.Table<Genre>().OrderBy(p => p.Name).ToListAsync());
            library.NotifyPropertyChanged("Songs");
            library.NotifyPropertyChanged("Artists");
            library.NotifyPropertyChanged("Albums");
            library.NotifyPropertyChanged("PlaylistManager");
            library.NotifyPropertyChanged("SavedPlaylists");
            library.NotifyPropertyChanged("Genres");

            return library;
        }
Ejemplo n.º 8
0
 public Album(string name, string artist, MusicLibrary library)
 {
     this.Name = name;
     this.Artist = artist;
     this.library = library;
 }
Ejemplo n.º 9
0
 public override void LoadData(MusicLibrary library)
 {
     this.Items = GroupedObservableCollection<char, string, string>.CreateAlpabeticalGrouping(library.Artists, p => p, p => true);
 }
Ejemplo n.º 10
0
 public override void LoadData(MusicLibrary library)
 {
     this.Items = GroupedObservableCollection<char, Song, string>.CreateAlpabeticalGrouping(library.Songs, p => p.Name, includeInList);
 }
Ejemplo n.º 11
0
        private async void LoadLibrary()
        {
            this.library = await libraryLoadingTask;

            this.audioControls.CurrentSongChanged += audioControls_CurrentSongChanged;
            this.audioControls.PropertyChanged += audioControls_PropertyChanged;

            audioControls_CurrentSongChanged(this, new CurrentSongChangedEventArgs(SongChangedType.None));

            if (ApplicationSettings.IsDatabaseSettingUp.Read())
            {
                this.IsCreatingLibrary = true;
                var progressBar = StatusBar.GetForCurrentView().ProgressIndicator;
                progressBar.ProgressValue = null;
                progressBar.Text = ResourceLoader.GetForViewIndependentUse().GetString("DatabaseSettingUpString");

                var showTask = progressBar.ShowAsync();
                await library.UpdateLibrary();

                await showTask;
                await progressBar.HideAsync();
                this.IsCreatingLibrary = false;
            }
            else
                await library.UpdateLibrary();
        }
Ejemplo n.º 12
0
 public async Task DeleteFromLibrary(MusicLibrary musicLibrary, SavedPlaylist savedPlaylist)
 {
     await databaseConnection.DeleteAsync(savedPlaylist);
     musicLibrary.SavedPlaylists.Remove(savedPlaylist);
 }
Ejemplo n.º 13
0
        public async Task SaveToLibrary(MusicLibrary musicLibrary, string playlistName)
        {
            SavedPlaylist savedPlaylist = null;
            await this.databaseConnection.TryRunInTransactionAsync(connection =>
            {
                savedPlaylist = new SavedPlaylist() { Name = playlistName };

                var mostCommonArtistNames = connection.Query<Song>("select s.Artist from Song s, CurrentPlaylistSong c where s.Id = c.SongId group by s.Artist order by count(s.Artist) desc limit 4").Select(p => p.Artist);
                if (mostCommonArtistNames.Any())
                {
                    savedPlaylist.ShortDescription = string.Join(", ", mostCommonArtistNames.Take(3));
                    if (mostCommonArtistNames.Count() > 3)
                        savedPlaylist.ShortDescription += ", ...";
                }

                connection.Insert(savedPlaylist);

                connection.Execute("delete from SavedPlaylistSong where PlaylistId = ?", savedPlaylist.Id);
                connection.Execute("insert into SavedPlaylistSong (SongId, Rank, PlaylistId) select SongId, Rank, ? from CurrentPlaylistSong", savedPlaylist.Id);
            });
            musicLibrary.SavedPlaylists.Add(savedPlaylist);
        }