From b33dcb8200cd53d1d7a1ab0c68cb14b3b700d06b Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 17 Aug 2021 14:44:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 12 +++-- .../java/io/legado/app/MigrationTest.kt | 50 +++++++++++++++++++ .../java/io/legado/app/data/AppDatabase.kt | 7 ++- .../io/legado/app/data/entities/BookSource.kt | 1 + .../app/ui/book/login/SourceLoginDialog.kt | 11 ++++ app/src/main/res/layout/dialog_login.xml | 20 ++++++++ 6 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 app/src/androidTest/java/io/legado/app/MigrationTest.kt create mode 100644 app/src/main/res/layout/dialog_login.xml diff --git a/app/build.gradle b/app/build.gradle index ca3acdd55..7326db6f9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,6 +14,10 @@ def gitCommits = Integer.parseInt('git rev-list --count HEAD'.execute([], projec android { compileSdkVersion 30 + buildToolsVersion '30.0.3' + kotlinOptions { + jvmTarget = "11" + } signingConfigs { if (project.hasProperty("RELEASE_STORE_FILE")) { myConfig { @@ -102,10 +106,10 @@ android { targetCompatibility JavaVersion.VERSION_11 } - kotlinOptions { - jvmTarget = "11" + sourceSets { + // Adds exported schema location as test app assets. + androidTest.assets.srcDirs += files("$projectDir/schemas".toString()) } - buildToolsVersion '30.0.3' tasks.withType(JavaCompile) { //options.compilerArgs << "-Xlint:unchecked" } @@ -166,7 +170,7 @@ dependencies { implementation("androidx.lifecycle:lifecycle-common-java8:$lifecycle_version") //room - def room_version = '2.3.0' + def room_version = '2.4.0-alpha04' implementation("androidx.room:room-runtime:$room_version") implementation("androidx.room:room-ktx:$room_version") kapt("androidx.room:room-compiler:$room_version") diff --git a/app/src/androidTest/java/io/legado/app/MigrationTest.kt b/app/src/androidTest/java/io/legado/app/MigrationTest.kt new file mode 100644 index 000000000..64b7c5f17 --- /dev/null +++ b/app/src/androidTest/java/io/legado/app/MigrationTest.kt @@ -0,0 +1,50 @@ +package io.legado.app + +import androidx.room.Room +import androidx.room.migration.Migration +import androidx.room.testing.MigrationTestHelper +import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.runner.AndroidJUnit4 +import io.legado.app.data.AppDatabase +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import java.io.IOException + +@RunWith(AndroidJUnit4::class) +class MigrationTest { + private val TEST_DB = "migration-test" + + private val ALL_MIGRATIONS = arrayOf( + + ) + + @Rule + val helper: MigrationTestHelper = MigrationTestHelper( + InstrumentationRegistry.getInstrumentation(), + AppDatabase::class.java.canonicalName, + FrameworkSQLiteOpenHelperFactory() + ) + + @Test + @Throws(IOException::class) + fun migrateAll() { + // Create earliest version of the database. + helper.createDatabase(TEST_DB, 30).apply { + close() + } + + // Open latest version of the database. Room will validate the schema + // once all migrations execute. + Room.databaseBuilder( + InstrumentationRegistry.getInstrumentation().targetContext, + AppDatabase::class.java, + TEST_DB + ).addMigrations(*ALL_MIGRATIONS) + .build().apply { + openHelper.writableDatabase + close() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 3f3f04de1..39230ab92 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -1,6 +1,7 @@ package io.legado.app.data import android.content.Context +import androidx.room.AutoMigration import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase @@ -19,13 +20,14 @@ val appDb by lazy { } @Database( + version = 35, + exportSchema = true, entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class, RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class, Cache::class, RuleSub::class], - version = 34, - exportSchema = true + autoMigrations = [AutoMigration(from = 34, to = 35)] ) abstract class AppDatabase : RoomDatabase() { @@ -337,6 +339,7 @@ abstract class AppDatabase : RoomDatabase() { database.execSQL("ALTER TABLE `book_groups` ADD `cover` TEXT") } } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 0d1553440..aa47ad73c 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -29,6 +29,7 @@ data class BookSource( var bookSourceUrl: String = "", // 地址,包括 http/https var bookSourceType: Int = BookType.default, // 类型,0 文本,1 音频 var bookUrlPattern: String? = null, // 详情页url正则 + var concurrentRate: String? = null, //并发率 var customOrder: Int = 0, // 手动排序编号 var enabled: Boolean = true, // 是否启用 var enabledExplore: Boolean = true, // 启用发现 diff --git a/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt b/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt index 320bf5dc9..8af31811a 100644 --- a/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/login/SourceLoginDialog.kt @@ -1,11 +1,22 @@ package io.legado.app.ui.book.login import android.os.Bundle +import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup +import io.legado.app.R import io.legado.app.base.BaseDialogFragment class SourceLoginDialog : BaseDialogFragment() { + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.dialog_login, container) + } + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { } diff --git a/app/src/main/res/layout/dialog_login.xml b/app/src/main/res/layout/dialog_login.xml new file mode 100644 index 000000000..d28eb9303 --- /dev/null +++ b/app/src/main/res/layout/dialog_login.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file