From 56a31e6ced95b9a923099503f66250067c4fc8d6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 17 Sep 2017 11:17:51 +0200 Subject: [PATCH] fix #326, properly set bottom padding in landscape mode videos --- .../gallery/extensions/context.kt | 29 +++++++++++++++++++ .../gallery/fragments/VideoFragment.kt | 6 ++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index 8a0613a58..51ac6da09 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -4,9 +4,12 @@ import android.content.Context import android.content.Intent import android.content.res.Configuration import android.database.Cursor +import android.graphics.Point import android.media.AudioManager import android.net.Uri +import android.os.Build import android.provider.MediaStore +import android.view.WindowManager import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.commons.helpers.SORT_BY_NAME @@ -19,6 +22,32 @@ import java.io.File val Context.portrait get() = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT val Context.audioManager get() = getSystemService(Context.AUDIO_SERVICE) as AudioManager +val Context.windowManager: WindowManager get() = getSystemService(Context.WINDOW_SERVICE) as WindowManager +val Context.navigationBarRight: Boolean get() = usableScreenSize.x < realScreenSize.x +val Context.navigationBarBottom: Boolean get() = usableScreenSize.y < realScreenSize.y +val Context.navigationBarHeight: Int get() = if (navigationBarBottom) navigationBarSize.y else 0 + +internal val Context.navigationBarSize: Point + get() = when { + navigationBarRight -> Point(realScreenSize.x - usableScreenSize.x, usableScreenSize.y) + navigationBarBottom -> Point(usableScreenSize.x, realScreenSize.y - usableScreenSize.y) + else -> Point() + } + +val Context.usableScreenSize: Point + get() { + val size = Point() + windowManager.defaultDisplay.getSize(size) + return size + } + +val Context.realScreenSize: Point + get() { + val size = Point() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) + windowManager.defaultDisplay.getRealSize(size) + return size + } fun Context.getRealPathFromURI(uri: Uri): String? { var cursor: Cursor? = null 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 a2762d99a..1828912e7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -20,10 +20,7 @@ import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.ViewPagerActivity -import com.simplemobiletools.gallery.extensions.audioManager -import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.extensions.getNavBarHeight -import com.simplemobiletools.gallery.extensions.hasNavBar +import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.pager_video_item.view.* @@ -273,6 +270,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee bottom += height } else { right += height + bottom += context.navigationBarHeight } mTimeHolder!!.setPadding(left, top, right, bottom) }