From 3768fc5614a86884a5371665886d35bf6595c920 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 19 Dec 2020 12:18:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/rss/RssFragment.kt | 7 +++- .../legado/app/ui/rss/read/ReadRssActivity.kt | 26 ++++--------- .../app/ui/rss/read/ReadRssViewModel.kt | 39 ++++++++++++------- .../rss/source/edit/RssSourceEditActivity.kt | 4 +- .../res/layout/activity_rss_source_edit.xml | 25 +++++++++--- app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 63 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 9d926c1b4..353fee6df 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -13,6 +13,7 @@ import io.legado.app.databinding.ItemRssBinding import io.legado.app.lib.theme.ATH import io.legado.app.ui.rss.article.RssSortActivity import io.legado.app.ui.rss.favorites.RssFavoritesActivity +import io.legado.app.ui.rss.read.ReadRssActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.ui.rss.source.manage.RssSourceActivity import io.legado.app.ui.rss.source.manage.RssSourceViewModel @@ -72,7 +73,11 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), } override fun openRss(rssSource: RssSource) { - startActivity(Pair("url", rssSource.sourceUrl)) + if (rssSource.singleUrl) { + startActivity(Pair("origin", rssSource.sourceUrl)) + } else { + startActivity(Pair("url", rssSource.sourceUrl)) + } } override fun toTop(rssSource: RssSource) { diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index ce3e2515c..eb211f0eb 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -227,34 +227,24 @@ class ReadRssActivity : VMBaseActivity @SuppressLint("SetJavaScriptEnabled") private fun initLiveData() { - viewModel.contentLiveData.observe(this, { content -> + viewModel.contentLiveData.observe(this) { content -> viewModel.rssArticle?.let { upJavaScriptEnable() val url = NetworkUtils.getAbsoluteURL(it.origin, it.link) val html = viewModel.clHtml(content) if (viewModel.rssSource?.loadWithBaseUrl == true) { - binding.webView.loadDataWithBaseURL( - url, - html, - "text/html", - "utf-8", - url - )//不想用baseUrl进else + binding.webView + .loadDataWithBaseURL(url, html, "text/html", "utf-8", url)//不想用baseUrl进else } else { - binding.webView.loadDataWithBaseURL( - null, - html, - "text/html;charset=utf-8", - "utf-8", - url - ) + binding.webView + .loadDataWithBaseURL(null, html, "text/html;charset=utf-8", "utf-8", url) } } - }) - viewModel.urlLiveData.observe(this, { + } + viewModel.urlLiveData.observe(this) { upJavaScriptEnable() binding.webView.loadUrl(it.url, it.headerMap) - }) + } } @SuppressLint("SetJavaScriptEnabled") diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index a9daa6654..0018c6e17 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -46,23 +46,32 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), execute { val origin = intent.getStringExtra("origin") val link = intent.getStringExtra("link") - if (origin != null && link != null) { + origin?.let { rssSource = App.db.rssSourceDao.getByKey(origin) - rssStar = App.db.rssStarDao.get(origin, link) - rssArticle = rssStar?.toRssArticle() ?: App.db.rssArticleDao.get(origin, link) - rssArticle?.let { rssArticle -> - if (!rssArticle.description.isNullOrBlank()) { - contentLiveData.postValue(rssArticle.description) - } else { - rssSource?.let { - val ruleContent = it.ruleContent - if (!ruleContent.isNullOrBlank()) { - loadContent(rssArticle, ruleContent) - } else { - loadUrl(rssArticle) - } - } ?: loadUrl(rssArticle) + if (link != null) { + rssStar = App.db.rssStarDao.get(origin, link) + rssArticle = rssStar?.toRssArticle() ?: App.db.rssArticleDao.get(origin, link) + rssArticle?.let { rssArticle -> + if (!rssArticle.description.isNullOrBlank()) { + contentLiveData.postValue(rssArticle.description) + } else { + rssSource?.let { + val ruleContent = it.ruleContent + if (!ruleContent.isNullOrBlank()) { + loadContent(rssArticle, ruleContent) + } else { + loadUrl(rssArticle) + } + } ?: loadUrl(rssArticle) + } } + } else { + val analyzeUrl = AnalyzeUrl( + origin, + useWebView = true, + headerMapF = rssSource?.getHeaderMap() + ) + urlLiveData.postValue(analyzeUrl) } } }.onFinally { 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 8ece8f354..2f11ad365 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 @@ -10,7 +10,6 @@ import android.view.MenuItem import android.view.ViewTreeObserver import android.widget.EditText import android.widget.PopupWindow -import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppConst @@ -124,13 +123,13 @@ class RssSourceEditActivity : ATH.applyEdgeEffectColor(binding.recyclerView) mSoftKeyboardTool = KeyboardToolPop(this, AppConst.keyboardToolChars, this) window.decorView.viewTreeObserver.addOnGlobalLayoutListener(this) - binding.recyclerView.layoutManager = LinearLayoutManager(this) binding.recyclerView.adapter = adapter } private fun upRecyclerView(rssSource: RssSource? = viewModel.rssSource) { rssSource?.let { binding.cbIsEnable.isChecked = rssSource.enabled + binding.cbSingleUrl.isChecked = rssSource.singleUrl binding.cbEnableJs.isChecked = rssSource.enableJs binding.cbEnableBaseUrl.isChecked = rssSource.loadWithBaseUrl } @@ -158,6 +157,7 @@ class RssSourceEditActivity : private fun getRssSource(): RssSource { val source = viewModel.rssSource source.enabled = binding.cbIsEnable.isChecked + source.singleUrl = binding.cbSingleUrl.isChecked source.enableJs = binding.cbEnableJs.isChecked source.loadWithBaseUrl = binding.cbEnableBaseUrl.isChecked sourceEntities.forEach { diff --git a/app/src/main/res/layout/activity_rss_source_edit.xml b/app/src/main/res/layout/activity_rss_source_edit.xml index bd51c3389..f8554ad65 100644 --- a/app/src/main/res/layout/activity_rss_source_edit.xml +++ b/app/src/main/res/layout/activity_rss_source_edit.xml @@ -18,6 +18,8 @@ @@ -28,13 +30,22 @@ android:checked="true" android:text="@string/is_enable" /> - + android:checked="true" + android:text="@string/single_url" /> + + + + + android:layout_height="match_parent" + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" + tools:listitem="@layout/item_source_edit" /> \ No newline at end of file diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 659f2fe15..bc5b42e2e 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -794,5 +794,6 @@ 同步阅读进度 进入退出阅读界面时同步阅读进度 创建书签失败 + 单URL diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index b8bf69e99..b68dbdc72 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -795,5 +795,6 @@ 同步閱讀進度 進入退出閱讀介面時同步閱讀進度 创建书签失败 + 单URL diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 6454737c3..6eda0ea3d 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -798,5 +798,6 @@ 同步阅读进度 进入退出阅读界面时同步阅读进度 创建书签失败 + 单URL diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f5a3a53e5..9a698af4b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -801,5 +801,6 @@ 同步阅读进度 进入退出阅读界面时同步阅读进度 创建书签失败 + 单URL