mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
replace PhotoView with GesturesView
This commit is contained in:
parent
77b6c64ee9
commit
1915afc508
6 changed files with 38 additions and 17 deletions
|
@ -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'
|
||||
}
|
||||
|
|
|
@ -366,7 +366,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
}
|
||||
|
||||
private fun updatePagerItems(media: MutableList<Medium>) {
|
||||
val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, media)
|
||||
val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, media, view_pager)
|
||||
if (!isDestroyed) {
|
||||
view_pager.apply {
|
||||
adapter = pagerAdapter
|
||||
|
|
|
@ -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<Medium>) : FragmentStatePagerAdapter(fm) {
|
||||
class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val media: MutableList<Medium>, val viewPager: MyViewPager) : FragmentStatePagerAdapter(fm) {
|
||||
private val fragments = HashMap<Int, ViewPagerFragment>()
|
||||
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
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.github.chrisbanes.photoview.PhotoView
|
||||
android:id="@+id/photo_view"
|
||||
<com.alexvasilkov.gestures.views.GestureImageView
|
||||
android:id="@+id/gestures_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
|
|
Loading…
Reference in a new issue