Reader background option
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.koitharu.kotatsu.reader.ui.config
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.view.View
|
||||
import androidx.lifecycle.MediatorLiveData
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -31,6 +32,11 @@ class ReaderSettings(
|
||||
val isPagesNumbersEnabled: Boolean
|
||||
get() = settings.isPagesNumbersEnabled
|
||||
|
||||
fun applyBackground(view: View) {
|
||||
val bg = settings.readerBackground
|
||||
view.background = bg.resolve(view.context)
|
||||
}
|
||||
|
||||
override fun onInactive() {
|
||||
super.onInactive()
|
||||
settings.unsubscribe(internalObserver)
|
||||
@@ -64,7 +70,12 @@ class ReaderSettings(
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
if (key == AppSettings.KEY_ZOOM_MODE || key == AppSettings.KEY_PAGES_NUMBERS || key == AppSettings.KEY_WEBTOON_ZOOM) {
|
||||
if (
|
||||
key == AppSettings.KEY_ZOOM_MODE ||
|
||||
key == AppSettings.KEY_PAGES_NUMBERS ||
|
||||
key == AppSettings.KEY_WEBTOON_ZOOM ||
|
||||
key == AppSettings.KEY_READER_BACKGROUND
|
||||
) {
|
||||
notifyChanged()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||
abstract class BasePageHolder<B : ViewBinding>(
|
||||
protected val binding: B,
|
||||
loader: PageLoader,
|
||||
settings: ReaderSettings,
|
||||
private val settings: ReaderSettings,
|
||||
networkState: NetworkState,
|
||||
exceptionResolver: ExceptionResolver,
|
||||
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
|
||||
@@ -28,6 +28,10 @@ abstract class BasePageHolder<B : ViewBinding>(
|
||||
var boundData: ReaderPage? = null
|
||||
private set
|
||||
|
||||
override fun onConfigChanged() {
|
||||
settings.applyBackground(itemView)
|
||||
}
|
||||
|
||||
fun requireData(): ReaderPage {
|
||||
return checkNotNull(boundData) { "Calling requireData() before bind()" }
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.plus
|
||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||
import org.koitharu.kotatsu.core.os.NetworkState
|
||||
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||
import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
@@ -39,6 +39,10 @@ class PageHolderDelegate(
|
||||
private var file: File? = null
|
||||
private var error: Throwable? = null
|
||||
|
||||
init {
|
||||
callback.onConfigChanged()
|
||||
}
|
||||
|
||||
fun onBind(page: MangaPage) {
|
||||
val prevJob = job
|
||||
job = scope.launch {
|
||||
@@ -107,6 +111,7 @@ class PageHolderDelegate(
|
||||
if (state == State.SHOWN) {
|
||||
callback.onImageShowing(readerSettings)
|
||||
}
|
||||
callback.onConfigChanged()
|
||||
}
|
||||
|
||||
private fun tryConvert(file: File, e: Exception) {
|
||||
@@ -178,5 +183,7 @@ class PageHolderDelegate(
|
||||
fun onImageShown()
|
||||
|
||||
fun onProgressChanged(progress: Int)
|
||||
|
||||
fun onConfigChanged()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user