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 e89d7042e..b44d3193b 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 @@ -19,7 +19,8 @@ class SourceEditActivity : BaseActivity() { get() = R.layout.activity_source_edit private val adapter = SourceEditAdapter() - private val sourceEditEntities: ArrayList = ArrayList() + private val editList: ArrayList = ArrayList() + private val findEditList: ArrayList = ArrayList() override fun onViewModelCreated(viewModel: SourceEditViewModel, savedInstanceState: Bundle?) { initRecyclerView() @@ -67,12 +68,63 @@ class SourceEditActivity : BaseActivity() { cb_is_enable.isChecked = it.enabled cb_is_enable_find.isChecked = it.enabledExplore } - sourceEditEntities.clear() - sourceEditEntities.add(SourceEditEntity("origin", bookSource?.bookSourceUrl, R.string.book_source_url)) - sourceEditEntities.add(SourceEditEntity("name", bookSource?.bookSourceName, R.string.book_source_name)) - sourceEditEntities.add(SourceEditEntity("group", bookSource?.bookSourceGroup, R.string.book_source_group)) + 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)) + //搜索 + 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)) + } + //详情页 + 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)) + } + //目录页 + 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)) + } + //正文页 + 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)) - adapter.sourceEditEntities = sourceEditEntities + } + + //发现 + 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)) + } + adapter.editEntities = editList adapter.notifyDataSetChanged() } @@ -80,7 +132,7 @@ class SourceEditActivity : BaseActivity() { val bookSource = BookSource() bookSource.enabled = cb_is_enable.isChecked bookSource.enabledExplore = cb_is_enable_find.isChecked - for (entity in adapter.sourceEditEntities) { + for (entity in adapter.editEntities) { when (entity.key) { "origin" -> { if (entity.value == null) { @@ -102,5 +154,5 @@ class SourceEditActivity : BaseActivity() { return bookSource } - class SourceEditEntity(var key: String, var value: String?, var hint: Int) + class EditEntity(var key: String, var value: String?, var hint: Int) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditAdapter.kt b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditAdapter.kt index 8b54223fe..e6ecc8891 100644 --- a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditAdapter.kt @@ -11,22 +11,22 @@ import kotlinx.android.synthetic.main.item_source_edit.view.* class SourceEditAdapter : RecyclerView.Adapter() { - var sourceEditEntities: ArrayList = ArrayList() + var editEntities: ArrayList = ArrayList() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_source_edit, parent, false)) } override fun onBindViewHolder(holder: MyViewHolder, position: Int) { - holder.bind(sourceEditEntities[position]) + holder.bind(editEntities[position]) } override fun getItemCount(): Int { - return sourceEditEntities.size + return editEntities.size } class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { - fun bind(sourceEditEntity: SourceEditActivity.SourceEditEntity) = with(itemView) { + fun bind(editEntity: SourceEditActivity.EditEntity) = with(itemView) { if (editText.getTag(R.id.tag1) == null) { val listener = object : View.OnAttachStateChangeListener { override fun onViewAttachedToWindow(v: View) { @@ -48,8 +48,8 @@ class SourceEditAdapter : RecyclerView.Adapter() editText.removeTextChangedListener(it) } } - editText.setText(sourceEditEntity.value) - textInputLayout.hint = context.getString(sourceEditEntity.hint) + editText.setText(editEntity.value) + textInputLayout.hint = context.getString(editEntity.hint) val textWatcher = object : TextWatcher { override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { @@ -60,7 +60,7 @@ class SourceEditAdapter : RecyclerView.Adapter() } override fun afterTextChanged(s: Editable?) { - sourceEditEntity.value = (s?.toString()) + editEntity.value = (s?.toString()) } } editText.addTextChangedListener(textWatcher)