pull/898/head 3.21.031511
gedoor 4 years ago
parent 1766ab0e91
commit f363d0f90d
  1. 16
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 2
      app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt
  3. 4
      app/src/main/java/io/legado/app/data/entities/ReadRecord.kt
  4. 4
      app/src/main/java/io/legado/app/help/storage/Restore.kt

@ -23,7 +23,7 @@ val appDb by lazy {
RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class,
RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class, Cache::class,
RuleSub::class, EpubChapter::class],
version = 30,
version = 31,
exportSchema = true
)
abstract class AppDatabase : RoomDatabase() {
@ -59,7 +59,7 @@ abstract class AppDatabase : RoomDatabase() {
migration_14_15, migration_15_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,
migration_27_28, migration_28_29, migration_29_30
migration_27_28, migration_28_29, migration_29_30, migration_30_31
)
.allowMainThreadQueries()
.addCallback(dbCallback)
@ -278,6 +278,18 @@ abstract class AppDatabase : RoomDatabase() {
database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_epubChapters_bookUrl_href` ON `epubChapters` (`bookUrl`, `href`)")
}
}
private val migration_30_31 = object : Migration(30, 31) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE readRecord RENAME TO readRecord1")
database.execSQL(
"""
CREATE TABLE IF NOT EXISTS `readRecord` (`deviceId` TEXT NOT NULL, `bookName` TEXT NOT NULL, `readTime` INTEGER NOT NULL, PRIMARY KEY(`deviceId`, `bookName`))
"""
)
database.execSQL("insert into readRecord (deviceId, bookName, readTime) select androidId, bookName, readTime from readRecord1")
}
}
}
}

@ -19,7 +19,7 @@ interface ReadRecordDao {
@Query("select sum(readTime) from readRecord where bookName = :bookName")
fun getReadTime(bookName: String): Long?
@Query("select readTime from readRecord where androidId = :androidId and bookName = :bookName")
@Query("select readTime from readRecord where deviceId = :androidId and bookName = :bookName")
fun getReadTime(androidId: String, bookName: String): Long?
@Insert(onConflict = OnConflictStrategy.REPLACE)

@ -2,9 +2,9 @@ package io.legado.app.data.entities
import androidx.room.Entity
@Entity(tableName = "readRecord", primaryKeys = ["androidId", "bookName"])
@Entity(tableName = "readRecord", primaryKeys = ["deviceId", "bookName"])
data class ReadRecord(
var androidId: String = "",
var deviceId: String = "",
var bookName: String = "",
var readTime: Long = 0L
)

@ -149,11 +149,11 @@ object Restore {
fileToListT<ReadRecord>(path, "readRecord.json")?.let {
it.forEach { readRecord ->
//判断是不是本机记录
if (readRecord.androidId != androidId) {
if (readRecord.deviceId != androidId) {
appDb.readRecordDao.insert(readRecord)
} else {
val time = appDb.readRecordDao
.getReadTime(readRecord.androidId, readRecord.bookName)
.getReadTime(readRecord.deviceId, readRecord.bookName)
if (time == null || time < readRecord.readTime) {
appDb.readRecordDao.insert(readRecord)
}

Loading…
Cancel
Save