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 ef87db307..78a646041 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.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 ) diff --git a/app/src/main/java/io/legado/app/data/dao/ExploreSearchUrlDao.kt b/app/src/main/java/io/legado/app/data/dao/ExploreSearchUrlDao.kt deleted file mode 100644 index eef3d93ed..000000000 --- a/app/src/main/java/io/legado/app/data/dao/ExploreSearchUrlDao.kt +++ /dev/null @@ -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 - - // 用于发现列表,按使用次数排序 - @Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE $ORDER_USAGE") - fun observeExploreUrlsByUsage(): DataSource.Factory - - // 用于发现列表,按使用时间排序 - @Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE $ORDER_TIME") - fun observeExploreUrlsByTime(): DataSource.Factory - - // 用于搜索时的发现列表,默认排序 - @Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE AND $QUERY_NAME $ORDER_DEFAULT") - fun observeFilteredExploreUrls(name: String): DataSource.Factory - - // 用于搜索时的发现列表,按使用次数排序 - @Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE AND $QUERY_NAME $ORDER_USAGE") - fun observeFilteredExploreUrlsByUsage(): DataSource.Factory - - // 用于搜索时的发现列表,按使用时间排序 - @Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE AND $QUERY_NAME $ORDER_TIME") - fun observeFilteredExploreUrlsByTime(): DataSource.Factory - - // 获取特定书源的发现 - @Query("SELECT * FROM explore_search_urls $QUERY_ENABLED_EXPLORE AND sourceId = :sourceId") - fun findExploreUrlsBySourceId(sourceId: Int): List - - // 获取特定书源的搜索链接 - @Query("SELECT * FROM explore_search_urls WHERE type = 1 AND sourceId = :sourceId") - fun findSearchUrlsBySourceId(sourceId: Int): List - - // 所有的搜索链接 - @get:Query("SELECT * FROM explore_search_urls WHERE type = 1") - val allSearchUrls: List - - @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) - -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/SourceCookieDao.kt b/app/src/main/java/io/legado/app/data/dao/SourceCookieDao.kt index fcf4abf70..4c7a062c7 100644 --- a/app/src/main/java/io/legado/app/data/dao/SourceCookieDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SourceCookieDao.kt @@ -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? } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/Chapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt similarity index 82% rename from app/src/main/java/io/legado/app/data/entities/Chapter.kt rename to app/src/main/java/io/legado/app/data/entities/BookChapter.kt index 288a1bd94..4b16519fe 100644 --- a/app/src/main/java/io/legado/app/data/entities/Chapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -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 = "", // 书籍地址 diff --git a/app/src/main/java/io/legado/app/data/entities/ExploreSearchUrl.kt b/app/src/main/java/io/legado/app/data/entities/ExploreSearchUrl.kt deleted file mode 100644 index 4b8c8cde2..000000000 --- a/app/src/main/java/io/legado/app/data/entities/ExploreSearchUrl.kt +++ /dev/null @@ -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 - diff --git a/app/src/main/java/io/legado/app/data/entities/SourceCookie.kt b/app/src/main/java/io/legado/app/data/entities/SourceCookie.kt index 62581a2f8..b770f16ae 100644 --- a/app/src/main/java/io/legado/app/data/entities/SourceCookie.kt +++ b/app/src/main/java/io/legado/app/data/entities/SourceCookie.kt @@ -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 = "", diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt index 08a0455a1..6f262857e 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt @@ -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 ) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt index 284369622..e0b047df5 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt @@ -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 ) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index e0366af9d..ea889688c 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -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"), diff --git a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt index d7ef2612d..aa7bab2d6 100644 --- a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt @@ -121,7 +121,7 @@ class SourceEditActivity : BaseActivity(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(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(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(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(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 diff --git a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt index b4a61e6ff..f75e01a1b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt +++ b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt @@ -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) + } } } }