Make keep screen on in reader optional

This commit is contained in:
Koitharu
2023-10-02 16:39:14 +03:00
parent cfda150630
commit b2927854d4
7 changed files with 30 additions and 4 deletions

View File

@@ -90,7 +90,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.core:core-ktx:1.12.0' implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.activity:activity-ktx:1.7.2' implementation 'androidx.activity:activity-ktx:1.8.0-rc01'
implementation 'androidx.fragment:fragment-ktx:1.6.1' implementation 'androidx.fragment:fragment-ktx:1.6.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'

View File

@@ -270,6 +270,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
val isReaderSliderEnabled: Boolean val isReaderSliderEnabled: Boolean
get() = prefs.getBoolean(KEY_READER_SLIDER, true) get() = prefs.getBoolean(KEY_READER_SLIDER, true)
val isReaderKeepScreenOn: Boolean
get() = prefs.getBoolean(KEY_READER_SCREEN_ON, true)
val isImagesProxyEnabled: Boolean val isImagesProxyEnabled: Boolean
get() = prefs.getBoolean(KEY_IMAGES_PROXY, false) get() = prefs.getBoolean(KEY_IMAGES_PROXY, false)
@@ -460,6 +463,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
const val KEY_READER_BAR = "reader_bar" const val KEY_READER_BAR = "reader_bar"
const val KEY_READER_SLIDER = "reader_slider" const val KEY_READER_SLIDER = "reader_slider"
const val KEY_READER_BACKGROUND = "reader_background" const val KEY_READER_BACKGROUND = "reader_background"
const val KEY_READER_SCREEN_ON = "reader_screen_on"
const val KEY_SHORTCUTS = "dynamic_shortcuts" const val KEY_SHORTCUTS = "dynamic_shortcuts"
const val KEY_READER_TAPS_LTR = "reader_taps_ltr" const val KEY_READER_TAPS_LTR = "reader_taps_ltr"
const val KEY_LOCAL_LIST_ORDER = "local_order" const val KEY_LOCAL_LIST_ORDER = "local_order"

View File

@@ -137,6 +137,7 @@ class ReaderActivity :
onLoadingStateChanged(viewModel.isLoading.value) onLoadingStateChanged(viewModel.isLoading.value)
} }
viewModel.isScreenshotsBlockEnabled.observe(this, this::setWindowSecure) viewModel.isScreenshotsBlockEnabled.observe(this, this::setWindowSecure)
viewModel.isKeepScreenOnEnabled.observe(this, this::setKeepScreenOn)
viewModel.isInfoBarEnabled.observe(this, ::onReaderBarChanged) viewModel.isInfoBarEnabled.observe(this, ::onReaderBarChanged)
viewModel.isBookmarkAdded.observe(this, this::onBookmarkStateChanged) viewModel.isBookmarkAdded.observe(this, this::onBookmarkStateChanged)
viewModel.onShowToast.observeEvent(this) { msgId -> viewModel.onShowToast.observeEvent(this) { msgId ->
@@ -304,6 +305,14 @@ class ReaderActivity :
} }
} }
private fun setKeepScreenOn(isKeep: Boolean) {
if (isKeep) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
private fun setUiIsVisible(isUiVisible: Boolean) { private fun setUiIsVisible(isUiVisible: Boolean) {
if (viewBinding.appbarTop.isVisible != isUiVisible) { if (viewBinding.appbarTop.isVisible != isUiVisible) {
if (isAnimationsEnabled) { if (isAnimationsEnabled) {

View File

@@ -113,6 +113,12 @@ class ReaderViewModel @Inject constructor(
valueProducer = { isReaderBarEnabled }, valueProducer = { isReaderBarEnabled },
) )
val isKeepScreenOnEnabled = settings.observeAsStateFlow(
scope = viewModelScope + Dispatchers.Default,
key = AppSettings.KEY_READER_SCREEN_ON,
valueProducer = { isReaderKeepScreenOn },
)
val isWebtoonZoomEnabled = settings.observeAsStateFlow( val isWebtoonZoomEnabled = settings.observeAsStateFlow(
scope = viewModelScope + Dispatchers.Default, scope = viewModelScope + Dispatchers.Default,
key = AppSettings.KEY_WEBTOON_ZOOM, key = AppSettings.KEY_WEBTOON_ZOOM,

View File

@@ -4,8 +4,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:keepScreenOn="true">
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
android:id="@+id/container" android:id="@+id/container"

View File

@@ -489,4 +489,6 @@
<string name="zoom_in">Zoom in</string> <string name="zoom_in">Zoom in</string>
<string name="reader_zoom_buttons">Show zoom buttons</string> <string name="reader_zoom_buttons">Show zoom buttons</string>
<string name="reader_zoom_buttons_summary">Whether to show zoom control buttons in the bottom right corner</string> <string name="reader_zoom_buttons_summary">Whether to show zoom control buttons in the bottom right corner</string>
<string name="keep_screen_on">Keep screen on</string>
<string name="keep_screen_on_summary">Do not turn the screen off while you\'re reading manga</string>
</resources> </resources>

View File

@@ -78,13 +78,19 @@
android:summary="@string/show_pages_numbers_summary" android:summary="@string/show_pages_numbers_summary"
android:title="@string/show_pages_numbers" /> android:title="@string/show_pages_numbers" />
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="reader_screen_on"
android:summary="@string/keep_screen_on_summary"
android:title="@string/keep_screen_on"
app:allowDividerAbove="true" />
<ListPreference <ListPreference
android:defaultValue="allow" android:defaultValue="allow"
android:entries="@array/screenshots_policy" android:entries="@array/screenshots_policy"
android:entryValues="@array/values_screenshots_policy" android:entryValues="@array/values_screenshots_policy"
android:key="screenshots_policy" android:key="screenshots_policy"
android:title="@string/screenshots_policy" android:title="@string/screenshots_policy"
app:allowDividerAbove="true"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
<ListPreference <ListPreference