From 82b5dcddc52d47a855b54e3835fad131fbf3a6ea Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Tue, 13 Feb 2018 22:09:23 -0500 Subject: [PATCH] Fix image scaling for PhotoView --- .../feature/gallery/GalleryActivity.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/qksms/src/main/java/presentation/feature/gallery/GalleryActivity.kt b/qksms/src/main/java/presentation/feature/gallery/GalleryActivity.kt index 995a1c4d..c02b0677 100644 --- a/qksms/src/main/java/presentation/feature/gallery/GalleryActivity.kt +++ b/qksms/src/main/java/presentation/feature/gallery/GalleryActivity.kt @@ -36,6 +36,24 @@ class GalleryActivity : QkActivity(), GalleryView { setContentView(R.layout.gallery_activity) supportActionBar?.setDisplayHomeAsUpEnabled(true) viewModel.bindView(this) + + // When calling the public setter, it doesn't allow the midscale to be the same as the + // maxscale or the minscale. We don't want 3 levels and we don't want to modify the library + // so let's celebrate the invention of reflection! + image.attacher.run { + javaClass.getDeclaredField("mMinScale").run { + isAccessible = true + setFloat(image.attacher, 1f) + } + javaClass.getDeclaredField("mMidScale").run { + isAccessible = true + setFloat(image.attacher, 1f) + } + javaClass.getDeclaredField("mMaxScale").run { + isAccessible = true + setFloat(image.attacher, 3f) + } + } } override fun render(state: GalleryState) {