From fc5876829c98fd876f2cef0c02715392114a297d Mon Sep 17 00:00:00 2001 From: CappielloAntonio Date: Sat, 4 Sep 2021 15:21:36 +0200 Subject: [PATCH] Room - Added schema export directory --- app/build.gradle | 10 ++++++++-- .../cappielloantonio/play/database/AppDatabase.java | 9 ++++++++- .../play/database/dao/DownloadDao.java | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 995474b8..10184e3b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,6 +13,12 @@ android { versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + javaCompileOptions { + annotationProcessorOptions { + arguments += ["room.schemaLocation": "$projectDir/schemas".toString()] + } + } } buildTypes { @@ -44,7 +50,7 @@ dependencies { implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' implementation 'androidx.recyclerview:recyclerview:1.2.1' - implementation "androidx.room:room-runtime:2.3.0" + implementation "androidx.room:room-runtime:2.4.0-alpha04" implementation "androidx.cardview:cardview:1.0.0" // Android Material @@ -62,7 +68,7 @@ dependencies { implementation 'com.google.android.exoplayer:exoplayer:2.12.2' annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' - annotationProcessor "androidx.room:room-compiler:2.3.0" + annotationProcessor "androidx.room:room-compiler:2.4.0-alpha04" // Retrofit implementation 'com.squareup.retrofit2:retrofit:2.9.0' diff --git a/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java b/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java index 3c8a6e6f..903fd1e0 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java +++ b/app/src/main/java/com/cappielloantonio/play/database/AppDatabase.java @@ -1,7 +1,9 @@ package com.cappielloantonio.play.database; +import android.annotation.SuppressLint; import android.content.Context; +import androidx.room.AutoMigration; import androidx.room.Database; import androidx.room.Room; import androidx.room.RoomDatabase; @@ -15,7 +17,12 @@ import com.cappielloantonio.play.model.Queue; import com.cappielloantonio.play.model.RecentSearch; import com.cappielloantonio.play.model.Server; -@Database(entities = {Queue.class, Server.class, RecentSearch.class, Download.class}, version = 23, exportSchema = false) +@SuppressLint("RestrictedApi") +@Database( + version = 23, + entities = {Queue.class, Server.class, RecentSearch.class, Download.class} + // autoMigrations = { @AutoMigration(from = 23, to = 24) } +) public abstract class AppDatabase extends RoomDatabase { private static final String TAG = "AppDatabase"; diff --git a/app/src/main/java/com/cappielloantonio/play/database/dao/DownloadDao.java b/app/src/main/java/com/cappielloantonio/play/database/dao/DownloadDao.java index 47afba1d..206f5cdd 100644 --- a/app/src/main/java/com/cappielloantonio/play/database/dao/DownloadDao.java +++ b/app/src/main/java/com/cappielloantonio/play/database/dao/DownloadDao.java @@ -30,7 +30,7 @@ public interface DownloadDao { @Query("SELECT * FROM download WHERE server=:server AND artistId=:artistId") LiveData> getAllFromArtist(String server, String artistId); - @Query("SELECT * FROM download WHERE server=:server AND albumId=:albumId") + @Query("SELECT * FROM download WHERE server=:server AND albumId=:albumId ORDER BY trackNumber ASC") LiveData> getAllFromAlbum(String server, String albumId); @Query("SELECT * FROM download WHERE server=:server AND playlistId=:playlistId")