2020-12-05 21:31:12 +01:00
|
|
|
package com.cappielloantonio.play.util;
|
|
|
|
|
|
2021-04-19 11:20:01 +02:00
|
|
|
import android.util.Log;
|
|
|
|
|
|
2020-12-05 21:31:12 +01:00
|
|
|
import com.cappielloantonio.play.model.Queue;
|
|
|
|
|
import com.cappielloantonio.play.model.Song;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class QueueUtil {
|
2021-04-19 11:20:01 +02:00
|
|
|
private static final String TAG = "QueueUtil";
|
2021-04-17 11:23:53 +02:00
|
|
|
|
|
|
|
|
public static Queue getQueueElementFromSong(Song song, int startingPosition) {
|
|
|
|
|
return new Queue(startingPosition, song.getId());
|
2020-12-05 21:31:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<Queue> getQueueElementsFromSongs(List<Song> songs) {
|
2021-04-16 18:00:19 +02:00
|
|
|
int counter = 0;
|
2020-12-05 21:31:12 +01:00
|
|
|
List<Queue> queue = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for(Song song: songs) {
|
2021-04-17 11:23:53 +02:00
|
|
|
queue.add(new Queue(counter, song.getId()));
|
|
|
|
|
counter++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return queue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-19 11:20:01 +02:00
|
|
|
public static List<String> getIDsFromSongs(List<Song> songs) {
|
|
|
|
|
List<String> IDs = new ArrayList<>();
|
2021-04-17 11:23:53 +02:00
|
|
|
|
|
|
|
|
for(Song song: songs) {
|
2021-04-19 11:20:01 +02:00
|
|
|
IDs.add(song.getId());
|
2020-12-05 21:31:12 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-19 11:20:01 +02:00
|
|
|
return IDs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<Song> orderSongByIdList(List<String> IDs, List<Song> songs) {
|
|
|
|
|
List<Song> orderedSong = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for(String ID: IDs) {
|
|
|
|
|
for(Song song: songs) {
|
|
|
|
|
if(ID.equals(song.getId())) {
|
|
|
|
|
orderedSong.add(song);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return orderedSong;
|
2020-12-05 21:31:12 +01:00
|
|
|
}
|
|
|
|
|
}
|