pull/32/head
kunfei 5 years ago
parent 452a3b6768
commit 510aa5b2cc
  1. 2
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  2. 71
      app/src/main/java/io/legado/app/data/dao/ExploreSearchUrlDao.kt
  3. 2
      app/src/main/java/io/legado/app/data/dao/SourceCookieDao.kt
  4. 6
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  5. 33
      app/src/main/java/io/legado/app/data/entities/ExploreSearchUrl.kt
  6. 2
      app/src/main/java/io/legado/app/data/entities/SourceCookie.kt
  7. 22
      app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt
  8. 22
      app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt
  9. 4
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  10. 10
      app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt
  11. 4
      app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt

@ -11,7 +11,7 @@ import io.legado.app.data.entities.*
@Database(
entities = [Book::class, BookGroup::class, BookSource::class, Chapter::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, SourceCookie::class],
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, SourceCookie::class],
version = 1,
exportSchema = true
)

@ -1,71 +0,0 @@
package io.legado.app.data.dao
import androidx.paging.DataSource
import androidx.room.*
import io.legado.app.data.entities.ExploreSearchUrl
@Dao
interface ExploreSearchUrlDao {
companion object {
private const val ORDER_DEFAULT = "ORDER BY sourceId ASC, defOrder ASC"
private const val ORDER_USAGE = "ORDER BY usage DESC, lastUseTime DESC"
private const val ORDER_TIME = "ORDER BY lastUseTime DESC"
private const val QUERY_NAME = "name LIKE '%' || :name || '%'"
private const val QUERY_ENABLED_EXPLORE = "WHERE type = 0 AND isEnabled = 1"
}
// 用于发现列表,默认排序
@Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE $ORDER_DEFAULT")
fun observeExploreUrls(): DataSource.Factory<Int, ExploreSearchUrl>
// 用于发现列表,按使用次数排序
@Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE $ORDER_USAGE")
fun observeExploreUrlsByUsage(): DataSource.Factory<Int, ExploreSearchUrl>
// 用于发现列表,按使用时间排序
@Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE $ORDER_TIME")
fun observeExploreUrlsByTime(): DataSource.Factory<Int, ExploreSearchUrl>
// 用于搜索时的发现列表,默认排序
@Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE AND $QUERY_NAME $ORDER_DEFAULT")
fun observeFilteredExploreUrls(name: String): DataSource.Factory<Int, ExploreSearchUrl>
// 用于搜索时的发现列表,按使用次数排序
@Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE AND $QUERY_NAME $ORDER_USAGE")
fun observeFilteredExploreUrlsByUsage(): DataSource.Factory<Int, ExploreSearchUrl>
// 用于搜索时的发现列表,按使用时间排序
@Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE AND $QUERY_NAME $ORDER_TIME")
fun observeFilteredExploreUrlsByTime(): DataSource.Factory<Int, ExploreSearchUrl>
// 获取特定书源的发现
@Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE AND sourceId = :sourceId")
fun findExploreUrlsBySourceId(sourceId: Int): List<ExploreSearchUrl>
// 获取特定书源的搜索链接
@Query("SELECT * FROM explore_search_urls WHERE type = 1 AND sourceId = :sourceId")
fun findSearchUrlsBySourceId(sourceId: Int): List<ExploreSearchUrl>
// 所有的搜索链接
@get:Query("SELECT * FROM explore_search_urls WHERE type = 1")
val allSearchUrls: List<ExploreSearchUrl>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg keywords: ExploreSearchUrl)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(keyword: ExploreSearchUrl): Long
@Update
fun update(vararg keywords: ExploreSearchUrl)
@Delete
fun delete(vararg keywords: ExploreSearchUrl)
// 批量删除特定书源的发现和搜索链接,一般用于更新书源时
@Query("DELETE FROM explore_search_urls WHERE sourceId = :sourceId")
fun deleteBySourceId(sourceId: Int)
}

@ -6,7 +6,7 @@ import androidx.room.Query
@Dao
interface SourceCookieDao {
@Query("SELECT cookie FROM cookies Where url = :url")
@Query("SELECT cookie FROM cookies Where exploreUrl = :exploreUrl")
fun getCookieByUrl(url: String): String?
}

