pull/32/head
kunfei 5 years ago
parent c0f6a4c972
commit 7d684b6668
  1. 7
      app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt
  2. 2
      app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt
  3. 9
      app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt
  4. 9
      app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt
  5. 2
      app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt
  6. 20
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  7. 209
      app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt
  8. 27
      app/src/main/res/values/strings.xml

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

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

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

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

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

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

@ -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<SourceEditViewModel>() {
get() = R.layout.activity_source_edit
private val adapter = SourceEditAdapter()
private val editList: ArrayList<EditEntity> = ArrayList()
private val sourceEditList: ArrayList<EditEntity> = ArrayList()
private val searchEditList: ArrayList<EditEntity> = ArrayList()
private val findEditList: ArrayList<EditEntity> = ArrayList()
private val infoEditList: ArrayList<EditEntity> = ArrayList()
private val tocEditList: ArrayList<EditEntity> = ArrayList()
private val contentEditList: ArrayList<EditEntity> = ArrayList()
override fun onViewModelCreated(viewModel: SourceEditViewModel, savedInstanceState: Bundle?) {
initRecyclerView()
@ -68,63 +73,70 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>() {
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<SourceEditViewModel>() {
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

@ -352,33 +352,20 @@
<string name="rule_chapter_list">目录列表规则(ruleChapterList)</string>
<string name="rule_chapter_name">章节名称规则(ruleChapterName)</string>
<string name="rule_chapter_list_url">目录URL规则(ruleChapterUrl)</string>
<string name="rule_chapter_list_url_next">目录下一页规则(ruleChapterUrlNext)</string>
<string name="rule_next_toc_url">目录下一页规则(ruleChapterUrlNext)</string>
<string name="rule_content_url">章节URL规则(ruleContentUrl)</string>
<string name="rule_cover_url">封面规则(ruleCoverUrl)</string>
<string name="rule_introduce">简介规则(ruleIntroduce)</string>
<string name="rule_search_author">搜索作者规则(ruleSearchAuthor)</string>
<string name="rule_find_author">发现作者规则(ruleFindAuthor)</string>
<string name="rule_search_cover_url">搜索封面规则(ruleSearchCoverUrl)</string>
<string name="rule_find_cover_url">发现封面规则(ruleFindCoverUrl)</string>
<string name="rule_search_kind">搜索分类规则(ruleSearchKind)</string>
<string name="rule_find_kind">发现分类规则(ruleFindKind)</string>
<string name="rule_search_last_chapter">搜索最新章节规则(ruleSearchLastChapter)</string>
<string name="rule_find_last_chapter">发现最新章节规则(ruleFindLastChapter)</string>
<string name="rule_search_list">搜索列表规则(ruleSearchList)</string>
<string name="rule_find_list">发现列表规则(ruleFindList)</string>
<string name="rule_search_name">搜索书名规则(ruleSearchName)</string>
<string name="rule_find_name">发现书名规则(ruleFindName)</string>
<string name="rule_search_note_url">搜索书籍URL规则(ruleSearchNoteUrl)</string>
<string name="rule_find_note_url">发现书籍URL规则(ruleFindNoteUrl)</string>
<string name="rule_search_introduce">搜索简介规则(ruleSearchIntroduce)</string>
<string name="rule_find_introduce">发现简介规则(ruleFindIntroduce)</string>
<string name="rule_book_intro">简介规则(ruleIntroduce)</string>
<string name="rule_word_count">字数规则(ruleFindKind)</string>
<string name="rule_book_list">书籍列表规则(ruleFindKind)</string>
<string name="rule_book_url">书籍url规则</string>
<string name="rule_search_url">搜索地址(ruleSearchUrl)</string>
<string name="rule_find_url">发现规则(ruleFindUrl)</string>
<string name="rule_find_url">发现地址规则(ruleFindUrl)</string>
<string name="rule_content_url_next">正文下一页URL规则(ruleContentUrlNext)</string>
<string name="book_url_pattern">书籍详情URL正则(ruleBookUrlPattern)</string>
<string name="rule_book_info_init">书籍详情预处理规则(ruleBookInfoInit)</string>
<string name="rule_book_kind">分类规则(ruleBookKind)</string>
<string name="rule_book_last_chapter">最新章节规则(ruleBookLastChapter)</string>
<string name="rule_last_chapter">最新章节规则(ruleBookLastChapter)</string>
<string name="source_user_agent">HttpUserAgent</string>
<string name="debug_source">调试书源</string>
<string name="import_by_qr_code">二维码导入</string>

Loading…
Cancel
Save