improve some double-tap zoom ratios

This commit is contained in:
tibbi 2017-11-16 19:26:25 +01:00
parent 73441a021a
commit 27f00cfe3c
3 changed files with 11 additions and 2 deletions

View File

@ -74,6 +74,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
companion object {
var screenWidth = 0
var screenHeight = 0
var wasDecodedByGlide = false
}
override fun onCreate(savedInstanceState: Bundle?) {

View File

@ -221,6 +221,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun addZoomableView() {
if ((medium.isImage()) && isFragmentVisible && view.subsampling_view.isGone()) {
ViewPagerActivity.wasDecodedByGlide = false
view.subsampling_view.apply {
setBitmapDecoderClass(GlideDecoder::class.java)
maxScale = 10f
@ -233,7 +234,8 @@ class PhotoFragment : ViewPagerFragment() {
override fun onReady() {
background = ColorDrawable(if (context.config.darkBackground) Color.BLACK else context.config.backgroundColor)
setDoubleTapZoomScale(getDoubleTapZoomScale())
val zoomScale = if (ViewPagerActivity.wasDecodedByGlide) 1f else getDoubleTapZoomScale()
setDoubleTapZoomScale(zoomScale)
}
override fun onTileLoadError(e: Exception?) {
@ -264,13 +266,18 @@ class PhotoFragment : ViewPagerFragment() {
val height = bitmapOptions.outHeight
val bitmapAspectRatio = height / (width).toFloat()
if (context == null)
if (context == null) {
return 2f
}
return if (context!!.portrait && bitmapAspectRatio <= 1f) {
ViewPagerActivity.screenHeight / height.toFloat()
} else if (context!!.portrait && bitmapAspectRatio > 1f) {
ViewPagerActivity.screenHeight / width.toFloat()
} else if (!context!!.portrait && bitmapAspectRatio >= 1f) {
ViewPagerActivity.screenWidth / width.toFloat()
} else if (!context!!.portrait && bitmapAspectRatio < 1f) {
ViewPagerActivity.screenWidth / height.toFloat()
} else {
2f
}

View File

@ -23,6 +23,7 @@ class GlideDecoder : ImageDecoder {
val targetWidth = if (ViewPagerActivity.screenWidth == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth
val targetHeight = if (ViewPagerActivity.screenHeight == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight
ViewPagerActivity.wasDecodedByGlide = true
val options = RequestOptions()
.signature(uri.path.getFileSignature())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)