Merge remote-tracking branch 'upstream/master' into master

pull/326/head
[用户名] 4 years ago
commit db29264b06
  1. 1
      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. 14
      app/src/main/java/io/legado/app/service/help/ReadBook.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
}

@ -9,6 +9,8 @@ interface ReadRecordDao {
@get:Query("select * from readRecord")
val all: List<ReadRecord>
@Query("select readTime from readRecord where bookName = :bookName")
fun getReadTime(bookName: String): Long?
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg readRecord: ReadRecord)

@ -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
)

@ -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<Int>()
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()
}
/**

Loading…
Cancel
Save