From ace15c42487ac96f59074e9d00bd23130de783c8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 9 Feb 2018 20:29:49 +0100 Subject: [PATCH] allow skipping forward/backward by pressing curr/max time at videos --- .../gallery/extensions/Context.kt | 1 + .../gallery/fragments/VideoFragment.kt | 27 +++++++++++++------ app/src/main/res/layout/pager_video_item.xml | 20 +++++++------- app/src/main/res/values-sw600dp/dimens.xml | 1 - app/src/main/res/values/dimens.xml | 1 - 5 files changed, 31 insertions(+), 19 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 62c8f95c7..4d3ac9961 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -23,6 +23,7 @@ val Context.windowManager: WindowManager get() = getSystemService(Context.WINDOW 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 +val Context.navigationBarWidth: Int get() = if (navigationBarRight) navigationBarSize.x else 0 internal val Context.navigationBarSize: Point get() = when { 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 6eb5b4c96..5cf2dc092 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -16,10 +16,7 @@ import android.widget.TextView import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.VideoActivity -import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.extensions.navigationBarHeight -import com.simplemobiletools.gallery.extensions.usableScreenSize -import com.simplemobiletools.gallery.extensions.windowManager +import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.helpers.MediaSideScroll import com.simplemobiletools.gallery.models.Medium @@ -93,6 +90,9 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee volumeSideScroll.initialize(activity!!, slide_info, false, container) { x, y -> video_holder.performClick() } + + video_curr_time.setOnClickListener { skip(false) } + video_duration.setOnClickListener { skip(true) } } return mView @@ -186,14 +186,14 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee val height = context!!.navigationBarHeight val left = mTimeHolder!!.paddingLeft val top = mTimeHolder!!.paddingTop - var right = res.getDimension(R.dimen.timer_padding).toInt() + var right = mTimeHolder!!.paddingRight var bottom = 0 if (hasNavBar()) { if (res.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { - bottom += height + bottom += context!!.navigationBarHeight } else { - right += height + right += context!!.navigationBarWidth bottom += context!!.navigationBarHeight } mTimeHolder!!.setPadding(left, top, right, bottom) @@ -203,8 +203,9 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee mSeekBar = mView!!.video_seekbar mSeekBar!!.setOnSeekBarChangeListener(this) - if (mIsFullscreen) + if (mIsFullscreen) { mTimeHolder!!.beInvisible() + } } private fun hasNavBar(): Boolean { @@ -469,6 +470,16 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee } } + private fun skip(forward: Boolean) { + val curr = mMediaPlayer!!.currentPosition + val twoPercents = mMediaPlayer!!.duration / 50 + val newProgress = if (forward) curr + twoPercents else curr - twoPercents + setProgress(Math.round(newProgress / 1000f)) + if (!mIsPlaying) { + togglePlayPause() + } + } + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { if (mMediaPlayer != null && fromUser) { setProgress(progress) diff --git a/app/src/main/res/layout/pager_video_item.xml b/app/src/main/res/layout/pager_video_item.xml index 8b3291419..1c19114cb 100644 --- a/app/src/main/res/layout/pager_video_item.xml +++ b/app/src/main/res/layout/pager_video_item.xml @@ -81,12 +81,11 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" - android:background="@drawable/gradient_background" - android:paddingLeft="@dimen/timer_padding" - android:paddingRight="@dimen/timer_padding"> + android:background="@drawable/gradient_background"> + android:paddingLeft="@dimen/activity_margin" + android:paddingRight="@dimen/activity_margin" + android:textColor="@android:color/white" + tools:text="00:00"/> + android:paddingLeft="@dimen/activity_margin" + android:paddingRight="@dimen/activity_margin" + android:textColor="@android:color/white" + tools:text="00:00"/> diff --git a/app/src/main/res/values-sw600dp/dimens.xml b/app/src/main/res/values-sw600dp/dimens.xml index a63e7ef7d..5ce6c1c68 100644 --- a/app/src/main/res/values-sw600dp/dimens.xml +++ b/app/src/main/res/values-sw600dp/dimens.xml @@ -5,6 +5,5 @@ 30dp 38dp 230dp - 32dp 60dp diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 1e64de613..0a0cdcd24 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -6,7 +6,6 @@ 22dp 26dp 150dp - 24dp 60dp 60dp 30dp