From e1ddcda5248d2106bdb2d7da3bc814c8fed4f1cf Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 18 Mar 2017 12:42:13 +0100 Subject: [PATCH] preload just 1 fullscreen image per side, with more dynamic resolution --- .../simplemobiletools/gallery/activities/ViewPagerActivity.kt | 3 ++- .../com/simplemobiletools/gallery/fragments/PhotoFragment.kt | 3 ++- 2 files changed, 4 insertions(+), 2 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 6b1a26c38..8941b48b1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -54,6 +54,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View companion object { var screenWidth = 0 var screenHeight = 0 + var screenDensity = 0f } override fun onCreate(savedInstanceState: Bundle?) { @@ -174,13 +175,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View windowManager.defaultDisplay.getMetrics(metrics) screenWidth = metrics.widthPixels screenHeight = metrics.heightPixels + screenDensity = metrics.density } private fun updatePagerItems() { val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, mMedia) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !isDestroyed) { view_pager?.apply { - offscreenPageLimit = 2 adapter = pagerAdapter currentItem = mPos addOnPageChangeListener(this@ViewPagerActivity) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index c84784e9b..2f647d44a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -134,9 +134,10 @@ class PhotoFragment : ViewPagerFragment() { } private fun loadBitmap(degrees: Float = 0f) { + val densiy = ViewPagerActivity.screenDensity Picasso.with(activity) .load("file:${medium.path}") - .resize(ViewPagerActivity.screenWidth * 2, ViewPagerActivity.screenHeight * 2) + .resize((ViewPagerActivity.screenWidth * densiy).toInt(), (ViewPagerActivity.screenHeight * densiy).toInt()) .priority(if (isFragmentVisible) Picasso.Priority.HIGH else Picasso.Priority.LOW) .rotate(degrees) .centerInside()