Add option to invert volume keys. Closes #834

This commit is contained in:
len
2017-06-11 11:36:12 +02:00
parent 0210ee8747
commit 1794782323
7 changed files with 15 additions and 7 deletions

View File

@ -41,6 +41,8 @@ object PreferenceKeys {
const val readWithVolumeKeys = "reader_volume_keys"
const val readWithVolumeKeysInverted = "reader_volume_keys_inverted"
const val portraitColumns = "pref_library_columns_portrait_key"
const val landscapeColumns = "pref_library_columns_landscape_key"

View File

@ -69,6 +69,8 @@ class PreferencesHelper(val context: Context) {
fun readWithVolumeKeys() = rxPrefs.getBoolean(Keys.readWithVolumeKeys, false)
fun readWithVolumeKeysInverted() = rxPrefs.getBoolean(Keys.readWithVolumeKeysInverted, false)
fun portraitColumns() = rxPrefs.getInteger(Keys.portraitColumns, 0)
fun landscapeColumns() = rxPrefs.getInteger(Keys.landscapeColumns, 0)

View File

@ -84,6 +84,8 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
private val volumeKeysEnabled by lazy { preferences.readWithVolumeKeys().getOrDefault() }
private val volumeKeysInverted by lazy { preferences.readWithVolumeKeysInverted().getOrDefault() }
val preferences by injectLazy<PreferencesHelper>()
private var systemUi: SystemUiHelper? = null
@ -194,7 +196,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
KeyEvent.KEYCODE_VOLUME_DOWN -> {
if (volumeKeysEnabled) {
if (event.action == KeyEvent.ACTION_UP) {
viewer?.moveDown()
if (!volumeKeysInverted) viewer?.moveDown() else viewer?.moveUp()
}
return true
}
@ -202,7 +204,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
KeyEvent.KEYCODE_VOLUME_UP -> {
if (volumeKeysEnabled) {
if (event.action == KeyEvent.ACTION_UP) {
viewer?.moveUp()
if (!volumeKeysInverted) viewer?.moveUp() else viewer?.moveDown()
}
return true
}

View File

@ -100,6 +100,11 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.pref_read_with_volume_keys
defaultValue = false
}
switchPreference {
key = Keys.readWithVolumeKeysInverted
titleRes = R.string.pref_read_with_volume_keys_inverted
defaultValue = false
}.apply { dependency = Keys.readWithVolumeKeys }
}
}