@@ -209,27 +209,24 @@ IEnumerable<ChildSong> playlistSongs
209209 } ) ;
210210 var db = new KeyValueStoreDatabaseService ( SharedLogic . Instance . DatabasePath , "PlaylistSongs" ) ;
211211 await db . InsertRecords ( playlistSongs ) ;
212- var s = await db . GetRecords < ChildSong > ( ) ;
213- //await AddSongsToPlaylist(plist, songs.ToList());
212+ await AddSongsToPlaylist ( plist ) ;
214213 }
215214 } ) ;
216215 }
217216
218- private async Task AddSongsToPlaylist ( Playlist list , IReadOnlyCollection < Mediafile > songsToadd )
217+ private async Task AddSongsToPlaylist ( Playlist list )
219218 {
220- if ( songsToadd . Any ( ) )
221- {
222- await PlaylistService . InsertTracksAsync ( songsToadd . Where ( t => ! PlaylistService . Exists ( t . Id ) ) , list ) ;
223- var pSongs = ( await PlaylistService . GetTracksAsync ( list . Id ) ) . ToList ( ) ;
219+ //await PlaylistService.InsertTracksAsync(songsToadd.Where(t => !PlaylistService.Exists(t.Id)), list);
220+ var pSongs = ( await PlaylistService . GetTracksAsync ( list . Id ) ) . ToList ( ) ;
224221
225- //update duration and songs count
226- var collectionPlaylist = Playlists . FirstOrDefault ( t => t . Name == list . Name ) ;
227- collectionPlaylist . SongsCount = pSongs . Count + " songs" ;
228- collectionPlaylist . ImagePath = pSongs . First ( t => t . AttachedPicture != null ) ? . AttachedPicture ?? "" ;
229- collectionPlaylist . ImageColor = ( await SharedLogic . Instance . GetDominantColor ( await StorageFile . GetFileFromPathAsync ( list . ImagePath ) ) ) . ToHexString ( ) ;
230- collectionPlaylist . Duration = string . Format ( "{0:0.0}" , Math . Truncate ( pSongs . Sum ( t => TimeSpan . ParseExact ( IsHour ( t . Length ) ? t . Length : "00:" + t . Length , @"hh\:mm\:ss" , CultureInfo . InvariantCulture ) . TotalMinutes ) * 10 ) / 10 ) + " Minutes" ;
231- await PlaylistService . UpdatePlaylistAsync ( collectionPlaylist ) . ConfigureAwait ( false ) ;
232- }
222+ //update duration and songs count
223+ var collectionPlaylist = Playlists . FirstOrDefault ( t => t . Name == list . Name ) ;
224+ collectionPlaylist . SongsCount = pSongs . Count + " songs" ;
225+ collectionPlaylist . ImagePath = pSongs . First ( t => t . AttachedPicture != null ) ? . AttachedPicture ?? "" ;
226+ if ( ! string . IsNullOrEmpty ( collectionPlaylist . ImagePath ) )
227+ collectionPlaylist . ImageColor = ( await SharedLogic . Instance . GetDominantColor ( await StorageFile . GetFileFromPathAsync ( collectionPlaylist . ImagePath ) ) ) . ToHexString ( ) ;
228+ collectionPlaylist . Duration = string . Format ( "{0:0.0}" , Math . Truncate ( pSongs . Sum ( t => TimeSpan . ParseExact ( IsHour ( t . Length ) ? t . Length : "00:" + t . Length , @"hh\:mm\:ss" , CultureInfo . InvariantCulture ) . TotalMinutes ) * 10 ) / 10 ) + " Minutes" ;
229+ await PlaylistService . UpdatePlaylistAsync ( collectionPlaylist ) . ConfigureAwait ( false ) ;
233230 }
234231
235232 private async void AddToPlaylist ( object file )
0 commit comments