mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-27 06:57:59 +01:00
make mView at VideoFragment nullable
This commit is contained in:
parent
0ed44b79c9
commit
7d4e413daa
1 changed files with 29 additions and 27 deletions
|
@ -36,6 +36,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
private var mTimerHandler: Handler? = null
|
private var mTimerHandler: Handler? = null
|
||||||
private var mSeekBar: SeekBar? = null
|
private var mSeekBar: SeekBar? = null
|
||||||
private var mTimeHolder: View? = null
|
private var mTimeHolder: View? = null
|
||||||
|
private var mView: View? = null
|
||||||
|
|
||||||
private var mIsPlaying = false
|
private var mIsPlaying = false
|
||||||
private var mIsDragged = false
|
private var mIsDragged = false
|
||||||
|
@ -62,12 +63,11 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
private var mSlideInfoText = ""
|
private var mSlideInfoText = ""
|
||||||
private var mSlideInfoFadeHandler = Handler()
|
private var mSlideInfoFadeHandler = Handler()
|
||||||
|
|
||||||
lateinit var mView: View
|
|
||||||
lateinit var medium: Medium
|
lateinit var medium: Medium
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
mView = inflater.inflate(R.layout.pager_video_item, container, false)
|
mView = inflater.inflate(R.layout.pager_video_item, container, false)
|
||||||
mTimeHolder = mView.video_time_holder
|
mTimeHolder = mView!!.video_time_holder
|
||||||
medium = arguments!!.getSerializable(MEDIUM) as Medium
|
medium = arguments!!.getSerializable(MEDIUM) as Medium
|
||||||
|
|
||||||
// setMenuVisibility is not called at VideoActivity (third party intent)
|
// setMenuVisibility is not called at VideoActivity (third party intent)
|
||||||
|
@ -89,9 +89,9 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
activity!!.updateTextColors(mView.video_holder)
|
activity!!.updateTextColors(mView!!.video_holder)
|
||||||
mView.video_volume_controller.beVisibleIf(context!!.config.allowVideoGestures)
|
mView!!.video_volume_controller.beVisibleIf(context!!.config.allowVideoGestures)
|
||||||
mView.video_brightness_controller.beVisibleIf(context!!.config.allowVideoGestures)
|
mView!!.video_brightness_controller.beVisibleIf(context!!.config.allowVideoGestures)
|
||||||
|
|
||||||
if (context!!.config.showExtendedDetails != mStoredShowExtendedDetails || context!!.config.extendedDetails != mStoredExtendedDetails) {
|
if (context!!.config.showExtendedDetails != mStoredShowExtendedDetails || context!!.config.extendedDetails != mStoredExtendedDetails) {
|
||||||
checkExtendedDetails()
|
checkExtendedDetails()
|
||||||
|
@ -116,19 +116,19 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
if (activity == null)
|
if (activity == null)
|
||||||
return
|
return
|
||||||
|
|
||||||
mView.video_play_outline.setOnClickListener { togglePlayPause() }
|
mView!!.video_play_outline.setOnClickListener { togglePlayPause() }
|
||||||
|
|
||||||
mSurfaceView = mView.video_surface
|
mSurfaceView = mView!!.video_surface
|
||||||
mSurfaceHolder = mSurfaceView!!.holder
|
mSurfaceHolder = mSurfaceView!!.holder
|
||||||
mSurfaceHolder!!.addCallback(this)
|
mSurfaceHolder!!.addCallback(this)
|
||||||
mSurfaceView!!.setOnClickListener { toggleFullscreen() }
|
mSurfaceView!!.setOnClickListener { toggleFullscreen() }
|
||||||
mView.video_holder.setOnClickListener { toggleFullscreen() }
|
mView!!.video_holder.setOnClickListener { toggleFullscreen() }
|
||||||
mView.video_volume_controller.setOnTouchListener { v, event ->
|
mView!!.video_volume_controller.setOnTouchListener { v, event ->
|
||||||
handleVolumeTouched(event)
|
handleVolumeTouched(event)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
mView.video_brightness_controller.setOnTouchListener { v, event ->
|
mView!!.video_brightness_controller.setOnTouchListener { v, event ->
|
||||||
handleBrightnessTouched(event)
|
handleBrightnessTouched(event)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
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) {
|
||||||
mView.video_holder.performClick()
|
mView!!.video_holder.performClick()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,12 +233,12 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
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) {
|
||||||
mView.video_holder.performClick()
|
mView!!.video_holder.performClick()
|
||||||
}
|
}
|
||||||
mTouchDownBrightness = mTempBrightness
|
mTouchDownBrightness = mTempBrightness
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mView.video_holder
|
mView!!.video_holder
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCurrentVolume() = context!!.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
|
private fun getCurrentVolume() = context!!.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
|
||||||
|
@ -254,14 +254,14 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
context!!.audioManager.setStreamVolume(stream, newVolume, 0)
|
context!!.audioManager.setStreamVolume(stream, newVolume, 0)
|
||||||
|
|
||||||
val absolutePercent = ((newVolume / maxVolume.toFloat()) * 100).toInt()
|
val absolutePercent = ((newVolume / maxVolume.toFloat()) * 100).toInt()
|
||||||
mView.slide_info.apply {
|
mView!!.slide_info.apply {
|
||||||
text = "$mSlideInfoText$absolutePercent%"
|
text = "$mSlideInfoText$absolutePercent%"
|
||||||
alpha = 1f
|
alpha = 1f
|
||||||
}
|
}
|
||||||
|
|
||||||
mSlideInfoFadeHandler.removeCallbacksAndMessages(null)
|
mSlideInfoFadeHandler.removeCallbacksAndMessages(null)
|
||||||
mSlideInfoFadeHandler.postDelayed({
|
mSlideInfoFadeHandler.postDelayed({
|
||||||
mView.slide_info.animate().alpha(0f)
|
mView!!.slide_info.animate().alpha(0f)
|
||||||
}, SLIDE_INFO_FADE_DELAY)
|
}, SLIDE_INFO_FADE_DELAY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
mTempBrightness = newBrightness.toInt()
|
mTempBrightness = newBrightness.toInt()
|
||||||
|
|
||||||
val absolutePercent = ((newBrightness / maxBrightness) * 100).toInt()
|
val absolutePercent = ((newBrightness / maxBrightness) * 100).toInt()
|
||||||
mView.slide_info.apply {
|
mView!!.slide_info.apply {
|
||||||
text = "$mSlideInfoText$absolutePercent%"
|
text = "$mSlideInfoText$absolutePercent%"
|
||||||
alpha = 1f
|
alpha = 1f
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
|
|
||||||
mSlideInfoFadeHandler.removeCallbacksAndMessages(null)
|
mSlideInfoFadeHandler.removeCallbacksAndMessages(null)
|
||||||
mSlideInfoFadeHandler.postDelayed({
|
mSlideInfoFadeHandler.postDelayed({
|
||||||
mView.slide_info.animate().alpha(0f)
|
mView!!.slide_info.animate().alpha(0f)
|
||||||
}, SLIDE_INFO_FADE_DELAY)
|
}, SLIDE_INFO_FADE_DELAY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,8 +305,8 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
mTimeHolder!!.setPadding(left, top, right, bottom)
|
mTimeHolder!!.setPadding(left, top, right, bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
mCurrTimeView = mView.video_curr_time
|
mCurrTimeView = mView!!.video_curr_time
|
||||||
mSeekBar = mView.video_seekbar
|
mSeekBar = mView!!.video_seekbar
|
||||||
mSeekBar!!.setOnSeekBarChangeListener(this)
|
mSeekBar!!.setOnSeekBarChangeListener(this)
|
||||||
|
|
||||||
if (mIsFullscreen)
|
if (mIsFullscreen)
|
||||||
|
@ -339,7 +339,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
|
|
||||||
private fun setupTimeHolder() {
|
private fun setupTimeHolder() {
|
||||||
mSeekBar!!.max = mDuration
|
mSeekBar!!.max = mDuration
|
||||||
mView.video_duration.text = mDuration.getFormattedDuration()
|
mView!!.video_duration.text = mDuration.getFormattedDuration()
|
||||||
mTimerHandler = Handler()
|
mTimerHandler = Handler()
|
||||||
setupTimer()
|
setupTimer()
|
||||||
}
|
}
|
||||||
|
@ -403,14 +403,14 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
} else {
|
} else {
|
||||||
mPlayOnPrepare = true
|
mPlayOnPrepare = true
|
||||||
}
|
}
|
||||||
mView.video_play_outline.setImageDrawable(null)
|
mView!!.video_play_outline.setImageDrawable(null)
|
||||||
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun pauseVideo() {
|
private fun pauseVideo() {
|
||||||
mIsPlaying = false
|
mIsPlaying = false
|
||||||
mMediaPlayer?.pause()
|
mMediaPlayer?.pause()
|
||||||
mView.video_play_outline.setImageDrawable(resources.getDrawable(R.drawable.img_play_outline_big))
|
mView?.video_play_outline?.setImageDrawable(resources.getDrawable(R.drawable.img_play_outline_big))
|
||||||
activity!!.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
activity!!.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,14 +500,16 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
|
|
||||||
override fun surfaceCreated(holder: SurfaceHolder) {
|
override fun surfaceCreated(holder: SurfaceHolder) {
|
||||||
mSurfaceHolder = holder
|
mSurfaceHolder = holder
|
||||||
if (mIsFragmentVisible)
|
if (mIsFragmentVisible) {
|
||||||
initMediaPlayer()
|
initMediaPlayer()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
|
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
|
||||||
if (width != 0 && height != 0 && mSurfaceView != null)
|
if (width != 0 && height != 0 && mSurfaceView != null) {
|
||||||
setVideoSize()
|
setVideoSize()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun surfaceDestroyed(holder: SurfaceHolder) {
|
override fun surfaceDestroyed(holder: SurfaceHolder) {
|
||||||
releaseMediaPlayer()
|
releaseMediaPlayer()
|
||||||
|
@ -557,7 +559,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
|
|
||||||
private fun checkExtendedDetails() {
|
private fun checkExtendedDetails() {
|
||||||
if (context!!.config.showExtendedDetails) {
|
if (context!!.config.showExtendedDetails) {
|
||||||
mView.video_details.apply {
|
mView!!.video_details.apply {
|
||||||
text = getMediumExtendedDetails(medium)
|
text = getMediumExtendedDetails(medium)
|
||||||
setTextColor(context.config.textColor)
|
setTextColor(context.config.textColor)
|
||||||
beVisibleIf(text.isNotEmpty())
|
beVisibleIf(text.isNotEmpty())
|
||||||
|
@ -568,7 +570,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mView.video_details.beGone()
|
mView!!.video_details.beGone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -600,7 +602,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
override fun fullscreenToggled(isFullscreen: Boolean) {
|
override fun fullscreenToggled(isFullscreen: Boolean) {
|
||||||
mIsFullscreen = isFullscreen
|
mIsFullscreen = isFullscreen
|
||||||
checkFullscreen()
|
checkFullscreen()
|
||||||
mView.video_details.apply {
|
mView!!.video_details.apply {
|
||||||
if (isVisible()) {
|
if (isVisible()) {
|
||||||
animate().y(getExtendedDetailsY(height))
|
animate().y(getExtendedDetailsY(height))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue