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 {
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)

View file

@ -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()