From 71249d0a1ef1f0d8db49c430cd02980d933fb114 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 24 Jun 2017 19:04:00 +0200 Subject: [PATCH] fill the viewpager at the viewpager activity only when its ready --- .../gallery/activities/ViewPagerActivity.kt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 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 7ac0c413a..315bc8c41 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -18,10 +18,7 @@ import android.os.Bundle import android.provider.MediaStore import android.support.v4.view.ViewPager import android.util.DisplayMetrics -import android.view.Menu -import android.view.MenuItem -import android.view.OrientationEventListener -import android.view.View +import android.view.* import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog @@ -100,9 +97,17 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View mDirectory = File(mPath).parent title = mPath.getFilenameFromPath() - if (mMedia.isNotEmpty()) { - gotMedia(mMedia) - } + 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 + + if (mMedia.isNotEmpty()) { + gotMedia(mMedia) + } + } + }) reloadViewPager() scanPath(mPath) {}