add a toggle for replacing zoomable images with better quality ones, related to #343

This commit is contained in:
tibbi 2018-01-28 16:39:12 +01:00
parent 7642f4948c
commit b824023722
6 changed files with 78 additions and 31 deletions

View file

@ -56,6 +56,7 @@ class SettingsActivity : SimpleActivity() {
setupShowInfoBubble() setupShowInfoBubble()
setupOneFingerZoom() setupOneFingerZoom()
setupAllowInstantChange() setupAllowInstantChange()
setupReplaceZoomableImages()
setupShowExtendedDetails() setupShowExtendedDetails()
setupManageExtendedDetails() setupManageExtendedDetails()
updateTextColors(settings_holder) 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() { private fun setupShowExtendedDetails() {
settings_show_extended_details.isChecked = config.showExtendedDetails settings_show_extended_details.isChecked = config.showExtendedDetails
settings_show_extended_details_holder.setOnClickListener { settings_show_extended_details_holder.setOnClickListener {

View file

@ -68,6 +68,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private var mIsOrientationLocked = false private var mIsOrientationLocked = false
private var mStoredUseEnglish = false private var mStoredUseEnglish = false
private var mStoredReplaceZoomableImages = false
private var mMediaFiles = ArrayList<Medium>() private var mMediaFiles = ArrayList<Medium>()
companion object { companion object {
@ -106,6 +107,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
return return
} }
if (mStoredReplaceZoomableImages != config.replaceZoomableImages) {
mPrevHashcode = 0
refreshViewPager()
}
supportActionBar?.setBackgroundDrawable(resources.getDrawable(R.drawable.actionbar_gradient_background)) supportActionBar?.setBackgroundDrawable(resources.getDrawable(R.drawable.actionbar_gradient_background))
if (config.maxBrightness) { if (config.maxBrightness) {
@ -204,7 +210,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
} }
reloadViewPager() refreshViewPager()
scanPath(mPath) scanPath(mPath)
if (config.blackBackground) { if (config.blackBackground) {
@ -291,7 +297,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
private fun storeStateVariables() { private fun storeStateVariables() {
mStoredUseEnglish = config.useEnglish config.apply {
mStoredUseEnglish = useEnglish
mStoredReplaceZoomableImages = replaceZoomableImages
}
} }
private fun updatePagerItems(media: MutableList<Medium>) { private fun updatePagerItems(media: MutableList<Medium>) {
@ -456,7 +465,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
tryCopyMoveFilesTo(files, isCopyOperation) { tryCopyMoveFilesTo(files, isCopyOperation) {
config.tempFolderPath = "" config.tempFolderPath = ""
if (!isCopyOperation) { if (!isCopyOperation) {
reloadViewPager() refreshViewPager()
} }
} }
} }
@ -605,8 +614,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun isShowHiddenFlagNeeded(): Boolean { private fun isShowHiddenFlagNeeded(): Boolean {
val file = File(mPath) val file = File(mPath)
if (file.isHidden) if (file.isHidden) {
return true return true
}
var parent = file.parentFile ?: return false var parent = file.parentFile ?: return false
while (true) { while (true) {
@ -692,7 +702,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (requestCode == REQUEST_EDIT_IMAGE) { if (requestCode == REQUEST_EDIT_IMAGE) {
if (resultCode == Activity.RESULT_OK && resultData != null) { if (resultCode == Activity.RESULT_OK && resultData != null) {
mPos = -1 mPos = -1
reloadViewPager() refreshViewPager()
} }
} else if (requestCode == REQUEST_SET_AS) { } else if (requestCode == REQUEST_SET_AS) {
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
@ -719,7 +729,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun deleteConfirmed() { private fun deleteConfirmed() {
deleteFile(File(getCurrentMedia()[mPos].path)) { 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) { GetMediaAsynctask(applicationContext, mDirectory, false, false, mShowAll) {
gotMedia(it) gotMedia(it)
}.execute() }.execute()

View file

@ -44,6 +44,7 @@ class PhotoFragment : ViewPagerFragment() {
private var wasInit = false private var wasInit = false
private var storedShowExtendedDetails = false private var storedShowExtendedDetails = false
private var storedExtendedDetails = 0 private var storedExtendedDetails = 0
private var imageOrientation = -1
private var gifDrawable: GifDrawable? = null private var gifDrawable: GifDrawable? = null
lateinit var view: ViewGroup lateinit var view: ViewGroup
@ -163,6 +164,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
private fun loadImage() { private fun loadImage() {
imageOrientation = getImageOrientation()
if (medium.isGif()) { if (medium.isGif()) {
loadGif() loadGif()
} else { } else {
@ -196,9 +198,7 @@ class PhotoFragment : ViewPagerFragment() {
if (degrees == 0f) { if (degrees == 0f) {
var targetWidth = if (ViewPagerActivity.screenWidth == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth var targetWidth = if (ViewPagerActivity.screenWidth == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth
var targetHeight = if (ViewPagerActivity.screenHeight == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight var targetHeight = if (ViewPagerActivity.screenHeight == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight
val exif = android.media.ExifInterface(medium.path) if (imageOrientation == ORIENTATION_ROTATE_90) {
val orientation = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, -1)
if (orientation == ORIENTATION_ROTATE_90) {
targetWidth = targetHeight targetWidth = targetHeight
targetHeight = Target.SIZE_ORIGINAL targetHeight = Target.SIZE_ORIGINAL
} }
@ -237,31 +237,14 @@ class PhotoFragment : ViewPagerFragment() {
} }
private fun addZoomableView() { private fun addZoomableView() {
if (medium.isImage() && isFragmentVisible && view.subsampling_view.isGone() && !medium.isDng()) { if (!context!!.config.replaceZoomableImages && 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) {
}
ViewPagerActivity.wasDecodedByGlide = false ViewPagerActivity.wasDecodedByGlide = false
view.subsampling_view.apply { view.subsampling_view.apply {
maxScale = 10f maxScale = 10f
beVisible() beVisible()
isQuickScaleEnabled = context.config.oneFingerZoom isQuickScaleEnabled = context.config.oneFingerZoom
setImage(ImageSource.uri(medium.path)) 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) setEagerLoadingEnabled(false)
setExecutor(AsyncTask.SERIAL_EXECUTOR) setExecutor(AsyncTask.SERIAL_EXECUTOR)
setOnImageEventListener(object : SubsamplingScaleImageView.OnImageEventListener { setOnImageEventListener(object : SubsamplingScaleImageView.OnImageEventListener {
@ -270,8 +253,8 @@ class PhotoFragment : ViewPagerFragment() {
override fun onReady() { override fun onReady() {
background = ColorDrawable(if (context.config.blackBackground) Color.BLACK else context.config.backgroundColor) 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 useWidth = if (imageOrientation == ORIENTATION_ROTATE_90 || imageOrientation == ORIENTATION_ROTATE_270) sHeight else sWidth
val useHeight = if (orient == ORIENTATION_ROTATE_90 || orient == ORIENTATION_ROTATE_270) sWidth else sHeight val useHeight = if (imageOrientation == ORIENTATION_ROTATE_90 || imageOrientation == ORIENTATION_ROTATE_270) sWidth else sHeight
setDoubleTapZoomScale(getDoubleTapZoomScale(useWidth, useHeight)) 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 { private fun getDoubleTapZoomScale(width: Int, height: Int): Float {
val bitmapAspectRatio = height / width.toFloat() val bitmapAspectRatio = height / width.toFloat()
val screenAspectRatio = ViewPagerActivity.screenHeight / ViewPagerActivity.screenWidth.toFloat() val screenAspectRatio = ViewPagerActivity.screenHeight / ViewPagerActivity.screenWidth.toFloat()

View file

@ -176,6 +176,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(ALLOW_INSTANT_CHANGE, false) get() = prefs.getBoolean(ALLOW_INSTANT_CHANGE, false)
set(allowInstantChange) = prefs.edit().putBoolean(ALLOW_INSTANT_CHANGE, allowInstantChange).apply() 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 { private fun getDirectoryColumnsField(): String {
val isPortrait = context.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT val isPortrait = context.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
return if (isPortrait) { return if (isPortrait) {

View file

@ -45,6 +45,7 @@ val EXTENDED_DETAILS = "extended_details"
val LAST_FILE_CLEANUP = "last_file_cleanup" val LAST_FILE_CLEANUP = "last_file_cleanup"
val ONE_FINGER_ZOOM = "one_finger_zoom" val ONE_FINGER_ZOOM = "one_finger_zoom"
val ALLOW_INSTANT_CHANGE = "allow_instant_change" val ALLOW_INSTANT_CHANGE = "allow_instant_change"
val REPLACE_ZOOMABLE_IMAGES = "replace_zoomable_images"
// slideshow // slideshow
val SLIDESHOW_INTERVAL = "slideshow_interval" val SLIDESHOW_INTERVAL = "slideshow_interval"

View file

@ -497,6 +497,26 @@
</RelativeLayout> </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 <RelativeLayout
android:id="@+id/settings_screen_rotation_holder" android:id="@+id/settings_screen_rotation_holder"
android:layout_width="match_parent" android:layout_width="match_parent"