@ -22,17 +22,17 @@ import android.os.Bundle
import android.os.Handler
import android.os.Handler
import android.os.Looper
import android.os.Looper
import android.support.v4.view.ViewCompat
import android.support.v4.view.ViewCompat
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.LayoutInflater
import android.view.View
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup
import android.widget.MediaController
import android.widget.MediaController
import android.widget.TextView
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.ViewMediaActivity
import com.keylesspalace.tusky.ViewMediaActivity
import com.keylesspalace.tusky.entity.Attachment
import com.keylesspalace.tusky.entity.Attachment
import com.keylesspalace.tusky.util.hide
import com.keylesspalace.tusky.util.hide
import com.keylesspalace.tusky.util.show
import com.keylesspalace.tusky.util.visible
import kotlinx.android.synthetic.main.activity_view_media.*
import kotlinx.android.synthetic.main.activity_view_media.*
import kotlinx.android.synthetic.main.fragment_view_video.*
import kotlinx.android.synthetic.main.fragment_view_video.*
@ -46,9 +46,8 @@ class ViewVideoFragment : ViewMediaFragment() {
}
}
private lateinit var mediaActivity : ViewMediaActivity
private lateinit var mediaActivity : ViewMediaActivity
private val TOOLBAR _HIDE _DELAY _MS = 3000L
private val TOOLBAR _HIDE _DELAY _MS = 3000L
override lateinit var descriptionView : TextView
private var showingDescription = false
private lateinit var mediaController : MediaController
private var isDescriptionVisible = false
companion object {
companion object {
private const val TAG = " ViewVideoFragment "
private const val TAG = " ViewVideoFragment "
@ -65,20 +64,23 @@ class ViewVideoFragment : ViewMediaFragment() {
if ( mediaActivity . isToolbarVisible ( ) ) {
if ( mediaActivity . isToolbarVisible ( ) ) {
handler . postDelayed ( hideToolbar , TOOLBAR _HIDE _DELAY _MS )
handler . postDelayed ( hideToolbar , TOOLBAR _HIDE _DELAY _MS )
}
}
videoPlayer ? .start ( )
videoPlayer . start ( )
} else {
} else {
handler . removeCallbacks ( hideToolbar )
handler . removeCallbacks ( hideToolbar )
videoPlayer ?. pause ( )
videoPlayer . pause ( )
mediaController . hide ( )
}
}
}
}
@SuppressLint ( " ClickableViewAccessibility " )
@SuppressLint ( " ClickableViewAccessibility " )
override fun setupMediaView ( url : String ) {
override fun setupMediaView ( url : String ) {
descriptionView = mediaDescription
val videoView = videoPlayer
val videoView = videoPlayer
ViewCompat . setTransitionName ( videoView , url )
videoView . setVideoPath ( url )
videoView . setVideoPath ( url )
val c ontroller = MediaController ( mediaActivity )
mediaC ontroller = MediaController ( mediaActivity )
c ontroller. setMediaPlayer ( videoView )
mediaC ontroller. setMediaPlayer ( videoPlayer )
videoView . setMediaController ( c ontroller)
videoPlayer . setMediaController ( mediaC ontroller)
videoView . requestFocus ( )
videoView . requestFocus ( )
videoView . setOnTouchListener { _ , _ ->
videoView . setOnTouchListener { _ , _ ->
mediaActivity . onPhotoTap ( )
mediaActivity . onPhotoTap ( )
@ -110,34 +112,14 @@ class ViewVideoFragment : ViewMediaFragment() {
override fun onViewCreated ( view : View , savedInstanceState : Bundle ? ) {
override fun onViewCreated ( view : View , savedInstanceState : Bundle ? ) {
super . onViewCreated ( view , savedInstanceState )
super . onViewCreated ( view , savedInstanceState )
val attachment = arguments ?. getParcelable < Attachment > ( ViewMediaFragment . ARG _ATTACHMENT )
val arguments = this . arguments !!
val attachment = arguments . getParcelable < Attachment > ( ViewMediaFragment . ARG _ATTACHMENT )
val url : String
val url : String
if ( attachment == null ) {
if ( attachment == null ) {
throw IllegalArgumentException ( " attachment has to be set " )
throw IllegalArgumentException ( " attachment has to be set " )
}
}
url = attachment . url
url = attachment . url
val description = attachment . description
finalizeViewSetup ( url , attachment . description )
mediaDescription . text = description
showingDescription = ! TextUtils . isEmpty ( description )
isDescriptionVisible = showingDescription
// Setting visibility without animations so it looks nice when you scroll media
//noinspection ConstantConditions
if ( showingDescription && mediaActivity . isToolbarVisible ( ) ) {
mediaDescription . show ( )
} else {
mediaDescription . hide ( )
}
ViewCompat . setTransitionName ( videoPlayer !! , url )
setupMediaView ( url )
setupToolbarVisibilityListener ( )
}
}
override fun onToolbarVisibilityChange ( visible : Boolean ) {
override fun onToolbarVisibilityChange ( visible : Boolean ) {
@ -147,14 +129,10 @@ class ViewVideoFragment : ViewMediaFragment() {
isDescriptionVisible = showingDescription && visible
isDescriptionVisible = showingDescription && visible
val alpha = if ( isDescriptionVisible ) 1.0f else 0.0f
val alpha = if ( isDescriptionVisible ) 1.0f else 0.0f
me diaD escription. animate ( ) . alpha ( alpha )
descriptionView . animate ( ) . alpha ( alpha )
. setListener ( object : AnimatorListenerAdapter ( ) {
. setListener ( object : AnimatorListenerAdapter ( ) {
override fun onAnimationEnd ( animation : Animator ) {
override fun onAnimationEnd ( animation : Animator ) {
if ( isDescriptionVisible ) {
descriptionView . visible ( isDescriptionVisible )
mediaDescription . show ( )
} else {
mediaDescription . hide ( )
}
animation . removeListener ( this )
animation . removeListener ( this )
}
}
} )
} )