From ae9cce880ae097c22cde2ec93c0d304926748a36 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 9 Nov 2017 19:09:31 +0100 Subject: [PATCH] make sure extended details are always properly positioned --- .../gallery/fragments/PhotoFragment.kt | 19 ++++++++++++------- .../gallery/fragments/VideoFragment.kt | 19 ++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) 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 e596e9d16..173becce8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -39,6 +39,7 @@ import java.io.FileOutputStream class PhotoFragment : ViewPagerFragment() { private var isFragmentVisible = false + private var isFullscreen = false private var wasInit = false private var storedShowExtendedDetails = false private var storedExtendedDetails = 0 @@ -86,6 +87,7 @@ class PhotoFragment : ViewPagerFragment() { } } + isFullscreen = activity!!.window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_FULLSCREEN == View.SYSTEM_UI_FLAG_FULLSCREEN view.subsampling_view.setOnClickListener { photoClicked() } view.gif_view.setOnClickListener { photoClicked() } loadImage() @@ -288,9 +290,8 @@ class PhotoFragment : ViewPagerFragment() { setTextColor(context.config.textColor) beVisibleIf(text.isNotEmpty()) onGlobalLayout { - if (height != 0) { - val smallMargin = resources.getDimension(R.dimen.small_margin) - y = context.usableScreenSize.y - height - if (context.navigationBarHeight == 0) smallMargin else 0f + if (height != 0 && isAdded) { + y = getExtendedDetailsY(height) } } } @@ -317,13 +318,17 @@ class PhotoFragment : ViewPagerFragment() { } override fun fullscreenToggled(isFullscreen: Boolean) { + this.isFullscreen = isFullscreen view.photo_details.apply { if (visibility == View.VISIBLE) { - val smallMargin = resources.getDimension(R.dimen.small_margin) - val fullscreenOffset = context.navigationBarHeight.toFloat() - smallMargin - val newY = context.usableScreenSize.y - height + if (isFullscreen) fullscreenOffset else -(if (context.navigationBarHeight == 0) smallMargin else 0f) - animate().y(newY) + animate().y(getExtendedDetailsY(height)) } } } + + private fun getExtendedDetailsY(height: Int): Float { + val smallMargin = resources.getDimension(R.dimen.small_margin) + val fullscreenOffset = context!!.navigationBarHeight.toFloat() - smallMargin + return context!!.usableScreenSize.y - height + if (isFullscreen) fullscreenOffset else -(if (context!!.navigationBarHeight == 0) smallMargin else 0f) + } } 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 47c97d86b..4bbb1e138 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -555,10 +555,8 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee setTextColor(context.config.textColor) beVisibleIf(text.isNotEmpty()) onGlobalLayout { - if (height != 0) { - val smallMargin = resources.getDimension(R.dimen.small_margin) - val timeHolderHeight = mTimeHolder!!.height - context.navigationBarHeight - y = context.usableScreenSize.y - height - timeHolderHeight - if (context.navigationBarHeight == 0) smallMargin else 0f + if (height != 0 && isAdded) { + y = getExtendedDetailsY(height) } } } @@ -597,12 +595,15 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee checkFullscreen() mView.video_details.apply { if (visibility == View.VISIBLE) { - val smallMargin = resources.getDimension(R.dimen.small_margin) - val timeHolderHeight = mTimeHolder!!.height - context.navigationBarHeight.toFloat() - val fullscreenOffset = context.navigationBarHeight.toFloat() - smallMargin - val newY = context.usableScreenSize.y - height + if (mIsFullscreen) fullscreenOffset else -(timeHolderHeight + if (context.navigationBarHeight == 0) smallMargin else 0f) - animate().y(newY) + animate().y(getExtendedDetailsY(height)) } } } + + private fun getExtendedDetailsY(height: Int): Float { + val smallMargin = resources.getDimension(R.dimen.small_margin) + val timeHolderHeight = mTimeHolder!!.height - context!!.navigationBarHeight.toFloat() + val fullscreenOffset = context!!.navigationBarHeight.toFloat() - smallMargin + return context!!.usableScreenSize.y - height + if (mIsFullscreen) fullscreenOffset else -(timeHolderHeight + if (context!!.navigationBarHeight == 0) smallMargin else 0f) + } }