|
|
@ -8,6 +8,7 @@ import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.BaseActivity |
|
|
|
import io.legado.app.base.BaseActivity |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
|
|
|
|
import io.legado.app.data.entities.rule.* |
|
|
|
import io.legado.app.utils.getViewModel |
|
|
|
import io.legado.app.utils.getViewModel |
|
|
|
import kotlinx.android.synthetic.main.activity_source_edit.* |
|
|
|
import kotlinx.android.synthetic.main.activity_source_edit.* |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import org.jetbrains.anko.toast |
|
|
@ -19,8 +20,12 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>() { |
|
|
|
get() = R.layout.activity_source_edit |
|
|
|
get() = R.layout.activity_source_edit |
|
|
|
|
|
|
|
|
|
|
|
private val adapter = SourceEditAdapter() |
|
|
|
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 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?) { |
|
|
|
override fun onViewModelCreated(viewModel: SourceEditViewModel, savedInstanceState: Bundle?) { |
|
|
|
initRecyclerView() |
|
|
|
initRecyclerView() |
|
|
@ -68,63 +73,70 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>() { |
|
|
|
cb_is_enable.isChecked = it.enabled |
|
|
|
cb_is_enable.isChecked = it.enabled |
|
|
|
cb_is_enable_find.isChecked = it.enabledExplore |
|
|
|
cb_is_enable_find.isChecked = it.enabledExplore |
|
|
|
} |
|
|
|
} |
|
|
|
editList.clear() |
|
|
|
sourceEditList.clear() |
|
|
|
editList.add(EditEntity("origin", bookSource?.bookSourceUrl, R.string.book_source_url)) |
|
|
|
sourceEditList.add(EditEntity("bookSourceUrl", bookSource?.bookSourceUrl, R.string.book_source_url)) |
|
|
|
editList.add(EditEntity("name", bookSource?.bookSourceName, R.string.book_source_name)) |
|
|
|
sourceEditList.add(EditEntity("bookSourceName", bookSource?.bookSourceName, R.string.book_source_name)) |
|
|
|
editList.add(EditEntity("group", bookSource?.bookSourceGroup, R.string.book_source_group)) |
|
|
|
sourceEditList.add(EditEntity("bookSourceGroup", bookSource?.bookSourceGroup, R.string.book_source_group)) |
|
|
|
editList.add(EditEntity("loginUrl", bookSource?.loginUrl, R.string.book_source_login_url)) |
|
|
|
sourceEditList.add(EditEntity("loginUrl", bookSource?.loginUrl, R.string.book_source_login_url)) |
|
|
|
editList.add(EditEntity("header", bookSource?.header, R.string.source_user_agent)) |
|
|
|
sourceEditList.add(EditEntity("header", bookSource?.header, R.string.source_user_agent)) |
|
|
|
//搜索 |
|
|
|
//搜索 |
|
|
|
with(bookSource?.getSearchRule()) { |
|
|
|
with(bookSource?.getSearchRule()) { |
|
|
|
editList.add(EditEntity("searchUrl", this?.searchUrl, R.string.rule_search_url)) |
|
|
|
searchEditList.clear() |
|
|
|
editList.add(EditEntity("searchList", this?.bookList, R.string.rule_search_list)) |
|
|
|
searchEditList.add(EditEntity("url", this?.url, R.string.rule_search_url)) |
|
|
|
editList.add(EditEntity("searchName", this?.name, R.string.rule_search_name)) |
|
|
|
searchEditList.add(EditEntity("bookList", this?.bookList, R.string.rule_book_list)) |
|
|
|
editList.add(EditEntity("searchAuthor", this?.author, R.string.rule_search_author)) |
|
|
|
searchEditList.add(EditEntity("name", this?.name, R.string.rule_book_name)) |
|
|
|
editList.add(EditEntity("searchKind", this?.meta, R.string.rule_search_kind)) |
|
|
|
searchEditList.add(EditEntity("author", this?.author, R.string.rule_book_author)) |
|
|
|
editList.add(EditEntity("searchLastChapter", this?.lastChapter, R.string.rule_search_last_chapter)) |
|
|
|
searchEditList.add(EditEntity("kind", this?.kind, R.string.rule_book_kind)) |
|
|
|
editList.add(EditEntity("searchIntroduce", this?.desc, R.string.rule_search_introduce)) |
|
|
|
searchEditList.add(EditEntity("wordCount", this?.wordCount, R.string.rule_word_count)) |
|
|
|
editList.add(EditEntity("searchCoverUrl", this?.coverUrl, R.string.rule_search_cover_url)) |
|
|
|
searchEditList.add(EditEntity("lastChapter", this?.lastChapter, R.string.rule_last_chapter)) |
|
|
|
editList.add(EditEntity("searchNoteUrl", this?.bookUrl, R.string.rule_search_note_url)) |
|
|
|
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()) { |
|
|
|
with(bookSource?.getBookInfoRule()) { |
|
|
|
editList.add(EditEntity("bookUrlPattern", this?.urlPattern, R.string.book_url_pattern)) |
|
|
|
infoEditList.clear() |
|
|
|
editList.add(EditEntity("bookInfoInit", this?.init, R.string.rule_book_info_init)) |
|
|
|
infoEditList.add(EditEntity("urlPattern", this?.urlPattern, R.string.book_url_pattern)) |
|
|
|
editList.add(EditEntity("bookName", this?.name, R.string.rule_book_name)) |
|
|
|
infoEditList.add(EditEntity("init", this?.init, R.string.rule_book_info_init)) |
|
|
|
editList.add(EditEntity("bookAuthor", this?.author, R.string.rule_book_author)) |
|
|
|
infoEditList.add(EditEntity("name", this?.name, R.string.rule_book_name)) |
|
|
|
editList.add(EditEntity("ruleCoverUrl", this?.coverUrl, R.string.rule_cover_url)) |
|
|
|
infoEditList.add(EditEntity("author", this?.author, R.string.rule_book_author)) |
|
|
|
editList.add(EditEntity("ruleIntroduce", this?.desc, R.string.rule_introduce)) |
|
|
|
infoEditList.add(EditEntity("coverUrl", this?.coverUrl, R.string.rule_cover_url)) |
|
|
|
editList.add(EditEntity("bookKind", this?.meta, R.string.rule_book_kind)) |
|
|
|
infoEditList.add(EditEntity("intro", this?.intro, R.string.rule_book_intro)) |
|
|
|
editList.add(EditEntity("bookLastChapter", this?.lastChapter, R.string.rule_book_last_chapter)) |
|
|
|
infoEditList.add(EditEntity("kind", this?.kind, R.string.rule_book_kind)) |
|
|
|
editList.add(EditEntity("tocUrl", this?.tocUrl, R.string.rule_chapter_list_url)) |
|
|
|
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()) { |
|
|
|
with(bookSource?.getTocRule()) { |
|
|
|
editList.add(EditEntity("chapterList", this?.chapterList, R.string.rule_chapter_list)) |
|
|
|
tocEditList.clear() |
|
|
|
editList.add(EditEntity("chapterName", this?.chapterName, R.string.rule_chapter_name)) |
|
|
|
tocEditList.add(EditEntity("chapterList", this?.chapterList, R.string.rule_chapter_list)) |
|
|
|
editList.add(EditEntity("chapterUrl", this?.chapterUrl, R.string.rule_content_url)) |
|
|
|
tocEditList.add(EditEntity("chapterName", this?.chapterName, R.string.rule_chapter_name)) |
|
|
|
editList.add(EditEntity("tocUrlNext", this?.nextUrl, R.string.rule_chapter_list_url_next)) |
|
|
|
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()) { |
|
|
|
with(bookSource?.getContentRule()) { |
|
|
|
editList.add(EditEntity("content", this?.content, R.string.rule_book_content)) |
|
|
|
contentEditList.clear() |
|
|
|
editList.add(EditEntity("contentUrlNext", this?.nextUrl, R.string.rule_content_url_next)) |
|
|
|
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()) { |
|
|
|
with(bookSource?.getExploreRule()) { |
|
|
|
findEditList.add(EditEntity("findUrl", this?.exploreUrl, R.string.rule_find_url)) |
|
|
|
findEditList.clear() |
|
|
|
findEditList.add(EditEntity("findList", this?.bookList, R.string.rule_find_list)) |
|
|
|
findEditList.add(EditEntity("url", this?.url, R.string.rule_find_url)) |
|
|
|
findEditList.add(EditEntity("findName", this?.name, R.string.rule_find_name)) |
|
|
|
findEditList.add(EditEntity("bookList", this?.bookList, R.string.rule_book_list)) |
|
|
|
findEditList.add(EditEntity("findAuthor", this?.author, R.string.rule_find_author)) |
|
|
|
findEditList.add(EditEntity("name", this?.name, R.string.rule_book_name)) |
|
|
|
findEditList.add(EditEntity("findKind", this?.meta, R.string.rule_find_kind)) |
|
|
|
findEditList.add(EditEntity("author", this?.author, R.string.rule_book_author)) |
|
|
|
findEditList.add(EditEntity("findIntroduce", this?.desc, R.string.rule_find_introduce)) |
|
|
|
findEditList.add(EditEntity("kind", this?.kind, R.string.rule_book_kind)) |
|
|
|
findEditList.add(EditEntity("findLastChapter", this?.lastChapter, R.string.rule_find_last_chapter)) |
|
|
|
findEditList.add(EditEntity("wordCount", this?.wordCount, R.string.rule_word_count)) |
|
|
|
findEditList.add(EditEntity("findCoverUrl", this?.coverUrl, R.string.rule_find_cover_url)) |
|
|
|
findEditList.add(EditEntity("intro", this?.intro, R.string.rule_book_intro)) |
|
|
|
findEditList.add(EditEntity("findNoteUrl", this?.bookUrl, R.string.rule_find_note_url)) |
|
|
|
findEditList.add(EditEntity("lastChapter", this?.lastChapter, R.string.rule_last_chapter)) |
|
|
|
} |
|
|
|
findEditList.add(EditEntity("coverUrl", this?.coverUrl, R.string.rule_cover_url)) |
|
|
|
adapter.editEntities = editList |
|
|
|
findEditList.add(EditEntity("bookUrl", this?.bookUrl, R.string.rule_book_url)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
adapter.editEntities = sourceEditList |
|
|
|
adapter.notifyDataSetChanged() |
|
|
|
adapter.notifyDataSetChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -132,23 +144,106 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>() { |
|
|
|
val bookSource = BookSource() |
|
|
|
val bookSource = BookSource() |
|
|
|
bookSource.enabled = cb_is_enable.isChecked |
|
|
|
bookSource.enabled = cb_is_enable.isChecked |
|
|
|
bookSource.enabledExplore = cb_is_enable_find.isChecked |
|
|
|
bookSource.enabledExplore = cb_is_enable_find.isChecked |
|
|
|
for (entity in adapter.editEntities) { |
|
|
|
val searchRule = SearchRule() |
|
|
|
when (entity.key) { |
|
|
|
val exploreRule = ExploreRule() |
|
|
|
"origin" -> { |
|
|
|
val bookInfoRule = BookInfoRule() |
|
|
|
if (entity.value == null) { |
|
|
|
val tocRule = TocRule() |
|
|
|
return null |
|
|
|
val contentRule = ContentRule() |
|
|
|
} else { |
|
|
|
for (entity in sourceEditList) { |
|
|
|
bookSource.bookSourceUrl = entity.value!! |
|
|
|
with(entity) { |
|
|
|
} |
|
|
|
when (key) { |
|
|
|
} |
|
|
|
"bookSourceUrl" -> if (value != null) bookSource.bookSourceUrl = value!! else return null |
|
|
|
"name" -> { |
|
|
|
"bookSourceName" -> if (value != null) bookSource.bookSourceName = value!! else return null |
|
|
|
if (entity.value == null) { |
|
|
|
"bookSourceGroup" -> bookSource.bookSourceGroup = value |
|
|
|
return null |
|
|
|
"loginUrl" -> bookSource.loginUrl = value |
|
|
|
} else { |
|
|
|
"header" -> bookSource.header = value |
|
|
|
bookSource.bookSourceName = entity.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 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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 |
|
|
|
return bookSource |
|
|
|