diff --git a/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt index 396f682c0..fd213d6ae 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt @@ -5,10 +5,11 @@ data class BookInfoRule( var init: String? = null, var name: String? = null, var author: String? = null, - var desc: String? = null, - var meta: String? = null, + var intro: String? = null, + var kind: String? = null, var lastChapter: String? = null, var updateTime: String? = null, var coverUrl: String? = null, - var tocUrl: String? = null + var tocUrl: 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/ContentRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt index c213a9fe8..36179bbce 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt @@ -2,5 +2,5 @@ package io.legado.app.data.entities.rule data class ContentRule( var content: String? = null, - var nextUrl: String? = null + var nextContentUrl: String? = null ) \ No newline at end of file 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 988679fec..08a0455a1 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,14 +1,15 @@ package io.legado.app.data.entities.rule data class ExploreRule( - var exploreUrl: String? = null, + var url: String? = null, var bookList: String? = null, var name: String? = null, var author: String? = null, - var desc: String? = null, - var meta: 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 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 82b0b9f4a..284369622 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,14 +1,15 @@ package io.legado.app.data.entities.rule data class SearchRule( - var searchUrl: String? = null, + var url: String? = null, var bookList: String? = null, var name: String? = null, var author: String? = null, - var desc: String? = null, - var meta: 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 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/TocRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt index d9fe9034c..60aabaa41 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt @@ -4,5 +4,5 @@ data class TocRule( var chapterList: String? = null, var chapterName: String? = null, var chapterUrl: String? = null, - var nextUrl: String? = null + var nextTocUrl: 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 34f8226af..e0366af9d 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,24 +106,24 @@ object Restore { source.bookSourceGroup = jsonItem.readString("bookSourceGroup") ?: "" source.loginUrl = jsonItem.readString("loginUrl") val searchRule = SearchRule( - searchUrl = jsonItem.readString("ruleSearchUrl"), + url = jsonItem.readString("ruleSearchUrl"), bookList = jsonItem.readString("ruleSearchList"), name = jsonItem.readString("ruleSearchName"), author = jsonItem.readString("ruleSearchAuthor"), - desc = jsonItem.readString("ruleSearchIntroduce"), - meta = jsonItem.readString("ruleSearchKind"), + intro = jsonItem.readString("ruleSearchIntroduce"), + kind = jsonItem.readString("ruleSearchKind"), bookUrl = jsonItem.readString("ruleSearchNoteUrl"), coverUrl = jsonItem.readString("ruleSearchCoverUrl"), lastChapter = jsonItem.readString("ruleSearchLastChapter") ) source.ruleSearch = GSON.toJson(searchRule) val exploreRule = ExploreRule( - exploreUrl = jsonItem.readString("ruleFindUrl"), + url = jsonItem.readString("ruleFindUrl"), bookList = jsonItem.readString("ruleFindList"), name = jsonItem.readString("ruleFindName"), author = jsonItem.readString("ruleFindAuthor"), - desc = jsonItem.readString("ruleFindIntroduce"), - meta = jsonItem.readString("ruleFindKind"), + intro = jsonItem.readString("ruleFindIntroduce"), + kind = jsonItem.readString("ruleFindKind"), bookUrl = jsonItem.readString("ruleFindNoteUrl"), coverUrl = jsonItem.readString("ruleFindCoverUrl"), lastChapter = jsonItem.readString("ruleFindLastChapter") @@ -134,8 +134,8 @@ object Restore { init = jsonItem.readString("ruleBookInfoInit"), name = jsonItem.readString("ruleBookName"), author = jsonItem.readString("ruleBookAuthor"), - desc = jsonItem.readString("ruleIntroduce"), - meta = jsonItem.readString("ruleBookKind"), + intro = jsonItem.readString("ruleIntroduce"), + kind = jsonItem.readString("ruleBookKind"), coverUrl = jsonItem.readString("ruleCoverUrl"), lastChapter = jsonItem.readString("ruleBookLastChapter"), tocUrl = jsonItem.readString("ruleChapterUrl") @@ -145,12 +145,12 @@ object Restore { chapterList = jsonItem.readString("ruleChapterUrlNext"), chapterName = jsonItem.readString("ruleChapterName"), chapterUrl = jsonItem.readString("ruleContentUrl"), - nextUrl = jsonItem.readString("ruleChapterUrlNext") + nextTocUrl = jsonItem.readString("ruleChapterUrlNext") ) source.ruleToc = GSON.toJson(chapterRule) val contentRule = ContentRule( content = jsonItem.readString("ruleBookContent"), - nextUrl = jsonItem.readString("ruleContentUrlNext") + nextContentUrl = jsonItem.readString("ruleContentUrlNext") ) source.ruleContent = GSON.toJson(contentRule) bookSources.add(source) 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 b44d3193b..9d971e7b7 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 @@ -8,6 +8,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.data.entities.BookSource +import io.legado.app.data.entities.rule.* import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_source_edit.* import org.jetbrains.anko.toast @@ -19,8 +20,12 @@ class SourceEditActivity : BaseActivity() { get() = R.layout.activity_source_edit private val adapter = SourceEditAdapter() - private val editList: ArrayList = ArrayList() + private val sourceEditList: ArrayList = ArrayList() + private val searchEditList: ArrayList = ArrayList() private val findEditList: ArrayList = ArrayList() + private val infoEditList: ArrayList = ArrayList() + private val tocEditList: ArrayList = ArrayList() + private val contentEditList: ArrayList = ArrayList() override fun onViewModelCreated(viewModel: SourceEditViewModel, savedInstanceState: Bundle?) { initRecyclerView() @@ -68,63 +73,70 @@ class SourceEditActivity : BaseActivity() { cb_is_enable.isChecked = it.enabled cb_is_enable_find.isChecked = it.enabledExplore } - editList.clear() - editList.add(EditEntity("origin", bookSource?.bookSourceUrl, R.string.book_source_url)) - editList.add(EditEntity("name", bookSource?.bookSourceName, R.string.book_source_name)) - editList.add(EditEntity("group", bookSource?.bookSourceGroup, R.string.book_source_group)) - editList.add(EditEntity("loginUrl", bookSource?.loginUrl, R.string.book_source_login_url)) - editList.add(EditEntity("header", bookSource?.header, R.string.source_user_agent)) + sourceEditList.clear() + sourceEditList.add(EditEntity("bookSourceUrl", bookSource?.bookSourceUrl, R.string.book_source_url)) + sourceEditList.add(EditEntity("bookSourceName", bookSource?.bookSourceName, R.string.book_source_name)) + sourceEditList.add(EditEntity("bookSourceGroup", bookSource?.bookSourceGroup, R.string.book_source_group)) + sourceEditList.add(EditEntity("loginUrl", bookSource?.loginUrl, R.string.book_source_login_url)) + sourceEditList.add(EditEntity("header", bookSource?.header, R.string.source_user_agent)) //搜索 with(bookSource?.getSearchRule()) { - editList.add(EditEntity("searchUrl", this?.searchUrl, R.string.rule_search_url)) - editList.add(EditEntity("searchList", this?.bookList, R.string.rule_search_list)) - editList.add(EditEntity("searchName", this?.name, R.string.rule_search_name)) - editList.add(EditEntity("searchAuthor", this?.author, R.string.rule_search_author)) - editList.add(EditEntity("searchKind", this?.meta, R.string.rule_search_kind)) - editList.add(EditEntity("searchLastChapter", this?.lastChapter, R.string.rule_search_last_chapter)) - editList.add(EditEntity("searchIntroduce", this?.desc, R.string.rule_search_introduce)) - editList.add(EditEntity("searchCoverUrl", this?.coverUrl, R.string.rule_search_cover_url)) - editList.add(EditEntity("searchNoteUrl", this?.bookUrl, R.string.rule_search_note_url)) + searchEditList.clear() + searchEditList.add(EditEntity("url", this?.url, 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)) + searchEditList.add(EditEntity("kind", this?.kind, R.string.rule_book_kind)) + searchEditList.add(EditEntity("wordCount", this?.wordCount, R.string.rule_word_count)) + searchEditList.add(EditEntity("lastChapter", this?.lastChapter, R.string.rule_last_chapter)) + searchEditList.add(EditEntity("intro", this?.intro, R.string.rule_book_intro)) + searchEditList.add(EditEntity("coverUrl", this?.coverUrl, R.string.rule_content_url)) + searchEditList.add(EditEntity("bookUrl", this?.bookUrl, R.string.rule_book_url)) } //详情页 with(bookSource?.getBookInfoRule()) { - editList.add(EditEntity("bookUrlPattern", this?.urlPattern, R.string.book_url_pattern)) - editList.add(EditEntity("bookInfoInit", this?.init, R.string.rule_book_info_init)) - editList.add(EditEntity("bookName", this?.name, R.string.rule_book_name)) - editList.add(EditEntity("bookAuthor", this?.author, R.string.rule_book_author)) - editList.add(EditEntity("ruleCoverUrl", this?.coverUrl, R.string.rule_cover_url)) - editList.add(EditEntity("ruleIntroduce", this?.desc, R.string.rule_introduce)) - editList.add(EditEntity("bookKind", this?.meta, R.string.rule_book_kind)) - editList.add(EditEntity("bookLastChapter", this?.lastChapter, R.string.rule_book_last_chapter)) - editList.add(EditEntity("tocUrl", this?.tocUrl, R.string.rule_chapter_list_url)) + infoEditList.clear() + infoEditList.add(EditEntity("urlPattern", this?.urlPattern, R.string.book_url_pattern)) + infoEditList.add(EditEntity("init", this?.init, R.string.rule_book_info_init)) + infoEditList.add(EditEntity("name", this?.name, R.string.rule_book_name)) + infoEditList.add(EditEntity("author", this?.author, R.string.rule_book_author)) + infoEditList.add(EditEntity("coverUrl", this?.coverUrl, R.string.rule_cover_url)) + infoEditList.add(EditEntity("intro", this?.intro, R.string.rule_book_intro)) + infoEditList.add(EditEntity("kind", this?.kind, R.string.rule_book_kind)) + infoEditList.add(EditEntity("wordCount", this?.wordCount, R.string.rule_word_count)) + infoEditList.add(EditEntity("lastChapter", this?.lastChapter, R.string.rule_last_chapter)) + infoEditList.add(EditEntity("tocUrl", this?.tocUrl, R.string.rule_chapter_list_url)) } //目录页 with(bookSource?.getTocRule()) { - editList.add(EditEntity("chapterList", this?.chapterList, R.string.rule_chapter_list)) - editList.add(EditEntity("chapterName", this?.chapterName, R.string.rule_chapter_name)) - editList.add(EditEntity("chapterUrl", this?.chapterUrl, R.string.rule_content_url)) - editList.add(EditEntity("tocUrlNext", this?.nextUrl, R.string.rule_chapter_list_url_next)) + tocEditList.clear() + tocEditList.add(EditEntity("chapterList", this?.chapterList, R.string.rule_chapter_list)) + tocEditList.add(EditEntity("chapterName", this?.chapterName, R.string.rule_chapter_name)) + tocEditList.add(EditEntity("chapterUrl", this?.chapterUrl, R.string.rule_content_url)) + tocEditList.add(EditEntity("nextTocUrl", this?.nextTocUrl, R.string.rule_next_toc_url)) } //正文页 with(bookSource?.getContentRule()) { - editList.add(EditEntity("content", this?.content, R.string.rule_book_content)) - editList.add(EditEntity("contentUrlNext", this?.nextUrl, R.string.rule_content_url_next)) - + contentEditList.clear() + contentEditList.add(EditEntity("content", this?.content, R.string.rule_book_content)) + contentEditList.add(EditEntity("nextContentUrl", this?.nextContentUrl, R.string.rule_content_url_next)) } //发现 with(bookSource?.getExploreRule()) { - findEditList.add(EditEntity("findUrl", this?.exploreUrl, R.string.rule_find_url)) - findEditList.add(EditEntity("findList", this?.bookList, R.string.rule_find_list)) - findEditList.add(EditEntity("findName", this?.name, R.string.rule_find_name)) - findEditList.add(EditEntity("findAuthor", this?.author, R.string.rule_find_author)) - findEditList.add(EditEntity("findKind", this?.meta, R.string.rule_find_kind)) - findEditList.add(EditEntity("findIntroduce", this?.desc, R.string.rule_find_introduce)) - findEditList.add(EditEntity("findLastChapter", this?.lastChapter, R.string.rule_find_last_chapter)) - findEditList.add(EditEntity("findCoverUrl", this?.coverUrl, R.string.rule_find_cover_url)) - findEditList.add(EditEntity("findNoteUrl", this?.bookUrl, R.string.rule_find_note_url)) + findEditList.clear() + findEditList.add(EditEntity("url", this?.url, 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)) + findEditList.add(EditEntity("kind", this?.kind, R.string.rule_book_kind)) + findEditList.add(EditEntity("wordCount", this?.wordCount, R.string.rule_word_count)) + findEditList.add(EditEntity("intro", this?.intro, R.string.rule_book_intro)) + findEditList.add(EditEntity("lastChapter", this?.lastChapter, R.string.rule_last_chapter)) + findEditList.add(EditEntity("coverUrl", this?.coverUrl, R.string.rule_cover_url)) + findEditList.add(EditEntity("bookUrl", this?.bookUrl, R.string.rule_book_url)) } - adapter.editEntities = editList + adapter.editEntities = sourceEditList adapter.notifyDataSetChanged() } @@ -132,23 +144,106 @@ class SourceEditActivity : BaseActivity() { val bookSource = BookSource() bookSource.enabled = cb_is_enable.isChecked bookSource.enabledExplore = cb_is_enable_find.isChecked - for (entity in adapter.editEntities) { - when (entity.key) { - "origin" -> { - if (entity.value == null) { - return null - } else { - bookSource.bookSourceUrl = entity.value!! - } + val searchRule = SearchRule() + val exploreRule = ExploreRule() + val bookInfoRule = BookInfoRule() + val tocRule = TocRule() + val contentRule = ContentRule() + for (entity in sourceEditList) { + with(entity) { + when (key) { + "bookSourceUrl" -> if (value != null) bookSource.bookSourceUrl = value!! else return null + "bookSourceName" -> if (value != null) bookSource.bookSourceName = value!! else return null + "bookSourceGroup" -> bookSource.bookSourceGroup = value + "loginUrl" -> bookSource.loginUrl = value + "header" -> bookSource.header = value + } + } + } + for (entity in searchEditList) { + with(entity) { + when (key) { + "url" -> searchRule.url = value + "searchList" -> searchRule.bookList = value + "searchName" -> searchRule.name = value + "searchAuthor" -> searchRule.author = value + "searchKind" -> searchRule.kind = value + "searchIntro" -> searchRule.intro = value + "updateTime" -> searchRule.updateTime = value + "wordCount" -> searchRule.wordCount = value + "lastChapter" -> searchRule.lastChapter = value + "coverUrl" -> searchRule.coverUrl = value + "bookUrl" -> searchRule.bookUrl = value + } + } + } + for (entity in findEditList) { + with(entity) { + when (key) { + "url" -> exploreRule.url = value + "searchList" -> exploreRule.bookList = value + "searchName" -> exploreRule.name = value + "searchAuthor" -> exploreRule.author = value + "searchKind" -> exploreRule.kind = value + "searchIntro" -> exploreRule.intro = value + "updateTime" -> exploreRule.updateTime = value + "wordCount" -> exploreRule.wordCount = value + "lastChapter" -> exploreRule.lastChapter = value + "coverUrl" -> exploreRule.coverUrl = value + "bookUrl" -> exploreRule.bookUrl = value + } + } + } + for (entity in infoEditList) { + with(entity) { + when (key) { + "urlPattern" -> bookInfoRule.urlPattern = value + "init" -> bookInfoRule.init = value + "searchName" -> bookInfoRule.name = value + "searchAuthor" -> bookInfoRule.author = value + "searchKind" -> bookInfoRule.kind = value + "searchIntro" -> bookInfoRule.intro = value + "updateTime" -> bookInfoRule.updateTime = value + "wordCount" -> bookInfoRule.wordCount = value + "lastChapter" -> bookInfoRule.lastChapter = value + "coverUrl" -> bookInfoRule.coverUrl = value + "tocUrl" -> bookInfoRule.tocUrl = value } - "name" -> { - if (entity.value == null) { - return null - } else { - bookSource.bookSourceName = entity.value!! - } + } + } + for (entity in infoEditList) { + with(entity) { + when (key) { + "urlPattern" -> bookInfoRule.urlPattern = value + "init" -> bookInfoRule.init = value + "searchName" -> bookInfoRule.name = value + "searchAuthor" -> bookInfoRule.author = value + "searchKind" -> bookInfoRule.kind = value + "searchIntro" -> bookInfoRule.intro = value + "updateTime" -> bookInfoRule.updateTime = value + "wordCount" -> bookInfoRule.wordCount = value + "lastChapter" -> bookInfoRule.lastChapter = value + "coverUrl" -> bookInfoRule.coverUrl = value + "tocUrl" -> bookInfoRule.tocUrl = value + } + } + } + for (entity in tocEditList) { + with(entity) { + when (key) { + "chapterList" -> tocRule.chapterList = value + "chapterName" -> tocRule.chapterName = value + "chapterUrl" -> tocRule.chapterUrl = value + "nextTocUrl" -> tocRule.nextTocUrl = value + } + } + } + for (entity in contentEditList) { + with(entity) { + when (key) { + "content" -> contentRule.content = value + "nextContentUrl" -> contentRule.nextContentUrl = value } - "group" -> bookSource.bookSourceGroup = entity.value } } return bookSource diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9af81ad1c..04397e50f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -352,33 +352,20 @@ 目录列表规则(ruleChapterList) 章节名称规则(ruleChapterName) 目录URL规则(ruleChapterUrl) - 目录下一页规则(ruleChapterUrlNext) + 目录下一页规则(ruleChapterUrlNext) 章节URL规则(ruleContentUrl) 封面规则(ruleCoverUrl) - 简介规则(ruleIntroduce) - 搜索作者规则(ruleSearchAuthor) - 发现作者规则(ruleFindAuthor) - 搜索封面规则(ruleSearchCoverUrl) - 发现封面规则(ruleFindCoverUrl) - 搜索分类规则(ruleSearchKind) - 发现分类规则(ruleFindKind) - 搜索最新章节规则(ruleSearchLastChapter) - 发现最新章节规则(ruleFindLastChapter) - 搜索列表规则(ruleSearchList) - 发现列表规则(ruleFindList) - 搜索书名规则(ruleSearchName) - 发现书名规则(ruleFindName) - 搜索书籍URL规则(ruleSearchNoteUrl) - 发现书籍URL规则(ruleFindNoteUrl) - 搜索简介规则(ruleSearchIntroduce) - 发现简介规则(ruleFindIntroduce) + 简介规则(ruleIntroduce) + 字数规则(ruleFindKind) + 书籍列表规则(ruleFindKind) + 书籍url规则 搜索地址(ruleSearchUrl) - 发现规则(ruleFindUrl) + 发现地址规则(ruleFindUrl) 正文下一页URL规则(ruleContentUrlNext) 书籍详情URL正则(ruleBookUrlPattern) 书籍详情预处理规则(ruleBookInfoInit) 分类规则(ruleBookKind) - 最新章节规则(ruleBookLastChapter) + 最新章节规则(ruleBookLastChapter) HttpUserAgent 调试书源 二维码导入