优化代码

pull/743/head
gedoor 4 years ago
parent 8a92a14944
commit 3768fc5614
  1. 7
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  2. 26
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  3. 39
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt
  4. 4
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  5. 25
      app/src/main/res/layout/activity_rss_source_edit.xml
  6. 1
      app/src/main/res/values-zh-rHK/strings.xml
  7. 1
      app/src/main/res/values-zh-rTW/strings.xml
  8. 1
      app/src/main/res/values-zh/strings.xml
  9. 1
      app/src/main/res/values/strings.xml

@ -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<RssSourceViewModel>(R.layout.fragment_rss),
}
override fun openRss(rssSource: RssSource) {
startActivity<RssSortActivity>(Pair("url", rssSource.sourceUrl))
if (rssSource.singleUrl) {
startActivity<ReadRssActivity>(Pair("origin", rssSource.sourceUrl))
} else {
startActivity<RssSortActivity>(Pair("url", rssSource.sourceUrl))
}
}
override fun toTop(rssSource: RssSource) {

@ -227,34 +227,24 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
@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")

@ -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 {

@ -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 {

@ -18,6 +18,8 @@
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:orientation="horizontal"
android:layout_gravity="center_vertical">
@ -28,13 +30,22 @@
android:checked="true"
android:text="@string/is_enable" />
<TextView
<io.legado.app.lib.theme.view.ATECheckBox
android:id="@+id/cb_single_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="|"
tools:ignore="HardcodedText,RtlHardcoded" />
android:checked="true"
android:text="@string/single_url" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:orientation="horizontal"
android:layout_gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
@ -61,6 +72,8 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_source_edit" />
</LinearLayout>

@ -794,5 +794,6 @@
<string name="sync_book_progress_t">同步阅读进度</string>
<string name="sync_book_progress_s">进入退出阅读界面时同步阅读进度</string>
<string name="create_bookmark_error">创建书签失败</string>
<string name="single_url">单URL</string>
</resources>

@ -795,5 +795,6 @@
<string name="sync_book_progress_t">同步閱讀進度</string>
<string name="sync_book_progress_s">進入退出閱讀介面時同步閱讀進度</string>
<string name="create_bookmark_error">创建书签失败</string>
<string name="single_url">单URL</string>
</resources>

@ -798,5 +798,6 @@
<string name="sync_book_progress_t">同步阅读进度</string>
<string name="sync_book_progress_s">进入退出阅读界面时同步阅读进度</string>
<string name="create_bookmark_error">创建书签失败</string>
<string name="single_url">单URL</string>
</resources>

@ -801,5 +801,6 @@
<string name="sync_book_progress_t">同步阅读进度</string>
<string name="sync_book_progress_s">进入退出阅读界面时同步阅读进度</string>
<string name="create_bookmark_error">创建书签失败</string>
<string name="single_url">单URL</string>
</resources>

Loading…
Cancel
Save