@ -10,8 +10,8 @@ import kotlinx.android.parcel.Parcelize
@Parcelize
@Entity(
tableName = "chapters",
primaryKeys = ["url", "bookUrl"],
indices = [(Index(value = ["url"], unique = true)), (Index(value = ["bookUrl", "index"], unique = true))],
primaryKeys = ["exploreUrl", "bookUrl"],
indices = [(Index(value = ["exploreUrl"], unique = true)), (Index(value = ["bookUrl", "index"], unique = true))],
foreignKeys = [(ForeignKey(
entity = Book::class,
parentColumns = ["descUrl"],
@ -19,7 +19,7 @@ import kotlinx.android.parcel.Parcelize
onDelete = ForeignKey.CASCADE
))]
) // 删除书籍时自动删除章节
data class Chapter(
data class BookChapter(
var url: String = "", // 章节地址
var title: String = "", // 章节标题
var bookUrl: String = "", // 书籍地址

@ -1,33 +0,0 @@
package io.legado.app.data.entities
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey
import kotlinx.android.parcel.Parcelize
@Parcelize
@Entity(
tableName = "explore_search_urls",
indices = [(Index(value = ["sourceId", "url"], unique = true))],
foreignKeys = [(ForeignKey(
entity = BookSource::class,
parentColumns = ["sourceId"],
childColumns = ["sourceId"],
onDelete = ForeignKey.CASCADE
))]
) // 删除书源时自动删除章节
data class ExploreSearchUrl(
@PrimaryKey(autoGenerate = true)
var esId: Int = 0, // 编号
var sourceId: Int = 0, // 书源Id
var name: String = "", // 发现名称,搜索可以没有
var url: String = "", // 地址
var type: Int = 0, // 类型,0 为发现,1 为搜索
var isEnabled: Boolean = true, // 是否启用
var defOrder: Int = 0, // 默认排序,是在编辑书源的时候的顺序
var usage: Int = 0, // 使用次数,用于按使用次数排序
var lastUseTime: Long = 0L // 最后一次使用的时间
) : Parcelable

@ -4,7 +4,7 @@ import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
@Entity(tableName = "cookies", indices = [(Index(value = ["url"], unique = true))])
@Entity(tableName = "cookies", indices = [(Index(value = ["exploreUrl"], unique = true))])
data class SourceCookie(
@PrimaryKey
var url: String = "",

@ -1,15 +1,15 @@
package io.legado.app.data.entities.rule
data class ExploreRule(
var url: String? = null,
var bookList: String? = null,
var name: String? = null,
var author: String? = null,
var intro: String? = null,
var kind: String? = null,
var lastChapter: String? = null,
var updateTime: String? = null,
var bookUrl: String? = null,
var coverUrl: String? = null,
var wordCount: String? = null
var exploreUrl: String? = null,
var bookList: String? = null,
var name: String? = null,
var author: String? = null,
var intro: String? = null,
var kind: String? = null,
var lastChapter: String? = null,
var updateTime: String? = null,
var bookUrl: String? = null,
var coverUrl: String? = null,
var wordCount: String? = null
)

@ -1,15 +1,15 @@
package io.legado.app.data.entities.rule
data class SearchRule(
var url: String? = null,
var bookList: String? = null,
var name: String? = null,
var author: String? = null,
var intro: String? = null,
var kind: String? = null,
var lastChapter: String? = null,
var updateTime: String? = null,
var bookUrl: String? = null,
var coverUrl: String? = null,
var wordCount: String? = null
var searchUrl: String? = null,
var bookList: String? = null,
var name: String? = null,
var author: String? = null,
var intro: String? = null,
var kind: String? = null,
var lastChapter: String? = null,
var updateTime: String? = null,
var bookUrl: String? = null,
var coverUrl: String? = null,
var wordCount: String? = null
)

@ -106,7 +106,7 @@ object Restore {
source.bookSourceGroup = jsonItem.readString("bookSourceGroup") ?: ""
source.loginUrl = jsonItem.readString("loginUrl")
val searchRule = SearchRule(
url = jsonItem.readString("ruleSearchUrl"),
searchUrl = jsonItem.readString("ruleSearchUrl"),
bookList = jsonItem.readString("ruleSearchList"),
name = jsonItem.readString("ruleSearchName"),
author = jsonItem.readString("ruleSearchAuthor"),
@ -118,7 +118,7 @@ object Restore {
)
source.ruleSearch = GSON.toJson(searchRule)
val exploreRule = ExploreRule(
url = jsonItem.readString("ruleFindUrl"),
exploreUrl = jsonItem.readString("ruleFindUrl"),
bookList = jsonItem.readString("ruleFindList"),
name = jsonItem.readString("ruleFindName"),
author = jsonItem.readString("ruleFindAuthor"),

@ -121,7 +121,7 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>(false), KeyboardToo
//搜索
with(bookSource?.getSearchRule()) {
searchEditList.clear()
searchEditList.add(EditEntity("url", this?.url, R.string.rule_search_url))
searchEditList.add(EditEntity("searchUrl", this?.searchUrl, R.string.rule_search_url))
searchEditList.add(EditEntity("bookList", this?.bookList, R.string.rule_book_list))
searchEditList.add(EditEntity("name", this?.name, R.string.rule_book_name))
searchEditList.add(EditEntity("author", this?.author, R.string.rule_book_author))
@ -164,7 +164,7 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>(false), KeyboardToo
//发现
with(bookSource?.getExploreRule()) {
findEditList.clear()
findEditList.add(EditEntity("url", this?.url, R.string.rule_find_url))
findEditList.add(EditEntity("exploreUrl", this?.exploreUrl, R.string.rule_find_url))
findEditList.add(EditEntity("bookList", this?.bookList, R.string.rule_book_list))
findEditList.add(EditEntity("name", this?.name, R.string.rule_book_name))
findEditList.add(EditEntity("author", this?.author, R.string.rule_book_author))
@ -206,7 +206,7 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>(false), KeyboardToo
for (entity in searchEditList) {
with(entity) {
when (key) {
"url" -> searchRule.url = value
"searchUrl" -> searchRule.searchUrl = value
"searchList" -> searchRule.bookList = value
"searchName" -> searchRule.name = value
"searchAuthor" -> searchRule.author = value
@ -223,7 +223,7 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>(false), KeyboardToo
for (entity in findEditList) {
with(entity) {
when (key) {
"url" -> exploreRule.url = value
"exploreUrl" -> exploreRule.exploreUrl = value
"searchList" -> exploreRule.bookList = value
"searchName" -> exploreRule.name = value
"searchAuthor" -> exploreRule.author = value
@ -299,7 +299,7 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>(false), KeyboardToo
}
override fun click(text: String) {
if (text.isNullOrBlank()) return
if (text.isBlank()) return
val view = window.decorView.findFocus()
if (view is EditText) {
val start = view.selectionStart

@ -27,7 +27,9 @@ class KeyboardToolPop(context: Context, onClickListener: OnClickListener?) : Pop
for (i in 0 until linearLayout.childCount) {
val tv = linearLayout.getChildAt(i) as TextView
tv.setOnClickListener { v ->
onClickListener?.click((v as TextView).text.toString())
(v as? TextView)?.text.toString().let {
onClickListener?.click(it)
}
}
}
}

Loading…
Cancel
Save