pull/1814/head
kunfei 3 years ago
parent 6e83e979c9
commit 338c32c92c
  1. 16
      app/src/main/java/io/legado/app/model/BookCover.kt
  2. 41
      app/src/main/java/io/legado/app/ui/widget/dialog/PhotoDialog.kt

@ -70,13 +70,17 @@ object BookCover {
fun load( fun load(
context: Context, context: Context,
path: String?, path: String?,
loadOnlyWifi: Boolean = false loadOnlyWifi: Boolean = false,
sourceOrigin: String? = null
): RequestBuilder<Drawable> { ): RequestBuilder<Drawable> {
if (AppConfig.useDefaultCover) { if (AppConfig.useDefaultCover) {
return ImageLoader.load(context, defaultDrawable) return ImageLoader.load(context, defaultDrawable)
.centerCrop() .centerCrop()
} }
val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi) var options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi)
if (sourceOrigin != null) {
options = options.set(OkHttpModelLoader.sourceOriginOption, sourceOrigin)
}
return ImageLoader.load(context, path) return ImageLoader.load(context, path)
.apply(options) .apply(options)
.placeholder(defaultDrawable) .placeholder(defaultDrawable)
@ -90,14 +94,18 @@ object BookCover {
fun loadBlur( fun loadBlur(
context: Context, context: Context,
path: String?, path: String?,
loadOnlyWifi: Boolean = false loadOnlyWifi: Boolean = false,
sourceOrigin: String? = null
): RequestBuilder<Drawable> { ): RequestBuilder<Drawable> {
val loadBlur = ImageLoader.load(context, defaultDrawable) val loadBlur = ImageLoader.load(context, defaultDrawable)
.transform(BlurTransformation(25), CenterCrop()) .transform(BlurTransformation(25), CenterCrop())
if (AppConfig.useDefaultCover) { if (AppConfig.useDefaultCover) {
return loadBlur return loadBlur
} }
val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi) var options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi)
if (sourceOrigin != null) {
options = options.set(OkHttpModelLoader.sourceOriginOption, sourceOrigin)
}
return ImageLoader.load(context, path) return ImageLoader.load(context, path)
.apply(options) .apply(options)
.transform(BlurTransformation(25), CenterCrop()) .transform(BlurTransformation(25), CenterCrop())

@ -1,12 +1,15 @@
package io.legado.app.ui.widget.dialog package io.legado.app.ui.widget.dialog
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.bumptech.glide.request.RequestOptions
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogPhotoViewBinding import io.legado.app.databinding.DialogPhotoViewBinding
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.glide.ImageLoader import io.legado.app.help.glide.ImageLoader
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.utils.setLayout import io.legado.app.utils.setLayout
@ -17,9 +20,10 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
*/ */
class PhotoDialog() : BaseDialogFragment(R.layout.dialog_photo_view) { class PhotoDialog() : BaseDialogFragment(R.layout.dialog_photo_view) {
constructor(src: String) : this() { constructor(src: String, sourceOrigin: String? = null) : this() {
arguments = Bundle().apply { arguments = Bundle().apply {
putString("src", src) putString("src", src)
putString("sourceOrigin", sourceOrigin)
} }
} }
@ -30,19 +34,30 @@ class PhotoDialog() : BaseDialogFragment(R.layout.dialog_photo_view) {
setLayout(1f, 1f) setLayout(1f, 1f)
} }
@SuppressLint("CheckResult")
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
arguments?.getString("src")?.let { src -> arguments?.let { arguments ->
val file = ReadBook.book?.let { book -> arguments.getString("src")?.let { src ->
BookHelp.getImage(book, src) val file = ReadBook.book?.let { book ->
} BookHelp.getImage(book, src)
if (file?.exists() == true) { }
ImageLoader.load(requireContext(), file) if (file?.exists() == true) {
.error(R.drawable.image_loading_error) ImageLoader.load(requireContext(), file)
.into(binding.photoView) .error(R.drawable.image_loading_error)
} else { .into(binding.photoView)
ImageLoader.load(requireContext(), src) } else {
.error(BookCover.defaultDrawable) ImageLoader.load(requireContext(), src).apply {
.into(binding.photoView) arguments.getString("sourceOrigin")?.let { sourceOrigin ->
apply(
RequestOptions().set(
OkHttpModelLoader.sourceOriginOption,
sourceOrigin
)
)
}
}.error(BookCover.defaultDrawable)
.into(binding.photoView)
}
} }
} }

Loading…
Cancel
Save