mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 19:55:11 +01:00
Fix #686
This commit is contained in:
parent
b7b91f4230
commit
bb26e3cc92
@ -2,6 +2,8 @@ package eu.kanade.tachiyomi.ui.reader.settings
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
|
import android.view.Window
|
||||||
|
import android.view.WindowManager
|
||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import eu.kanade.tachiyomi.databinding.ReaderColorFilterBinding
|
import eu.kanade.tachiyomi.databinding.ReaderColorFilterBinding
|
||||||
@ -11,10 +13,13 @@ import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
|
|||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.sample
|
import kotlinx.coroutines.flow.sample
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
class ReaderFilterView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
class ReaderFilterView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||||
BaseReaderSettingsView<ReaderColorFilterBinding>(context, attrs) {
|
BaseReaderSettingsView<ReaderColorFilterBinding>(context, attrs) {
|
||||||
|
|
||||||
|
var window: Window? = null
|
||||||
|
|
||||||
override fun inflateBinding() = ReaderColorFilterBinding.bind(this)
|
override fun inflateBinding() = ReaderColorFilterBinding.bind(this)
|
||||||
override fun initGeneralPreferences() {
|
override fun initGeneralPreferences() {
|
||||||
activity = context as? ReaderActivity ?: return
|
activity = context as? ReaderActivity ?: return
|
||||||
@ -166,6 +171,10 @@ class ReaderFilterView @JvmOverloads constructor(context: Context, attrs: Attrib
|
|||||||
setCustomBrightnessSeekBar(enabled)
|
setCustomBrightnessSeekBar(enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setWindowBrightness() {
|
||||||
|
setCustomBrightnessValue(preferences.customBrightnessValue().get(), !preferences.customBrightness().get())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the brightness of the screen. Range is [-75, 100].
|
* Sets the brightness of the screen. Range is [-75, 100].
|
||||||
* From -75 to -1 a semi-transparent black view is shown at the top with the minimum brightness.
|
* From -75 to -1 a semi-transparent black view is shown at the top with the minimum brightness.
|
||||||
@ -176,6 +185,9 @@ class ReaderFilterView @JvmOverloads constructor(context: Context, attrs: Attrib
|
|||||||
// Set black overlay visibility.
|
// Set black overlay visibility.
|
||||||
if (!isDisabled) {
|
if (!isDisabled) {
|
||||||
binding.txtBrightnessSeekbarValue.text = value.toString()
|
binding.txtBrightnessSeekbarValue.text = value.toString()
|
||||||
|
window?.attributes = window?.attributes?.apply { screenBrightness = max(0.01f, value / 100f) }
|
||||||
|
} else {
|
||||||
|
window?.attributes = window?.attributes?.apply { screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
package eu.kanade.tachiyomi.ui.reader.settings
|
package eu.kanade.tachiyomi.ui.reader.settings
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import com.google.android.material.tabs.TabLayout
|
import com.google.android.material.tabs.TabLayout
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.ui.main.SearchActivity
|
import eu.kanade.tachiyomi.ui.main.SearchActivity
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||||
import eu.kanade.tachiyomi.util.view.gone
|
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||||
|
import eu.kanade.tachiyomi.util.view.expand
|
||||||
import eu.kanade.tachiyomi.util.view.visInvisIf
|
import eu.kanade.tachiyomi.util.view.visInvisIf
|
||||||
import eu.kanade.tachiyomi.util.view.visible
|
import eu.kanade.tachiyomi.util.view.visible
|
||||||
import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog
|
import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog
|
||||||
|
|
||||||
class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) : TabbedBottomSheetDialog(
|
class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) :
|
||||||
readerActivity
|
TabbedBottomSheetDialog(readerActivity) {
|
||||||
) {
|
|
||||||
private val generalView: ReaderGeneralView = View.inflate(
|
private val generalView: ReaderGeneralView = View.inflate(
|
||||||
readerActivity,
|
readerActivity,
|
||||||
R.layout.reader_general_layout,
|
R.layout.reader_general_layout,
|
||||||
@ -48,10 +51,12 @@ class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) : TabbedBott
|
|||||||
R.string.filter
|
R.string.filter
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var sheetBehavior: BottomSheetBehavior<*>
|
||||||
init {
|
init {
|
||||||
generalView.activity = readerActivity
|
generalView.activity = readerActivity
|
||||||
pagedView.activity = readerActivity
|
pagedView.activity = readerActivity
|
||||||
filterView.activity = readerActivity
|
filterView.activity = readerActivity
|
||||||
|
filterView.window = window
|
||||||
generalView.sheet = this
|
generalView.sheet = this
|
||||||
|
|
||||||
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
|
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
|
||||||
@ -78,6 +83,15 @@ class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) : TabbedBott
|
|||||||
override fun onTabSelected(tab: TabLayout.Tab?) {
|
override fun onTabSelected(tab: TabLayout.Tab?) {
|
||||||
window?.setDimAmount(if (tab?.position == 2) 0f else ogDim)
|
window?.setDimAmount(if (tab?.position == 2) 0f else ogDim)
|
||||||
readerActivity.binding.appBar.visInvisIf(tab?.position != 2)
|
readerActivity.binding.appBar.visInvisIf(tab?.position != 2)
|
||||||
|
if (tab?.position == 2) {
|
||||||
|
sheetBehavior.skipCollapsed = false
|
||||||
|
sheetBehavior.peekHeight = 100.dpToPx
|
||||||
|
filterView.setWindowBrightness()
|
||||||
|
} else {
|
||||||
|
sheetBehavior.expand()
|
||||||
|
sheetBehavior.skipCollapsed = true
|
||||||
|
window?.attributes = window?.attributes?.apply { screenBrightness = 0.01f }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTabUnselected(tab: TabLayout.Tab?) {
|
override fun onTabUnselected(tab: TabLayout.Tab?) {
|
||||||
|
Loading…
Reference in New Issue
Block a user