Merge remote-tracking branch 'origin/master'

pull/2084/head
kunfei 2 years ago
commit 9a56e9834c
  1. 9
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 26
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt
  4. 8
      app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt
  5. 16
      app/src/main/java/io/legado/app/ui/login/WebViewLoginFragment.kt
  6. 8
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  7. 18
      app/src/main/res/layout/activity_rss_read.xml
  8. 18
      app/src/main/res/layout/activity_web_view.xml
  9. 18
      app/src/main/res/layout/fragment_web_view_login.xml

@ -96,7 +96,14 @@ interface BookSourceDao {
@Query("select * from book_sources where bookSourceGroup like '%' || :group || '%'") @Query("select * from book_sources where bookSourceGroup like '%' || :group || '%'")
fun getByGroup(group: String): List<BookSource> fun getByGroup(group: String): List<BookSource>
@Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'") @Query(
"""select * from book_sources
where enabled = 1
and (bookSourceGroup = :group
or bookSourceGroup like :group || ',%'
or bookSourceGroup like '%,' || :group
or bookSourceGroup like '%,' || :group || ',%')"""
)
fun getEnabledByGroup(group: String): List<BookSource> fun getEnabledByGroup(group: String): List<BookSource>
@Query("select * from book_sources where enabled = 1 and bookSourceType = :type") @Query("select * from book_sources where enabled = 1 and bookSourceType = :type")

