Merge remote-tracking branch 'origin/master'

pull/1905/head
kunfei 3 years ago
commit 313c59b318
  1. 14
      app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt
  2. 1
      app/src/main/java/io/legado/app/help/config/ThemeConfig.kt
  3. 1
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  4. 1
      app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt
  5. 1
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  6. 1
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  7. 19
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  8. 10
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  9. 9
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
  10. 20
      app/src/main/java/io/legado/app/utils/BitmapUtils.kt
  11. 2
      app/src/main/java/io/legado/app/utils/QRCodeUtils.kt

@ -37,7 +37,6 @@ object ReadBookConfig {
if (shareLayout) { if (shareLayout) {
shareConfig = value shareConfig = value
} }
upBg()
} }
var bg: Drawable? = null var bg: Drawable? = null
@ -88,11 +87,8 @@ object ReadBookConfig {
shareConfig = c ?: configList.getOrNull(5) ?: Config() shareConfig = c ?: configList.getOrNull(5) ?: Config()
} }
fun upBg() { fun upBg(width: Int, height: Int) {
val resources = appCtx.resources val tmp = bg
val dm = resources.displayMetrics
val width = dm.widthPixels
val height = dm.heightPixels
bg = durConfig.curBgDrawable(width, height).apply { bg = durConfig.curBgDrawable(width, height).apply {
if (this is BitmapDrawable) { if (this is BitmapDrawable) {
bgMeanColor = bitmap.getMeanColor() bgMeanColor = bitmap.getMeanColor()
@ -100,6 +96,7 @@ object ReadBookConfig {
bgMeanColor = color bgMeanColor = color
} }
} }
(tmp as? BitmapDrawable)?.bitmap?.recycle()
} }
fun save() { fun save() {
@ -123,7 +120,6 @@ object ReadBookConfig {
if (styleSelect > 0) { if (styleSelect > 0) {
styleSelect -= 1 styleSelect -= 1
} }
upBg()
return true return true
} }
return false return false
@ -572,11 +568,11 @@ object ReadBookConfig {
1 -> { 1 -> {
val path = "bg" + File.separator + curBgStr() val path = "bg" + File.separator + curBgStr()
val bitmap = BitmapUtils.decodeAssetsBitmap(appCtx, path, width, height) val bitmap = BitmapUtils.decodeAssetsBitmap(appCtx, path, width, height)
BitmapDrawable(resources, bitmap) BitmapDrawable(resources, bitmap?.copyAndRecycle(width, height))
} }
else -> { else -> {
val bitmap = BitmapUtils.decodeBitmap(curBgStr(), width, height) val bitmap = BitmapUtils.decodeBitmap(curBgStr(), width, height)
BitmapDrawable(resources, bitmap) BitmapDrawable(resources, bitmap?.copyAndRecycle(width, height))
} }
} }
} catch (e: OutOfMemoryError) { } catch (e: OutOfMemoryError) {

@ -38,7 +38,6 @@ object ThemeConfig {
} }
fun applyDayNight(context: Context) { fun applyDayNight(context: Context) {
ReadBookConfig.upBg()
applyTheme(context) applyTheme(context)
initNightMode() initNightMode()
BookCover.upDefaultCover() BookCover.upDefaultCover()

@ -984,7 +984,6 @@ class ReadBookActivity : BaseReadBookActivity(),
} }
BG_COLOR -> { BG_COLOR -> {
setCurBg(0, "#${color.hexString}") setCurBg(0, "#${color.hexString}")
ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
} }
TIP_COLOR -> { TIP_COLOR -> {

@ -41,7 +41,6 @@ class BgAdapter(context: Context, val textColor: Int) :
this.setOnClickListener { this.setOnClickListener {
getItemByLayoutPosition(holder.layoutPosition)?.let { getItemByLayoutPosition(holder.layoutPosition)?.let {
ReadBookConfig.durConfig.setCurBg(1, it) ReadBookConfig.durConfig.setCurBg(1, it)
ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
} }
} }

@ -358,7 +358,6 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
inputStream.copyTo(outputStream) inputStream.copyTo(outputStream)
} }
ReadBookConfig.durConfig.setCurBg(2, file.absolutePath) ReadBookConfig.durConfig.setCurBg(2, file.absolutePath)
ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
} }
} }

