|
@@ -1,10 +1,12 @@
|
|
|
package com.bomostory.sceneeditmodule.share
|
|
|
|
|
|
-import android.content.DialogInterface
|
|
|
+import android.graphics.PorterDuff
|
|
|
import android.graphics.drawable.Drawable
|
|
|
+import android.media.MediaMetadataRetriever
|
|
|
import android.os.Bundle
|
|
|
import android.support.v4.app.DialogFragment
|
|
|
import android.support.v4.app.FragmentManager
|
|
|
+import android.support.v4.content.ContextCompat
|
|
|
import android.support.v7.widget.LinearLayoutManager
|
|
|
import android.support.v7.widget.RecyclerView
|
|
|
import android.view.LayoutInflater
|
|
@@ -12,48 +14,25 @@ import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
import android.widget.SeekBar
|
|
|
import com.bomostory.sceneeditmodule.basicdata.Project
|
|
|
-import com.bomostory.sceneeditmodule.basicdata.Scene
|
|
|
import com.bomostory.sceneeditmodule.utils.HorizontalItemDecoration
|
|
|
import com.bomostory.sceneeditmodule.utils.TimeUtils
|
|
|
import com.example.tfat.myapplication.R
|
|
|
-import kotlinx.android.synthetic.main.dialog_share.*
|
|
|
import kotlinx.android.synthetic.main.dialog_share.view.*
|
|
|
import kotlinx.android.synthetic.main.movie_item_view.view.*
|
|
|
+import java.io.File
|
|
|
+import java.util.*
|
|
|
|
|
|
class ShareDialog : DialogFragment() {
|
|
|
|
|
|
private val dialogTag = this::class.java.simpleName
|
|
|
|
|
|
- var dismissListener: DialogInterface.OnDismissListener? = null
|
|
|
-
|
|
|
- var seekBarChangedListener: SeekBar.OnSeekBarChangeListener? = null
|
|
|
+ lateinit var file: File
|
|
|
|
|
|
lateinit var project: Project
|
|
|
|
|
|
- var storyPeriod: Long = 0
|
|
|
-
|
|
|
- var scene: Scene? = null
|
|
|
- set(value) {
|
|
|
- field = value
|
|
|
- movieView_shareDialog_preview?.let {
|
|
|
- it.scene = value
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var x: Int = 0
|
|
|
- set(value) {
|
|
|
- field = value
|
|
|
- movieView_shareDialog_preview?.let {
|
|
|
- it.x = value
|
|
|
- }
|
|
|
- }
|
|
|
+ var timer: Timer? = null
|
|
|
|
|
|
- var time: Long = 0
|
|
|
- set(value) {
|
|
|
- field = value
|
|
|
- seekBarMoviePlay?.progress = value.toInt()
|
|
|
- tv_shareDialog_time?.text = "${TimeUtils.getPlayMovieTimeFormat(time)}/${TimeUtils.getPlayMovieTimeFormat(storyPeriod)}"
|
|
|
- }
|
|
|
+ var isPause = false
|
|
|
|
|
|
var onClickEditCover = Runnable {}
|
|
|
var onClickExportPdf = Runnable {}
|
|
@@ -71,9 +50,6 @@ class ShareDialog : DialogFragment() {
|
|
|
movieView_shareDialog_preview.scene = project.story?.scenes?.get(0)
|
|
|
tv_shareDialog_name.text = project.name
|
|
|
tv_shareDialog_author.text = project.author
|
|
|
- seekBarMoviePlay.max = storyPeriod.toInt()
|
|
|
- tv_shareDialog_time.text = "${TimeUtils.getPlayMovieTimeFormat(time)}/${TimeUtils.getPlayMovieTimeFormat(storyPeriod)}"
|
|
|
- seekBarMoviePlay.setOnSeekBarChangeListener(seekBarChangedListener)
|
|
|
btn_shareDialog_editCover.setOnClickListener { onClickEditCover.run() }
|
|
|
btn_shareDialog_exportPdf.setOnClickListener { onClickExportPdf.run() }
|
|
|
btn_shareDialog_print.setOnClickListener { onClickPrint.run() }
|
|
@@ -82,7 +58,76 @@ class ShareDialog : DialogFragment() {
|
|
|
iv_shareDialog_facebook.setOnClickListener { onClickFacebook.run() }
|
|
|
iv_shareDialog_twitter.setOnClickListener { onClickTwitter.run() }
|
|
|
iv_shareDialog_more.setOnClickListener { onClickMore.run() }
|
|
|
- iv_shareDialog_play.setOnClickListener { onClickPlay.run() }
|
|
|
+
|
|
|
+ try {
|
|
|
+ val mediaMetadataRetriever = MediaMetadataRetriever()
|
|
|
+ mediaMetadataRetriever.setDataSource(file.path)
|
|
|
+
|
|
|
+ seekBarMoviePlay.apply {
|
|
|
+ max = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION).toInt()
|
|
|
+ }
|
|
|
+
|
|
|
+ videoShareDialogPreview.apply {
|
|
|
+ setZOrderOnTop(true)
|
|
|
+ setVideoPath(file.path)
|
|
|
+ setOnCompletionListener {
|
|
|
+ timer?.cancel()
|
|
|
+ timer?.purge()
|
|
|
+ timer = null
|
|
|
+
|
|
|
+ this@apply.iv_shareDialog_pause?.visibility = View.INVISIBLE
|
|
|
+ this@apply.iv_shareDialog_play?.visibility = View.VISIBLE
|
|
|
+ this@apply.seekBarMoviePlay?.progress = videoShareDialogPreview.currentPosition
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ iv_shareDialog_play.setOnClickListener {
|
|
|
+ it.visibility = View.INVISIBLE
|
|
|
+ iv_shareDialog_pause.visibility = View.VISIBLE
|
|
|
+
|
|
|
+ videoShareDialogPreview.start()
|
|
|
+ if (timer == null) {
|
|
|
+ timer = Timer()
|
|
|
+ timer?.scheduleAtFixedRate(object : TimerTask() {
|
|
|
+ override fun run() {
|
|
|
+ activity?.runOnUiThread {
|
|
|
+ if (!isPause) {
|
|
|
+ seekBarMoviePlay.progress = videoShareDialogPreview.currentPosition
|
|
|
+ tv_shareDialog_time?.text = "${TimeUtils.getPlayMovieTimeFormat(seekBarMoviePlay.progress.toLong())}/${TimeUtils.getPlayMovieTimeFormat(seekBarMoviePlay.max.toLong())}"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 0, 1)
|
|
|
+ } else {
|
|
|
+ isPause = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ iv_shareDialog_pause.setOnClickListener {
|
|
|
+ it.visibility = View.INVISIBLE
|
|
|
+ iv_shareDialog_play.visibility = View.VISIBLE
|
|
|
+ videoShareDialogPreview.pause()
|
|
|
+ isPause = true
|
|
|
+ }
|
|
|
+
|
|
|
+ tv_shareDialog_time?.text = "${TimeUtils.getPlayMovieTimeFormat(seekBarMoviePlay.progress.toLong())}/${TimeUtils.getPlayMovieTimeFormat(seekBarMoviePlay.max.toLong())}"
|
|
|
+
|
|
|
+ seekBarMoviePlay.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
|
+ override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
|
|
+ if (fromUser) {
|
|
|
+ videoShareDialogPreview.seekTo(progress)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onStartTrackingTouch(seekBar: SeekBar?) {
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onStopTrackingTouch(seekBar: SeekBar?) {
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (e: Exception) {
|
|
|
+ disableMovieView(this)
|
|
|
+ }
|
|
|
|
|
|
sceneList.apply {
|
|
|
setHasFixedSize(true)
|
|
@@ -93,6 +138,29 @@ class ShareDialog : DialogFragment() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun disableMovieView(view: View) {
|
|
|
+ view.apply {
|
|
|
+ videoShareDialogPreview?.apply {
|
|
|
+ isEnabled = false
|
|
|
+ }
|
|
|
+ seekBarMoviePlay?.apply {
|
|
|
+ isEnabled = false
|
|
|
+ }
|
|
|
+ iv_shareDialog_play?.apply {
|
|
|
+ isEnabled = false
|
|
|
+ setColorFilter(ContextCompat.getColor(context, android.R.color.darker_gray), PorterDuff.Mode.SRC_ATOP)
|
|
|
+ }
|
|
|
+ iv_shareDialog_bomo?.apply {
|
|
|
+ isEnabled = false
|
|
|
+ setColorFilter(ContextCompat.getColor(context, android.R.color.darker_gray), PorterDuff.Mode.SRC_ATOP)
|
|
|
+ }
|
|
|
+ iv_shareDialog_more?.apply {
|
|
|
+ isEnabled = false
|
|
|
+ setColorFilter(ContextCompat.getColor(context, android.R.color.darker_gray), PorterDuff.Mode.SRC_ATOP)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
fun show(manager: FragmentManager?) {
|
|
|
manager?.apply {
|
|
|
val ft = beginTransaction()
|
|
@@ -103,16 +171,6 @@ class ShareDialog : DialogFragment() {
|
|
|
super.show(manager, dialogTag)
|
|
|
}
|
|
|
|
|
|
- override fun onDetach() {
|
|
|
- super.onDetach()
|
|
|
- dismissListener = null
|
|
|
- }
|
|
|
-
|
|
|
- override fun onDismiss(dialog: DialogInterface?) {
|
|
|
- super.onDismiss(dialog)
|
|
|
- dismissListener?.onDismiss(dialog)
|
|
|
- }
|
|
|
-
|
|
|
inner class MovieAdapter : RecyclerView.Adapter<MovieAdapter.ViewHolder>() {
|
|
|
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ViewHolder {
|
|
|
val view = LayoutInflater.from(p0.context).inflate(R.layout.scene_item_view, p0, false)
|