From 705b47e6a83a25b523e4b05714937393e9a66df0 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 21 Aug 2020 15:10:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=98=85=E8=AF=BB=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/AppDatabase.kt | 1 + .../java/io/legado/app/data/dao/ReadRecordDao.kt | 2 ++ .../java/io/legado/app/data/entities/ReadRecord.kt | 4 ++-- .../java/io/legado/app/service/help/ReadBook.kt | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) 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 f5d8d0927..cbff7a715 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -111,4 +111,5 @@ abstract class AppDatabase : RoomDatabase() { abstract fun rssStarDao(): RssStarDao abstract fun cookieDao(): CookieDao abstract fun txtTocRule(): TxtTocRuleDao + abstract fun readRecordDao(): ReadRecordDao } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt b/app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt index 0e1d2672e..92ba736ef 100644 --- a/app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt @@ -9,6 +9,8 @@ interface ReadRecordDao { @get:Query("select * from readRecord") val all: List + @Query("select readTime from readRecord where bookName = :bookName") + fun getReadTime(bookName: String): Long? @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg readRecord: ReadRecord) diff --git a/app/src/main/java/io/legado/app/data/entities/ReadRecord.kt b/app/src/main/java/io/legado/app/data/entities/ReadRecord.kt index 72e2bb0b2..488dc0205 100644 --- a/app/src/main/java/io/legado/app/data/entities/ReadRecord.kt +++ b/app/src/main/java/io/legado/app/data/entities/ReadRecord.kt @@ -6,6 +6,6 @@ import androidx.room.PrimaryKey @Entity(tableName = "readRecord") data class ReadRecord( @PrimaryKey - val bookName: String = "", - val readTime: Long = 0L + var bookName: String = "", + var readTime: Long = 0L ) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index afb7702a8..2827ba5ee 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -8,6 +8,7 @@ import io.legado.app.constant.BookType import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookSource +import io.legado.app.data.entities.ReadRecord import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp import io.legado.app.help.IntentDataHelp @@ -40,9 +41,13 @@ object ReadBook { var webBook: WebBook? = null var msg: String? = null private val loadingChapters = arrayListOf() + private val readRecord = ReadRecord() + var readStartTime: Long = System.currentTimeMillis() fun resetData(book: Book) { this.book = book + readRecord.bookName = book.name + readRecord.readTime = App.db.readRecordDao().getReadTime(book.name) ?: 0 durChapterIndex = book.durChapterIndex durPageIndex = book.durChapterPos isLocalBook = book.origin == BookType.local @@ -70,6 +75,14 @@ object ReadBook { } } + fun upReadStartTime() { + Coroutine.async { + readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime + readStartTime = System.currentTimeMillis() + App.db.readRecordDao().insert(readRecord) + } + } + fun upMsg(msg: String?) { this.msg = msg callBack?.upContent() @@ -159,6 +172,7 @@ object ReadBook { if (BaseReadAloudService.isRun) { readAloud(!BaseReadAloudService.pause) } + upReadStartTime() } /**