修复验证码不刷新的bug

pull/2605/head
kunfei 2 years ago
parent 671d078d0b
commit 2df79ecbf7
  1. 9
      app/src/main/java/io/legado/app/help/glide/OkHttpStreamFetcher.kt
  2. 7
      app/src/main/java/io/legado/app/help/source/SourceHelp.kt
  3. 38
      app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt
  4. 9
      app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt

@ -8,21 +8,21 @@ import com.bumptech.glide.load.data.DataFetcher
import com.bumptech.glide.load.model.GlideUrl import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.util.ContentLengthInputStream import com.bumptech.glide.util.ContentLengthInputStream
import com.bumptech.glide.util.Preconditions import com.bumptech.glide.util.Preconditions
import io.legado.app.data.appDb
import io.legado.app.data.entities.BaseSource import io.legado.app.data.entities.BaseSource
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.http.addHeaders import io.legado.app.help.http.addHeaders
import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.okHttpClient
import io.legado.app.utils.isWifiConnect import io.legado.app.help.source.SourceHelp
import io.legado.app.utils.ImageUtils import io.legado.app.utils.ImageUtils
import io.legado.app.utils.isWifiConnect
import okhttp3.Call import okhttp3.Call
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import okhttp3.ResponseBody import okhttp3.ResponseBody
import splitties.init.appCtx import splitties.init.appCtx
import java.io.ByteArrayInputStream
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.io.ByteArrayInputStream
class OkHttpStreamFetcher(private val url: GlideUrl, private val options: Options) : class OkHttpStreamFetcher(private val url: GlideUrl, private val options: Options) :
@ -44,8 +44,7 @@ class OkHttpStreamFetcher(private val url: GlideUrl, private val options: Option
val requestBuilder: Request.Builder = Request.Builder().url(url.toStringUrl()) val requestBuilder: Request.Builder = Request.Builder().url(url.toStringUrl())
val headerMap = HashMap<String, String>() val headerMap = HashMap<String, String>()
options.get(OkHttpModelLoader.sourceOriginOption)?.let { sourceUrl -> options.get(OkHttpModelLoader.sourceOriginOption)?.let { sourceUrl ->
source = appDb.bookSourceDao.getBookSource(sourceUrl) source = SourceHelp.getSource(sourceUrl)
?: appDb.rssSourceDao.getByKey(sourceUrl)
source?.getHeaderMap(true)?.let { source?.getHeaderMap(true)?.let {
headerMap.putAll(it) headerMap.putAll(it)
} }

@ -3,6 +3,7 @@ package io.legado.app.help.source
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.BaseSource
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
@ -24,6 +25,12 @@ object SourceHelp {
} }
} }
fun getSource(key: String?): BaseSource? {
key ?: return null
return appDb.bookSourceDao.getBookSource(key)
?: appDb.rssSourceDao.getByKey(key)
}
fun insertRssSource(vararg rssSources: RssSource) { fun insertRssSource(vararg rssSources: RssSource) {
rssSources.forEach { rssSource -> rssSources.forEach { rssSource ->
if (is18Plus(rssSource.sourceUrl)) { if (is18Plus(rssSource.sourceUrl)) {

@ -16,11 +16,15 @@ import io.legado.app.help.glide.ImageLoader
import io.legado.app.help.glide.OkHttpModelLoader import io.legado.app.help.glide.OkHttpModelLoader
import io.legado.app.help.source.SourceVerificationHelp import io.legado.app.help.source.SourceVerificationHelp
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.ui.widget.dialog.PhotoDialog import io.legado.app.ui.widget.dialog.PhotoDialog
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.setLayout import io.legado.app.utils.setLayout
import io.legado.app.utils.showDialogFragment import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
/** /**
* 图片验证码对话框 * 图片验证码对话框
@ -50,7 +54,6 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification
setLayout(1f, ViewGroup.LayoutParams.WRAP_CONTENT) setLayout(1f, ViewGroup.LayoutParams.WRAP_CONTENT)
} }
@SuppressLint("CheckResult")
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
initMenu() initMenu()
binding.run { binding.run {
@ -59,16 +62,7 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification
toolBar.subtitle = arguments.getString("sourceName") toolBar.subtitle = arguments.getString("sourceName")
val sourceOrigin = arguments.getString("sourceOrigin") val sourceOrigin = arguments.getString("sourceOrigin")
arguments.getString("imageUrl")?.let { imageUrl -> arguments.getString("imageUrl")?.let { imageUrl ->
ImageLoader.load(requireContext(), imageUrl).apply { loadImage(imageUrl, sourceOrigin)
sourceOrigin?.let {
apply(
RequestOptions().set(OkHttpModelLoader.sourceOriginOption, it)
)
}
}.error(R.drawable.image_loading_error)
.diskCacheStrategy(DiskCacheStrategy.NONE)
//.skipMemoryCache(true)
.into(verificationCodeImageView)
verificationCodeImageView.setOnClickListener { verificationCodeImageView.setOnClickListener {
showDialogFragment(PhotoDialog(imageUrl, sourceOrigin)) showDialogFragment(PhotoDialog(imageUrl, sourceOrigin))
} }
@ -83,6 +77,28 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification
binding.toolBar.menu.applyTint(requireContext()) binding.toolBar.menu.applyTint(requireContext())
} }
@SuppressLint("CheckResult")
private fun loadImage(url: String, sourceUrl: String?) {
launch {
ImageProvider.bitmapLruCache.remove(url)
val image = withContext(IO) {
ImageLoader.loadBitmap(requireContext(), url).apply {
sourceUrl?.let {
apply(
RequestOptions().set(OkHttpModelLoader.sourceOriginOption, it)
)
}
}.error(R.drawable.image_loading_error)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.submit()
.get()
}
ImageProvider.bitmapLruCache.put(url, image)
binding.verificationCodeImageView.setImageBitmap(image)
}
}
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
override fun onMenuItemClick(item: MenuItem): Boolean { override fun onMenuItemClick(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {

@ -12,6 +12,7 @@ import io.legado.app.help.glide.ImageLoader
import io.legado.app.help.glide.OkHttpModelLoader import io.legado.app.help.glide.OkHttpModelLoader
import io.legado.app.model.BookCover import io.legado.app.model.BookCover
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.utils.setLayout import io.legado.app.utils.setLayout
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -36,8 +37,12 @@ class PhotoDialog() : BaseDialogFragment(R.layout.dialog_photo_view) {
@SuppressLint("CheckResult") @SuppressLint("CheckResult")
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
arguments?.let { arguments -> val arguments = arguments ?: return
arguments.getString("src")?.let { src -> arguments.getString("src")?.let { src ->
ImageProvider.bitmapLruCache.get(src)?.let {
binding.photoView.setImageBitmap(it)
return
}
val file = ReadBook.book?.let { book -> val file = ReadBook.book?.let { book ->
BookHelp.getImage(book, src) BookHelp.getImage(book, src)
} }
@ -62,5 +67,3 @@ class PhotoDialog() : BaseDialogFragment(R.layout.dialog_photo_view) {
} }
} }
}

Loading…
Cancel
Save