pull/1738/head
kunfei 3 years ago
parent 323367b855
commit 77d35687e4
  1. 39
      app/src/main/java/io/legado/app/model/BookCover.kt
  2. 13
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  3. 11
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt

@ -5,6 +5,7 @@ import android.content.Context
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import io.legado.app.R
import io.legado.app.constant.PreferKey
@ -15,6 +16,7 @@ import io.legado.app.help.CacheManager
import io.legado.app.help.DefaultData
import io.legado.app.help.config.AppConfig
import io.legado.app.help.glide.ImageLoader
import io.legado.app.help.glide.OkHttpModelLoader
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.*
@ -61,11 +63,46 @@ object BookCover {
}.getOrDefault(appCtx.resources.getDrawable(R.drawable.image_cover_default, null))
}
fun getBlurDefaultCover(context: Context): RequestBuilder<Drawable> {
private fun getBlurDefaultCover(context: Context): RequestBuilder<Drawable> {
return ImageLoader.load(context, defaultDrawable)
.apply(RequestOptions.bitmapTransform(BlurTransformation(context, 25)))
}
fun load(
context: Context,
path: String?,
loadOnlyWifi: Boolean = false
): RequestBuilder<Drawable> {
return if (AppConfig.useDefaultCover) {
ImageLoader.load(context, defaultDrawable)
.centerCrop()
} else {
val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi)
ImageLoader.load(context, path)
.apply(options)
.placeholder(defaultDrawable)
.error(defaultDrawable)
}
}
fun loadBlur(
context: Context,
path: String?,
loadOnlyWifi: Boolean = false
): RequestBuilder<Drawable> {
return if (AppConfig.useDefaultCover) {
getBlurDefaultCover(context)
.centerCrop()
} else {
val options = RequestOptions().set(OkHttpModelLoader.loadOnlyWifiOption, loadOnlyWifi)
ImageLoader.load(context, path)
.apply(options)
.transition(DrawableTransitionOptions.withCrossFade(1500))
.thumbnail(getBlurDefaultCover(context))
.apply(RequestOptions.bitmapTransform(BlurTransformation(context, 25)))
}
}
suspend fun searchCover(book: Book): String? {
val config = coverRuleConfig
if (!config.enable || config.searchUrl.isBlank() || config.coverRule.isBlank()) {

@ -8,8 +8,6 @@ import android.view.Menu
import android.view.MenuItem
import android.widget.SeekBar
import androidx.activity.viewModels
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions.bitmapTransform
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.EventBus
@ -18,8 +16,6 @@ import io.legado.app.constant.Theme
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.ActivityAudioPlayBinding
import io.legado.app.help.BlurTransformation
import io.legado.app.help.glide.ImageLoader
import io.legado.app.lib.dialogs.alert
import io.legado.app.model.AudioPlay
import io.legado.app.model.BookCover
@ -169,14 +165,9 @@ class AudioPlayActivity :
}
private fun upCover(path: String?) {
ImageLoader.load(this, path)
.placeholder(BookCover.defaultDrawable)
.error(BookCover.defaultDrawable)
BookCover.load(this, path)
.into(binding.ivCover)
ImageLoader.load(this, path)
.transition(DrawableTransitionOptions.withCrossFade(1500))
.thumbnail(BookCover.getBlurDefaultCover(this))
.apply(bitmapTransform(BlurTransformation(this, 25)))
BookCover.loadBlur(this, path)
.into(binding.ivBg)
}

@ -9,8 +9,6 @@ import android.widget.CheckBox
import android.widget.LinearLayout
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions.bitmapTransform
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.BookType
@ -21,8 +19,6 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.ActivityBookInfoBinding
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.BlurTransformation
import io.legado.app.help.glide.ImageLoader
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.bottomBackground
@ -224,11 +220,8 @@ class BookInfoActivity :
private fun showCover(book: Book) {
binding.ivCover.load(book.getDisplayCover(), book.name, book.author)
ImageLoader.load(this, book.getDisplayCover())
.transition(DrawableTransitionOptions.withCrossFade(1500))
.thumbnail(BookCover.getBlurDefaultCover(this))
.apply(bitmapTransform(BlurTransformation(this, 25)))
.into(binding.bgBook) //模糊、渐变、缩小效果
BookCover.loadBlur(this, book.getDisplayCover())
.into(binding.bgBook)
}
private fun upLoading(isLoading: Boolean, chapterList: List<BookChapter>? = null) {

Loading…
Cancel
Save