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.util.AttributeSet
import android.view.Window
import android.view.WindowManager
import android.widget.SeekBar
import androidx.annotation.ColorInt
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.onEach
import kotlinx.coroutines.flow.sample
import kotlin.math.max
class ReaderFilterView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
BaseReaderSettingsView<ReaderColorFilterBinding>(context, attrs) {
var window: Window? = null
override fun inflateBinding() = ReaderColorFilterBinding.bind(this)
override fun initGeneralPreferences() {
activity = context as? ReaderActivity ?: return
@ -166,6 +171,10 @@ class ReaderFilterView @JvmOverloads constructor(context: Context, attrs: Attrib
setCustomBrightnessSeekBar(enabled)
}
fun setWindowBrightness() {
setCustomBrightnessValue(preferences.customBrightnessValue().get(), !preferences.customBrightness().get())
}
/**
* 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.
@ -176,6 +185,9 @@ class ReaderFilterView @JvmOverloads constructor(context: Context, attrs: Attrib
// Set black overlay visibility.
if (!isDisabled) {
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
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 eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.main.SearchActivity
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.visible
import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog
class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) : TabbedBottomSheetDialog(
readerActivity
) {
class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) :
TabbedBottomSheetDialog(readerActivity) {
private val generalView: ReaderGeneralView = View.inflate(
readerActivity,
R.layout.reader_general_layout,
@ -48,10 +51,12 @@ class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) : TabbedBott
R.string.filter
)
var sheetBehavior: BottomSheetBehavior<*>
init {
generalView.activity = readerActivity
pagedView.activity = readerActivity
filterView.activity = readerActivity
filterView.window = window
generalView.sheet = this
sheetBehavior = BottomSheetBehavior.from(binding.root.parent as ViewGroup)
@ -78,6 +83,15 @@ class TabbedReaderSettingsSheet(val readerActivity: ReaderActivity) : TabbedBott
override fun onTabSelected(tab: TabLayout.Tab?) {
window?.setDimAmount(if (tab?.position == 2) 0f else ogDim)
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?) {