Merge remote-tracking branch 'origin/master'

This commit is contained in:
kunfei
2022-07-19 22:02:33 +08:00
9 changed files with 102 additions and 37 deletions
@@ -96,7 +96,14 @@ interface BookSourceDao {
@Query("select * from book_sources where bookSourceGroup like '%' || :group || '%'")
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>
@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.launch
import kotlinx.coroutines.withContext
import splitties.init.appCtx
class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(),
BookAdapter.CallBack,
@@ -65,21 +66,29 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
private var menu: Menu? = null
private var precisionSearchMenuItem: MenuItem? = null
private var groups = linkedSetOf<String>()
private val searchFinishCallback: (isEmpty: Boolean) -> Unit = {
if (it) {
val searchGroup = AppConfig.searchGroup
if (searchGroup.isNotEmpty()) {
launch {
alert("搜索结果为空") {
setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组")
noButton()
yesButton {
AppConfig.searchGroup = ""
viewModel.searchKey = ""
viewModel.search(searchView.query.toString())
}
private val searchFinishCallback: (isEmpty: Boolean) -> Unit = searchFinish@{ isEmpty ->
val searchGroup = AppConfig.searchGroup
if (!isEmpty || searchGroup.isEmpty()) return@searchFinish
launch {
alert("搜索结果为空") {
val precisionSearch = appCtx.getPrefBoolean(PreferKey.precisionSearch)
if (precisionSearch) {
setMessage("${searchGroup}分组搜索结果为空,是否关闭精准搜索?")
yesButton {
appCtx.putPrefBoolean(PreferKey.precisionSearch, false)
precisionSearchMenuItem?.isChecked = false
viewModel.searchKey = ""
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> {
putExtra("name", name)
putExtra("author", author)
putExtra("bookUrl", bookUrl)
}
}
@@ -370,7 +380,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
* 显示书籍详情
*/
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) {
binding.root.setOnClickListener {
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 {
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.http.CookieStore
import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.theme.accentColor
import io.legado.app.model.Download
import io.legado.app.ui.association.OnLineImportActivity
import io.legado.app.ui.document.HandleFileContract
@@ -81,6 +82,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
@SuppressLint("JavascriptInterface", "SetJavaScriptEnabled")
private fun initWebView(url: String, headerMap: HashMap<String, String>) {
binding.progressBar.fontColor = accentColor
binding.webView.webChromeClient = CustomWebChromeClient()
binding.webView.webViewClient = CustomWebViewClient()
binding.webView.settings.apply {
@@ -191,6 +193,12 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
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?) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
binding.llView.invisible()
@@ -14,6 +14,8 @@ import io.legado.app.constant.AppConst
import io.legado.app.data.entities.BaseSource
import io.legado.app.databinding.FragmentWebViewLoginBinding
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.viewbindingdelegate.viewBinding
@@ -54,6 +56,7 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) {
@SuppressLint("SetJavaScriptEnabled")
private fun initWebView(source: BaseSource) {
binding.progressBar.fontColor = accentColor
binding.webView.settings.apply {
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
domStorageEnabled = true
@@ -86,14 +89,13 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) {
}
}
binding.webView.webChromeClient = object : WebChromeClient() {
override fun onJsAlert(
view: WebView?,
url: String?,
message: String?,
result: JsResult?
): Boolean {
return super.onJsAlert(view, url, message, result)
override fun onProgressChanged(view: WebView?, newProgress: Int) {
super.onProgressChanged(view, newProgress)
binding.progressBar.setDurProgress(newProgress)
binding.progressBar.gone(newProgress == 100)
}
}
source.loginUrl?.let {
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.help.config.AppConfig
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.model.Download
import io.legado.app.ui.association.OnLineImportActivity
@@ -118,6 +119,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
@SuppressLint("SetJavaScriptEnabled")
private fun initWebView() {
binding.progressBar.fontColor = accentColor
binding.webView.webChromeClient = CustomWebChromeClient()
binding.webView.webViewClient = CustomWebViewClient()
binding.webView.settings.apply {
@@ -295,6 +297,12 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
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?) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
binding.llView.invisible()