From 0400612f8649676b5ccc491d9b3a4784c720f266 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 19 Oct 2017 21:24:32 +0200 Subject: [PATCH] replace some GlobalLayoutListeners with the helper view extension --- .../gallery/activities/ViewPagerActivity.kt | 20 ++++++------------- 1 file changed, 6 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 68a5908c3..bdf472480 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -123,17 +123,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View mDirectory = File(mPath).parent title = mPath.getFilenameFromPath() - view_pager.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { - override fun onGlobalLayout() { - view_pager.viewTreeObserver.removeOnGlobalLayoutListener(this) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && isDestroyed) - return - + view_pager.onGlobalLayout { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1 || !isDestroyed) { if (mMedia.isNotEmpty()) { gotMedia(mMedia) } } - }) + } reloadViewPager() scanPath(mPath) {} @@ -284,12 +280,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun startSlideshow() { if (getMediaForSlideshow()) { - view_pager.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { - override fun onGlobalLayout() { - view_pager.viewTreeObserver.removeOnGlobalLayoutListener(this) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && isDestroyed) - return - + view_pager.onGlobalLayout { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1 || !isDestroyed) { hideSystemUI() mSlideshowInterval = config.slideshowInterval mSlideshowMoveBackwards = config.slideshowMoveBackwards @@ -297,7 +289,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) scheduleSwipe() } - }) + } } }