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