From 1915afc5084b96a3c3eb8eba99c56dda0ac36ce9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 17 Jan 2019 16:40:27 +0100 Subject: [PATCH] replace PhotoView with GesturesView --- app/build.gradle | 4 +-- .../pro/activities/ViewPagerActivity.kt | 2 +- .../gallery/pro/adapters/MyPagerAdapter.kt | 7 +++- .../gallery/pro/extensions/Activity.kt | 2 +- .../gallery/pro/fragments/PhotoFragment.kt | 36 ++++++++++++++----- app/src/main/res/layout/pager_photo_item.xml | 4 +-- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8e1c23607..f119a5bd2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -70,6 +70,7 @@ dependencies { implementation 'info.androidhive:imagefilters:1.0.7' implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.caverock:androidsvg-aar:1.3' + implementation 'com.alexvasilkov:gesture-views:2.5.2' kapt 'com.github.bumptech.glide:compiler:4.8.0' // keep it here too, not just in Commons, else loading SVGs wont work kapt 'androidx.room:room-compiler:2.0.0' @@ -79,7 +80,4 @@ dependencies { //implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0' //implementation 'com.github.tibbi:subsampling-scale-image-view:v3.10.1-fork' implementation 'com.github.tibbi:subsampling-scale-image-view:9e9a393cc3' - - // implementation 'com.github.chrisbanes:PhotoView:2.3.0' - implementation 'com.github.tibbi:PhotoView:2.3.0-fork' } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 2100ea9ec..7ede5d47e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -366,7 +366,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun updatePagerItems(media: MutableList) { - val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, media) + val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, media, view_pager) if (!isDestroyed) { view_pager.apply { adapter = pagerAdapter diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MyPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MyPagerAdapter.kt index dad510f72..a2531c2b5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MyPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MyPagerAdapter.kt @@ -7,6 +7,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter import androidx.viewpager.widget.PagerAdapter +import com.simplemobiletools.commons.views.MyViewPager import com.simplemobiletools.gallery.pro.activities.ViewPagerActivity import com.simplemobiletools.gallery.pro.fragments.PhotoFragment import com.simplemobiletools.gallery.pro.fragments.VideoFragment @@ -14,7 +15,7 @@ import com.simplemobiletools.gallery.pro.fragments.ViewPagerFragment import com.simplemobiletools.gallery.pro.helpers.MEDIUM import com.simplemobiletools.gallery.pro.models.Medium -class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val media: MutableList) : FragmentStatePagerAdapter(fm) { +class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val media: MutableList, val viewPager: MyViewPager) : FragmentStatePagerAdapter(fm) { private val fragments = HashMap() override fun getCount() = media.size @@ -28,6 +29,10 @@ class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val m PhotoFragment() } + if (!medium.isVideo()) { + (fragment as? PhotoFragment)?.mViewPager = viewPager + } + fragment.arguments = bundle fragment.listener = activity return fragment diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index d6b730259..7faf9c013 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -74,7 +74,7 @@ fun Activity.launchCamera() { fun SimpleActivity.launchAbout() { val licenses = LICENSE_GLIDE or LICENSE_CROPPER or LICENSE_RTL or LICENSE_SUBSAMPLING or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GIF_DRAWABLE or - LICENSE_PHOTOVIEW or LICENSE_PICASSO or LICENSE_EXOPLAYER or LICENSE_PANORAMA_VIEW or LICENSE_SANSELAN or LICENSE_FILTERS + LICENSE_PICASSO or LICENSE_EXOPLAYER or LICENSE_PANORAMA_VIEW or LICENSE_SANSELAN or LICENSE_FILTERS val faqItems = arrayListOf( FAQItem(R.string.faq_5_title_commons, R.string.faq_5_text_commons), diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index 49cdabda3..1e336f9c4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -28,6 +28,7 @@ import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder import com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.OTG_PATH +import com.simplemobiletools.commons.views.MyViewPager import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.activities.PanoramaPhotoActivity import com.simplemobiletools.gallery.pro.activities.PhotoActivity @@ -76,6 +77,7 @@ class PhotoFragment : ViewPagerFragment() { private var mStoredShowHighestQuality = false private var mStoredAllowOneFingerZoom = false private var mStoredExtendedDetails = 0 + var mViewPager: MyViewPager? = null private lateinit var mView: ViewGroup private lateinit var mMedium: Medium @@ -83,7 +85,7 @@ class PhotoFragment : ViewPagerFragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { mView = (inflater.inflate(R.layout.pager_photo_item, container, false) as ViewGroup).apply { subsampling_view.setOnClickListener { photoClicked() } - photo_view.setOnClickListener { photoClicked() } + gestures_view.setOnClickListener { photoClicked() } gif_view.setOnClickListener { photoClicked() } instant_prev_item.setOnClickListener { listener?.goToPrevItem() } instant_next_item.setOnClickListener { listener?.goToNextItem() } @@ -97,12 +99,17 @@ class PhotoFragment : ViewPagerFragment() { if (subsampling_view.isVisible()) { subsampling_view.sendFakeClick(x, y) } else { - photo_view.sendFakeClick(x, y) + gestures_view.sendFakeClick(x, y) } } } if (context.config.allowDownGesture) { + gestures_view.setOnTouchListener { v, event -> + handleEvent(event) + false + } + subsampling_view.setOnTouchListener { v, event -> if (mView.subsampling_view.scale == mOriginalSubsamplingScale) { handleEvent(event) @@ -190,7 +197,6 @@ class PhotoFragment : ViewPagerFragment() { photo_brightness_controller.beVisibleIf(allowPhotoGestures) instant_prev_item.beVisibleIf(allowInstantChange) instant_next_item.beVisibleIf(allowInstantChange) - photo_view.setAllowFingerDragZoom(config.oneFingerZoom) } storeStateVariables() @@ -302,7 +308,7 @@ class PhotoFragment : ViewPagerFragment() { InputSource.FileSource(pathToLoad) } - mView.photo_view.beGone() + mView.gestures_view.beGone() val resolution = mMedium.path.getImageResolution() ?: Point(0, 0) mView.gif_view.apply { setInputSource(source) @@ -318,11 +324,12 @@ class PhotoFragment : ViewPagerFragment() { } private fun loadSVG() { + setupGestureView() Glide.with(context!!) .`as`(PictureDrawable::class.java) .listener(SvgSoftwareLayerSetter()) .load(mMedium.path) - .into(mView.photo_view) + .into(mView.gestures_view) } private fun loadBitmap(degrees: Int = 0) { @@ -340,9 +347,10 @@ class PhotoFragment : ViewPagerFragment() { picasso.rotate(degrees.toFloat()) } - picasso.into(mView.photo_view, object : Callback { + setupGestureView() + picasso.into(mView.gestures_view, object : Callback { override fun onSuccess() { - mView.photo_view.isZoomable = degrees != 0 || context?.config?.allowZoomingImages == false + mView.gestures_view.controller.settings.isZoomEnabled = degrees != 0 || context?.config?.allowZoomingImages == false if (mIsFragmentVisible && degrees == 0) { scheduleZoomableView() } @@ -358,6 +366,16 @@ class PhotoFragment : ViewPagerFragment() { } } + private fun setupGestureView() { + mView.gestures_view.controller.apply { + settings.maxZoom = 3f + settings.overzoomFactor = 1.2f + if (mViewPager != null) { + enableScrollInViewPager(mViewPager) + } + } + } + private fun tryLoadingWithGlide() { var targetWidth = if (mScreenWidth == 0) com.bumptech.glide.request.target.Target.SIZE_ORIGINAL else mScreenWidth var targetHeight = if (mScreenHeight == 0) com.bumptech.glide.request.target.Target.SIZE_ORIGINAL else mScreenHeight @@ -386,7 +404,7 @@ class PhotoFragment : ViewPagerFragment() { } return false } - }).into(mView.photo_view) + }).into(mView.gestures_view) } private fun openPanorama() { @@ -452,7 +470,7 @@ class PhotoFragment : ViewPagerFragment() { } override fun onImageLoadError(e: Exception) { - mView.photo_view.isZoomable = true + mView.gestures_view.controller.settings.isZoomEnabled = true background = ColorDrawable(Color.TRANSPARENT) mIsSubsamplingVisible = false beGone() diff --git a/app/src/main/res/layout/pager_photo_item.xml b/app/src/main/res/layout/pager_photo_item.xml index bc3ec30e8..eeaedb050 100644 --- a/app/src/main/res/layout/pager_photo_item.xml +++ b/app/src/main/res/layout/pager_photo_item.xml @@ -6,8 +6,8 @@ android:layout_width="match_parent" android:layout_height="match_parent"> -