mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 07:19:18 +01:00
Using bit shift left instead of manually adding flag values
This commit is contained in:
parent
5911ad2fd4
commit
e840e622df
@ -5,17 +5,21 @@ import androidx.annotation.DrawableRes
|
|||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
|
||||||
enum class OrientationType(val prefValue: Int, val flag: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int, val flagValue: Int) {
|
enum class OrientationType(val prefValue: Int, val flag: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int) {
|
||||||
DEFAULT(0, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, R.string.default_value, R.drawable.ic_screen_rotation_24dp, 0x00000000),
|
DEFAULT(0, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, R.string.default_value, R.drawable.ic_screen_rotation_24dp),
|
||||||
FREE(1, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, R.string.free, R.drawable.ic_screen_rotation_24dp, 0x00000008),
|
FREE(1, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, R.string.free, R.drawable.ic_screen_rotation_24dp),
|
||||||
PORTRAIT(2, ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT, R.string.portrait, R.drawable.ic_stay_current_portrait_24dp, 0x00000010),
|
PORTRAIT(2, ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT, R.string.portrait, R.drawable.ic_stay_current_portrait_24dp),
|
||||||
LANDSCAPE(3, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, R.string.landscape, R.drawable.ic_stay_current_landscape_24dp, 0x00000018),
|
LANDSCAPE(3, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, R.string.landscape, R.drawable.ic_stay_current_landscape_24dp),
|
||||||
LOCKED_PORTRAIT(4, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, R.string.locked_portrait, R.drawable.ic_screen_lock_portrait_24dp, 0x00000020),
|
LOCKED_PORTRAIT(4, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, R.string.locked_portrait, R.drawable.ic_screen_lock_portrait_24dp),
|
||||||
LOCKED_LANDSCAPE(5, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, R.string.locked_landscape, R.drawable.ic_screen_lock_landscape_24dp, 0x00000028),
|
LOCKED_LANDSCAPE(5, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, R.string.locked_landscape, R.drawable.ic_screen_lock_landscape_24dp),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@Suppress("RemoveRedundantQualifierName")
|
||||||
|
val flagValue = prefValue shl OrientationType.SHIFT
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val MASK = 0x00000038
|
private const val SHIFT = 0x00000003
|
||||||
|
const val MASK = 7 shl SHIFT
|
||||||
|
|
||||||
fun fromPreference(preference: Int): OrientationType =
|
fun fromPreference(preference: Int): OrientationType =
|
||||||
values().find { it.flagValue == preference } ?: FREE
|
values().find { it.flagValue == preference } ?: FREE
|
||||||
|
@ -5,18 +5,22 @@ import androidx.annotation.StringRes
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.util.lang.next
|
import eu.kanade.tachiyomi.util.lang.next
|
||||||
|
|
||||||
enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int, val flagValue: Int) {
|
enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int, @DrawableRes val iconRes: Int) {
|
||||||
DEFAULT(0, R.string.default_value, R.drawable.ic_reader_default_24dp, 0x00000000),
|
DEFAULT(0, R.string.default_value, R.drawable.ic_reader_default_24dp),
|
||||||
LEFT_TO_RIGHT(1, R.string.left_to_right_viewer, R.drawable.ic_reader_ltr_24dp, 0x00000001),
|
LEFT_TO_RIGHT(1, R.string.left_to_right_viewer, R.drawable.ic_reader_ltr_24dp),
|
||||||
RIGHT_TO_LEFT(2, R.string.right_to_left_viewer, R.drawable.ic_reader_rtl_24dp, 0x00000002),
|
RIGHT_TO_LEFT(2, R.string.right_to_left_viewer, R.drawable.ic_reader_rtl_24dp),
|
||||||
VERTICAL(3, R.string.vertical_viewer, R.drawable.ic_reader_vertical_24dp, 0x00000003),
|
VERTICAL(3, R.string.vertical_viewer, R.drawable.ic_reader_vertical_24dp),
|
||||||
WEBTOON(4, R.string.webtoon, R.drawable.ic_reader_webtoon_24dp, 0x00000004),
|
WEBTOON(4, R.string.webtoon, R.drawable.ic_reader_webtoon_24dp),
|
||||||
CONTINUOUS_VERTICAL(5, R.string.continuous_vertical, R.drawable.ic_reader_continuous_vertical_24dp, 0x00000005),
|
CONTINUOUS_VERTICAL(5, R.string.continuous_vertical, R.drawable.ic_reader_continuous_vertical_24dp),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@Suppress("RemoveRedundantQualifierName")
|
||||||
|
val flagValue = prefValue shl ReadingModeType.SHIFT
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun fromPreference(preference: Int): ReadingModeType = values().find { it.flagValue == preference } ?: DEFAULT
|
fun fromPreference(preference: Int): ReadingModeType = values().find { it.flagValue == preference } ?: DEFAULT
|
||||||
const val MASK = 0x00000007
|
private const val SHIFT = 0x00000000
|
||||||
|
const val MASK = 7 shl SHIFT
|
||||||
|
|
||||||
fun getNextReadingMode(preference: Int): ReadingModeType {
|
fun getNextReadingMode(preference: Int): ReadingModeType {
|
||||||
val current = fromPreference(preference)
|
val current = fromPreference(preference)
|
||||||
|
Loading…
Reference in New Issue
Block a user