diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index cc8bfe8df..ceb6f77c1 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -329,11 +329,14 @@ class BookSourceEditActivity : "searchUrl" -> source.searchUrl = it.value "checkKeyWord" -> searchRule.checkKeyWord = it.value "bookList" -> searchRule.bookList = it.value ?: "" - "name" -> searchRule.name = viewModel.ruleComplete(it.value, searchRule.bookList) + "name" -> searchRule.name = + viewModel.ruleComplete(it.value, searchRule.bookList) "author" -> searchRule.author = viewModel.ruleComplete(it.value, searchRule.bookList) - "kind" -> searchRule.kind = viewModel.ruleComplete(it.value, searchRule.bookList) - "intro" -> searchRule.intro = viewModel.ruleComplete(it.value, searchRule.bookList) + "kind" -> searchRule.kind = + viewModel.ruleComplete(it.value, searchRule.bookList) + "intro" -> searchRule.intro = + viewModel.ruleComplete(it.value, searchRule.bookList) "updateTime" -> searchRule.updateTime = viewModel.ruleComplete(it.value, searchRule.bookList) "wordCount" -> searchRule.wordCount = @@ -350,10 +353,12 @@ class BookSourceEditActivity : when (it.key) { "exploreUrl" -> source.exploreUrl = it.value "bookList" -> exploreRule.bookList = it.value ?: "" - "name" -> exploreRule.name = viewModel.ruleComplete(it.value, exploreRule.bookList) + "name" -> exploreRule.name = + viewModel.ruleComplete(it.value, exploreRule.bookList) "author" -> exploreRule.author = viewModel.ruleComplete(it.value, exploreRule.bookList) - "kind" -> exploreRule.kind = viewModel.ruleComplete(it.value, exploreRule.bookList) + "kind" -> exploreRule.kind = + viewModel.ruleComplete(it.value, exploreRule.bookList) "intro" -> exploreRule.intro = viewModel.ruleComplete(it.value, exploreRule.bookList) "updateTime" -> exploreRule.updateTime = @@ -374,8 +379,10 @@ class BookSourceEditActivity : "name" -> bookInfoRule.name = viewModel.ruleComplete(it.value, bookInfoRule.init) "author" -> bookInfoRule.author = viewModel.ruleComplete(it.value, bookInfoRule.init) - "kind" -> bookInfoRule.kind = viewModel.ruleComplete(it.value, bookInfoRule.init) - "intro" -> bookInfoRule.intro = viewModel.ruleComplete(it.value, bookInfoRule.init) + "kind" -> bookInfoRule.kind = + viewModel.ruleComplete(it.value, bookInfoRule.init) + "intro" -> bookInfoRule.intro = + viewModel.ruleComplete(it.value, bookInfoRule.init) "updateTime" -> bookInfoRule.updateTime = viewModel.ruleComplete(it.value, bookInfoRule.init) "wordCount" -> bookInfoRule.wordCount = @@ -406,7 +413,8 @@ class BookSourceEditActivity : } contentEntities.forEach { when (it.key) { - "content" -> contentRule.content = viewModel.ruleComplete(it.value) + "content" -> contentRule.content = + viewModel.ruleComplete(it.value) "nextContentUrl" -> contentRule.nextContentUrl = viewModel.ruleComplete(it.value, type = 2) "webJs" -> contentRule.webJs = it.value diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index f6229d0c1..58e6ad542 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -84,12 +84,12 @@ class RssSourceEditActivity : override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.source_edit, menu) - menu.findItem(R.id.menu_login).isVisible = false return super.onCompatCreateOptionsMenu(menu) } override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { menu.findItem(R.id.menu_login)?.isVisible = !viewModel.rssSource.loginUrl.isNullOrBlank() + menu.findItem(R.id.menu_auto_complete)?.isChecked = viewModel.autoComplete return super.onMenuOpened(featureId, menu) } @@ -124,6 +124,7 @@ class RssSourceEditActivity : } } } + R.id.menu_auto_complete -> viewModel.autoComplete = !viewModel.autoComplete R.id.menu_copy_source -> sendToClip(GSON.toJson(getRssSource())) R.id.menu_qr_code_camera -> qrCodeResult.launch() R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } @@ -202,13 +203,20 @@ class RssSourceEditActivity : "concurrentRate" -> source.concurrentRate = it.value "sortUrl" -> source.sortUrl = it.value "ruleArticles" -> source.ruleArticles = it.value - "ruleNextPage" -> source.ruleNextPage = it.value - "ruleTitle" -> source.ruleTitle = it.value - "rulePubDate" -> source.rulePubDate = it.value - "ruleDescription" -> source.ruleDescription = it.value - "ruleImage" -> source.ruleImage = it.value - "ruleLink" -> source.ruleLink = it.value - "ruleContent" -> source.ruleContent = it.value + "ruleNextPage" -> source.ruleNextPage = + viewModel.ruleComplete(it.value, source.ruleArticles, 2) + "ruleTitle" -> source.ruleTitle = + viewModel.ruleComplete(it.value, source.ruleArticles) + "rulePubDate" -> source.rulePubDate = + viewModel.ruleComplete(it.value, source.ruleArticles) + "ruleDescription" -> source.ruleDescription = + viewModel.ruleComplete(it.value, source.ruleArticles) + "ruleImage" -> source.ruleImage = + viewModel.ruleComplete(it.value, source.ruleArticles, 3) + "ruleLink" -> source.ruleLink = + viewModel.ruleComplete(it.value, source.ruleArticles) + "ruleContent" -> source.ruleContent = + viewModel.ruleComplete(it.value, source.ruleArticles) "style" -> source.style = it.value } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 62d2e3fcc..b37bcfc2d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -5,6 +5,7 @@ import android.content.Intent import io.legado.app.base.BaseViewModel import io.legado.app.data.appDb import io.legado.app.data.entities.RssSource +import io.legado.app.help.RuleComplete import io.legado.app.utils.getClipText import io.legado.app.utils.msg import io.legado.app.utils.printOnDebug @@ -14,7 +15,7 @@ import kotlinx.coroutines.Dispatchers class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { - + var autoComplete = false var rssSource: RssSource = RssSource() private var oldSourceUrl: String = "" @@ -76,4 +77,8 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati } } + fun ruleComplete(rule: String?, preRule: String? = null, type: Int = 1): String? { + return RuleComplete.autoComplete(rule, preRule, type, autoComplete) + } + } \ No newline at end of file