preload just 1 fullscreen image per side, with more dynamic resolution

This commit is contained in:
tibbi 2017-03-18 12:42:13 +01:00
parent 2100004168
commit e1ddcda524
2 changed files with 4 additions and 2 deletions

View File

@ -54,6 +54,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
companion object { companion object {
var screenWidth = 0 var screenWidth = 0
var screenHeight = 0 var screenHeight = 0
var screenDensity = 0f
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -174,13 +175,13 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
windowManager.defaultDisplay.getMetrics(metrics) windowManager.defaultDisplay.getMetrics(metrics)
screenWidth = metrics.widthPixels screenWidth = metrics.widthPixels
screenHeight = metrics.heightPixels screenHeight = metrics.heightPixels
screenDensity = metrics.density
} }
private fun updatePagerItems() { private fun updatePagerItems() {
val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, mMedia) val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, mMedia)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !isDestroyed) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !isDestroyed) {
view_pager?.apply { view_pager?.apply {
offscreenPageLimit = 2
adapter = pagerAdapter adapter = pagerAdapter
currentItem = mPos currentItem = mPos
addOnPageChangeListener(this@ViewPagerActivity) addOnPageChangeListener(this@ViewPagerActivity)

View File

@ -134,9 +134,10 @@ class PhotoFragment : ViewPagerFragment() {
} }
private fun loadBitmap(degrees: Float = 0f) { private fun loadBitmap(degrees: Float = 0f) {
val densiy = ViewPagerActivity.screenDensity
Picasso.with(activity) Picasso.with(activity)
.load("file:${medium.path}") .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) .priority(if (isFragmentVisible) Picasso.Priority.HIGH else Picasso.Priority.LOW)
.rotate(degrees) .rotate(degrees)
.centerInside() .centerInside()