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 b5efcc49c..d50d3e62f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -25,7 +25,9 @@ import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.Target import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView -import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.extensions.beGone +import com.simplemobiletools.commons.extensions.beVisible +import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.extensions.* @@ -271,20 +273,10 @@ class PhotoFragment : ViewPagerFragment() { private fun checkExtendedDetails() { if (context.config.showExtendedDetails) { - val file = File(medium.path) - val name = medium.name - val path = "${File(medium.path).parent.trimEnd('/')}/" - val exif = android.media.ExifInterface(medium.path) - val size = file.length().formatSize() - val resolution = file.getResolution().formatAsResolution() - val lastModified = file.lastModified().formatLastModified() - val dateTaken = path.getExifDateTaken(exif) - val cameraModel = path.getExifCameraModel(exif) - val exifProperties = path.getExifProperties(exif) view.photo_details.apply { beVisible() setTextColor(context.config.textColor) - text = "$name\n$path\n$size\n$resolution\n$lastModified\n$dateTaken\n$cameraModel\n$exifProperties" + text = getMediumExtendedDetails(medium) (layoutParams as RelativeLayout.LayoutParams).bottomMargin = (resources.getDimension(R.dimen.small_margin) + context.navigationBarHeight).toInt() } } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index c457e08fd..4cfba5eab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -24,7 +24,6 @@ import com.simplemobiletools.gallery.extensions.navigationBarHeight import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.pager_video_item.view.* -import java.io.File import java.io.IOException class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSeekBarChangeListener { @@ -505,23 +504,10 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee private fun checkExtendedDetails() { if (context.config.showExtendedDetails) { - val file = File(medium.path) - val name = medium.name - val path = "${File(medium.path).parent.trimEnd('/')}/" - val exif = android.media.ExifInterface(medium.path) - val size = file.length().formatSize() - val resolution = file.getResolution().formatAsResolution() - val duration = file.getDuration() - val artist = file.getArtist() ?: "" - val album = file.getAlbum() ?: "" - val lastModified = file.lastModified().formatLastModified() - val dateTaken = path.getExifDateTaken(exif) - val cameraModel = path.getExifCameraModel(exif) - val exifProperties = path.getExifProperties(exif) mView.video_details.apply { beVisible() setTextColor(context.config.textColor) - text = "$name\n$path\n$size\n$resolution\n$duration\n$artist\n$album\n$lastModified\n$dateTaken\n$cameraModel\n$exifProperties" + text = getMediumExtendedDetails(medium) } } else { mView.video_details.beGone() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt index 6121151ba..31a2888c4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt @@ -1,6 +1,11 @@ package com.simplemobiletools.gallery.fragments import android.support.v4.app.Fragment +import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.helpers.* +import com.simplemobiletools.gallery.models.Medium +import java.io.File abstract class ViewPagerFragment : Fragment() { var listener: FragmentListener? = null @@ -12,4 +17,44 @@ abstract class ViewPagerFragment : Fragment() { fun videoEnded(): Boolean } + + fun getMediumExtendedDetails(medium: Medium): String { + val file = File(medium.path) + val path = "${file.parent.trimEnd('/')}/" + val exif = android.media.ExifInterface(medium.path) + val details = StringBuilder() + val detailsFlag = context.config.extendedDetails + if (detailsFlag and EXT_NAME != 0) { + medium.name.let { if (it.isNotEmpty()) details.appendln(it) } + } + + if (detailsFlag and EXT_PATH != 0) { + path.let { if (it.isNotEmpty()) details.appendln(it) } + } + + if (detailsFlag and EXT_SIZE != 0) { + file.length().formatSize().let { if (it.isNotEmpty()) details.appendln(it) } + } + + if (detailsFlag and EXT_RESOLUTION != 0) { + file.getResolution().formatAsResolution().let { if (it.isNotEmpty()) details.appendln(it) } + } + + if (detailsFlag and EXT_LAST_MODIFIED != 0) { + file.lastModified().formatLastModified().let { if (it.isNotEmpty()) details.appendln(it) } + } + + if (detailsFlag and EXT_DATE_TAKEN != 0) { + path.getExifDateTaken(exif).let { if (it.isNotEmpty()) details.appendln(it) } + } + + if (detailsFlag and EXT_CAMERA_MODEL != 0) { + path.getExifCameraModel(exif).let { if (it.isNotEmpty()) details.appendln(it) } + } + + if (detailsFlag and EXT_EXIF_PROPERTIES != 0) { + path.getExifProperties(exif).let { if (it.isNotEmpty()) details.appendln(it) } + } + return details.toString().trim() + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 949419c3b..c42db1b4e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -110,8 +110,8 @@ class MediaFetcher(val context: Context) { if (shouldStop) break - val path = cur.getStringValue(MediaStore.Images.Media.DATA) - var filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: "" + val path = cur.getStringValue(MediaStore.Images.Media.DATA).trim() + var filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME)?.trim() ?: "" if (filename.isEmpty()) filename = path.getFilenameFromPath()