diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index 9df154732..ebbf2772f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.extensions import android.content.Context import android.content.Intent +import android.content.res.Configuration import android.database.Cursor import android.net.Uri import android.provider.MediaStore @@ -19,6 +20,8 @@ import com.simplemobiletools.gallery.models.Medium import java.io.File import java.util.* +val Context.portrait get() = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT + fun Context.getRealPathFromURI(uri: Uri): String? { var cursor: Cursor? = null try { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index eaa7bfc91..e1fc50186 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -27,6 +27,7 @@ import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getFileSignature import com.simplemobiletools.gallery.extensions.getRealPathFromURI +import com.simplemobiletools.gallery.extensions.portrait import com.simplemobiletools.gallery.helpers.GlideRotateTransformation import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.models.Medium @@ -238,12 +239,12 @@ class PhotoFragment : ViewPagerFragment() { val height = bitmapOptions.outHeight val bitmapAspectRatio = height / (width).toFloat() - return if (Math.abs(displayAspectRatio - bitmapAspectRatio) < RATIO_THRESHOLD) { - 2f - } else if (bitmapAspectRatio > 1f) { - width / (height).toFloat() + return if (context.portrait && bitmapAspectRatio <= 1f) { + ViewPagerActivity.screenHeight / height.toFloat() + } else if (!context.portrait && bitmapAspectRatio >= 1f) { + ViewPagerActivity.screenWidth / width.toFloat() } else { - bitmapAspectRatio + 2f } }