|
@@ -6,8 +6,6 @@ import android.app.ProgressDialog
|
|
import android.content.ClipData
|
|
import android.content.ClipData
|
|
import android.content.Context
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import android.content.Intent
|
|
-import android.content.pm.ActivityInfo
|
|
|
|
-import android.content.res.Configuration
|
|
|
|
import android.graphics.Bitmap
|
|
import android.graphics.Bitmap
|
|
import android.graphics.Color
|
|
import android.graphics.Color
|
|
import android.os.Build
|
|
import android.os.Build
|
|
@@ -21,6 +19,7 @@ import android.view.WindowManager
|
|
import android.view.animation.Animation
|
|
import android.view.animation.Animation
|
|
import android.view.animation.AnimationUtils
|
|
import android.view.animation.AnimationUtils
|
|
import android.widget.SeekBar
|
|
import android.widget.SeekBar
|
|
|
|
+import android.widget.Toast
|
|
import androidx.core.view.ViewCompat
|
|
import androidx.core.view.ViewCompat
|
|
import androidx.core.view.WindowInsetsCompat
|
|
import androidx.core.view.WindowInsetsCompat
|
|
import androidx.core.view.isVisible
|
|
import androidx.core.view.isVisible
|
|
@@ -111,6 +110,8 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
@Suppress("DEPRECATION")
|
|
@Suppress("DEPRECATION")
|
|
private var progressDialog: ProgressDialog? = null
|
|
private var progressDialog: ProgressDialog? = null
|
|
|
|
|
|
|
|
+ private var rotationToast: Toast? = null
|
|
|
|
+
|
|
companion object {
|
|
companion object {
|
|
@Suppress("unused")
|
|
@Suppress("unused")
|
|
const val LEFT_TO_RIGHT = 1
|
|
const val LEFT_TO_RIGHT = 1
|
|
@@ -344,6 +345,21 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ binding.actionRotation.setOnClickListener {
|
|
|
|
+ val newOrientation = OrientationType.getNextOrientation(preferences.rotation().get(), resources)
|
|
|
|
+
|
|
|
|
+ preferences.rotation().set(newOrientation.prefValue)
|
|
|
|
+ setOrientation(newOrientation.flag)
|
|
|
|
+
|
|
|
|
+ rotationToast?.cancel()
|
|
|
|
+ rotationToast = toast(newOrientation.stringRes)
|
|
|
|
+ }
|
|
|
|
+ preferences.rotation().asImmediateFlow { updateRotationShortcut(it) }
|
|
|
|
+ .onEach {
|
|
|
|
+ updateRotationShortcut(it)
|
|
|
|
+ }
|
|
|
|
+ .launchIn(lifecycleScope)
|
|
|
|
+
|
|
binding.actionCustomFilter.setOnClickListener {
|
|
binding.actionCustomFilter.setOnClickListener {
|
|
val sheet = ReaderColorFilterSheet(this)
|
|
val sheet = ReaderColorFilterSheet(this)
|
|
// Remove dimmed backdrop so changes can be previewed
|
|
// Remove dimmed backdrop so changes can be previewed
|
|
@@ -363,6 +379,11 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
setMenuVisibility(menuVisible)
|
|
setMenuVisibility(menuVisible)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private fun updateRotationShortcut(preference: Int) {
|
|
|
|
+ val orientation = OrientationType.fromPreference(preference, resources)
|
|
|
|
+ binding.actionRotation.setImageResource(orientation.iconRes)
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Sets the visibility of the menu according to [visible] and with an optional parameter to
|
|
* Sets the visibility of the menu according to [visible] and with an optional parameter to
|
|
* [animate] the views.
|
|
* [animate] the views.
|
|
@@ -382,7 +403,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
toolbarAnimation.setAnimationListener(
|
|
toolbarAnimation.setAnimationListener(
|
|
object : SimpleAnimationListener() {
|
|
object : SimpleAnimationListener() {
|
|
override fun onAnimationStart(animation: Animation) {
|
|
override fun onAnimationStart(animation: Animation) {
|
|
-// Fix status bar being translucent the first time it's opened.
|
|
|
|
|
|
+ // Fix status bar being translucent the first time it's opened.
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -668,6 +689,16 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Forces the user preferred [orientation] on the activity.
|
|
|
|
+ */
|
|
|
|
+ private fun setOrientation(orientation: Int) {
|
|
|
|
+ val newOrientation = OrientationType.fromPreference(orientation, resources)
|
|
|
|
+ if (newOrientation.flag != requestedOrientation) {
|
|
|
|
+ requestedOrientation = newOrientation.flag
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Class that handles the user preferences of the reader.
|
|
* Class that handles the user preferences of the reader.
|
|
*/
|
|
*/
|
|
@@ -721,33 +752,6 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|
.launchIn(lifecycleScope)
|
|
.launchIn(lifecycleScope)
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Forces the user preferred [orientation] on the activity.
|
|
|
|
- */
|
|
|
|
- private fun setOrientation(orientation: Int) {
|
|
|
|
- val newOrientation = when (orientation) {
|
|
|
|
- // Lock in current orientation
|
|
|
|
- 2 -> {
|
|
|
|
- val currentOrientation = resources.configuration.orientation
|
|
|
|
- if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
|
|
- ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
|
|
|
|
- } else {
|
|
|
|
- ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // Lock in portrait
|
|
|
|
- 3 -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
|
|
|
|
- // Lock in landscape
|
|
|
|
- 4 -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
|
|
|
- // Rotation free
|
|
|
|
- else -> ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (newOrientation != requestedOrientation) {
|
|
|
|
- requestedOrientation = newOrientation
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Sets the visibility of the bottom page indicator according to [visible].
|
|
* Sets the visibility of the bottom page indicator according to [visible].
|
|
*/
|
|
*/
|