Rename callback and allow it to be set externally

This commit is contained in:
Nikola Trubitsyn 2018-02-02 17:07:49 +03:00
parent 5ab2bc2fe7
commit 467058583b
3 changed files with 9 additions and 6 deletions

View file

@ -114,7 +114,7 @@ class PhotoFragment : ViewPagerFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
mediaSideScroll = MediaSideScroll(activity!!, view.slide_info, {}) mediaSideScroll = MediaSideScroll(activity!!, view.slide_info)
} }
override fun onPause() { override fun onPause() {

View file

@ -87,9 +87,10 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
mediaSideScroll = MediaSideScroll(activity!!, view.slide_info, { mediaSideScroll = MediaSideScroll(activity!!, view.slide_info)
mediaSideScroll.onClickOnSlider = {
view.video_holder.performClick() view.video_holder.performClick()
}) }
} }
override fun onResume() { override fun onResume() {

View file

@ -10,7 +10,7 @@ import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.activities.ViewPagerActivity
import com.simplemobiletools.gallery.extensions.audioManager 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 CLICK_MAX_DURATION = 150
private val SLIDE_INFO_FADE_DELAY = 1000L private val SLIDE_INFO_FADE_DELAY = 1000L
private var mTouchDownX = 0f private var mTouchDownX = 0f
@ -24,6 +24,8 @@ class MediaSideScroll(val activity: Activity, val slideInfoView: TextView, val o
private var mSlideInfoText = "" private var mSlideInfoText = ""
private var mSlideInfoFadeHandler = Handler() private var mSlideInfoFadeHandler = Handler()
var onClickOnSlider: (() -> Unit)? = null
fun handleVolumeTouched(event: MotionEvent) { fun handleVolumeTouched(event: MotionEvent) {
when (event.action) { when (event.action) {
MotionEvent.ACTION_DOWN -> { 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 diffX = Math.abs(event.x - mTouchDownX)
val diffY = Math.abs(event.y - mTouchDownY) val diffY = Math.abs(event.y - mTouchDownY)
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION && diffX < 20 && diffY < 20) { 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 diffX = Math.abs(event.x - mTouchDownX)
val diffY = Math.abs(event.y - mTouchDownY) val diffY = Math.abs(event.y - mTouchDownY)
if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION && diffX < 20 && diffY < 20) { if (System.currentTimeMillis() - mTouchDownTime < CLICK_MAX_DURATION && diffX < 20 && diffY < 20) {
onSpecialEvent() onClickOnSlider?.invoke()
} }
mTouchDownBrightness = mTempBrightness mTouchDownBrightness = mTempBrightness
} }