@ -158,7 +158,6 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style),
val oldIndex = ReadBookConfig.styleSelect val oldIndex = ReadBookConfig.styleSelect
if (index != oldIndex) { if (index != oldIndex) {
ReadBookConfig.styleSelect = index ReadBookConfig.styleSelect = index
ReadBookConfig.upBg()
upView() upView()
styleAdapter.notifyItemChanged(oldIndex) styleAdapter.notifyItemChanged(oldIndex)
styleAdapter.notifyItemChanged(index) styleAdapter.notifyItemChanged(index)

@ -2,8 +2,6 @@ package io.legado.app.ui.book.read.page
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.view.LayoutInflater import android.view.LayoutInflater
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.core.view.isGone import androidx.core.view.isGone
@ -41,7 +39,6 @@ class PageView(context: Context) : FrameLayout(context) {
private var tvBookName: BatteryView? = null private var tvBookName: BatteryView? = null
private var tvTimeBattery: BatteryView? = null private var tvTimeBattery: BatteryView? = null
private var tvTimeBatteryP: BatteryView? = null private var tvTimeBatteryP: BatteryView? = null
private var bitmap: Bitmap? = null
val headerHeight: Int val headerHeight: Int
get() { get() {
@ -61,13 +58,9 @@ class PageView(context: Context) : FrameLayout(context) {
} }
} }
fun getBitmap(): Bitmap? { override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
return bitmap?.copy(Bitmap.Config.ARGB_8888, false) super.onSizeChanged(w, h, oldw, oldh)
} upBg()
private fun upBitmap() {
bitmap?.recycle()
bitmap = screenshot()
} }
fun upStyle() = binding.run { fun upStyle() = binding.run {
@ -208,9 +201,9 @@ class PageView(context: Context) : FrameLayout(context) {
} }
} }
fun setBg(bg: Drawable?) { fun upBg() {
binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor
binding.vwBg.background = bg binding.vwBg.background = ReadBookConfig.bg
upBgAlpha() upBgAlpha()
} }
@ -236,7 +229,6 @@ class PageView(context: Context) : FrameLayout(context) {
val time = timeFormat.format(Date(System.currentTimeMillis())) val time = timeFormat.format(Date(System.currentTimeMillis()))
tvTimeBattery?.setBattery(battery, time) tvTimeBattery?.setBattery(battery, time)
tvTimeBatteryP?.text = "$time $battery%" tvTimeBatteryP?.text = "$time $battery%"
upBitmap()
} }
fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) { fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {
@ -245,7 +237,6 @@ class PageView(context: Context) : FrameLayout(context) {
resetPageOffset() resetPageOffset()
} }
binding.contentTextView.setContent(textPage) binding.contentTextView.setContent(textPage)
upBitmap()
} }
fun setContentDescription(content: String) { fun setContentDescription(content: String) {

@ -489,12 +489,10 @@ class ReadView(context: Context, attrs: AttributeSet) :
} }
fun upBg() { fun upBg() {
ReadBookConfig.bg ?: let { ReadBookConfig.upBg(width, height)
ReadBookConfig.upBg() curPage.upBg()
} prevPage.upBg()
curPage.setBg(ReadBookConfig.bg) nextPage.upBg()
prevPage.setBg(ReadBookConfig.bg)
nextPage.setBg(ReadBookConfig.bg)
} }
fun upBgAlpha() { fun upBgAlpha() {

@ -4,6 +4,7 @@ import android.graphics.Bitmap
import android.view.MotionEvent import android.view.MotionEvent
import io.legado.app.ui.book.read.page.ReadView import io.legado.app.ui.book.read.page.ReadView
import io.legado.app.ui.book.read.page.entities.PageDirection import io.legado.app.ui.book.read.page.entities.PageDirection
import io.legado.app.utils.screenshot
abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readView) { abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readView) {
@ -20,15 +21,15 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
when (mDirection) { when (mDirection) {
PageDirection.PREV -> { PageDirection.PREV -> {
prevBitmap?.recycle() prevBitmap?.recycle()
prevBitmap = prevPage.getBitmap() prevBitmap = prevPage.screenshot()
curBitmap?.recycle() curBitmap?.recycle()
curBitmap = curPage.getBitmap() curBitmap = curPage.screenshot()
} }
PageDirection.NEXT -> { PageDirection.NEXT -> {
nextBitmap?.recycle() nextBitmap?.recycle()
nextBitmap = nextPage.getBitmap() nextBitmap = nextPage.screenshot()
curBitmap?.recycle() curBitmap?.recycle()
curBitmap = curPage.getBitmap() curBitmap = curPage.screenshot()
} }
else -> Unit else -> Unit
} }

@ -210,27 +210,27 @@ object BitmapUtils {
} }
fun Bitmap.changeSize(newWidth: Int, newHeight: Int): Bitmap { /**
* 获取指定宽高的图片
*/
fun Bitmap.copyAndRecycle(newWidth: Int, newHeight: Int): Bitmap {
val width = this.width val width = this.width
val height = this.height val height = this.height
//计算压缩的比率 //计算压缩的比率
var scaleWidth = newWidth.toFloat() / width val scaleWidth = newWidth.toFloat() / width
var scaleHeight = newHeight.toFloat() / height val scaleHeight = newHeight.toFloat() / height
if (scaleWidth > scaleHeight) {
scaleWidth = scaleHeight
} else {
scaleHeight = scaleWidth
}
//获取想要缩放的matrix //获取想要缩放的matrix
val matrix = Matrix() val matrix = Matrix()
matrix.postScale(scaleWidth, scaleHeight) matrix.postScale(scaleWidth, scaleHeight)
//获取新的bitmap //获取新的bitmap
return Bitmap.createBitmap(this, 0, 0, width, height, matrix, true) val bitmap = Bitmap.createBitmap(this, 0, 0, width, height, matrix, true)
recycle()
return bitmap
} }
/** /**

@ -182,7 +182,7 @@ object QRCodeUtils {
hints: Map<DecodeHintType?, Any?> = DecodeFormatManager.ALL_HINTS hints: Map<DecodeHintType?, Any?> = DecodeFormatManager.ALL_HINTS
): Result? { ): Result? {
if (bitmap.width > reqWidth || bitmap.height > reqHeight) { if (bitmap.width > reqWidth || bitmap.height > reqHeight) {
val bm = bitmap.changeSize(reqWidth, reqHeight) val bm = bitmap.copyAndRecycle(reqWidth, reqHeight)
return parseCodeResult(getRGBLuminanceSource(bm), hints) return parseCodeResult(getRGBLuminanceSource(bm), hints)
} }
return parseCodeResult(getRGBLuminanceSource(bitmap), hints) return parseCodeResult(getRGBLuminanceSource(bitmap), hints)

Loading…
Cancel
Save