Autmotic Reader theme now based on page or by theme
This commit is contained in:
parent
198803e019
commit
78b3ff97d2
@ -231,10 +231,12 @@ class HttpPageLoader(
|
||||
}
|
||||
}
|
||||
.doOnNext {
|
||||
if (preferences.readerTheme().get() == 2) {
|
||||
val readerTheme = preferences.readerTheme().getOrDefault()
|
||||
if (readerTheme >= 2) {
|
||||
val stream = chapterCache.getImageFile(imageUrl).inputStream()
|
||||
val image = BitmapFactory.decodeStream(stream)
|
||||
page.bg = ImageUtil.autoSetBackground(image)
|
||||
page.bg = ImageUtil.autoSetBackground(image, readerTheme == 2)
|
||||
page.bgAlwaysWhite = readerTheme == 2
|
||||
stream.close()
|
||||
}
|
||||
page.stream = { chapterCache.getImageFile(imageUrl).inputStream() }
|
||||
|
@ -9,7 +9,8 @@ class ReaderPage(
|
||||
url: String = "",
|
||||
imageUrl: String? = null,
|
||||
var stream: (() -> InputStream)? = null,
|
||||
var bg: Drawable? = null
|
||||
var bg: Drawable? = null,
|
||||
var bgAlwaysWhite: Boolean? = null
|
||||
) : Page(index, url, imageUrl, null) {
|
||||
|
||||
lateinit var chapter: ReaderChapter
|
||||
|
@ -3,7 +3,9 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
import android.graphics.PointF
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.view.GestureDetector
|
||||
@ -29,6 +31,8 @@ import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||
import com.github.chrisbanes.photoview.PhotoView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressBar
|
||||
@ -45,6 +49,7 @@ import rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.schedulers.Schedulers
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.io.InputStream
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@ -248,9 +253,10 @@ class PagerPageHolder(
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext { isAnimated ->
|
||||
if (!isAnimated) {
|
||||
if (viewer.config.readerTheme == 2) {
|
||||
if (viewer.config.readerTheme >= 2) {
|
||||
val imageView = initSubsamplingImageView()
|
||||
if (page.bg != null) {
|
||||
if (page.bg != null &&
|
||||
page.bgAlwaysWhite == (viewer.config.readerTheme == 2)) {
|
||||
imageView.setImage(ImageSource.inputStream(openStream!!))
|
||||
imageView.background = page.bg
|
||||
}
|
||||
@ -264,6 +270,7 @@ class PagerPageHolder(
|
||||
launchUI {
|
||||
imageView.background = setBG(bytesArray)
|
||||
page.bg = imageView.background
|
||||
page.bgAlwaysWhite = viewer.config.readerTheme == 2
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -273,7 +280,7 @@ class PagerPageHolder(
|
||||
} else {
|
||||
val imageView = initImageView()
|
||||
imageView.setImage(openStream!!)
|
||||
if (viewer.config.readerTheme == 2 && page.bg != null)
|
||||
if (viewer.config.readerTheme >= 2 && page.bg != null)
|
||||
imageView.background = page.bg
|
||||
}
|
||||
}
|
||||
@ -285,9 +292,10 @@ class PagerPageHolder(
|
||||
|
||||
private suspend fun setBG(bytesArray: ByteArray): Drawable {
|
||||
return withContext(Default) {
|
||||
val preferences by injectLazy<PreferencesHelper>()
|
||||
ImageUtil.autoSetBackground(BitmapFactory.decodeByteArray(
|
||||
bytesArray, 0, bytesArray.size
|
||||
))
|
||||
), preferences.readerTheme().getOrDefault() == 2)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,9 @@ class SettingsReaderController : SettingsController() {
|
||||
intListPreference {
|
||||
key = Keys.readerTheme
|
||||
titleRes = R.string.pref_reader_theme
|
||||
entriesRes = arrayOf(R.string.white_background, R.string.black_background, R.string.zoom_start_automatic)
|
||||
entryValues = arrayOf("0", "1", "2")
|
||||
entriesRes = arrayOf(R.string.white_background, R.string.black_background, R.string
|
||||
.reader_theme_smart, R.string.reader_theme_smart_theme)
|
||||
entryValues = arrayOf("0", "1", "2", "3")
|
||||
defaultValue = "0"
|
||||
summary = "%s"
|
||||
}
|
||||
|
@ -53,9 +53,10 @@ object ImageUtil {
|
||||
return null
|
||||
}
|
||||
|
||||
fun autoSetBackground(image: Bitmap): Drawable {
|
||||
fun autoSetBackground(image: Bitmap, useWhiteAlways: Boolean): Drawable {
|
||||
val backgroundColor = if (useWhiteAlways) Color.WHITE else android.R.attr.colorBackground
|
||||
if (image.width < 50 || image.height < 50)
|
||||
return ColorDrawable(android.R.attr.colorBackground)
|
||||
return ColorDrawable(backgroundColor)
|
||||
val top = 5
|
||||
val bot = image.height - 5
|
||||
val left = (image.width * 0.0275).toInt()
|
||||
@ -94,7 +95,7 @@ object ImageUtil {
|
||||
topRightIsDark -> image.getPixel(right, top)
|
||||
botLeftIsDark -> image.getPixel(left, bot)
|
||||
botRightIsDark -> image.getPixel(right, bot)
|
||||
else -> android.R.attr.colorBackground
|
||||
else -> backgroundColor
|
||||
}
|
||||
|
||||
var overallWhitePixels = 0
|
||||
@ -179,25 +180,24 @@ object ImageUtil {
|
||||
darkBG = false
|
||||
if (topIsBlackStreak && bottomIsBlackStreak)
|
||||
darkBG = true
|
||||
val whiteColor = android.R.attr.colorBackground
|
||||
if (darkBG) {
|
||||
return if (isWhite(image.getPixel(left, bot)) && isWhite(image.getPixel(right, bot))) GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
|
||||
intArrayOf(blackPixel, blackPixel, whiteColor, whiteColor))
|
||||
intArrayOf(blackPixel, blackPixel, backgroundColor, backgroundColor))
|
||||
else if (isWhite(image.getPixel(left, top)) && isWhite(image.getPixel(right, top))) GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
|
||||
intArrayOf(whiteColor, whiteColor, blackPixel, blackPixel))
|
||||
intArrayOf(backgroundColor, backgroundColor, blackPixel, blackPixel))
|
||||
else ColorDrawable(blackPixel)
|
||||
}
|
||||
if (topIsBlackStreak || (topLeftIsDark && topRightIsDark
|
||||
&& isDark(image.getPixel(left - offsetX, top)) && isDark(image.getPixel(right + offsetX, top))
|
||||
&& (topMidIsDark || overallBlackPixels > 9)))
|
||||
return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
|
||||
intArrayOf(blackPixel, blackPixel, whiteColor, whiteColor))
|
||||
intArrayOf(blackPixel, blackPixel, backgroundColor, backgroundColor))
|
||||
else if (bottomIsBlackStreak || (botLeftIsDark && botRightIsDark
|
||||
&& isDark(image.getPixel(left - offsetX, bot)) && isDark(image.getPixel(right + offsetX, bot))
|
||||
&& (isDark(image.getPixel(midX, bot)) || overallBlackPixels > 9)))
|
||||
return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
|
||||
intArrayOf(whiteColor, whiteColor, blackPixel, blackPixel))
|
||||
return ColorDrawable(whiteColor)
|
||||
intArrayOf(backgroundColor, backgroundColor, blackPixel, blackPixel))
|
||||
return ColorDrawable(backgroundColor)
|
||||
}
|
||||
|
||||
fun Boolean.toInt() = if (this) 1 else 0
|
||||
|
@ -25,7 +25,8 @@
|
||||
<string-array name="reader_themes">
|
||||
<item>@string/white_background</item>
|
||||
<item>@string/black_background</item>
|
||||
<item>@string/auto_background</item>
|
||||
<item>@string/smart_background</item>
|
||||
<item>@string/smart_theme_background</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="reader_themes_values">
|
||||
|
@ -241,7 +241,8 @@
|
||||
<string name="pref_reader_theme">Background color</string>
|
||||
<string name="white_background">White</string>
|
||||
<string name="black_background">Black</string>
|
||||
<string name="auto_background">Automatic</string>
|
||||
<string name="smart_background">Smart (by page)</string>
|
||||
<string name="smart_theme_background">Smart (by theme)</string>
|
||||
<string name="pref_viewer_type">Default viewer</string>
|
||||
<string name="default_viewer">Default</string>
|
||||
<string name="left_to_right_viewer">Left to right</string>
|
||||
@ -274,6 +275,8 @@
|
||||
<string name="color_filter_g_value">G</string>
|
||||
<string name="color_filter_b_value">B</string>
|
||||
<string name="color_filter_a_value">A</string>
|
||||
<string name="reader_theme_smart">Smart (based on page)</string>
|
||||
<string name="reader_theme_smart_theme">Smart (based on page and theme)</string>
|
||||
|
||||
|
||||
<!-- Downloads section -->
|
||||
|
Loading…
Reference in New Issue
Block a user