mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 06:17:57 +01:00 
			
		
		
		
	Remove "Locked" orientation, replace with explicit orientations
Portrait/Landscape allow sensor, Locked Portrait/Landscape don't.
This commit is contained in:
		| @@ -139,6 +139,10 @@ object Migrations { | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             if (oldVersion < 59) { | ||||
|                 // Reset rotation to Free after replacing Lock | ||||
|                 preferences.rotation().set(1) | ||||
|             } | ||||
|             return true | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -372,8 +372,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>() | ||||
|             setTooltip(R.string.pref_rotation_type) | ||||
|  | ||||
|             setOnClickListener { | ||||
|                 val newOrientation = | ||||
|                     OrientationType.getNextOrientation(preferences.rotation().get(), resources) | ||||
|                 val newOrientation = OrientationType.getNextOrientation(preferences.rotation().get()) | ||||
|  | ||||
|                 preferences.rotation().set(newOrientation.prefValue) | ||||
|                 setOrientation(newOrientation.flag) | ||||
| @@ -422,7 +421,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>() | ||||
|     } | ||||
|  | ||||
|     private fun updateRotationShortcut(preference: Int) { | ||||
|         val orientation = OrientationType.fromPreference(preference, resources) | ||||
|         val orientation = OrientationType.fromPreference(preference) | ||||
|         binding.actionRotation.setImageResource(orientation.iconRes) | ||||
|     } | ||||
|  | ||||
| @@ -768,7 +767,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>() | ||||
|      * Forces the user preferred [orientation] on the activity. | ||||
|      */ | ||||
|     private fun setOrientation(orientation: Int) { | ||||
|         val newOrientation = OrientationType.fromPreference(orientation, resources) | ||||
|         val newOrientation = OrientationType.fromPreference(orientation) | ||||
|         if (newOrientation.flag != requestedOrientation) { | ||||
|             requestedOrientation = newOrientation.flag | ||||
|         } | ||||
|   | ||||
| @@ -1,8 +1,6 @@ | ||||
| package eu.kanade.tachiyomi.ui.reader.setting | ||||
|  | ||||
| import android.content.pm.ActivityInfo | ||||
| import android.content.res.Configuration | ||||
| import android.content.res.Resources | ||||
| import androidx.annotation.DrawableRes | ||||
| import androidx.annotation.StringRes | ||||
| import eu.kanade.tachiyomi.R | ||||
| @@ -10,33 +8,18 @@ import eu.kanade.tachiyomi.util.lang.next | ||||
|  | ||||
| enum class OrientationType(val prefValue: Int, val flag: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int) { | ||||
|     FREE(1, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, R.string.rotation_free, R.drawable.ic_screen_rotation_24dp), | ||||
|     LOCKED_PORTRAIT(2, ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT, R.string.rotation_lock, R.drawable.ic_screen_lock_rotation_24dp), | ||||
|     LOCKED_LANDSCAPE(2, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, R.string.rotation_lock, R.drawable.ic_screen_lock_rotation_24dp), | ||||
|     PORTRAIT(3, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, R.string.rotation_force_portrait, R.drawable.ic_screen_lock_portrait_24dp), | ||||
|     LANDSCAPE(4, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, R.string.rotation_force_landscape, R.drawable.ic_screen_lock_landscape_24dp); | ||||
|     PORTRAIT(2, ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT, R.string.rotation_portrait, R.drawable.ic_stay_current_portrait_24dp), | ||||
|     LANDSCAPE(3, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, R.string.rotation_landscape, R.drawable.ic_stay_current_landscape_24dp), | ||||
|     LOCKED_PORTRAIT(4, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, R.string.rotation_force_portrait, R.drawable.ic_screen_lock_portrait_24dp), | ||||
|     LOCKED_LANDSCAPE(5, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, R.string.rotation_force_landscape, R.drawable.ic_screen_lock_landscape_24dp), | ||||
|     ; | ||||
|  | ||||
|     companion object { | ||||
|         fun fromPreference(preference: Int, resources: Resources): OrientationType = when (preference) { | ||||
|             2 -> { | ||||
|                 val currentOrientation = resources.configuration.orientation | ||||
|                 if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { | ||||
|                     LOCKED_PORTRAIT | ||||
|                 } else { | ||||
|                     LOCKED_LANDSCAPE | ||||
|                 } | ||||
|             } | ||||
|             3 -> PORTRAIT | ||||
|             4 -> LANDSCAPE | ||||
|             else -> FREE | ||||
|         } | ||||
|         fun fromPreference(preference: Int): OrientationType = | ||||
|             values().find { it.prefValue == preference } ?: FREE | ||||
|  | ||||
|         fun getNextOrientation(preference: Int, resources: Resources): OrientationType { | ||||
|             val current = if (preference == 2) { | ||||
|                 // Avoid issue due to 2 types having the same prefValue | ||||
|                 LOCKED_LANDSCAPE | ||||
|             } else { | ||||
|                 fromPreference(preference, resources) | ||||
|             } | ||||
|         fun getNextOrientation(preference: Int): OrientationType { | ||||
|             val current = fromPreference(preference) | ||||
|             return current.next() | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -78,11 +78,12 @@ class SettingsReaderController : SettingsController() { | ||||
|                 titleRes = R.string.pref_rotation_type | ||||
|                 entriesRes = arrayOf( | ||||
|                     R.string.rotation_free, | ||||
|                     R.string.rotation_lock, | ||||
|                     R.string.rotation_portrait, | ||||
|                     R.string.rotation_landscape, | ||||
|                     R.string.rotation_force_portrait, | ||||
|                     R.string.rotation_force_landscape | ||||
|                     R.string.rotation_force_landscape, | ||||
|                 ) | ||||
|                 entryValues = arrayOf("1", "2", "3", "4") | ||||
|                 entryValues = arrayOf("1", "2", "3", "4", "5") | ||||
|                 defaultValue = "1" | ||||
|                 summary = "%s" | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user