From 330d501889c9aa9bbfcb362501b009162b0e3b42 Mon Sep 17 00:00:00 2001 From: Nikola Trubitsyn Date: Fri, 2 Feb 2018 16:50:19 +0300 Subject: [PATCH] Remove Context from MediaSideScroll constructor --- .../gallery/fragments/PhotoFragment.kt | 2 +- .../gallery/fragments/VideoFragment.kt | 2 +- .../gallery/helpers/MediaSideScroll.kt | 13 ++++++------- 3 files changed, 8 insertions(+), 9 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 d689fa449..0b077c905 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(context!!, 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 1c3516642..968ee24b2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -87,7 +87,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - mediaSideScroll = MediaSideScroll(context!!, activity!!, view.slide_info, { + mediaSideScroll = MediaSideScroll(activity!!, view.slide_info, { view.video_holder.performClick() }) } 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 9536f7abb..3aaf33ff0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt @@ -1,7 +1,6 @@ package com.simplemobiletools.gallery.helpers import android.app.Activity -import android.content.Context import android.media.AudioManager import android.os.Handler import android.provider.Settings @@ -11,7 +10,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.extensions.audioManager -class MediaSideScroll(val context: Context, val activity: Activity, val slideInfoView: TextView, val onSpecialEvent: () -> Unit) { +class MediaSideScroll(val activity: Activity, val slideInfoView: TextView, val onSpecialEvent: () -> Unit) { private val CLICK_MAX_DURATION = 150 private val SLIDE_INFO_FADE_DELAY = 1000L private var mTouchDownX = 0f @@ -33,7 +32,7 @@ class MediaSideScroll(val context: Context, val activity: Activity, val slideInf mLastTouchY = event.y mTouchDownTime = System.currentTimeMillis() mTouchDownVolume = getCurrentVolume() - mSlideInfoText = "${context.getString(R.string.volume)}:\n" + mSlideInfoText = "${activity.getString(R.string.volume)}:\n" } MotionEvent.ACTION_MOVE -> { val diffX = mTouchDownX - event.x @@ -69,7 +68,7 @@ class MediaSideScroll(val context: Context, val activity: Activity, val slideInf mTouchDownY = event.y mLastTouchY = event.y mTouchDownTime = System.currentTimeMillis() - mSlideInfoText = "${context.getString(R.string.brightness)}:\n" + mSlideInfoText = "${activity.getString(R.string.brightness)}:\n" if (mTouchDownBrightness == -1) mTouchDownBrightness = getCurrentBrightness() } @@ -102,17 +101,17 @@ class MediaSideScroll(val context: Context, val activity: Activity, val slideInf //mView.video_holder } - private fun getCurrentVolume() = context.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) + private fun getCurrentVolume() = activity.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) private fun getCurrentBrightness() = Settings.System.getInt(activity.contentResolver, Settings.System.SCREEN_BRIGHTNESS) private fun volumePercentChanged(percent: Int) { val stream = AudioManager.STREAM_MUSIC - val maxVolume = context.audioManager.getStreamMaxVolume(stream) + val maxVolume = activity.audioManager.getStreamMaxVolume(stream) val percentPerPoint = 100 / maxVolume val addPoints = percent / percentPerPoint val newVolume = Math.min(maxVolume, Math.max(0, mTouchDownVolume + addPoints)) - context.audioManager.setStreamVolume(stream, newVolume, 0) + activity.audioManager.setStreamVolume(stream, newVolume, 0) val absolutePercent = ((newVolume / maxVolume.toFloat()) * 100).toInt() slideInfoView.apply {