some code style updates

This commit is contained in:
tibbi 2017-08-31 16:22:19 +02:00
parent c7307ce523
commit b455721b17

View file

@ -150,23 +150,19 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun setupOrientationEventListener() { private fun setupOrientationEventListener() {
mOrientationEventListener = object : OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { mOrientationEventListener = object : OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {
override fun onOrientationChanged(orientation: Int) { override fun onOrientationChanged(orientation: Int) {
val currOrient = if (orientation in 45..134) { val currOrient = when (orientation) {
ORIENT_LANDSCAPE_RIGHT in 45..134 -> ORIENT_LANDSCAPE_RIGHT
} else if (orientation in 225..314) { in 225..314 -> ORIENT_LANDSCAPE_LEFT
ORIENT_LANDSCAPE_LEFT else -> ORIENT_PORTRAIT
} else {
ORIENT_PORTRAIT
} }
if (mLastHandledOrientation != currOrient) { if (mLastHandledOrientation != currOrient) {
mLastHandledOrientation = currOrient mLastHandledOrientation = currOrient
if (currOrient == ORIENT_LANDSCAPE_LEFT) { requestedOrientation = when (currOrient) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ORIENT_LANDSCAPE_LEFT -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
} else if (currOrient == ORIENT_LANDSCAPE_RIGHT) { ORIENT_LANDSCAPE_RIGHT -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE else -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
} else {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
} }
} }
} }
@ -597,10 +593,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
mPrevHashcode = media.hashCode() mPrevHashcode = media.hashCode()
mMedia = media mMedia = media
if (mPos == -1) { mPos = if (mPos == -1) {
mPos = getPositionInList(media) getPositionInList(media)
} else { } else {
mPos = Math.min(mPos, mMedia.size - 1) Math.min(mPos, mMedia.size - 1)
} }
updateActionbarTitle() updateActionbarTitle()
@ -611,12 +607,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun getPositionInList(items: MutableList<Medium>): Int { private fun getPositionInList(items: MutableList<Medium>): Int {
mPos = 0 mPos = 0
var i = 0 for ((i, medium) in items.withIndex()) {
for (medium in items) {
if (medium.path == mPath) { if (medium.path == mPath) {
return i return i
} }
i++
} }
return mPos return mPos
} }