@ -36,6 +36,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import splitties.init.appCtx
class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(), class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(),
BookAdapter.CallBack, BookAdapter.CallBack,
@ -65,21 +66,29 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
private var menu: Menu? = null private var menu: Menu? = null
private var precisionSearchMenuItem: MenuItem? = null private var precisionSearchMenuItem: MenuItem? = null
private var groups = linkedSetOf<String>() private var groups = linkedSetOf<String>()
private val searchFinishCallback: (isEmpty: Boolean) -> Unit = { private val searchFinishCallback: (isEmpty: Boolean) -> Unit = searchFinish@{ isEmpty ->
if (it) {
val searchGroup = AppConfig.searchGroup val searchGroup = AppConfig.searchGroup
if (searchGroup.isNotEmpty()) { if (!isEmpty || searchGroup.isEmpty()) return@searchFinish
launch { launch {
alert("搜索结果为空") { alert("搜索结果为空") {
setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组") val precisionSearch = appCtx.getPrefBoolean(PreferKey.precisionSearch)
noButton() if (precisionSearch) {
setMessage("${searchGroup}分组搜索结果为空,是否关闭精准搜索?")
yesButton { yesButton {
AppConfig.searchGroup = "" appCtx.putPrefBoolean(PreferKey.precisionSearch, false)
precisionSearchMenuItem?.isChecked = false
viewModel.searchKey = "" viewModel.searchKey = ""
viewModel.search(searchView.query.toString()) viewModel.search(searchView.query.toString())
} }
} else {
setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组?")
yesButton {
AppConfig.searchGroup = ""
viewModel.searchKey = ""
viewModel.search(searchView.query.toString())
} }
} }
noButton()
} }
} }
} }
@ -359,10 +368,11 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
/** /**
* 显示书籍详情 * 显示书籍详情
*/ */
override fun showBookInfo(name: String, author: String) { override fun showBookInfo(name: String, author: String, bookUrl: String) {
startActivity<BookInfoActivity> { startActivity<BookInfoActivity> {
putExtra("name", name) putExtra("name", name)
putExtra("author", author) putExtra("author", author)
putExtra("bookUrl", bookUrl)
} }
} }
@ -370,7 +380,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
* 显示书籍详情 * 显示书籍详情
*/ */
override fun showBookInfo(book: Book) { override fun showBookInfo(book: Book) {
showBookInfo(book.name, book.author) showBookInfo(book.name, book.author, book.bookUrl)
} }
/** /**

@ -69,7 +69,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) {
binding.root.setOnClickListener { binding.root.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.showBookInfo(it.name, it.author) callBack.showBookInfo(it.name, it.author, it.bookUrl)
} }
} }
} }
@ -128,6 +128,6 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
} }
interface CallBack { interface CallBack {
fun showBookInfo(name: String, author: String) fun showBookInfo(name: String, author: String, bookUrl: String)
} }
} }

@ -21,6 +21,7 @@ import io.legado.app.help.SourceVerificationHelp
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.http.CookieStore import io.legado.app.help.http.CookieStore
import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.theme.accentColor
import io.legado.app.model.Download import io.legado.app.model.Download
import io.legado.app.ui.association.OnLineImportActivity import io.legado.app.ui.association.OnLineImportActivity
import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.document.HandleFileContract
@ -81,6 +82,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
@SuppressLint("JavascriptInterface", "SetJavaScriptEnabled") @SuppressLint("JavascriptInterface", "SetJavaScriptEnabled")
private fun initWebView(url: String, headerMap: HashMap<String, String>) { private fun initWebView(url: String, headerMap: HashMap<String, String>) {
binding.progressBar.fontColor = accentColor
binding.webView.webChromeClient = CustomWebChromeClient() binding.webView.webChromeClient = CustomWebChromeClient()
binding.webView.webViewClient = CustomWebViewClient() binding.webView.webViewClient = CustomWebViewClient()
binding.webView.settings.apply { binding.webView.settings.apply {
@ -191,6 +193,12 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
inner class CustomWebChromeClient : WebChromeClient() { inner class CustomWebChromeClient : WebChromeClient() {
override fun onProgressChanged(view: WebView?, newProgress: Int) {
super.onProgressChanged(view, newProgress)
binding.progressBar.setDurProgress(newProgress)
binding.progressBar.gone(newProgress == 100)
}
override fun onShowCustomView(view: View?, callback: CustomViewCallback?) { override fun onShowCustomView(view: View?, callback: CustomViewCallback?) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
binding.llView.invisible() binding.llView.invisible()

@ -14,6 +14,8 @@ import io.legado.app.constant.AppConst
import io.legado.app.data.entities.BaseSource import io.legado.app.data.entities.BaseSource
import io.legado.app.databinding.FragmentWebViewLoginBinding import io.legado.app.databinding.FragmentWebViewLoginBinding
import io.legado.app.help.http.CookieStore import io.legado.app.help.http.CookieStore
import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.gone
import io.legado.app.utils.snackbar import io.legado.app.utils.snackbar
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -54,6 +56,7 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) {
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
private fun initWebView(source: BaseSource) { private fun initWebView(source: BaseSource) {
binding.progressBar.fontColor = accentColor
binding.webView.settings.apply { binding.webView.settings.apply {
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
domStorageEnabled = true domStorageEnabled = true
@ -86,14 +89,13 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) {
} }
} }
binding.webView.webChromeClient = object : WebChromeClient() { binding.webView.webChromeClient = object : WebChromeClient() {
override fun onJsAlert(
view: WebView?, override fun onProgressChanged(view: WebView?, newProgress: Int) {
url: String?, super.onProgressChanged(view, newProgress)
message: String?, binding.progressBar.setDurProgress(newProgress)
result: JsResult? binding.progressBar.gone(newProgress == 100)
): Boolean {
return super.onJsAlert(view, url, message, result)
} }
} }
source.loginUrl?.let { source.loginUrl?.let {
binding.webView.loadUrl(it, source.getHeaderMap(true)) binding.webView.loadUrl(it, source.getHeaderMap(true))

@ -17,6 +17,7 @@ import io.legado.app.constant.AppConst
import io.legado.app.databinding.ActivityRssReadBinding import io.legado.app.databinding.ActivityRssReadBinding
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.model.Download import io.legado.app.model.Download
import io.legado.app.ui.association.OnLineImportActivity import io.legado.app.ui.association.OnLineImportActivity
@ -118,6 +119,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
private fun initWebView() { private fun initWebView() {
binding.progressBar.fontColor = accentColor
binding.webView.webChromeClient = CustomWebChromeClient() binding.webView.webChromeClient = CustomWebChromeClient()
binding.webView.webViewClient = CustomWebViewClient() binding.webView.webViewClient = CustomWebViewClient()
binding.webView.settings.apply { binding.webView.settings.apply {
@ -295,6 +297,12 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
inner class CustomWebChromeClient : WebChromeClient() { inner class CustomWebChromeClient : WebChromeClient() {
override fun onProgressChanged(view: WebView?, newProgress: Int) {
super.onProgressChanged(view, newProgress)
binding.progressBar.setDurProgress(newProgress)
binding.progressBar.gone(newProgress == 100)
}
override fun onShowCustomView(view: View?, callback: CustomViewCallback?) { override fun onShowCustomView(view: View?, callback: CustomViewCallback?) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
binding.llView.invisible() binding.llView.invisible()

@ -5,7 +5,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ll_view" android:id="@+id/ll_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -15,14 +15,24 @@
android:id="@+id/title_bar" android:id="@+id/title_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:fitStatusBar="false" /> app:fitStatusBar="false"
app:layout_constraintTop_toTopOf="parent" />
<io.legado.app.ui.rss.read.VisibleWebView <io.legado.app.ui.rss.read.VisibleWebView
android:id="@+id/web_view" android:id="@+id/web_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/title_bar"
app:layout_constraintBottom_toBottomOf="parent" />
<io.legado.app.ui.widget.anima.RefreshProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="1dp"
app:max_progress="100"
app:layout_constraintTop_toTopOf="@id/web_view" />
</LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<FrameLayout <FrameLayout
android:id="@+id/custom_web_view" android:id="@+id/custom_web_view"

@ -5,7 +5,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ll_view" android:id="@+id/ll_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -15,14 +15,24 @@
android:id="@+id/title_bar" android:id="@+id/title_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:fitStatusBar="false" /> app:fitStatusBar="false"
app:layout_constraintTop_toTopOf="parent" />
<io.legado.app.ui.rss.read.VisibleWebView <io.legado.app.ui.rss.read.VisibleWebView
android:id="@+id/web_view" android:id="@+id/web_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/title_bar"
app:layout_constraintBottom_toBottomOf="parent" />
<io.legado.app.ui.widget.anima.RefreshProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="1dp"
app:max_progress="100"
app:layout_constraintTop_toTopOf="@id/web_view" />
</LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<FrameLayout <FrameLayout
android:id="@+id/custom_web_view" android:id="@+id/custom_web_view"

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
@ -10,11 +10,21 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:attachToActivity="false" app:attachToActivity="false"
app:title="@string/login" /> app:title="@string/login"
app:layout_constraintTop_toTopOf="parent" />
<WebView <WebView
android:id="@+id/web_view" android:id="@+id/web_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/title_bar"
app:layout_constraintBottom_toBottomOf="parent" />
</LinearLayout> <io.legado.app.ui.widget.anima.RefreshProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="1dp"
app:max_progress="100"
app:layout_constraintTop_toTopOf="@id/web_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save