From 467058583bc37b835a00246ba0953eeebccd3b3e Mon Sep 17 00:00:00 2001 From: Nikola Trubitsyn Date: Fri, 2 Feb 2018 17:07:49 +0300 Subject: [PATCH] Rename callback and allow it to be set externally --- .../simplemobiletools/gallery/fragments/PhotoFragment.kt | 2 +- .../simplemobiletools/gallery/fragments/VideoFragment.kt | 5 +++-- .../simplemobiletools/gallery/helpers/MediaSideScroll.kt | 8 +++++--- 3 files changed, 9 insertions(+), 6 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 0b077c905..bac0962cb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -114,7 +114,7 @@ class PhotoFragment : ViewPagerFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - mediaSideScroll = MediaSideScroll(activity!!, view.slide_info, {}) + mediaSideScroll = MediaSideScroll(activity!!, view.slide_info) } override fun onPause() { 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 968ee24b2..0cab540ba 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -87,9 +87,10 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - mediaSideScroll = MediaSideScroll(activity!!, view.slide_info, { + mediaSideScroll = MediaSideScroll(activity!!, view.slide_info) + mediaSideScroll.onClickOnSlider = { view.video_holder.performClick() - }) + } } override fun onResume() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt index 35117fc27..f94ae7411 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt @@ -10,7 +10,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.extensions.audioManager -class MediaSideScroll(val activity: Activity, val slideInfoView: TextView, val onSpecialEvent: () -> Unit) { +class MediaSideScroll(val activity: Activity, val slideInfoView: TextView) { private val CLICK_MAX_DURATION = 150 private val SLIDE_INFO_FADE_DELAY = 1000L private var mTouchDownX = 0f @@ -24,6 +24,8 @@ class MediaSideScroll(val activity: Activity, val slideInfoView: TextView, val o private var mSlideInfoText = "" private var mSlideInfoFadeHandler = Handler() + var onClickOnSlider: (() -> Unit)? = null + fun handleVolumeTouched(event: MotionEvent) { when (event.action) { MotionEvent.ACTION_DOWN -> { @@ -55,7 +57,7 @@ class MediaSideScroll(val activity: Activity, val slideInfoView: TextView, val o val diffX = Math.abs(event.x - mTouchDownX) val diffY = Math.abs(event.y - mTouchDownY) if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION && diffX < 20 && diffY < 20) { - onSpecialEvent() + onClickOnSlider?.invoke() } } } @@ -93,7 +95,7 @@ class MediaSideScroll(val activity: Activity, val slideInfoView: TextView, val o val diffX = Math.abs(event.x - mTouchDownX) val diffY = Math.abs(event.y - mTouchDownY) if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION && diffX < 20 && diffY < 20) { - onSpecialEvent() + onClickOnSlider?.invoke() } mTouchDownBrightness = mTempBrightness }