图片加入下载

pull/326/head
AndyBernie 4 years ago
commit bad4afb790
  1. 4
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 19
      app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt
  3. 11
      app/src/main/java/io/legado/app/data/entities/ReadRecord.kt
  4. 9
      app/src/main/java/io/legado/app/help/BookHelp.kt
  5. 6
      build.gradle

@ -18,8 +18,8 @@ import kotlinx.coroutines.launch
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class, RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class,
RssStar::class, TxtTocRule::class], RssStar::class, TxtTocRule::class, ReadRecord::class],
version = 15, version = 17,
exportSchema = true exportSchema = true
) )
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {

@ -0,0 +1,19 @@
package io.legado.app.data.dao
import androidx.room.*
import io.legado.app.data.entities.ReadRecord
@Dao
interface ReadRecordDao {
@get:Query("select * from readRecord")
val all: List<ReadRecord>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg readRecord: ReadRecord)
@Update
fun update(vararg record: ReadRecord)
}

@ -0,0 +1,11 @@
package io.legado.app.data.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "readRecord")
data class ReadRecord(
@PrimaryKey
val bookName: String = "",
val readTime: Long = 0L
)

@ -9,22 +9,25 @@ import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.ui.book.read.page.provider.ChapterProvider.srcPattern
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
import io.legado.app.utils.MD5Utils import io.legado.app.utils.MD5Utils
import io.legado.app.utils.externalFilesDir import io.legado.app.utils.externalFilesDir
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.apache.commons.text.similarity.JaccardSimilarity import org.apache.commons.text.similarity.JaccardSimilarity
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.io.File import java.io.File
import java.util.regex.Pattern
import kotlin.math.min import kotlin.math.min
object BookHelp { object BookHelp {
private const val cacheFolderName = "book_cache" private const val cacheFolderName = "book_cache"
private val downloadDir: File = App.INSTANCE.externalFilesDir private val downloadDir: File = App.INSTANCE.externalFilesDir
private val srcPattern =
Pattern.compile("<img .*?src.*?=.*?\"(.*?(?:,\\{.*\\})?)\".*?>", Pattern.CASE_INSENSITIVE)
private fun bookFolderName(book: Book): String { private fun bookFolderName(book: Book): String {
return formatFolderName(book.name) + MD5Utils.md5Encode16(book.bookUrl) return formatFolderName(book.name) + MD5Utils.md5Encode16(book.bookUrl)
@ -72,8 +75,8 @@ object BookHelp {
subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) subDirs = *arrayOf(cacheFolderName, bookFolderName(book))
).writeText(content) ).writeText(content)
//保存图片 //保存图片
content.forEachIndexed { index, text -> content.split("\n").forEach {
val matcher = srcPattern.matcher(text) val matcher = srcPattern.matcher(it)
if (matcher.find()) { if (matcher.find()) {
var src = matcher.group(1) var src = matcher.group(1)
src = NetworkUtils.getAbsoluteURL(bookChapter.url, src) src = NetworkUtils.getAbsoluteURL(bookChapter.url, src)

@ -5,8 +5,8 @@ buildscript {
repositories { repositories {
google() google()
jcenter() jcenter()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://s3.amazonaws.com/fabric-artifacts/public' } maven { url 'https://s3.amazonaws.com/fabric-artifacts/public' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.fabric.io/public' } maven { url 'https://maven.fabric.io/public' }
maven { url 'https://plugins.gradle.org/m2/' } maven { url 'https://plugins.gradle.org/m2/' }
@ -24,7 +24,7 @@ allprojects {
repositories { repositories {
google() google()
jcenter() jcenter()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url "https://jitpack.io" } maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com/' } maven { url 'https://maven.google.com/' }
maven { url 'https://github.com/psiegman/mvn-repo/raw/master/releases' } maven { url 'https://github.com/psiegman/mvn-repo/raw/master/releases' }

Loading…
Cancel
Save