Skip to content
Snippets Groups Projects
Commit 5fc48e37 authored by Habib Kazemi's avatar Habib Kazemi Committed by Geoffrey Métais
Browse files

Migrate database to Room


Database migrated to Room Android Room Persistence Library.
Also, Android testing dependencies added to build.gradle.
I also wrote Tests for Dao and repository

Signed-off-by: default avatarGeoffrey Métais <geoffrey.metais@gmail.com>
parent e7c04c2b
No related branches found
No related tags found
No related merge requests found
Showing
with 1380 additions and 1 deletion
......@@ -27,7 +27,10 @@ ext {
appCompatVersion = '27.1.1'
constraintLayoutVersion = '1.1.2'
archVersion = '1.1.1'
roomVersion = '1.1.1'
compileSdkVersion = 26
junitVersion = '4.12'
espressoVersion = '3.0.1'
minSdkVersion = 14
targetSdkVersion = 26
versionName = '3.0.13'
......
/*******************************************************************************
* BrowserFavDaoTest.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database
import android.arch.persistence.room.Room
import android.net.Uri
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.*
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.videolan.vlc.database.models.BrowserFav
import org.videolan.vlc.util.Constants
@RunWith(AndroidJUnit4::class)
class BrowserFavDaoTest {
private lateinit var database: MediaDatabase
private lateinit var browserFavDao: BrowserFavDao
val netwrokFav1: BrowserFav = BrowserFav(Uri.parse("upnp://http://[fe80::61a1:a5a4:c66:bc5d]:2869/u"), Constants.TYPE_NETWORK_FAV, "Test1", null)
val netwrokFav2: BrowserFav = BrowserFav(Uri.parse("upnp://http://[fe80::61a1:a5a4:c66:bc6d]:2869/u"), Constants.TYPE_NETWORK_FAV, "Test2", null)
val localFav1: BrowserFav = BrowserFav(Uri.parse("/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.mkv"), Constants.TYPE_LOCAL_FAV, "Test3", null)
@Before fun createDao() {
val context = InstrumentationRegistry.getTargetContext()
database = Room.inMemoryDatabaseBuilder(context, MediaDatabase::class.java).build()
browserFavDao = database.browserFavDao()
browserFavDao.insert(netwrokFav1)
browserFavDao.insert(netwrokFav2)
browserFavDao.insert(localFav1)
}
@After fun closeDb() {
database.close()
}
@Test fun getAllBrowserFavs() {
val browsersFavs = browserFavDao.getAll()
assertThat(browsersFavs.size, equalTo(3))
assertThat(browsersFavs, hasItem(netwrokFav1))
assertThat(browsersFavs, hasItem(netwrokFav2))
assertThat(browsersFavs, hasItem(localFav1))
}
@Test fun getAllNetworkFavs() {
val networkFavs = browserFavDao.getAllNetwrokFavs()
assertThat(networkFavs.size, equalTo(2))
assertThat(networkFavs, hasItem(netwrokFav1))
assertThat(networkFavs, hasItem(netwrokFav2))
}
@Test fun getAllLocalFavs() {
val localFavs = browserFavDao.getAllLocalFavs()
assertThat(localFavs.size, equalTo(1))
assertThat(localFavs, hasItem(localFav1))
}
@Test fun getBrowserFav() {
val browser = browserFavDao.get(netwrokFav1.uri)
assertThat(browser.size, equalTo(1))
assertThat(browser[0], equalTo(netwrokFav1))
}
@Test fun deleteBrowserFav() {
browserFavDao.delete(netwrokFav1.uri)
val browsers = browserFavDao.getAll()
assertThat(browsers.size, equalTo(2))
assertThat(browsers, not(hasItem(netwrokFav1)))
assertThat(browsers, hasItem(netwrokFav2))
browserFavDao.delete(netwrokFav2.uri)
browserFavDao.delete(localFav1.uri)
val browserFavsAfterDeleteAll = browserFavDao.getAll()
assertThat(browserFavsAfterDeleteAll.size, equalTo(0))
}
}
\ No newline at end of file
/*******************************************************************************
* ConvertersTest.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database
import android.net.Uri
import android.support.test.runner.AndroidJUnit4
import junit.framework.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ConvertersTest {
private val str = "upnp://http://[fe80::61a1:a5a4:c66:bc5d]:2869/u"
private val uri = Uri.parse(str)
@Test fun uriToString() {
assertEquals(str, Converters().uriToString(uri))
}
@Test fun stringToUri() {
assertEquals(uri, Converters().stringToUri(str))
}
}
\ No newline at end of file
/*******************************************************************************
* ExternalSubDaoTest.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database
import android.arch.persistence.room.Room
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.hamcrest.Matchers.*
import org.junit.After
import org.junit.Assert.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.videolan.vlc.database.models.ExternalSub
@RunWith(AndroidJUnit4::class)
class ExternalSubDaoTest {
private lateinit var database: MediaDatabase
private lateinit var externalSubDao: ExternalSubDao
private val file1 = "file1.mkv"
private val file2 = "file2.mkv"
private val file1Sub1 = ExternalSub("/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.eng.srt", file1)
private val file1Sub2 = ExternalSub("/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.fa.srt", file1)
private val file1Sub3 = ExternalSub("/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.fr.srt", file1)
private val file2Sub1 = ExternalSub("/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file2.eng.srt", file2)
@Before fun createDao() {
val context = InstrumentationRegistry.getTargetContext()
database = Room.inMemoryDatabaseBuilder(context, MediaDatabase::class.java).build()
externalSubDao = database.externalSubDao()
externalSubDao.insert(file1Sub1)
externalSubDao.insert(file1Sub2)
externalSubDao.insert(file1Sub3)
externalSubDao.insert(file2Sub1)
}
@After fun closeDb() {
database.close()
}
@Test fun getExternalSubtitles() {
val file1Subtitles = externalSubDao.get(file1)
assertThat(file1Subtitles.size, equalTo(3))
assertThat(file1Subtitles, hasItem(file1Sub1))
assertThat(file1Subtitles, hasItem(file1Sub2))
assertThat(file1Subtitles, hasItem(file1Sub3))
val file2Subtitles = externalSubDao.get(file2)
assertThat(file2Subtitles.size, equalTo(1))
assertThat(file2Subtitles, hasItem(file2Sub1))
}
@Test fun deleteSubtitle(){
externalSubDao.delete(file1Sub1)
var file1Subtitles = externalSubDao.get(file1)
assertThat(file1Subtitles, not(hasItem(file1Sub1)))
assertThat(file1Subtitles, hasItem(file1Sub2))
assertThat(file1Subtitles, hasItem(file1Sub3))
externalSubDao.delete(file1Sub2)
file1Subtitles = externalSubDao.get(file1)
assertThat(file1Subtitles, not(hasItem(file2)))
assertThat(file1Subtitles, hasItem(file1Sub3))
externalSubDao.delete(file1Sub3)
file1Subtitles = externalSubDao.get(file1)
assertThat(file1Subtitles, not(hasItem(file1Sub3)))
assertThat(file1Subtitles, empty())
externalSubDao.delete(file2Sub1)
val file2Subtitles = externalSubDao.get(file2)
assertThat(file2Subtitles, empty())
}
}
\ No newline at end of file
/*******************************************************************************
* MigrationTest.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database
import android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory
import android.arch.persistence.room.Room
import android.arch.persistence.room.testing.MigrationTestHelper
import android.net.Uri
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.videolan.libvlc.Media
import org.videolan.vlc.database.helpers.*
import org.videolan.vlc.database.models.BrowserFav
import org.videolan.vlc.database.models.ExternalSub
import org.videolan.vlc.database.models.Slave
import org.videolan.vlc.util.Constants
@RunWith(AndroidJUnit4::class)
class MigrationTest {
// Slave
private val slaveMedia1Path = "/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.mkv"
private val slaveMedia1UriFa = "file:///storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.fa.srt"
// External Sub
private val exSubMedia1Name = "file1.mkv"
private val exSubMedisubsFolder = "/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/"
private val exSubfile1Sub1 = "${exSubMedisubsFolder}file1.eng.srt"
// Favs
private val favUri = Uri.parse("/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.mkv")
private val favTitle = "test1"
private val TEST_DB_NAME = "test-db"
@get:Rule
val migrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
MediaDatabase::class.java.canonicalName,
FrameworkSQLiteOpenHelperFactory())
@Test fun migrate26To27() {
val sqliteTestDbOpenHelper = SqliteTestDbOpenHelper(InstrumentationRegistry.getTargetContext(), TEST_DB_NAME, 26)
createSlavesTable(sqliteTestDbOpenHelper)
createExternalSubsTable(sqliteTestDbOpenHelper)
createNetworkFavsTable(sqliteTestDbOpenHelper)
// Insert Data before migration
saveSlave(slaveMedia1Path, Media.Slave.Type.Subtitle, 2, slaveMedia1UriFa, sqliteTestDbOpenHelper)
saveExSubtitle(exSubfile1Sub1, exSubMedia1Name, sqliteTestDbOpenHelper)
saveNetworkFavItem(favUri, favTitle, null, sqliteTestDbOpenHelper)
migrationTestHelper.runMigrationsAndValidate(TEST_DB_NAME, 27, true, migration_26_27)
val migratedDb = getMigratedRoomDatabase()
val slave: Slave = migratedDb.slaveDao().get(slaveMedia1Path)[0]
val exSub: ExternalSub = migratedDb.externalSubDao().get(exSubMedia1Name)[0]
val fav: BrowserFav = migratedDb.browserFavDao().get(favUri)[0]
assertEquals(slave.mediaPath, slaveMedia1Path)
assertEquals(slave.type, Media.Slave.Type.Subtitle)
assertEquals(slave.priority, 2)
assertEquals(slave.uri, slaveMedia1UriFa)
assertEquals(exSub.uri, exSubfile1Sub1)
assertEquals(exSub.mediaName, exSubMedia1Name)
assertEquals(fav.uri, favUri)
assertEquals(fav.title, favTitle)
assertEquals(fav.iconUrl, null)
assertEquals(fav.type, Constants.TYPE_NETWORK_FAV)
clearDatabase(sqliteTestDbOpenHelper)
}
fun getMigratedRoomDatabase(): MediaDatabase {
val database: MediaDatabase = Room.databaseBuilder(
InstrumentationRegistry.getTargetContext(),
MediaDatabase::class.java, TEST_DB_NAME )
.addMigrations(migration_26_27)
.build()
// close the database and release any stream resources when the test finishes
migrationTestHelper.closeWhenFinished(database);
return database
}
}
\ No newline at end of file
/*******************************************************************************
* SlaveDaoTest.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database
import android.arch.persistence.room.Room
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.*
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.videolan.libvlc.Media
import org.videolan.vlc.database.models.Slave
@RunWith(AndroidJUnit4::class)
class SlaveDaoTest {
private lateinit var database: MediaDatabase
private lateinit var slaveDao: SlaveDao
val media1Path = "/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.mkv"
val media1UriEng = "file:///storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.eng.srt"
val media1UriFa = "file:///storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.fa.srt"
val media2Path = "/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file2.mkv"
val media2UriEng = "file:///storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file2.eng.srt"
private val slave1eng = Slave(media1Path, Media.Slave.Type.Subtitle, 0, media1UriEng)
private val slave1fa = Slave(media1Path, Media.Slave.Type.Subtitle, 0, media1UriFa)
private val slave2 = Slave(media2Path, Media.Slave.Type.Subtitle, 1, media2UriEng )
@Before fun createDao() {
val context = InstrumentationRegistry.getTargetContext()
database = Room.inMemoryDatabaseBuilder(context, MediaDatabase::class.java).build()
slaveDao = database.slaveDao()
slaveDao.insert(slave1eng)
slaveDao.insert(slave1fa)
slaveDao.insert(slave2)
}
@After fun closeDb() {
database.close()
}
@Test fun getSlaves() {
val s1 = slaveDao.get(media1Path)
assertThat(s1.size, equalTo(1))
assertThat(s1, not(hasItem(slave1eng)))
assertThat(s1, hasItem(slave1fa))
val s2 = slaveDao.get(media2Path)
assertThat(s2.size, equalTo(1))
assertThat(s2, hasItem(slave2))
}
}
/*******************************************************************************
* SqliteDatabaseTestHelper
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*/
package org.videolan.vlc.database.helpers
import android.content.ContentValues
import android.net.Uri
import android.text.TextUtils
private val NETWORK_FAV_TABLE_NAME = "fav_table"
private val NETWORK_FAV_URI = "uri"
private val NETWORK_FAV_TITLE = "title"
private val NETWORK_FAV_ICON_URL = "icon_url"
private val EXTERNAL_SUBTITLES_TABLE_NAME = "external_subtitles_table"
private val EXTERNAL_SUBTITLES_MEDIA_NAME = "media_name"
private val EXTERNAL_SUBTITLES_URI = "uri"
private val SLAVES_TABLE_NAME = "SLAVES_table"
private val SLAVES_MEDIA_PATH = "slave_media_mrl"
private val SLAVES_TYPE = "slave_type"
private val SLAVES_PRIORITY = "slave_priority"
private val SLAVES_URI = "slave_uri"
fun createSlavesTable(helper: SqliteTestDbOpenHelper) {
val db = helper.writableDatabase
db.execSQL("CREATE TABLE IF NOT EXISTS $SLAVES_TABLE_NAME ( slave_media_mrl TEXT PRIMARY KEY NOT NULL, slave_type INTEGER NOT NULL, slave_priority INTEGER, slave_uri TEXT NOT NULL);")
db.close()
}
fun createExternalSubsTable(helper: SqliteTestDbOpenHelper) {
val db = helper.writableDatabase
db.execSQL("CREATE TABLE IF NOT EXISTS $EXTERNAL_SUBTITLES_TABLE_NAME ( uri TEXT PRIMARY KEY NOT NULL, media_name TEXT NOT NULL);")
db.close()
}
fun createNetworkFavsTable(helper: SqliteTestDbOpenHelper) {
val db = helper.writableDatabase
db.execSQL("CREATE TABLE IF NOT EXISTS $NETWORK_FAV_TABLE_NAME ( uri TEXT PRIMARY KEY NOT NULL, title TEXT NOT NULL, icon_url TEXT);")
db.close()
}
fun saveSlave(mediaPath: String, type: Int, priority: Int, uriString: String, helper: SqliteTestDbOpenHelper) {
val db = helper.writableDatabase
val values = ContentValues()
values.put(SLAVES_MEDIA_PATH, mediaPath)
values.put(SLAVES_TYPE, type)
values.put(SLAVES_PRIORITY, priority)
values.put(SLAVES_URI, uriString)
db.replace(SLAVES_TABLE_NAME, null, values)
db.close()
}
fun saveExSubtitle(path: String, mediaName: String, helper: SqliteTestDbOpenHelper) {
val db = helper.writableDatabase
if (TextUtils.isEmpty(path) || TextUtils.isEmpty(mediaName))
return
val values = ContentValues()
values.put(EXTERNAL_SUBTITLES_URI, path)
values.put(EXTERNAL_SUBTITLES_MEDIA_NAME, mediaName)
db.replace(EXTERNAL_SUBTITLES_TABLE_NAME, null, values)
db.close()
}
fun saveNetworkFavItem(uri: Uri, title: String, iconUrl: String?, helper: SqliteTestDbOpenHelper) {
val db = helper.writableDatabase
val values = ContentValues()
values.put(NETWORK_FAV_URI, uri.toString())
values.put(NETWORK_FAV_TITLE, Uri.encode(title))
values.put(NETWORK_FAV_ICON_URL, Uri.encode(iconUrl))
db.replace(NETWORK_FAV_TABLE_NAME, null, values)
db.close()
}
fun clearDatabase(helper: SqliteTestDbOpenHelper) {
val db = helper.writableDatabase
db.execSQL("DROP TABLE IF EXISTS $EXTERNAL_SUBTITLES_TABLE_NAME")
db.execSQL("DROP TABLE IF EXISTS $SLAVES_TABLE_NAME")
db.execSQL("DROP TABLE IF EXISTS $NETWORK_FAV_TABLE_NAME")
db.close()
}
/*******************************************************************************
* SqliteTestDbOpenHelper
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*/
package org.videolan.vlc.database.helpers
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
class SqliteTestDbOpenHelper(context: Context, databaseName: String, version: Int) : SQLiteOpenHelper(context, databaseName, null, version) {
override fun onCreate(db: SQLiteDatabase) {
}
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
// Not required as at version 1
}
override fun onDowngrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
// Not required as at version 1
}
}
/*******************************************************************************
* BrowserFavRepositoryTest.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.repository
import android.arch.persistence.room.Room
import android.net.Uri
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import junit.framework.Assert.assertNull
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.runBlocking
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.videolan.vlc.database.MediaDatabase
import org.videolan.vlc.util.runBackground
@RunWith(AndroidJUnit4::class)
class BrowserFavRepositoryTest {
private lateinit var database: MediaDatabase
private lateinit var browserFavRepository: BrowserFavRepository
private val uri = Uri.parse("/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.mkv")
@Before
fun onCreateRepository() {
val context = InstrumentationRegistry.getTargetContext()
database = Room.inMemoryDatabaseBuilder(context, MediaDatabase::class.java).build()
browserFavRepository = BrowserFavRepository(context, mediaDatabase = database)
}
@Test fun addBrowserFaveItem() {
val title = "test1"
runBlocking {
browserFavRepository.addLocalFavItem(uri, title, null).join()
val exists = browserFavRepository.browserFavExists(uri)
assertThat(exists, equalTo(true))
}
val browserFavs = browserFavRepository.getAllBrowserFavs()
assertThat(browserFavs[0].uri, equalTo(uri))
assertThat(browserFavs[0].title, equalTo(title))
assertNull(browserFavs[0].artworkURL)
}
@Test fun deleteBrowserFav() = runBlocking {
val title = "test1"
browserFavRepository.addLocalFavItem(uri, title, null).join()
browserFavRepository.deleteBrowserFav(uri)
val favs = browserFavRepository.getAllBrowserFavs()
assertThat(favs.size, equalTo(0))
}
}
\ No newline at end of file
/*******************************************************************************
* ExternalSubRepositoryTest.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.repository
import android.arch.persistence.room.Room
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import kotlinx.coroutines.experimental.runBlocking
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.videolan.vlc.database.MediaDatabase
import java.io.File
@RunWith(AndroidJUnit4::class)
class ExternalSubRepositoryTest {
private lateinit var database: MediaDatabase
private lateinit var externalSubRepository: ExternalSubRepository
private val media1Name = "file1.mkv"
private val subsFolder = "/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/"
private val file1Sub1 = "${subsFolder}file1.eng.srt"
private val file1Sub2 = "${subsFolder}file1.fa.srt"
private val file1Sub3 = "${subsFolder}file1.fr.srt"
@Before
fun onCreateRepository() {
val context = InstrumentationRegistry.getTargetContext()
database = Room.inMemoryDatabaseBuilder(context, MediaDatabase::class.java).build()
externalSubRepository = ExternalSubRepository(context, mediaDatabase = database)
val subsFolder = File(subsFolder)
subsFolder.mkdirs()
}
@After fun clean() {
val subsFolder = File(subsFolder)
subsFolder.deleteRecursively()
}
@Test fun saveSubtitle() = runBlocking{
externalSubRepository.saveSubtitle(file1Sub1, media1Name)
externalSubRepository.saveSubtitle(file1Sub2, media1Name)
externalSubRepository.saveSubtitle(file1Sub3, media1Name)
val file1 = File(file1Sub1)
file1.createNewFile()
val file2 = File(file1Sub2)
file2.createNewFile()
val file3 = File(file1Sub3)
file3.createNewFile()
val externalSubs = externalSubRepository.getSubtitles(media1Name)
assertThat(externalSubs.size, equalTo(3))
file1.delete()
var externalSubsAfterDelete = externalSubRepository.getSubtitles(media1Name)
assertThat(externalSubsAfterDelete.size, equalTo(2))
file2.delete()
externalSubsAfterDelete = externalSubRepository.getSubtitles(media1Name)
assertThat(externalSubsAfterDelete.size, equalTo(1))
file3.delete()
externalSubsAfterDelete = externalSubRepository.getSubtitles(media1Name)
assertThat(externalSubsAfterDelete.size, equalTo(0))
}
}
\ No newline at end of file
/*******************************************************************************
* SlaveRepositoryTest.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.repository
import android.arch.persistence.room.Room
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import junit.framework.Assert.assertEquals
import kotlinx.coroutines.experimental.runBlocking
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.videolan.libvlc.Media
import org.videolan.vlc.database.MediaDatabase
@RunWith(AndroidJUnit4::class)
class SlaveRepositoryTest {
private lateinit var database: MediaDatabase
private lateinit var slaveRepository: SlaveRepository
val media1Path = "/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.mkv"
val media1UriEng = "file:///storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.eng.srt"
val media1UriFa = "file:///storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file1.fa.srt"
val media2Path = "/storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file2.mkv"
val media2UriEng = "file:///storage/emulated/0/Android/data/org.videolan.vlc.debug/files/subs/file2.eng.srt"
@Before fun onCreateRepository() {
val context = InstrumentationRegistry.getTargetContext()
database = Room.inMemoryDatabaseBuilder(context, MediaDatabase::class.java).build()
slaveRepository = SlaveRepository(context, mediaDatabase = database)
}
@After fun closeDb() {
database.close()
}
@Test fun saveSlave() = runBlocking {
val slavesBeforeInsert = slaveRepository.getSlaves(media1Path)
assertThat(slavesBeforeInsert.size, equalTo(0))
slaveRepository.saveSlave(media1Path, Media.Slave.Type.Subtitle, 2, media1UriEng).join()
slaveRepository.saveSlave(media1Path, Media.Slave.Type.Subtitle, 2, media1UriFa).join()
val slavesAfterInsert = slaveRepository.getSlaves(media1Path)
assertThat(slavesAfterInsert.size, equalTo(1))
}
@Test fun getSlaves() = runBlocking{
slaveRepository.saveSlave(media1Path, Media.Slave.Type.Subtitle, 2, media1UriEng).join()
val correctMediSlave = Media.Slave(Media.Slave.Type.Subtitle, 2, media1UriEng)
val slaves = slaveRepository.getSlaves(media1Path)
assertEquals(slaves[0].uri, correctMediSlave.uri)
assertEquals(slaves[0].type, correctMediSlave.type)
assertEquals(slaves[0].priority, correctMediSlave.priority)
}
}
\ No newline at end of file
{
"formatVersion": 1,
"database": {
"version": 27,
"identityHash": "4c65aef518538cee6b0a4de5ceb1bd73",
"entities": [
{
"tableName": "external_subtitles_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uri` TEXT NOT NULL, `media_name` TEXT NOT NULL, PRIMARY KEY(`uri`))",
"fields": [
{
"fieldPath": "uri",
"columnName": "uri",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "mediaName",
"columnName": "media_name",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"uri"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "SLAVES_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`slave_media_mrl` TEXT NOT NULL, `slave_type` INTEGER NOT NULL, `slave_priority` INTEGER NOT NULL, `slave_uri` TEXT NOT NULL, PRIMARY KEY(`slave_media_mrl`))",
"fields": [
{
"fieldPath": "mediaPath",
"columnName": "slave_media_mrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "type",
"columnName": "slave_type",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "priority",
"columnName": "slave_priority",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "uri",
"columnName": "slave_uri",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"slave_media_mrl"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "fav_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uri` TEXT NOT NULL, `type` INTEGER NOT NULL, `title` TEXT NOT NULL, `icon_url` TEXT, PRIMARY KEY(`uri`))",
"fields": [
{
"fieldPath": "uri",
"columnName": "uri",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "type",
"columnName": "type",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "iconUrl",
"columnName": "icon_url",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"uri"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"4c65aef518538cee6b0a4de5ceb1bd73\")"
]
}
}
\ No newline at end of file
......@@ -46,6 +46,8 @@ android {
resValue "string", "build_revision", revision()
resValue "string", "build_vlc_revision", vlcRevision()
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
......@@ -57,6 +59,13 @@ android {
task.dependsOn luaMetaCopy
}
}
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation":
"$projectDir/assets/schemas".toString()]
}
}
}
signingConfigs {
......@@ -170,6 +179,10 @@ android {
sourceSets.test {
java.srcDirs = ['test']
}
sourceSets.androidTest {
java.srcDirs = ['androidTest']
assets.srcDirs += files("$projectDir/assets/schemas".toString())
}
}
kotlin.experimental.coroutines = "enable"
......@@ -194,7 +207,6 @@ dependencies {
implementation "com.android.support:leanback-v17:$rootProject.ext.appCompatVersion"
implementation "com.android.support:preference-leanback-v17:$rootProject.ext.appCompatVersion"
implementation "com.android.support:support-tv-provider:$rootProject.ext.appCompatVersion"
testImplementation 'junit:junit:4.12'
// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
kapt "com.android.databinding:compiler:$rootProject.ext.android_plugin_version"
......@@ -202,7 +214,15 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.ext.kotlinx_version"
implementation "android.arch.lifecycle:extensions:$rootProject.ext.archVersion"
kapt "android.arch.lifecycle:compiler:$rootProject.ext.archVersion"
implementation "android.arch.persistence.room:runtime:$rootProject.ext.roomVersion"
kapt "android.arch.persistence.room:compiler:$rootProject.ext.roomVersion"
implementation project(':tools')
// Test
androidTestImplementation "com.android.support.test.espresso:espresso-contrib:$rootProject.espressoVersion"
androidTestImplementation "com.android.support.test.espresso:espresso-core:$rootProject.espressoVersion"
testImplementation "junit:junit:$rootProject.ext.junitVersion"
androidTestImplementation "android.arch.persistence.room:testing:$rootProject.ext.roomVersion"
}
static def buildTime() {
......
/*******************************************************************************
* BrowserFavDao.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database
import android.arch.persistence.room.Dao
import android.arch.persistence.room.Insert
import android.arch.persistence.room.OnConflictStrategy
import android.arch.persistence.room.Query
import android.net.Uri
import org.videolan.vlc.database.models.BrowserFav
@Dao
interface BrowserFavDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(browserFav: BrowserFav)
@Query("SELECT * FROM fav_table where uri = :uri")
fun get(uri: Uri): List<BrowserFav>
@Query("SELECT * from fav_table")
fun getAll(): List<BrowserFav>
@Query("SELECT * from fav_table where type = 0")
fun getAllNetwrokFavs(): List<BrowserFav>
@Query("SELECT * from fav_table where type = 1")
fun getAllLocalFavs(): List<BrowserFav>
@Query("DELETE from fav_table where uri = :uri")
fun delete(uri: Uri)
}
\ No newline at end of file
/*******************************************************************************
* Converters.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database
import android.arch.persistence.room.TypeConverter
import android.net.Uri
import org.videolan.libvlc.Media
import org.videolan.vlc.database.models.Slave
class Converters {
@TypeConverter fun uriToString(uri: Uri): String = uri.toString()
@TypeConverter fun stringToUri(value: String): Uri = Uri.parse(value)
}
\ No newline at end of file
/*******************************************************************************
* ExternalSubDao.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database
import android.arch.persistence.room.*
import org.videolan.vlc.database.models.ExternalSub
@Dao
interface ExternalSubDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(externalSub: ExternalSub)
@Delete
fun delete(externalSub: ExternalSub)
@Query("SELECT * from external_subtitles_table where media_name = :mediaName")
fun get(mediaName: String): List<ExternalSub>
}
/*******************************************************************************
* MediaDatabase.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database
import android.arch.persistence.room.Database
import android.arch.persistence.room.Room
import android.arch.persistence.room.RoomDatabase
import android.arch.persistence.room.TypeConverters
import android.content.Context
import org.videolan.vlc.database.models.BrowserFav
import org.videolan.vlc.database.models.ExternalSub
import org.videolan.vlc.database.models.Slave
@Database(entities = [ExternalSub::class, Slave::class, BrowserFav::class], version = 27)
@TypeConverters(Converters::class)
abstract class MediaDatabase: RoomDatabase() {
abstract fun externalSubDao(): ExternalSubDao
abstract fun slaveDao(): SlaveDao
abstract fun browserFavDao(): BrowserFavDao
companion object {
private const val DB_NAME = "vlc_database"
@Volatile private var instance: MediaDatabase? = null
fun getDatabase(context: Context): MediaDatabase =
instance ?: synchronized(this) {
instance ?: buildDatabase(context).also { instance = it }
}
private fun buildDatabase(context: Context) =
Room.databaseBuilder(context.applicationContext,
MediaDatabase::class.java, DB_NAME)
.addMigrations(migration_1_2, migration_2_3, migration_3_4, migration_4_5,
migration_5_6, migration_6_7, migration_7_8, migration_8_9,
migration_9_10, migration_10_11, migration_11_12, migration_12_13,
migration_13_14, migration_14_15, migration_15_16, migration_16_17,
migration_17_18, migration_18_19, migration_19_20, migration_20_21,
migration_21_22, migration_22_23, migration_23_24, migration_24_25,
migration_25_26, migration_26_27)
.build()
}
}
/*******************************************************************************
* Migrations.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database
import android.arch.persistence.db.SupportSQLiteDatabase
import android.arch.persistence.room.migration.Migration
import org.videolan.vlc.util.Constants
private const val DIR_TABLE_NAME = "directories_table"
private const val MEDIA_TABLE_NAME = "media_table"
private const val PLAYLIST_TABLE_NAME = "playlist_table"
private const val PLAYLIST_MEDIA_TABLE_NAME = "playlist_media_table"
private const val SEARCHHISTORY_TABLE_NAME = "searchhistory_table"
private const val MRL_TABLE_NAME = "mrl_table"
private const val HISTORY_TABLE_NAME = "history_table"
private const val EXTERNAL_SUBTITLES_TABLE_NAME = "external_subtitles_table"
private const val SLAVES_TABLE_NAME = "SLAVES_table"
private const val FAV_TABLE_NAME = "fav_table"
fun dropUnnecessaryTables(database: SupportSQLiteDatabase) {
database.execSQL("DROP TABLE IF EXISTS $DIR_TABLE_NAME;")
database.execSQL("DROP TABLE IF EXISTS $MEDIA_TABLE_NAME;")
database.execSQL("DROP TABLE IF EXISTS $PLAYLIST_MEDIA_TABLE_NAME;")
database.execSQL("DROP TABLE IF EXISTS $PLAYLIST_TABLE_NAME;")
database.execSQL("DROP TABLE IF EXISTS $PLAYLIST_TABLE_NAME;")
database.execSQL("DROP TABLE IF EXISTS $SEARCHHISTORY_TABLE_NAME;")
database.execSQL("DROP TABLE IF EXISTS $MRL_TABLE_NAME;")
database.execSQL("DROP TABLE IF EXISTS $HISTORY_TABLE_NAME;")
}
val migration_1_2 = object:Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {}
}
val migration_2_3 = object:Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {}
}
val migration_3_4 = object:Migration(3, 4) {
override fun migrate(database: SupportSQLiteDatabase) {}
}
val migration_4_5 = object:Migration(4, 5) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_5_6 = object:Migration(5, 6) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_6_7 = object:Migration(6, 7) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_7_8 = object:Migration(7, 8) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_8_9 = object:Migration(8, 9) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_9_10 = object:Migration(9, 10) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_10_11 = object:Migration(10, 11) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_11_12 = object:Migration(11, 12) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_12_13 = object:Migration(12, 13) {
override fun migrate(database: SupportSQLiteDatabase) {
}
}
val migration_13_14 = object:Migration(13, 14) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_14_15 = object:Migration(14, 15) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_15_16 = object:Migration(15, 16) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_16_17 = object:Migration(16, 17) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_17_18 = object:Migration(17, 18) {
override fun migrate(database: SupportSQLiteDatabase) {
}
}
val migration_18_19 = object:Migration(18, 19) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_19_20 = object:Migration(19, 20) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_20_21 = object:Migration(20, 21) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_21_22 = object:Migration(21, 22) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_22_23 = object:Migration(22, 23) {
override fun migrate(database: SupportSQLiteDatabase) { }
}
val migration_23_24 = object:Migration(23, 24) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("DROP TABLE IF EXISTS $FAV_TABLE_NAME;")
database.execSQL("CREATE TABLE IF NOT EXISTS $FAV_TABLE_NAME ( uri TEXT PRIMARY KEY NOT NULL, title TEXT NOT NULL, icon_url TEXT);")
}
}
val migration_24_25 = object:Migration(24, 25) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS $EXTERNAL_SUBTITLES_TABLE_NAME ( uri TEXT PRIMARY KEY NOT NULL, media_name TEXT NOT NULL);")
}
}
val migration_25_26 = object:Migration(25, 26) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS $SLAVES_TABLE_NAME ( slave_media_mrl TEXT PRIMARY KEY NOT NULL, slave_type INTEGER NOT NULL, slave_priority INTEGER, slave_uri TEXT NOT NULL);")
}
}
val migration_26_27 = object:Migration(26, 27) {
override fun migrate(database: SupportSQLiteDatabase) {
dropUnnecessaryTables(database)
val SLAVES_TABLE_NAME_TEMP = "${SLAVES_TABLE_NAME}_TEMP"
database.execSQL("UPDATE $SLAVES_TABLE_NAME SET slave_priority=2 WHERE slave_priority IS NULL;")
database.execSQL("CREATE TABLE IF NOT EXISTS $SLAVES_TABLE_NAME_TEMP ( slave_media_mrl TEXT PRIMARY KEY NOT NULL, slave_type INTEGER NOT NULL, slave_priority INTEGER NOT NULL, slave_uri TEXT NOT NULL);")
database.execSQL("INSERT INTO $SLAVES_TABLE_NAME_TEMP(slave_media_mrl, slave_type, slave_priority, slave_uri) SELECT slave_media_mrl, slave_type, slave_priority, slave_uri FROM $SLAVES_TABLE_NAME")
database.execSQL("DROP TABLE $SLAVES_TABLE_NAME")
database.execSQL("ALTER TABLE $SLAVES_TABLE_NAME_TEMP RENAME TO $SLAVES_TABLE_NAME")
// Add a type column and set its value to 0 (till this version all favs were network favs)
database.execSQL("ALTER TABLE $FAV_TABLE_NAME ADD COLUMN type INTEGER NOT NULL DEFAULT 0;")
}
}
/*******************************************************************************
* SlaveDao.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database
import android.arch.persistence.room.Dao
import android.arch.persistence.room.Insert
import android.arch.persistence.room.OnConflictStrategy
import android.arch.persistence.room.Query
import org.videolan.vlc.database.models.Slave
@Dao
interface SlaveDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(slave: Slave)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(slaves: Array<Slave>)
@Query("SELECT * from SLAVES_table where slave_media_mrl = :mrl")
fun get(mrl: String): List<Slave>
}
\ No newline at end of file
/*******************************************************************************
* BrowserFav.kt
* ****************************************************************************
* Copyright © 2018 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
package org.videolan.vlc.database.models
import android.arch.persistence.room.ColumnInfo
import android.arch.persistence.room.Entity
import android.arch.persistence.room.PrimaryKey
import android.net.Uri
@Entity(tableName = "fav_table")
data class BrowserFav (
@PrimaryKey
@ColumnInfo(name = "uri")
val uri: Uri,
@ColumnInfo(name = "type")
val type: Int,
@ColumnInfo(name = "title")
val title: String,
@ColumnInfo(name = "icon_url")
val iconUrl: String?
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment