use of com.sdsmdg.harjot.MusicDNA.models.MusicFolder in project MusicDNA by harjot-oberai.
the class HomeActivity method getLocalSongs.
private void getLocalSongs() {
localTrackList.clear();
finalLocalSearchResultList.clear();
albums.clear();
finalAlbums.clear();
artists.clear();
finalArtists.clear();
ContentResolver musicResolver = this.getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
if (musicCursor != null && musicCursor.moveToFirst()) {
//get columns
int titleColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
int albumColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM);
int pathColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.DATA);
int durationColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.DURATION);
//add songs to list
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String thisAlbum = musicCursor.getString(albumColumn);
String path = musicCursor.getString(pathColumn);
long duration = musicCursor.getLong(durationColumn);
if (duration > 10000) {
LocalTrack lt = new LocalTrack(thisId, thisTitle, thisArtist, thisAlbum, path, duration);
localTrackList.add(lt);
finalLocalSearchResultList.add(lt);
int pos;
if (thisAlbum != null) {
pos = checkAlbum(thisAlbum);
if (pos != -1) {
albums.get(pos).getAlbumSongs().add(lt);
} else {
List<LocalTrack> llt = new ArrayList<>();
llt.add(lt);
Album ab = new Album(thisAlbum, llt);
albums.add(ab);
}
if (pos != -1) {
finalAlbums.get(pos).getAlbumSongs().add(lt);
} else {
List<LocalTrack> llt = new ArrayList<>();
llt.add(lt);
Album ab = new Album(thisAlbum, llt);
finalAlbums.add(ab);
}
}
if (thisArtist != null) {
pos = checkArtist(thisArtist);
if (pos != -1) {
artists.get(pos).getArtistSongs().add(lt);
} else {
List<LocalTrack> llt = new ArrayList<>();
llt.add(lt);
Artist ab = new Artist(thisArtist, llt);
artists.add(ab);
}
if (pos != -1) {
finalArtists.get(pos).getArtistSongs().add(lt);
} else {
List<LocalTrack> llt = new ArrayList<>();
llt.add(lt);
Artist ab = new Artist(thisArtist, llt);
finalArtists.add(ab);
}
}
File f = new File(path);
String dirName = f.getParentFile().getName();
if (getFolder(dirName) == null) {
MusicFolder mf = new MusicFolder(dirName);
mf.getLocalTracks().add(lt);
allMusicFolders.getMusicFolders().add(mf);
} else {
getFolder(dirName).getLocalTracks().add(lt);
}
}
} while (musicCursor.moveToNext());
}
if (musicCursor != null)
musicCursor.close();
System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
try {
if (localTrackList.size() > 0) {
Collections.sort(localTrackList, new LocalMusicComparator());
Collections.sort(finalLocalSearchResultList, new LocalMusicComparator());
}
if (albums.size() > 0) {
Collections.sort(albums, new AlbumComparator());
Collections.sort(finalAlbums, new AlbumComparator());
}
if (artists.size() > 0) {
Collections.sort(artists, new ArtistComparator());
Collections.sort(finalArtists, new ArtistComparator());
}
} catch (Exception e) {
e.printStackTrace();
}
List<UnifiedTrack> tmp = new ArrayList<>();
boolean queueCurrentIndexCollision = false;
int indexCorrection = 0;
for (int i = 0; i < queue.getQueue().size(); i++) {
UnifiedTrack ut = queue.getQueue().get(i);
if (ut.getType()) {
if (!checkTrack(ut.getLocalTrack())) {
if (i == queueCurrentIndex) {
queueCurrentIndexCollision = true;
} else if (i < queueCurrentIndex) {
indexCorrection++;
}
tmp.add(ut);
}
}
}
for (int i = 0; i < tmp.size(); i++) {
queue.getQueue().remove(tmp.get(i));
}
if (queueCurrentIndexCollision) {
if (queue.getQueue().size() > 0) {
queueCurrentIndex = 0;
} else {
queue = new Queue();
}
} else {
queueCurrentIndex -= indexCorrection;
}
tmp.clear();
for (int i = 0; i < recentlyPlayed.getRecentlyPlayed().size(); i++) {
UnifiedTrack ut = recentlyPlayed.getRecentlyPlayed().get(i);
if (ut.getType()) {
if (!checkTrack(ut.getLocalTrack())) {
tmp.add(ut);
}
}
}
for (int i = 0; i < tmp.size(); i++) {
recentlyPlayed.getRecentlyPlayed().remove(tmp.get(i));
}
List<UnifiedTrack> temp = new ArrayList<>();
List<Playlist> tmpPL = new ArrayList<>();
for (int i = 0; i < allPlaylists.getPlaylists().size(); i++) {
Playlist pl = allPlaylists.getPlaylists().get(i);
for (int j = 0; j < pl.getSongList().size(); j++) {
UnifiedTrack ut = pl.getSongList().get(j);
if (ut.getType()) {
if (!checkTrack(ut.getLocalTrack())) {
temp.add(ut);
}
}
}
for (int j = 0; j < temp.size(); j++) {
pl.getSongList().remove(temp.get(j));
}
temp.clear();
if (pl.getSongList().size() == 0) {
tmpPL.add(pl);
}
}
for (int i = 0; i < tmpPL.size(); i++) {
allPlaylists.getPlaylists().remove(tmpPL.get(i));
}
tmpPL.clear();
}
use of com.sdsmdg.harjot.MusicDNA.models.MusicFolder in project MusicDNA by harjot-oberai.
the class FolderFragment method initializeHeaderImages.
public void initializeHeaderImages(View v) {
imgView[0] = (ImageView) v.findViewById(R.id.all_folder_img_1);
imgView[1] = (ImageView) v.findViewById(R.id.all_folder_img_2);
imgView[2] = (ImageView) v.findViewById(R.id.all_folder_img_3);
imgView[3] = (ImageView) v.findViewById(R.id.all_folder_img_4);
imgView[4] = (ImageView) v.findViewById(R.id.all_folder_img_5);
imgView[5] = (ImageView) v.findViewById(R.id.all_folder_img_6);
imgView[6] = (ImageView) v.findViewById(R.id.all_folder_img_7);
imgView[7] = (ImageView) v.findViewById(R.id.all_folder_img_8);
imgView[8] = (ImageView) v.findViewById(R.id.all_folder_img_9);
imgView[9] = (ImageView) v.findViewById(R.id.all_folder_img_10);
int numFolders = HomeActivity.allMusicFolders.getMusicFolders().size();
MusicFolder mf1, mf2;
if (numFolders == 0) {
for (int i = 0; i < 10; i++) {
imgLoader.DisplayImage("folder" + i, imgView[i]);
}
} else if (numFolders == 1) {
mf1 = HomeActivity.allMusicFolders.getMusicFolders().get(0);
for (int i = 0; i < Math.min(10, mf1.getLocalTracks().size()); i++) {
imgLoader.DisplayImage(mf1.getLocalTracks().get(i).getPath(), imgView[i]);
}
if (mf1.getLocalTracks().size() < 10) {
for (int i = mf1.getLocalTracks().size(); i < 10; i++) {
imgLoader.DisplayImage("folder" + i, imgView[i]);
}
}
} else {
mf1 = HomeActivity.allMusicFolders.getMusicFolders().get(0);
mf2 = HomeActivity.allMusicFolders.getMusicFolders().get(1);
for (int i = 0; i < Math.min(10, mf1.getLocalTracks().size()); i++) {
imgLoader.DisplayImage(mf1.getLocalTracks().get(i).getPath(), imgView[i]);
}
if (mf1.getLocalTracks().size() < 10) {
if (mf2.getLocalTracks().size() >= (10 - mf1.getLocalTracks().size())) {
for (int i = mf1.getLocalTracks().size(); i < 10; i++) {
LocalTrack lt = mf2.getLocalTracks().get(i - mf1.getLocalTracks().size());
imgLoader.DisplayImage(lt.getPath(), imgView[i]);
}
} else {
for (int i = mf1.getLocalTracks().size(); i < mf1.getLocalTracks().size() + mf2.getLocalTracks().size(); i++) {
LocalTrack lt = mf2.getLocalTracks().get(i - mf1.getLocalTracks().size());
imgLoader.DisplayImage(lt.getPath(), imgView[i]);
}
for (int i = mf1.getLocalTracks().size() + mf2.getLocalTracks().size(); i < 10; i++) {
imgLoader.DisplayImage("folder" + i, imgView[i]);
}
}
}
}
}
use of com.sdsmdg.harjot.MusicDNA.models.MusicFolder in project MusicDNA by harjot-oberai.
the class FolderRecyclerAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
MusicFolder mf = musicFolders.get(position);
List<LocalTrack> list = mf.getLocalTracks();
// holder.playListName.setText(mf.getFolderName() + " (" + mf.getLocalTracks().size() + ")");
holder.playListName.setText(mf.getFolderName());
if (list.size() >= 3) {
String[] names = new String[3];
for (int i = 0; i < 3; i++) {
names[i] = list.get(i).getTitle();
imgLoader.DisplayImage(list.get(i).getPath(), holder.img[i]);
holder.name[i].setText(names[i]);
}
holder.continuedSymbol.setVisibility(View.VISIBLE);
} else {
int sz = list.size();
String[] names = new String[3];
for (int i = 0; i < sz; i++) {
names[i] = list.get(i).getTitle();
imgLoader.DisplayImage(list.get(i).getPath(), holder.img[i]);
holder.name[i].setText(names[i]);
}
}
}
Aggregations