|
|
@ -12,7 +12,6 @@ import android.view.MenuItem |
|
|
|
import android.view.ViewTreeObserver |
|
|
|
import android.view.ViewTreeObserver |
|
|
|
import android.widget.EditText |
|
|
|
import android.widget.EditText |
|
|
|
import android.widget.PopupWindow |
|
|
|
import android.widget.PopupWindow |
|
|
|
import androidx.lifecycle.Observer |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
@ -21,10 +20,14 @@ import io.legado.app.constant.AppConst |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.data.entities.EditEntity |
|
|
|
import io.legado.app.data.entities.EditEntity |
|
|
|
import io.legado.app.data.entities.rule.* |
|
|
|
import io.legado.app.data.entities.rule.* |
|
|
|
|
|
|
|
import io.legado.app.lib.dialogs.alert |
|
|
|
|
|
|
|
import io.legado.app.lib.dialogs.noButton |
|
|
|
|
|
|
|
import io.legado.app.lib.dialogs.yesButton |
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity |
|
|
|
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity |
|
|
|
import io.legado.app.ui.widget.KeyboardToolPop |
|
|
|
import io.legado.app.ui.widget.KeyboardToolPop |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
|
|
|
|
import io.legado.app.utils.applyTint |
|
|
|
import io.legado.app.utils.getViewModel |
|
|
|
import io.legado.app.utils.getViewModel |
|
|
|
import kotlinx.android.synthetic.main.activity_book_source_edit.* |
|
|
|
import kotlinx.android.synthetic.main.activity_book_source_edit.* |
|
|
|
import org.jetbrains.anko.displayMetrics |
|
|
|
import org.jetbrains.anko.displayMetrics |
|
|
@ -51,10 +54,9 @@ class BookSourceEditActivity : |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
initView() |
|
|
|
initView() |
|
|
|
viewModel.sourceLiveData.observe(this, Observer { |
|
|
|
viewModel.initData(intent) { |
|
|
|
upRecyclerView(it) |
|
|
|
upRecyclerView() |
|
|
|
}) |
|
|
|
} |
|
|
|
viewModel.initData(intent) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { |
|
|
|
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { |
|
|
@ -65,14 +67,16 @@ class BookSourceEditActivity : |
|
|
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
when (item.itemId) { |
|
|
|
when (item.itemId) { |
|
|
|
R.id.menu_save -> { |
|
|
|
R.id.menu_save -> { |
|
|
|
getSource()?.let { |
|
|
|
val source = getSource() |
|
|
|
viewModel.save(it) { setResult(Activity.RESULT_OK); finish() } |
|
|
|
if (checkSource(source)) { |
|
|
|
|
|
|
|
viewModel.save(source) { setResult(Activity.RESULT_OK); finish() } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
R.id.menu_debug_source -> { |
|
|
|
R.id.menu_debug_source -> { |
|
|
|
getSource()?.let { |
|
|
|
val source = getSource() |
|
|
|
viewModel.save(it) { |
|
|
|
if (checkSource(source)) { |
|
|
|
startActivity<BookSourceDebugActivity>(Pair("key", it.bookSourceUrl)) |
|
|
|
viewModel.save(source) { |
|
|
|
|
|
|
|
startActivity<BookSourceDebugActivity>(Pair("key", source.bookSourceUrl)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -82,7 +86,7 @@ class BookSourceEditActivity : |
|
|
|
clipboard?.primaryClip = ClipData.newPlainText(null, sourceStr) |
|
|
|
clipboard?.primaryClip = ClipData.newPlainText(null, sourceStr) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
R.id.menu_paste_source -> viewModel.pasteSource() |
|
|
|
R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView() } |
|
|
|
} |
|
|
|
} |
|
|
|
return super.onCompatOptionsItemSelected(item) |
|
|
|
return super.onCompatOptionsItemSelected(item) |
|
|
|
} |
|
|
|
} |
|
|
@ -109,8 +113,22 @@ class BookSourceEditActivity : |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun finish() { |
|
|
|
override fun finish() { |
|
|
|
|
|
|
|
val source = getSource() |
|
|
|
|
|
|
|
if (!source.equal(viewModel.bookSource)) { |
|
|
|
|
|
|
|
alert(title = "是否保存") { |
|
|
|
|
|
|
|
yesButton { |
|
|
|
|
|
|
|
if (checkSource(source)) { |
|
|
|
|
|
|
|
viewModel.save(source) { |
|
|
|
super.finish() |
|
|
|
super.finish() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
noButton { } |
|
|
|
|
|
|
|
}.show().applyTint() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
super.finish() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
|
override fun onDestroy() { |
|
|
|
super.onDestroy() |
|
|
|
super.onDestroy() |
|
|
@ -129,33 +147,34 @@ class BookSourceEditActivity : |
|
|
|
recycler_view.scrollToPosition(0) |
|
|
|
recycler_view.scrollToPosition(0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun upRecyclerView(bookSource: BookSource?) { |
|
|
|
private fun upRecyclerView() { |
|
|
|
bookSource?.let { |
|
|
|
val source = viewModel.bookSource |
|
|
|
|
|
|
|
source?.let { |
|
|
|
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 |
|
|
|
sp_type.setSelection(bookSource.bookSourceType) |
|
|
|
sp_type.setSelection(it.bookSourceType) |
|
|
|
} |
|
|
|
} |
|
|
|
//基本信息 |
|
|
|
//基本信息 |
|
|
|
sourceEntities.clear() |
|
|
|
sourceEntities.clear() |
|
|
|
sourceEntities.apply { |
|
|
|
sourceEntities.apply { |
|
|
|
add(EditEntity("bookSourceUrl", bookSource?.bookSourceUrl, R.string.book_source_url)) |
|
|
|
add(EditEntity("bookSourceUrl", source?.bookSourceUrl, R.string.book_source_url)) |
|
|
|
add(EditEntity("bookSourceName", bookSource?.bookSourceName, R.string.book_source_name)) |
|
|
|
add(EditEntity("bookSourceName", source?.bookSourceName, R.string.book_source_name)) |
|
|
|
add( |
|
|
|
add( |
|
|
|
EditEntity( |
|
|
|
EditEntity( |
|
|
|
"bookSourceGroup", |
|
|
|
"bookSourceGroup", |
|
|
|
bookSource?.bookSourceGroup, |
|
|
|
source?.bookSourceGroup, |
|
|
|
R.string.book_source_group |
|
|
|
R.string.book_source_group |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
add(EditEntity("loginUrl", bookSource?.loginUrl, R.string.book_source_login_url)) |
|
|
|
add(EditEntity("loginUrl", source?.loginUrl, R.string.book_source_login_url)) |
|
|
|
add(EditEntity("bookUrlPattern", bookSource?.bookUrlPattern, R.string.book_url_pattern)) |
|
|
|
add(EditEntity("bookUrlPattern", source?.bookUrlPattern, R.string.book_url_pattern)) |
|
|
|
add(EditEntity("header", bookSource?.header, R.string.source_http_header)) |
|
|
|
add(EditEntity("header", source?.header, R.string.source_http_header)) |
|
|
|
} |
|
|
|
} |
|
|
|
//搜索 |
|
|
|
//搜索 |
|
|
|
(bookSource?.getSearchRule()).let { searchRule -> |
|
|
|
(source?.getSearchRule()).let { searchRule -> |
|
|
|
searchEntities.clear() |
|
|
|
searchEntities.clear() |
|
|
|
searchEntities.apply { |
|
|
|
searchEntities.apply { |
|
|
|
add(EditEntity("searchUrl", bookSource?.searchUrl, R.string.rule_search_url)) |
|
|
|
add(EditEntity("searchUrl", source?.searchUrl, R.string.rule_search_url)) |
|
|
|
add(EditEntity("bookList", searchRule?.bookList, R.string.rule_book_list)) |
|
|
|
add(EditEntity("bookList", searchRule?.bookList, R.string.rule_book_list)) |
|
|
|
add(EditEntity("name", searchRule?.name, R.string.rule_book_name)) |
|
|
|
add(EditEntity("name", searchRule?.name, R.string.rule_book_name)) |
|
|
|
add(EditEntity("author", searchRule?.author, R.string.rule_book_author)) |
|
|
|
add(EditEntity("author", searchRule?.author, R.string.rule_book_author)) |
|
|
@ -168,7 +187,7 @@ class BookSourceEditActivity : |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//详情页 |
|
|
|
//详情页 |
|
|
|
(bookSource?.getBookInfoRule()).let { infoRule -> |
|
|
|
(source?.getBookInfoRule()).let { infoRule -> |
|
|
|
infoEntities.clear() |
|
|
|
infoEntities.clear() |
|
|
|
infoEntities.apply { |
|
|
|
infoEntities.apply { |
|
|
|
add(EditEntity("init", infoRule?.init, R.string.rule_book_info_init)) |
|
|
|
add(EditEntity("init", infoRule?.init, R.string.rule_book_info_init)) |
|
|
@ -183,7 +202,7 @@ class BookSourceEditActivity : |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//目录页 |
|
|
|
//目录页 |
|
|
|
(bookSource?.getTocRule()).let { tocRule -> |
|
|
|
(source?.getTocRule()).let { tocRule -> |
|
|
|
tocEntities.clear() |
|
|
|
tocEntities.clear() |
|
|
|
tocEntities.apply { |
|
|
|
tocEntities.apply { |
|
|
|
add(EditEntity("chapterList", tocRule?.chapterList, R.string.rule_chapter_list)) |
|
|
|
add(EditEntity("chapterList", tocRule?.chapterList, R.string.rule_chapter_list)) |
|
|
@ -193,7 +212,7 @@ class BookSourceEditActivity : |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//正文页 |
|
|
|
//正文页 |
|
|
|
(bookSource?.getContentRule()).let { contentRule -> |
|
|
|
(source?.getContentRule()).let { contentRule -> |
|
|
|
contentEntities.clear() |
|
|
|
contentEntities.clear() |
|
|
|
contentEntities.apply { |
|
|
|
contentEntities.apply { |
|
|
|
add(EditEntity("content", contentRule?.content, R.string.rule_book_content)) |
|
|
|
add(EditEntity("content", contentRule?.content, R.string.rule_book_content)) |
|
|
@ -208,10 +227,10 @@ class BookSourceEditActivity : |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//发现 |
|
|
|
//发现 |
|
|
|
(bookSource?.getExploreRule()).let { exploreRule -> |
|
|
|
(source?.getExploreRule()).let { exploreRule -> |
|
|
|
findEntities.clear() |
|
|
|
findEntities.clear() |
|
|
|
findEntities.apply { |
|
|
|
findEntities.apply { |
|
|
|
add(EditEntity("exploreUrl", bookSource?.exploreUrl, R.string.rule_find_url)) |
|
|
|
add(EditEntity("exploreUrl", source?.exploreUrl, R.string.rule_find_url)) |
|
|
|
add(EditEntity("bookList", exploreRule?.bookList, R.string.rule_book_list)) |
|
|
|
add(EditEntity("bookList", exploreRule?.bookList, R.string.rule_book_list)) |
|
|
|
add(EditEntity("name", exploreRule?.name, R.string.rule_book_name)) |
|
|
|
add(EditEntity("name", exploreRule?.name, R.string.rule_book_name)) |
|
|
|
add(EditEntity("author", exploreRule?.author, R.string.rule_book_author)) |
|
|
|
add(EditEntity("author", exploreRule?.author, R.string.rule_book_author)) |
|
|
@ -226,15 +245,11 @@ class BookSourceEditActivity : |
|
|
|
setEditEntities(0) |
|
|
|
setEditEntities(0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getSource(): BookSource? { |
|
|
|
private fun getSource(): BookSource { |
|
|
|
val source = viewModel.sourceLiveData.value ?: BookSource() |
|
|
|
val source = viewModel.bookSource?.copy() ?: BookSource() |
|
|
|
source.enabled = cb_is_enable.isChecked |
|
|
|
source.enabled = cb_is_enable.isChecked |
|
|
|
source.enabledExplore = cb_is_enable_find.isChecked |
|
|
|
source.enabledExplore = cb_is_enable_find.isChecked |
|
|
|
source.bookSourceType = sp_type.selectedItemPosition |
|
|
|
source.bookSourceType = sp_type.selectedItemPosition |
|
|
|
viewModel.sourceLiveData.value?.let { |
|
|
|
|
|
|
|
source.customOrder = it.customOrder |
|
|
|
|
|
|
|
source.weight = it.weight |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
val searchRule = SearchRule() |
|
|
|
val searchRule = SearchRule() |
|
|
|
val exploreRule = ExploreRule() |
|
|
|
val exploreRule = ExploreRule() |
|
|
|
val bookInfoRule = BookInfoRule() |
|
|
|
val bookInfoRule = BookInfoRule() |
|
|
@ -250,10 +265,6 @@ class BookSourceEditActivity : |
|
|
|
"header" -> source.header = it.value |
|
|
|
"header" -> source.header = it.value |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (source.bookSourceUrl.isBlank() || source.bookSourceName.isBlank()) { |
|
|
|
|
|
|
|
toast("书源名称和URL不能为空") |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
searchEntities.forEach { |
|
|
|
searchEntities.forEach { |
|
|
|
when (it.key) { |
|
|
|
when (it.key) { |
|
|
|
"searchUrl" -> source.searchUrl = it.value |
|
|
|
"searchUrl" -> source.searchUrl = it.value |
|
|
@ -320,6 +331,14 @@ class BookSourceEditActivity : |
|
|
|
return source |
|
|
|
return source |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun checkSource(source: BookSource): Boolean { |
|
|
|
|
|
|
|
if (source.bookSourceUrl.isBlank() || source.bookSourceName.isBlank()) { |
|
|
|
|
|
|
|
toast("书源名称和URL不能为空") |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun sendText(text: String) { |
|
|
|
override fun sendText(text: String) { |
|
|
|
if (text.isBlank()) return |
|
|
|
if (text.isBlank()) return |
|
|
|
val view = window.decorView.findFocus() |
|
|
|
val view = window.decorView.findFocus() |
|
|
|