2018-01-15 21:30:52 +01:00
|
|
|
package org.schabi.newpipe.database.playlist.dao;
|
|
|
|
|
|
|
|
import android.arch.persistence.room.Dao;
|
|
|
|
import android.arch.persistence.room.Query;
|
|
|
|
import android.arch.persistence.room.Transaction;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.database.BasicDAO;
|
|
|
|
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
|
2018-01-28 07:14:38 +01:00
|
|
|
import org.schabi.newpipe.database.playlist.PlaylistStreamEntry;
|
2018-01-15 21:30:52 +01:00
|
|
|
import org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import io.reactivex.Flowable;
|
|
|
|
|
|
|
|
import static org.schabi.newpipe.database.playlist.PlaylistMetadataEntry.PLAYLIST_STREAM_COUNT;
|
|
|
|
import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.*;
|
|
|
|
import static org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity.*;
|
|
|
|
import static org.schabi.newpipe.database.stream.model.StreamEntity.*;
|
|
|
|
|
|
|
|
@Dao
|
|
|
|
public abstract class PlaylistStreamDAO implements BasicDAO<PlaylistStreamEntity> {
|
|
|
|
@Override
|
|
|
|
@Query("SELECT * FROM " + PLAYLIST_STREAM_JOIN_TABLE)
|
|
|
|
public abstract Flowable<List<PlaylistStreamEntity>> getAll();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Query("DELETE FROM " + PLAYLIST_STREAM_JOIN_TABLE)
|
|
|
|
public abstract int deleteAll();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Flowable<List<PlaylistStreamEntity>> listByService(int serviceId) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Query("DELETE FROM " + PLAYLIST_STREAM_JOIN_TABLE +
|
|
|
|
" WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
|
|
|
public abstract void deleteBatch(final long playlistId);
|
|
|
|
|
2018-01-28 07:14:38 +01:00
|
|
|
@Query("SELECT COALESCE(MAX(" + JOIN_INDEX + "), -1)" +
|
2018-01-15 21:30:52 +01:00
|
|
|
" FROM " + PLAYLIST_STREAM_JOIN_TABLE +
|
|
|
|
" WHERE " + JOIN_PLAYLIST_ID + " = :playlistId")
|
|
|
|
public abstract Flowable<Integer> getMaximumIndexOf(final long playlistId);
|
|
|
|
|
|
|
|
@Transaction
|
2018-01-28 07:14:38 +01:00
|
|
|
@Query("SELECT * FROM " + STREAM_TABLE + " INNER JOIN " +
|
2018-01-15 21:30:52 +01:00
|
|
|
// get ids of streams of the given playlist
|
|
|
|
"(SELECT " + JOIN_STREAM_ID + "," + JOIN_INDEX +
|
2018-01-31 20:51:47 +01:00
|
|
|
" FROM " + PLAYLIST_STREAM_JOIN_TABLE +
|
|
|
|
" WHERE " + JOIN_PLAYLIST_ID + " = :playlistId)" +
|
2018-01-15 21:30:52 +01:00
|
|
|
|
|
|
|
// then merge with the stream metadata
|
|
|
|
" ON " + STREAM_ID + " = " + JOIN_STREAM_ID +
|
|
|
|
" ORDER BY " + JOIN_INDEX + " ASC")
|
2018-01-28 07:14:38 +01:00
|
|
|
public abstract Flowable<List<PlaylistStreamEntry>> getOrderedStreamsOf(long playlistId);
|
2018-01-15 21:30:52 +01:00
|
|
|
|
|
|
|
@Transaction
|
|
|
|
@Query("SELECT " + PLAYLIST_ID + ", " + PLAYLIST_NAME + ", " +
|
2018-01-28 07:14:38 +01:00
|
|
|
PLAYLIST_THUMBNAIL_URL + ", " +
|
|
|
|
"COALESCE(COUNT(" + JOIN_PLAYLIST_ID + "), 0) AS " + PLAYLIST_STREAM_COUNT +
|
2018-01-15 21:30:52 +01:00
|
|
|
|
2018-01-28 07:14:38 +01:00
|
|
|
" FROM " + PLAYLIST_TABLE +
|
|
|
|
" LEFT JOIN " + PLAYLIST_STREAM_JOIN_TABLE +
|
|
|
|
" ON " + PLAYLIST_ID + " = " + JOIN_PLAYLIST_ID +
|
2018-01-31 01:01:11 +01:00
|
|
|
" GROUP BY " + JOIN_PLAYLIST_ID +
|
|
|
|
" ORDER BY " + PLAYLIST_NAME + " COLLATE NOCASE ASC")
|
2018-01-15 21:30:52 +01:00
|
|
|
public abstract Flowable<List<PlaylistMetadataEntry>> getPlaylistMetadata();
|
|
|
|
}
|