This commit is contained in:
Jays2Kings 2021-03-30 02:11:32 -04:00
parent b7b91f4230
commit bb26e3cc92
2 changed files with 30 additions and 4 deletions

View File

@ -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 }
} }
} }

View File

@ -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?) {