From 2e339f08e4b5265d9ca77988e3e31d511eb986e4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 18 Oct 2017 21:54:08 +0200 Subject: [PATCH] show extended details at photos/videos if appropriate --- app/build.gradle | 2 +- .../gallery/fragments/PhotoFragment.kt | 35 ++++++++--- .../gallery/fragments/VideoFragment.kt | 58 ++++++++++++++----- app/src/main/res/layout/pager_photo_item.xml | 15 +++++ app/src/main/res/layout/pager_video_item.xml | 15 +++++ 5 files changed, 102 insertions(+), 23 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5ed3e1770..a35f18b9f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,7 +37,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.29.18' + compile 'com.simplemobiletools:commons:2.29.20' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' 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 108cf9bc9..f5d278619 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -12,6 +12,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.RelativeLayout import com.bumptech.glide.Glide import com.bumptech.glide.Priority import com.bumptech.glide.load.DataSource @@ -24,15 +25,10 @@ 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.beGone -import com.simplemobiletools.commons.extensions.beVisible -import com.simplemobiletools.commons.extensions.toast +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R 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.extensions.* import com.simplemobiletools.gallery.helpers.GlideRotateTransformation import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.models.Medium @@ -101,6 +97,7 @@ class PhotoFragment : ViewPagerFragment() { } } loadImage() + checkExtendedDetails() wasInit = true @@ -258,6 +255,29 @@ class PhotoFragment : ViewPagerFragment() { loadBitmap(degrees) } + 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" + (layoutParams as RelativeLayout.LayoutParams).bottomMargin = (resources.getDimension(R.dimen.small_margin) + context.navigationBarHeight).toInt() + } + } else { + view.photo_details.beGone() + } + } + override fun onDestroyView() { super.onDestroyView() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !activity.isDestroyed) { @@ -268,6 +288,7 @@ class PhotoFragment : ViewPagerFragment() { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) loadImage() + checkExtendedDetails() } private fun photoClicked() { 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 1e945a15e..4c36de74a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -14,16 +14,17 @@ import android.view.* import android.view.animation.AnimationUtils import android.widget.SeekBar import android.widget.TextView -import com.simplemobiletools.commons.extensions.beVisibleIf -import com.simplemobiletools.commons.extensions.getFormattedDuration -import com.simplemobiletools.commons.extensions.toast -import com.simplemobiletools.commons.extensions.updateTextColors +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.ViewPagerActivity -import com.simplemobiletools.gallery.extensions.* +import com.simplemobiletools.gallery.extensions.audioManager +import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.extensions.hasNavBar +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 { @@ -36,7 +37,6 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee private var mCurrTimeView: TextView? = null private var mTimerHandler: Handler? = null private var mSeekBar: SeekBar? = null - private var mTimeHolder: View? = null private var mIsPlaying = false private var mIsDragged = false @@ -59,6 +59,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee lateinit var mView: View lateinit var medium: Medium + lateinit var mTimeHolder: View companion object { private val TAG = VideoFragment::class.java.simpleName @@ -67,9 +68,10 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { mView = inflater.inflate(R.layout.pager_video_item, container, false) - setupPlayer() - + mTimeHolder = mView.video_time_holder medium = arguments.getSerializable(MEDIUM) as Medium + + setupPlayer() if (savedInstanceState != null) { mCurrTime = savedInstanceState.getInt(PROGRESS) } @@ -109,6 +111,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee } initTimeHolder() + checkExtendedDetails() } override fun setMenuVisibility(menuVisible: Boolean) { @@ -131,6 +134,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee super.onConfigurationChanged(newConfig) setVideoSize() initTimeHolder() + checkExtendedDetails() } private fun toggleFullscreen() { @@ -261,11 +265,10 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee } private fun initTimeHolder() { - mTimeHolder = mView.video_time_holder val res = resources - val height = res.getNavBarHeight() - val left = mTimeHolder!!.paddingLeft - val top = mTimeHolder!!.paddingTop + val height = context.navigationBarHeight + val left = mTimeHolder.paddingLeft + val top = mTimeHolder.paddingTop var right = res.getDimension(R.dimen.timer_padding).toInt() var bottom = 0 @@ -276,7 +279,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee right += height bottom += context.navigationBarHeight } - mTimeHolder!!.setPadding(left, top, right, bottom) + mTimeHolder.setPadding(left, top, right, bottom) } mCurrTimeView = mView.video_curr_time @@ -284,7 +287,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee mSeekBar!!.setOnSeekBarChangeListener(this) if (mIsFullscreen) - mTimeHolder!!.visibility = View.INVISIBLE + mTimeHolder.beInvisible() } private fun setupTimeHolder() { @@ -328,7 +331,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee AnimationUtils.loadAnimation(activity, anim).apply { duration = 150 fillAfter = true - mTimeHolder!!.startAnimation(this) + mTimeHolder.startAnimation(this) } } @@ -494,6 +497,31 @@ 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" + } + } else { + mView.video_details.beGone() + } + } + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { if (mMediaPlayer != null && fromUser) { setProgress(progress) diff --git a/app/src/main/res/layout/pager_photo_item.xml b/app/src/main/res/layout/pager_photo_item.xml index 1c4d2d76a..6a8b21a47 100644 --- a/app/src/main/res/layout/pager_photo_item.xml +++ b/app/src/main/res/layout/pager_photo_item.xml @@ -1,6 +1,7 @@ @@ -16,4 +17,18 @@ android:layout_height="match_parent" android:visibility="gone"/> + + diff --git a/app/src/main/res/layout/pager_video_item.xml b/app/src/main/res/layout/pager_video_item.xml index 3d88f52f7..5a104f2ef 100644 --- a/app/src/main/res/layout/pager_video_item.xml +++ b/app/src/main/res/layout/pager_video_item.xml @@ -1,6 +1,7 @@ @@ -50,6 +51,20 @@ android:textColor="@android:color/white" android:textSize="@dimen/extra_big_text_size"/> + +