add a toggle for replacing zoomable images with better quality ones, related to #343
This commit is contained in:
parent
7642f4948c
commit
b824023722
|
@ -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 {
|
||||
|
|
|
@ -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<Medium>()
|
||||
|
||||
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<Medium>) {
|
||||
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -497,6 +497,26 @@
|
|||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_replace_zoomable_images_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||
android:id="@+id/settings_replace_zoomable_images"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/replace_zoomable_images"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_screen_rotation_holder"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in New Issue