load the proper Portrait image

This commit is contained in:
tibbi 2019-10-02 23:39:29 +02:00
parent 04e49086f8
commit b6c919be85

View file

@ -342,16 +342,17 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadImage() { private fun loadImage() {
checkScreenDimensions() checkScreenDimensions()
if (mMedium.isPortrait() && context != null) {
showPortraitStripe()
}
mImageOrientation = getImageOrientation() mImageOrientation = getImageOrientation()
when { when {
mMedium.isGIF() -> loadGif() mMedium.isGIF() -> loadGif()
mMedium.isSVG() -> loadSVG() mMedium.isSVG() -> loadSVG()
else -> loadBitmap() else -> loadBitmap()
} }
if (mMedium.isPortrait() && context != null) {
showPortraitStripe()
}
} }
private fun loadGif() { private fun loadGif() {
@ -386,7 +387,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadBitmap(addZoomableView: Boolean = true) { private fun loadBitmap(addZoomableView: Boolean = true) {
val priority = if (mIsFragmentVisible) Priority.IMMEDIATE else Priority.NORMAL val priority = if (mIsFragmentVisible) Priority.IMMEDIATE else Priority.NORMAL
val options = RequestOptions() val options = RequestOptions()
.signature(mMedium.path.getFileSignature()) .signature(getFilePathToShow().getFileSignature())
.format(DecodeFormat.PREFER_ARGB_8888) .format(DecodeFormat.PREFER_ARGB_8888)
.priority(priority) .priority(priority)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
@ -398,7 +399,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
Glide.with(context!!) Glide.with(context!!)
.load(mMedium.path) .load(getFilePathToShow())
.apply(options) .apply(options)
.listener(object : RequestListener<Drawable> { .listener(object : RequestListener<Drawable> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean { override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
@ -419,7 +420,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
private fun tryLoadingWithPicasso(addZoomableView: Boolean) { private fun tryLoadingWithPicasso(addZoomableView: Boolean) {
var pathToLoad = if (mMedium.path.startsWith("content://")) mMedium.path else "file://${mMedium.path}" var pathToLoad = if (getFilePathToShow().startsWith("content://")) getFilePathToShow() else "file://${getFilePathToShow()}"
pathToLoad = pathToLoad.replace("%", "%25").replace("#", "%23") pathToLoad = pathToLoad.replace("%", "%25").replace("#", "%23")
try { try {
@ -468,6 +469,8 @@ class PhotoFragment : ViewPagerFragment() {
mView.photo_portrait_stripe.smoothScrollBy((x + itemWidth / 2) - screenWidth / 2, 0) mView.photo_portrait_stripe.smoothScrollBy((x + itemWidth / 2) - screenWidth / 2, 0)
if (paths[position] != mCurrentPortraitPhotoPath) { if (paths[position] != mCurrentPortraitPhotoPath) {
mCurrentPortraitPhotoPath = paths[position] mCurrentPortraitPhotoPath = paths[position]
hideZoomableView()
loadBitmap()
} }
} }
@ -550,6 +553,8 @@ class PhotoFragment : ViewPagerFragment() {
} }
} }
private fun getFilePathToShow() = if (mMedium.isPortrait()) mCurrentPortraitPhotoPath else mMedium.path
private fun openPanorama() { private fun openPanorama() {
Intent(context, PanoramaPhotoActivity::class.java).apply { Intent(context, PanoramaPhotoActivity::class.java).apply {
putExtra(PATH, mMedium.path) putExtra(PATH, mMedium.path)
@ -597,7 +602,7 @@ class PhotoFragment : ViewPagerFragment() {
rotationEnabled = config.allowRotatingWithGestures rotationEnabled = config.allowRotatingWithGestures
isOneToOneZoomEnabled = config.allowOneToOneZoom isOneToOneZoomEnabled = config.allowOneToOneZoom
orientation = newOrientation orientation = newOrientation
setImage(mMedium.path) setImage(getFilePathToShow())
onImageEventListener = object : SubsamplingScaleImageView.OnImageEventListener { onImageEventListener = object : SubsamplingScaleImageView.OnImageEventListener {
override fun onReady() { override fun onReady() {
@ -661,7 +666,7 @@ class PhotoFragment : ViewPagerFragment() {
var orient = defaultOrientation var orient = defaultOrientation
try { try {
val path = mMedium.path val path = getFilePathToShow()
orient = if (path.startsWith("content:/")) { orient = if (path.startsWith("content:/")) {
val inputStream = context!!.contentResolver.openInputStream(Uri.parse(path)) val inputStream = context!!.contentResolver.openInputStream(Uri.parse(path))
val exif = ExifInterface() val exif = ExifInterface()
@ -673,7 +678,7 @@ class PhotoFragment : ViewPagerFragment() {
exif.getAttributeInt(TAG_ORIENTATION, defaultOrientation) exif.getAttributeInt(TAG_ORIENTATION, defaultOrientation)
} }
if (orient == defaultOrientation || context!!.isPathOnOTG(mMedium.path)) { if (orient == defaultOrientation || context!!.isPathOnOTG(getFilePathToShow())) {
val uri = if (path.startsWith("content:/")) Uri.parse(path) else Uri.fromFile(File(path)) val uri = if (path.startsWith("content:/")) Uri.parse(path) else Uri.fromFile(File(path))
val inputStream = context!!.contentResolver.openInputStream(uri) val inputStream = context!!.contentResolver.openInputStream(uri)
val exif2 = ExifInterface() val exif2 = ExifInterface()