allow skipping forward/backward by pressing curr/max time at videos

This commit is contained in:
tibbi 2018-02-09 20:29:49 +01:00
parent 0616117f36
commit ace15c4248
5 changed files with 31 additions and 19 deletions

View file

@ -23,6 +23,7 @@ val Context.windowManager: WindowManager get() = getSystemService(Context.WINDOW
val Context.navigationBarRight: Boolean get() = usableScreenSize.x < realScreenSize.x val Context.navigationBarRight: Boolean get() = usableScreenSize.x < realScreenSize.x
val Context.navigationBarBottom: Boolean get() = usableScreenSize.y < realScreenSize.y val Context.navigationBarBottom: Boolean get() = usableScreenSize.y < realScreenSize.y
val Context.navigationBarHeight: Int get() = if (navigationBarBottom) navigationBarSize.y else 0 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 internal val Context.navigationBarSize: Point
get() = when { get() = when {

View file

@ -16,10 +16,7 @@ import android.widget.TextView
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.VideoActivity import com.simplemobiletools.gallery.activities.VideoActivity
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.*
import com.simplemobiletools.gallery.extensions.navigationBarHeight
import com.simplemobiletools.gallery.extensions.usableScreenSize
import com.simplemobiletools.gallery.extensions.windowManager
import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.helpers.MediaSideScroll import com.simplemobiletools.gallery.helpers.MediaSideScroll
import com.simplemobiletools.gallery.models.Medium 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 -> volumeSideScroll.initialize(activity!!, slide_info, false, container) { x, y ->
video_holder.performClick() video_holder.performClick()
} }
video_curr_time.setOnClickListener { skip(false) }
video_duration.setOnClickListener { skip(true) }
} }
return mView return mView
@ -186,14 +186,14 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
val height = context!!.navigationBarHeight val height = context!!.navigationBarHeight
val left = mTimeHolder!!.paddingLeft val left = mTimeHolder!!.paddingLeft
val top = mTimeHolder!!.paddingTop val top = mTimeHolder!!.paddingTop
var right = res.getDimension(R.dimen.timer_padding).toInt() var right = mTimeHolder!!.paddingRight
var bottom = 0 var bottom = 0
if (hasNavBar()) { if (hasNavBar()) {
if (res.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) { if (res.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
bottom += height bottom += context!!.navigationBarHeight
} else { } else {
right += height right += context!!.navigationBarWidth
bottom += context!!.navigationBarHeight bottom += context!!.navigationBarHeight
} }
mTimeHolder!!.setPadding(left, top, right, bottom) mTimeHolder!!.setPadding(left, top, right, bottom)
@ -203,8 +203,9 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
mSeekBar = mView!!.video_seekbar mSeekBar = mView!!.video_seekbar
mSeekBar!!.setOnSeekBarChangeListener(this) mSeekBar!!.setOnSeekBarChangeListener(this)
if (mIsFullscreen) if (mIsFullscreen) {
mTimeHolder!!.beInvisible() mTimeHolder!!.beInvisible()
}
} }
private fun hasNavBar(): Boolean { 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) { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
if (mMediaPlayer != null && fromUser) { if (mMediaPlayer != null && fromUser) {
setProgress(progress) setProgress(progress)

View file

@ -81,12 +81,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:background="@drawable/gradient_background" android:background="@drawable/gradient_background">
android:paddingLeft="@dimen/timer_padding"
android:paddingRight="@dimen/timer_padding">
<TextView <TextView
android:id="@+id/video_curr_time" android:id="@+id/video_curr_time"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignBottom="@+id/video_seekbar" android:layout_alignBottom="@+id/video_seekbar"
@ -94,15 +93,15 @@
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_alignTop="@+id/video_seekbar" android:layout_alignTop="@+id/video_seekbar"
android:gravity="center_vertical" android:gravity="center_vertical"
android:text="00:00" android:paddingLeft="@dimen/activity_margin"
android:textColor="@android:color/white"/> android:paddingRight="@dimen/activity_margin"
android:textColor="@android:color/white"
tools:text="00:00"/>
<com.simplemobiletools.commons.views.MySeekBar <com.simplemobiletools.commons.views.MySeekBar
android:id="@+id/video_seekbar" android:id="@+id/video_seekbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_marginRight="@dimen/activity_margin"
android:layout_toEndOf="@+id/video_curr_time" android:layout_toEndOf="@+id/video_curr_time"
android:layout_toLeftOf="@+id/video_duration" android:layout_toLeftOf="@+id/video_duration"
android:layout_toRightOf="@+id/video_curr_time" android:layout_toRightOf="@+id/video_curr_time"
@ -112,6 +111,7 @@
<TextView <TextView
android:id="@+id/video_duration" android:id="@+id/video_duration"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="@+id/video_seekbar" android:layout_alignBottom="@+id/video_seekbar"
@ -119,8 +119,10 @@
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignTop="@+id/video_seekbar" android:layout_alignTop="@+id/video_seekbar"
android:gravity="center_vertical" android:gravity="center_vertical"
android:text="00:00" android:paddingLeft="@dimen/activity_margin"
android:textColor="@android:color/white"/> android:paddingRight="@dimen/activity_margin"
android:textColor="@android:color/white"
tools:text="00:00"/>
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>

View file

@ -5,6 +5,5 @@
<dimen name="sd_card_icon_size">30dp</dimen> <dimen name="sd_card_icon_size">30dp</dimen>
<dimen name="selection_check_size">38dp</dimen> <dimen name="selection_check_size">38dp</dimen>
<dimen name="play_outline_size_big">230dp</dimen> <dimen name="play_outline_size_big">230dp</dimen>
<dimen name="timer_padding">32dp</dimen>
<dimen name="tmb_shadow_height">60dp</dimen> <dimen name="tmb_shadow_height">60dp</dimen>
</resources> </resources>

View file

@ -6,7 +6,6 @@
<dimen name="play_outline_icon_size">22dp</dimen> <dimen name="play_outline_icon_size">22dp</dimen>
<dimen name="selection_check_size">26dp</dimen> <dimen name="selection_check_size">26dp</dimen>
<dimen name="play_outline_size_big">150dp</dimen> <dimen name="play_outline_size_big">150dp</dimen>
<dimen name="timer_padding">24dp</dimen>
<dimen name="tmb_shadow_height">60dp</dimen> <dimen name="tmb_shadow_height">60dp</dimen>
<dimen name="media_side_slider_width">60dp</dimen> <dimen name="media_side_slider_width">60dp</dimen>
<dimen name="instant_change_bar_width">30dp</dimen> <dimen name="instant_change_bar_width">30dp</dimen>