Reader screen orientation settings
This commit is contained in:
@@ -16,8 +16,8 @@ android {
|
||||
applicationId 'org.koitharu.kotatsu'
|
||||
minSdk = 21
|
||||
targetSdk = 35
|
||||
versionCode = 680
|
||||
versionName = '7.7-a1'
|
||||
versionCode = 681
|
||||
versionName = '7.7-a2'
|
||||
generatedDensities = []
|
||||
testInstrumentationRunner 'org.koitharu.kotatsu.HiltTestRunner'
|
||||
ksp {
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.core.prefs
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
@@ -119,6 +120,10 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||
get() = prefs.getBoolean(KEY_READER_DOUBLE_PAGES, false)
|
||||
set(value) = prefs.edit { putBoolean(KEY_READER_DOUBLE_PAGES, value) }
|
||||
|
||||
val readerScreenOrientation: Int
|
||||
get() = prefs.getString(KEY_READER_ORIENTATION, null)?.toIntOrNull()
|
||||
?: ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||
|
||||
val isReaderVolumeButtonsEnabled: Boolean
|
||||
get() = prefs.getBoolean(KEY_READER_VOLUME_BUTTONS, false)
|
||||
|
||||
@@ -588,6 +593,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
||||
const val KEY_READER_CONTROL_LTR = "reader_taps_ltr"
|
||||
const val KEY_READER_FULLSCREEN = "reader_fullscreen"
|
||||
const val KEY_READER_VOLUME_BUTTONS = "reader_volume_buttons"
|
||||
const val KEY_READER_ORIENTATION = "reader_orientation"
|
||||
const val KEY_TRACKER_ENABLED = "tracker_enabled"
|
||||
const val KEY_TRACKER_WIFI_ONLY = "tracker_wifi"
|
||||
const val KEY_TRACKER_FREQUENCY = "tracker_freq"
|
||||
|
||||
@@ -12,6 +12,7 @@ import kotlinx.coroutines.channels.trySendBlocking
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
@@ -338,6 +339,7 @@ class MangaSourcesRepository @Inject constructor(
|
||||
}.map {
|
||||
getExternalSources()
|
||||
}.distinctUntilChanged()
|
||||
.conflate()
|
||||
}
|
||||
|
||||
private fun getExternalSources() = context.packageManager.queryIntentContentProviders(
|
||||
|
||||
@@ -32,8 +32,8 @@ import okio.use
|
||||
import org.koitharu.kotatsu.core.network.CommonHeaders
|
||||
import org.koitharu.kotatsu.core.network.MangaHttpClient
|
||||
import org.koitharu.kotatsu.core.network.imageproxy.ImageProxyInterceptor
|
||||
import org.koitharu.kotatsu.core.parser.CachingMangaRepository
|
||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||
import org.koitharu.kotatsu.core.parser.ParserMangaRepository
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.util.FileSize
|
||||
import org.koitharu.kotatsu.core.util.RetainedLifecycleCoroutineScope
|
||||
@@ -93,7 +93,7 @@ class PageLoader @Inject constructor(
|
||||
private val edgeDetector = EdgeDetector(context)
|
||||
|
||||
fun isPrefetchApplicable(): Boolean {
|
||||
return repository is ParserMangaRepository
|
||||
return repository is CachingMangaRepository
|
||||
&& settings.isPagesPreloadEnabled
|
||||
&& !context.isPowerSaveMode()
|
||||
&& !isLowRam()
|
||||
|
||||
@@ -83,6 +83,12 @@ class ReaderActivity :
|
||||
@Inject
|
||||
lateinit var tapGridSettings: TapGridSettings
|
||||
|
||||
@Inject
|
||||
lateinit var scrollTimerFactory: ScrollTimer.Factory
|
||||
|
||||
@Inject
|
||||
lateinit var screenOrientationHelper: ScreenOrientationHelper
|
||||
|
||||
private val idlingDetector = IdlingDetector(TimeUnit.SECONDS.toMillis(10), this)
|
||||
private val savePageRequest = registerForActivityResult(PageSaveContract(), this)
|
||||
|
||||
@@ -97,9 +103,6 @@ class ReaderActivity :
|
||||
scrollTimer.isEnabled = value
|
||||
}
|
||||
|
||||
@Inject
|
||||
lateinit var scrollTimerFactory: ScrollTimer.Factory
|
||||
|
||||
private lateinit var scrollTimer: ScrollTimer
|
||||
private lateinit var touchHelper: TapGridDispatcher
|
||||
private lateinit var controlDelegate: ReaderControlDelegate
|
||||
@@ -110,6 +113,7 @@ class ReaderActivity :
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(ActivityReaderBinding.inflate(layoutInflater))
|
||||
screenOrientationHelper.init(settings.readerScreenOrientation)
|
||||
readerManager = ReaderManager(supportFragmentManager, viewBinding.container, settings)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
touchHelper = TapGridDispatcher(this, this)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.koitharu.kotatsu.core.util
|
||||
package org.koitharu.kotatsu.reader.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.pm.ActivityInfo
|
||||
@@ -10,6 +10,7 @@ import dagger.hilt.android.scopes.ActivityScoped
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.channels.trySendBlocking
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import javax.inject.Inject
|
||||
@@ -44,6 +45,13 @@ class ScreenOrientationHelper @Inject constructor(private val activity: Activity
|
||||
}
|
||||
}
|
||||
|
||||
fun init(orientation: Int) {
|
||||
if (activity.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
|
||||
// https://developer.android.com/reference/android/R.attr.html#screenOrientation
|
||||
activity.requestedOrientation = orientation
|
||||
}
|
||||
}
|
||||
|
||||
fun observeAutoOrientation() = callbackFlow {
|
||||
val observer = object : ContentObserver(Handler(activity.mainLooper)) {
|
||||
override fun onChange(selfChange: Boolean) {
|
||||
@@ -59,4 +67,5 @@ class ScreenOrientationHelper @Inject constructor(private val activity: Activity
|
||||
}.onStart {
|
||||
emit(isAutoRotationEnabled)
|
||||
}.distinctUntilChanged()
|
||||
.conflate()
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||
import org.koitharu.kotatsu.core.prefs.observeAsStateFlow
|
||||
import org.koitharu.kotatsu.core.ui.sheet.BaseAdaptiveSheet
|
||||
import org.koitharu.kotatsu.core.util.ScreenOrientationHelper
|
||||
import org.koitharu.kotatsu.core.util.ext.findParentCallback
|
||||
import org.koitharu.kotatsu.core.util.ext.observe
|
||||
import org.koitharu.kotatsu.core.util.ext.showDistinct
|
||||
@@ -33,6 +32,7 @@ import org.koitharu.kotatsu.core.util.ext.withArgs
|
||||
import org.koitharu.kotatsu.databinding.SheetReaderConfigBinding
|
||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||
import org.koitharu.kotatsu.reader.ui.ReaderViewModel
|
||||
import org.koitharu.kotatsu.reader.ui.ScreenOrientationHelper
|
||||
import org.koitharu.kotatsu.reader.ui.colorfilter.ColorFilterConfigActivity
|
||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.settings
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.preference.ListPreference
|
||||
@@ -38,6 +39,15 @@ class ReaderSettingsFragment :
|
||||
)
|
||||
setDefaultValueCompat(ReaderMode.STANDARD.name)
|
||||
}
|
||||
findPreference<ListPreference>(AppSettings.KEY_READER_ORIENTATION)?.run {
|
||||
entryValues = arrayOf(
|
||||
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED.toString(),
|
||||
ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR.toString(),
|
||||
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT.toString(),
|
||||
ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE.toString(),
|
||||
)
|
||||
setDefaultValueCompat(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED.toString())
|
||||
}
|
||||
findPreference<ListPreference>(AppSettings.KEY_READER_BACKGROUND)?.run {
|
||||
entryValues = ReaderBackground.entries.names()
|
||||
setDefaultValueCompat(ReaderBackground.DEFAULT.name)
|
||||
|
||||
@@ -118,4 +118,10 @@
|
||||
<item>@string/ask_every_time</item>
|
||||
<item>@string/dont_allow</item>
|
||||
</string-array>
|
||||
<string-array name="screen_orientations" translatable="false">
|
||||
<item>@string/system_default</item>
|
||||
<item>@string/automatic</item>
|
||||
<item>@string/portrait</item>
|
||||
<item>@string/landscape</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
@@ -754,4 +754,7 @@
|
||||
<string name="allow_always">Allow always</string>
|
||||
<string name="allow_once">Allow once</string>
|
||||
<string name="ask_every_time">Ask every time</string>
|
||||
<string name="screen_orientation">Screen orientation</string>
|
||||
<string name="portrait">Portrait</string>
|
||||
<string name="landscape">Landscape</string>
|
||||
</resources>
|
||||
|
||||
@@ -101,11 +101,24 @@
|
||||
android:title="@string/fullscreen_mode"
|
||||
app:allowDividerAbove="true" />
|
||||
|
||||
<ListPreference
|
||||
android:entries="@array/screen_orientations"
|
||||
android:key="reader_orientation"
|
||||
android:title="@string/screen_orientation"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="reader_screen_on"
|
||||
android:summary="@string/keep_screen_on_summary"
|
||||
android:title="@string/keep_screen_on" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="reader_bar"
|
||||
android:summary="@string/reader_info_bar_summary"
|
||||
android:title="@string/reader_info_bar" />
|
||||
android:title="@string/reader_info_bar"
|
||||
app:allowDividerAbove="true" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
@@ -122,14 +135,7 @@
|
||||
android:defaultValue="false"
|
||||
android:key="pages_numbers"
|
||||
android:summary="@string/show_pages_numbers_summary"
|
||||
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" />
|
||||
android:title="@string/show_pages_numbers" />x
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="2"
|
||||
|
||||
Reference in New Issue
Block a user