aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-11-12 02:48:36 -0500
committerGitHub <noreply@github.com>2017-11-12 02:48:36 -0500
commit2b51bc4bfa86863ed14b550fe3281840587ab038 (patch)
tree0fd7276e326ed0901b1af980d07d57f3bbb7d7eb /app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
parentec7fdc2521463d0a773bb9d0be454f3b2a60eee3 (diff)
downloadfrost-2b51bc4bfa86863ed14b550fe3281840587ab038.tar.gz
frost-2b51bc4bfa86863ed14b550fe3281840587ab038.tar.bz2
frost-2b51bc4bfa86863ed14b550fe3281840587ab038.zip
enhancement/video-player (#480)v1.6.3
* Add toolbar visibility toggle and draw it over viewer * Set contract bindings once available * Fix video url param error and prepare progressanimator * Add gif support and better transitions * Interface a lot of things * Reorder back press * Clean up files and fix selector * Add gif support * Redraw bounds when necessary
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt49
1 files changed, 34 insertions, 15 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
index bf4df8fe..3a773288 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
@@ -13,6 +13,7 @@ import android.view.ViewTreeObserver
import android.widget.FrameLayout
import android.widget.ImageView
import ca.allanwang.kau.utils.*
+import com.devbrackets.android.exomedia.listener.VideoControlsVisibilityListener
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.pitchedapps.frost.R
import com.pitchedapps.frost.facebook.formattedFbUrl
@@ -35,17 +36,21 @@ class FrostVideoViewer @JvmOverloads constructor(
companion object {
/**
+ * Matches VideoControls.CONTROL_VISIBILITY_ANIMATION_LENGTH
+ */
+ private const val CONTROL_ANIMATION_DURATION = 300L
+
+ /**
* Simplified binding to add video to layout, and remove it when finished
* This is under the assumption that the container allows for overlays,
* such as a FrameLayout
*/
- fun showVideo(url: String, contract: FrostVideoContainerContract): FrostVideoViewer {
+ fun showVideo(url: String, repeat: Boolean, contract: FrostVideoContainerContract): FrostVideoViewer {
val container = contract.videoContainer
val videoViewer = FrostVideoViewer(container.context)
container.addView(videoViewer)
videoViewer.bringToFront()
- L.d("Create video view", url)
- videoViewer.setVideo(url)
+ videoViewer.setVideo(url, repeat)
videoViewer.video.containerContract = contract
videoViewer.video.onFinishedListener = { container.removeView(videoViewer); contract.onVideoFinished() }
return videoViewer
@@ -56,11 +61,9 @@ class FrostVideoViewer @JvmOverloads constructor(
inflate(R.layout.view_video, true)
alpha = 0f
background.setBackgroundColor(if (Prefs.bgColor.isColorDark) Prefs.bgColor.withMinAlpha(200) else Color.BLACK)
- video.backgroundView = background
- video.viewerContract = this
+ video.setViewerContract(this)
video.pause()
toolbar.inflateMenu(R.menu.menu_video)
- toolbar.setBackgroundColor(Prefs.headerColor)
context.setMenuIcons(toolbar.menu, Prefs.iconColor,
R.id.action_pip to GoogleMaterial.Icon.gmd_picture_in_picture_alt,
R.id.action_download to GoogleMaterial.Icon.gmd_file_download
@@ -77,12 +80,14 @@ class FrostVideoViewer @JvmOverloads constructor(
video.restart()
restarter.fadeOut { restarter.gone() }
}
-// toolbar.setOnTouchListener { _, event -> video.shouldParentAcceptTouch(event) }
}
- fun setVideo(url: String) {
+ fun setVideo(url: String, repeat: Boolean = false) {
+ val formattedUrl = url.formattedFbUrl
+ L.d("Load video view; repeat: $repeat", url)
animate().alpha(1f).setDuration(FrostVideoView.ANIMATION_DURATION).start()
- video.setVideoURI(Uri.parse(url.formattedFbUrl))
+ video.setVideoURI(Uri.parse(formattedUrl))
+ video.repeat = repeat
}
/**
@@ -106,10 +111,9 @@ class FrostVideoViewer @JvmOverloads constructor(
* -------------------------------------------------------------
*/
- override fun onFade(alpha: Float, duration: Long) {
- toolbar.visible().animate().alpha(alpha).setDuration(duration).withEndAction {
- if (alpha == 0f) toolbar.gone()
- }
+ override fun onExpand(progress: Float) {
+ toolbar.goneIf(progress == 0f).alpha = progress
+ background.alpha = progress
}
override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
@@ -134,11 +138,26 @@ class FrostVideoViewer @JvmOverloads constructor(
})
}
+ override fun onControlsShown() {
+ if (video.isExpanded)
+ toolbar.fadeIn(duration = CONTROL_ANIMATION_DURATION, onStart = { toolbar.visible() })
+ }
+
+ override fun onControlsHidden() {
+ if (!toolbar.isGone)
+ toolbar.fadeOut(duration = CONTROL_ANIMATION_DURATION) { toolbar.gone() }
+ }
+
}
-interface FrostVideoViewerContract {
+interface FrostVideoViewerContract : VideoControlsVisibilityListener {
fun onSingleTapConfirmed(event: MotionEvent): Boolean
- fun onFade(alpha: Float, duration: Long)
+ /**
+ * Process of expansion
+ * 1f represents an expanded view, 0f represents a minimized view
+ */
+ fun onExpand(progress: Float)
+
fun onVideoComplete()
}