diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt index bfc4875dc..f3aeeb21e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -56,6 +56,7 @@ class SettingsActivity : SimpleActivity() { setupShowInfoBubble() setupOneFingerZoom() setupAllowInstantChange() + setupReplaceZoomableImages() setupShowExtendedDetails() setupManageExtendedDetails() updateTextColors(settings_holder) @@ -296,6 +297,14 @@ class SettingsActivity : SimpleActivity() { } } + private fun setupReplaceZoomableImages() { + settings_replace_zoomable_images.isChecked = config.replaceZoomableImages + settings_replace_zoomable_images_holder.setOnClickListener { + settings_replace_zoomable_images.toggle() + config.replaceZoomableImages = settings_replace_zoomable_images.isChecked + } + } + private fun setupShowExtendedDetails() { settings_show_extended_details.isChecked = config.showExtendedDetails settings_show_extended_details_holder.setOnClickListener { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 26104988a..f9a813d6d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -68,6 +68,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private var mIsOrientationLocked = false private var mStoredUseEnglish = false + private var mStoredReplaceZoomableImages = false private var mMediaFiles = ArrayList() companion object { @@ -106,6 +107,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View return } + if (mStoredReplaceZoomableImages != config.replaceZoomableImages) { + mPrevHashcode = 0 + refreshViewPager() + } + supportActionBar?.setBackgroundDrawable(resources.getDrawable(R.drawable.actionbar_gradient_background)) if (config.maxBrightness) { @@ -204,7 +210,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - reloadViewPager() + refreshViewPager() scanPath(mPath) if (config.blackBackground) { @@ -291,7 +297,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun storeStateVariables() { - mStoredUseEnglish = config.useEnglish + config.apply { + mStoredUseEnglish = useEnglish + mStoredReplaceZoomableImages = replaceZoomableImages + } } private fun updatePagerItems(media: MutableList) { @@ -456,7 +465,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View tryCopyMoveFilesTo(files, isCopyOperation) { config.tempFolderPath = "" if (!isCopyOperation) { - reloadViewPager() + refreshViewPager() } } } @@ -605,8 +614,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun isShowHiddenFlagNeeded(): Boolean { val file = File(mPath) - if (file.isHidden) + if (file.isHidden) { return true + } var parent = file.parentFile ?: return false while (true) { @@ -692,7 +702,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (requestCode == REQUEST_EDIT_IMAGE) { if (resultCode == Activity.RESULT_OK && resultData != null) { mPos = -1 - reloadViewPager() + refreshViewPager() } } else if (requestCode == REQUEST_SET_AS) { if (resultCode == Activity.RESULT_OK) { @@ -719,7 +729,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun deleteConfirmed() { deleteFile(File(getCurrentMedia()[mPos].path)) { - reloadViewPager() + refreshViewPager() } } @@ -758,7 +768,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - private fun reloadViewPager() { + private fun refreshViewPager() { GetMediaAsynctask(applicationContext, mDirectory, false, false, mShowAll) { gotMedia(it) }.execute() 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 603cc8546..d6934cf78 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -44,6 +44,7 @@ class PhotoFragment : ViewPagerFragment() { private var wasInit = false private var storedShowExtendedDetails = false private var storedExtendedDetails = 0 + private var imageOrientation = -1 private var gifDrawable: GifDrawable? = null lateinit var view: ViewGroup @@ -163,6 +164,7 @@ class PhotoFragment : ViewPagerFragment() { } private fun loadImage() { + imageOrientation = getImageOrientation() if (medium.isGif()) { loadGif() } else { @@ -196,9 +198,7 @@ class PhotoFragment : ViewPagerFragment() { if (degrees == 0f) { var targetWidth = if (ViewPagerActivity.screenWidth == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth var targetHeight = if (ViewPagerActivity.screenHeight == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight - val exif = android.media.ExifInterface(medium.path) - val orientation = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, -1) - if (orientation == ORIENTATION_ROTATE_90) { + if (imageOrientation == ORIENTATION_ROTATE_90) { targetWidth = targetHeight targetHeight = Target.SIZE_ORIGINAL } @@ -237,31 +237,14 @@ class PhotoFragment : ViewPagerFragment() { } private fun addZoomableView() { - if (medium.isImage() && isFragmentVisible && view.subsampling_view.isGone() && !medium.isDng()) { - val defaultOrientation = -1 - var orient = defaultOrientation - - try { - val exif = android.media.ExifInterface(medium.path) - orient = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, defaultOrientation) - - if (orient == defaultOrientation) { - val uri = if (medium.path.startsWith("content:/")) Uri.parse(medium.path) else Uri.fromFile(File(medium.path)) - val inputStream = context!!.contentResolver.openInputStream(uri) - val exif2 = ExifInterface() - exif2.readExif(inputStream, ExifInterface.Options.OPTION_ALL) - orient = exif2.getTag(ExifInterface.TAG_ORIENTATION)?.getValueAsInt(defaultOrientation) ?: defaultOrientation - } - } catch (ignored: Exception) { - } - + if (!context!!.config.replaceZoomableImages && medium.isImage() && isFragmentVisible && view.subsampling_view.isGone() && !medium.isDng()) { ViewPagerActivity.wasDecodedByGlide = false view.subsampling_view.apply { maxScale = 10f beVisible() isQuickScaleEnabled = context.config.oneFingerZoom setImage(ImageSource.uri(medium.path)) - orientation = if (orient == -1) SubsamplingScaleImageView.ORIENTATION_USE_EXIF else degreesForRotation(orient) + orientation = if (imageOrientation == -1) SubsamplingScaleImageView.ORIENTATION_USE_EXIF else degreesForRotation(imageOrientation) setEagerLoadingEnabled(false) setExecutor(AsyncTask.SERIAL_EXECUTOR) setOnImageEventListener(object : SubsamplingScaleImageView.OnImageEventListener { @@ -270,8 +253,8 @@ class PhotoFragment : ViewPagerFragment() { override fun onReady() { background = ColorDrawable(if (context.config.blackBackground) Color.BLACK else context.config.backgroundColor) - val useWidth = if (orient == ORIENTATION_ROTATE_90 || orient == ORIENTATION_ROTATE_270) sHeight else sWidth - val useHeight = if (orient == ORIENTATION_ROTATE_90 || orient == ORIENTATION_ROTATE_270) sWidth else sHeight + val useWidth = if (imageOrientation == ORIENTATION_ROTATE_90 || imageOrientation == ORIENTATION_ROTATE_270) sHeight else sWidth + val useHeight = if (imageOrientation == ORIENTATION_ROTATE_90 || imageOrientation == ORIENTATION_ROTATE_270) sWidth else sHeight setDoubleTapZoomScale(getDoubleTapZoomScale(useWidth, useHeight)) } @@ -295,6 +278,26 @@ class PhotoFragment : ViewPagerFragment() { } } + private fun getImageOrientation(): Int { + val defaultOrientation = -1 + var orient = defaultOrientation + + try { + val exif = android.media.ExifInterface(medium.path) + orient = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, defaultOrientation) + + if (orient == defaultOrientation) { + val uri = if (medium.path.startsWith("content:/")) Uri.parse(medium.path) else Uri.fromFile(File(medium.path)) + val inputStream = context!!.contentResolver.openInputStream(uri) + val exif2 = ExifInterface() + exif2.readExif(inputStream, ExifInterface.Options.OPTION_ALL) + orient = exif2.getTag(ExifInterface.TAG_ORIENTATION)?.getValueAsInt(defaultOrientation) ?: defaultOrientation + } + } catch (ignored: Exception) { + } + return orient + } + private fun getDoubleTapZoomScale(width: Int, height: Int): Float { val bitmapAspectRatio = height / width.toFloat() val screenAspectRatio = ViewPagerActivity.screenHeight / ViewPagerActivity.screenWidth.toFloat() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index e76e02c38..743cae29e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -176,6 +176,10 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(ALLOW_INSTANT_CHANGE, false) set(allowInstantChange) = prefs.edit().putBoolean(ALLOW_INSTANT_CHANGE, allowInstantChange).apply() + var replaceZoomableImages: Boolean + get() = prefs.getBoolean(REPLACE_ZOOMABLE_IMAGES, false) + set(replaceZoomableImages) = prefs.edit().putBoolean(REPLACE_ZOOMABLE_IMAGES, replaceZoomableImages).apply() + private fun getDirectoryColumnsField(): String { val isPortrait = context.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT return if (isPortrait) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 1ef5d45b1..1a8dbb70e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -45,6 +45,7 @@ val EXTENDED_DETAILS = "extended_details" val LAST_FILE_CLEANUP = "last_file_cleanup" val ONE_FINGER_ZOOM = "one_finger_zoom" val ALLOW_INSTANT_CHANGE = "allow_instant_change" +val REPLACE_ZOOMABLE_IMAGES = "replace_zoomable_images" // slideshow val SLIDESHOW_INTERVAL = "slideshow_interval" diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 93654cdc0..a27c81258 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -497,6 +497,26 @@ + + + + + +