From f06fe6a299a65a45aefb7b5204e923e3f37ef7d1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 6 Nov 2017 16:25:58 +0100 Subject: [PATCH] make orientationEventListener nullable --- .../gallery/activities/ViewPagerActivity.kt | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 7bf5371d3..4c3176613 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -44,15 +44,11 @@ import com.simplemobiletools.gallery.fragments.ViewPagerFragment import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.activity_medium.* -import java.io.File -import java.io.FileInputStream -import java.io.FileOutputStream -import java.io.InputStream -import java.io.OutputStream +import java.io.* import java.util.* class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, ViewPagerFragment.FragmentListener { - lateinit var mOrientationEventListener: OrientationEventListener + private var mOrientationEventListener: OrientationEventListener? = null private var mPath = "" private var mDirectory = "" @@ -214,8 +210,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View window.attributes = attributes } - if (config.screenRotation == ROTATE_BY_DEVICE_ROTATION && mOrientationEventListener.canDetectOrientation()) { - mOrientationEventListener.enable() + if (config.screenRotation == ROTATE_BY_DEVICE_ROTATION && mOrientationEventListener?.canDetectOrientation() == true) { + mOrientationEventListener?.enable() } else if (config.screenRotation == ROTATE_BY_SYSTEM_SETTING) { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED } @@ -225,7 +221,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View override fun onPause() { super.onPause() - mOrientationEventListener.disable() + mOrientationEventListener?.disable() stopSlideshow() } @@ -241,11 +237,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View findItem(R.id.menu_hide).isVisible = !currentMedium.name.startsWith('.') findItem(R.id.menu_unhide).isVisible = currentMedium.name.startsWith('.') findItem(R.id.menu_rotate).setShowAsAction( - if (mRotationDegrees !== 0f) { - MenuItem.SHOW_AS_ACTION_ALWAYS - } else { - MenuItem.SHOW_AS_ACTION_IF_ROOM - }) + if (mRotationDegrees != 0f) { + MenuItem.SHOW_AS_ACTION_ALWAYS + } else { + MenuItem.SHOW_AS_ACTION_IF_ROOM + }) } return true