Hide cutout toggle button if fullscreen is off (#6150)

This commit is contained in:
Riztard Lanthorn 2021-10-30 23:19:15 +07:00 committed by GitHub
parent f0a5557e60
commit 33a02b47d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -5,11 +5,14 @@ import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView import androidx.core.widget.NestedScrollView
import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.databinding.ReaderGeneralSettingsBinding import eu.kanade.tachiyomi.databinding.ReaderGeneralSettingsBinding
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.util.preference.bindToPreference import eu.kanade.tachiyomi.util.preference.bindToPreference
import kotlinx.coroutines.flow.launchIn
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
/** /**
@ -35,15 +38,17 @@ class ReaderGeneralSettings @JvmOverloads constructor(context: Context, attrs: A
binding.backgroundColor.bindToIntPreference(preferences.readerTheme(), R.array.reader_themes_values) binding.backgroundColor.bindToIntPreference(preferences.readerTheme(), R.array.reader_themes_values)
binding.showPageNumber.bindToPreference(preferences.showPageNumber()) binding.showPageNumber.bindToPreference(preferences.showPageNumber())
binding.fullscreen.bindToPreference(preferences.fullscreen()) binding.fullscreen.bindToPreference(preferences.fullscreen())
preferences.fullscreen()
.asImmediateFlow {
// If the preference is explicitly disabled, that means the setting was configured since there is a cutout
binding.cutoutShort.isVisible = it && ((context as ReaderActivity).hasCutout || !preferences.cutoutShort().get())
binding.cutoutShort.bindToPreference(preferences.cutoutShort())
}
.launchIn((context as ReaderActivity).lifecycleScope)
binding.keepscreen.bindToPreference(preferences.keepScreenOn()) binding.keepscreen.bindToPreference(preferences.keepScreenOn())
binding.longTap.bindToPreference(preferences.readWithLongTap()) binding.longTap.bindToPreference(preferences.readWithLongTap())
binding.alwaysShowChapterTransition.bindToPreference(preferences.alwaysShowChapterTransition()) binding.alwaysShowChapterTransition.bindToPreference(preferences.alwaysShowChapterTransition())
binding.pageTransitions.bindToPreference(preferences.pageTransitions()) binding.pageTransitions.bindToPreference(preferences.pageTransitions())
// If the preference is explicitly disabled, that means the setting was configured since there is a cutout
if ((context as ReaderActivity).hasCutout || !preferences.cutoutShort().get()) {
binding.cutoutShort.isVisible = true
binding.cutoutShort.bindToPreference(preferences.cutoutShort())
}
} }
} }

View File

@ -111,6 +111,7 @@ class SettingsReaderController : SettingsController() {
key = Keys.cutoutShort key = Keys.cutoutShort
titleRes = R.string.pref_cutout_short titleRes = R.string.pref_cutout_short
defaultValue = true defaultValue = true
preferences.fullscreen().asImmediateFlow { isVisible = it }.launchIn(viewScope)
} }
} }