mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
tweak the photo fragment a bit
This commit is contained in:
parent
7b9503229f
commit
c564e63135
1 changed files with 41 additions and 36 deletions
|
@ -7,6 +7,7 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.DecodeFormat
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
|
@ -22,28 +23,28 @@ import kotlinx.android.synthetic.main.pager_photo_item.view.*
|
|||
|
||||
class PhotoFragment : ViewPagerFragment() {
|
||||
lateinit var medium: Medium
|
||||
lateinit var mView: View
|
||||
lateinit var subsamplingView: SubsamplingScaleImageView
|
||||
lateinit var glideView: ImageView
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
mView = inflater.inflate(R.layout.pager_photo_item, container, false)
|
||||
val view = inflater.inflate(R.layout.pager_photo_item, container, false)
|
||||
|
||||
medium = arguments.getSerializable(MEDIUM) as Medium
|
||||
if (medium.path.startsWith("content://"))
|
||||
medium.path = context.getRealPathFromURI(Uri.parse(medium.path)) ?: ""
|
||||
|
||||
subsamplingView = view.photo_view.apply { setOnClickListener({ photoClicked() }) }
|
||||
glideView = view.glide_view.apply { setOnClickListener({ photoClicked() }) }
|
||||
loadImage(medium)
|
||||
|
||||
activity.window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
|
||||
listener?.systemUiVisibilityChanged(visibility)
|
||||
}
|
||||
|
||||
return mView
|
||||
return view
|
||||
}
|
||||
|
||||
private fun loadImage(medium: Medium) {
|
||||
val subsamplingView = mView.photo_view.apply { setOnClickListener({ photoClicked() }) }
|
||||
val glideView = mView.glide_view.apply { setOnClickListener({ photoClicked() }) }
|
||||
|
||||
if (medium.isGif()) {
|
||||
Glide.with(this)
|
||||
.load(medium.path)
|
||||
|
@ -62,42 +63,46 @@ class PhotoFragment : ViewPagerFragment() {
|
|||
}
|
||||
|
||||
override fun onResourceReady(resource: Bitmap?, model: String?, target: Target<Bitmap>?, isFromMemoryCache: Boolean, isFirstResource: Boolean): Boolean {
|
||||
if (!medium.isPng()) {
|
||||
subsamplingView.visibility = View.VISIBLE
|
||||
subsamplingView.apply {
|
||||
setDoubleTapZoomScale(1.2f)
|
||||
setImage(ImageSource.uri(medium.path))
|
||||
orientation = SubsamplingScaleImageView.ORIENTATION_USE_EXIF
|
||||
maxScale = 5f
|
||||
setOnImageEventListener(object : SubsamplingScaleImageView.OnImageEventListener {
|
||||
override fun onImageLoaded() {
|
||||
}
|
||||
|
||||
override fun onReady() {
|
||||
glideView.visibility = View.GONE
|
||||
subsamplingView.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
override fun onTileLoadError(p0: Exception?) {
|
||||
}
|
||||
|
||||
override fun onPreviewReleased() {
|
||||
}
|
||||
|
||||
override fun onImageLoadError(p0: Exception?) {
|
||||
}
|
||||
|
||||
override fun onPreviewLoadError(p0: Exception?) {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
addZoomableView()
|
||||
return false
|
||||
}
|
||||
}).into(glideView)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addZoomableView() {
|
||||
if (!medium.isPng()) {
|
||||
subsamplingView.visibility = View.VISIBLE
|
||||
subsamplingView.apply {
|
||||
setDoubleTapZoomScale(1.2f)
|
||||
setImage(ImageSource.uri(medium.path))
|
||||
orientation = SubsamplingScaleImageView.ORIENTATION_USE_EXIF
|
||||
maxScale = 5f
|
||||
setOnImageEventListener(object : SubsamplingScaleImageView.OnImageEventListener {
|
||||
override fun onImageLoaded() {
|
||||
}
|
||||
|
||||
override fun onReady() {
|
||||
glideView.visibility = View.GONE
|
||||
glideView.setImageBitmap(null)
|
||||
}
|
||||
|
||||
override fun onTileLoadError(p0: Exception?) {
|
||||
}
|
||||
|
||||
override fun onPreviewReleased() {
|
||||
}
|
||||
|
||||
override fun onImageLoadError(p0: Exception?) {
|
||||
}
|
||||
|
||||
override fun onPreviewLoadError(p0: Exception?) {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration?) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
loadImage(medium)
|
||||
|
|
Loading…
Reference in a new issue