utilize downloaded files within detail activities
This commit is contained in:
parent
5bde02dc8b
commit
395b1227c9
11 changed files with 100 additions and 15 deletions
29
app/src/main/java/com/dkanada/gramophone/database/Cache.java
Normal file
29
app/src/main/java/com/dkanada/gramophone/database/Cache.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package com.dkanada.gramophone.database;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import com.dkanada.gramophone.model.Song;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity(tableName = "cache")
|
||||
public class Cache {
|
||||
@NonNull
|
||||
@PrimaryKey
|
||||
public String id;
|
||||
|
||||
@ColumnInfo(defaultValue = "1")
|
||||
public Boolean cache;
|
||||
|
||||
public Cache() {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public Cache(Song song) {
|
||||
this.id = song.id;
|
||||
this.cache = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.dkanada.gramophone.database;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
|
||||
import com.dkanada.gramophone.model.Song;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface CacheDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertCache(Cache cache);
|
||||
|
||||
@Query("SELECT * FROM songs LEFT JOIN cache USING(id) WHERE songs.id IN (:ids)")
|
||||
List<Song> getSongs(List<String> ids);
|
||||
}
|
||||
|
|
@ -10,14 +10,16 @@ import com.dkanada.gramophone.model.User;
|
|||
|
||||
@androidx.room.Database(
|
||||
entities = {
|
||||
Cache.class,
|
||||
Song.class,
|
||||
QueueSong.class,
|
||||
User.class
|
||||
},
|
||||
version = 4,
|
||||
version = 5,
|
||||
exportSchema = false
|
||||
)
|
||||
public abstract class JellyDatabase extends RoomDatabase {
|
||||
public abstract CacheDao cacheDao();
|
||||
public abstract SongDao songDao();
|
||||
public abstract QueueSongDao queueSongDao();
|
||||
public abstract UserDao userDao();
|
||||
|
|
@ -52,4 +54,12 @@ public abstract class JellyDatabase extends RoomDatabase {
|
|||
+ "name TEXT, server TEXT, token TEXT)");
|
||||
}
|
||||
};
|
||||
|
||||
public static final Migration Migration5 = new Migration(4, 5) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("CREATE TABLE cache (id TEXT NOT NULL PRIMARY KEY,"
|
||||
+ "cache INTEGER NOT NULL)");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import androidx.room.Dao;
|
|||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Transaction;
|
||||
|
||||
import com.dkanada.gramophone.App;
|
||||
import com.dkanada.gramophone.model.Song;
|
||||
|
|
@ -22,6 +23,7 @@ public abstract class QueueSongDao {
|
|||
@Query("SELECT * from queueSongs WHERE queue = :queue ORDER BY `index`")
|
||||
public abstract List<QueueSong> getQueueSongs(int queue);
|
||||
|
||||
@Transaction
|
||||
public List<Song> getQueue(int queue) {
|
||||
List<QueueSong> queueSongs = getQueueSongs(queue);
|
||||
List<Song> songs = new ArrayList<>();
|
||||
|
|
@ -34,6 +36,7 @@ public abstract class QueueSongDao {
|
|||
return songs;
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public void setQueue(List<Song> songs, int queue) {
|
||||
List<QueueSong> queueSongs = new ArrayList<>();
|
||||
for (int i = 0; i < songs.size(); i++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue