I have made a method which returns a list of all songs on my device. Now I want to get a list of albums out of these songs.
What I basically do is go through every song I have in my list, check if its album is already in the list and if not I create a new album.
This method will take some time since there are 1400 songs on my device so I wondered how I can make this method any faster? Also, any other improvements?
public static ArrayList<Album> loadAlbums( Context c ){
ArrayList<Song> tmpList = getAllSongs( c);
ArrayList<Album> albumList = new ArrayList<Album>();
for( Song s : tmpList ){
boolean added = false;
for( Album a : albumList ){
if( a.getAlbumName().contentEquals( s.getAlbum() ) && a.getArtistName().contentEquals( s.getArtist() ) ){
a.addSong( s.getPath() );
added = true;
}
}
if( !added ){
Album a = new Album( s.getAlbum() );
a.setAlbum_id( s.getAlbumId() );
a.setArtistName( s.getArtist() );
a.addSong( s.getPath() );
albumList.add(a);
}
}
tmpList = null;
return albumList;
}