Jelajahi Sumber

New: share dialog movie preview

liweihao 6 tahun lalu
induk
melakukan
5f8c11f5b2

File diff ditekan karena terlalu besar
+ 85 - 34
src/main/java/com/bomostory/sceneeditmodule/screen/movie/MovieEditActivity.kt


+ 90 - 0
src/main/java/com/bomostory/sceneeditmodule/share/ShareDialog.kt

@@ -1,21 +1,60 @@
 package com.bomostory.sceneeditmodule.share
 
+import android.content.DialogInterface
+import android.graphics.drawable.Drawable
 import android.os.Bundle
 import android.support.v4.app.DialogFragment
 import android.support.v4.app.FragmentManager
+import android.support.v7.widget.LinearLayoutManager
+import android.support.v7.widget.RecyclerView
 import android.view.LayoutInflater
 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.*
 
 class ShareDialog : DialogFragment() {
 
     private val dialogTag = this::class.java.simpleName
 
+     var dismissListener: DialogInterface.OnDismissListener? = null
+
+    var seekBarChangedListener: SeekBar.OnSeekBarChangeListener? = null
+
     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 time: Long = 0
+        set(value) {
+            field = value
+            seekBarMoviePlay?.progress = value.toInt()
+            tv_shareDialog_time?.text = "${TimeUtils.getPlayMovieTimeFormat(time)}/${TimeUtils.getPlayMovieTimeFormat(storyPeriod)}"
+        }
+
     var onClickEditCover = Runnable {}
     var onClickExportPdf = Runnable {}
     var onClickPrint = Runnable {}
@@ -24,12 +63,17 @@ class ShareDialog : DialogFragment() {
     var onClickFacebook = Runnable {}
     var onClickTwitter = Runnable {}
     var onClickMore = Runnable {}
+    var onClickPlay = Runnable {}
+
 
     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
         return inflater.inflate(R.layout.dialog_share, container, false).apply {
             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() }
@@ -38,6 +82,14 @@ 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() }
+
+            sceneList.apply {
+                setHasFixedSize(true)
+                addItemDecoration(HorizontalItemDecoration(resources.getDimensionPixelSize(R.dimen.horizontal_item_spacing)))
+                layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
+                adapter = MovieAdapter()
+            }
         }
     }
 
@@ -50,4 +102,42 @@ 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)
+            return ViewHolder(view)
+        }
+
+        override fun getItemCount(): Int {
+            project.story?.let {
+                return it.scenes.size
+            }
+            return 0
+        }
+
+        override fun onBindViewHolder(p0: ViewHolder, p1: Int) {
+            p0.bind(p1)
+        }
+
+        inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
+            fun bind(p1: Int) {
+                itemView.apply {
+                    project.story?.apply {
+                        screenshot.setImageDrawable(Drawable.createFromPath(this.scenes[p1].backgroundPath))
+                    }
+                }
+            }
+        }
+    }
 }

+ 5 - 1
src/main/java/com/bomostory/sceneeditmodule/utils/MoviePlayerV2.kt

@@ -32,6 +32,8 @@ class MoviePlayerV2 {
     var mediaPlayers = ArrayList<MediaPlayer>()
 
     fun init() {
+        isPause = false
+
         timer?.cancel()
         timer?.purge()
         timer = null
@@ -40,7 +42,10 @@ class MoviePlayerV2 {
 
         updateMovie()
 
+        tryStopMusic()
+
         initMediaPlayer()
+
     }
 
     fun start() {
@@ -58,7 +63,6 @@ class MoviePlayerV2 {
 
                         if (currentTime >= period) {
                             moviePlayListener?.onMoviePlayComplete()
-                            tryStopMusic()
                             init()
                         }
                     }

+ 34 - 33
src/main/res/layout/dialog_share.xml

@@ -15,6 +15,7 @@
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
+
     <TextView
 
         android:id="@+id/tv_shareDialog_name"
@@ -59,15 +60,15 @@
     <Button
         android:id="@+id/btn_shareDialog_editCover"
         style="@style/Body2"
-        android:layout_height="wrap_content"
-        android:background="@null"
-        android:drawableTint="@android:color/darker_gray"
         android:layout_width="104dp"
-        android:enabled="false"
+        android:layout_height="wrap_content"
         android:layout_marginLeft="16dp"
         android:layout_marginTop="16dp"
-        android:drawableTop="@drawable/ic_cover_36dp"
+        android:background="@null"
         android:drawablePadding="8dp"
+        android:drawableTint="@android:color/darker_gray"
+        android:drawableTop="@drawable/ic_cover_36dp"
+        android:enabled="false"
         android:gravity="center"
         android:text="@string/share_dialog_edit_cover"
         app:layout_constraintBottom_toTopOf="@id/btn_shareDialog_exportPdf"
@@ -78,13 +79,13 @@
     <Button
         android:id="@+id/btn_shareDialog_exportPdf"
         style="@style/Body2"
-        android:layout_height="wrap_content"
         android:layout_width="104dp"
-        android:background="?attr/selectableItemBackground"
+        android:layout_height="wrap_content"
         android:layout_marginLeft="16dp"
         android:layout_marginTop="16dp"
-        android:drawableTop="@drawable/ic_exportpdf_36dp"
+        android:background="?attr/selectableItemBackground"
         android:drawablePadding="8dp"
+        android:drawableTop="@drawable/ic_exportpdf_36dp"
         android:gravity="center"
         android:text="@string/share_dialog_export_pdf"
         app:layout_constraintBottom_toTopOf="@id/btn_shareDialog_print"
@@ -95,15 +96,15 @@
     <TextView
         android:id="@+id/btn_shareDialog_print"
         style="@style/Body2"
-        android:layout_height="wrap_content"
-        android:background="@null"
-        android:drawableTint="@android:color/darker_gray"
         android:layout_width="104dp"
-        android:enabled="false"
+        android:layout_height="wrap_content"
         android:layout_marginLeft="16dp"
         android:layout_marginTop="16dp"
-        android:drawableTop="@drawable/ic_print_36dp"
+        android:background="@null"
         android:drawablePadding="8dp"
+        android:drawableTint="@android:color/darker_gray"
+        android:drawableTop="@drawable/ic_print_36dp"
+        android:enabled="false"
         android:gravity="center"
         android:text="@string/share_dialog_print"
         app:layout_constraintLeft_toLeftOf="parent"
@@ -112,66 +113,65 @@
 
     <ImageView
         android:id="@+id/iv_shareDialog_bomo"
-        android:background="?attr/selectableItemBackground"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginLeft="36dp"
         android:layout_marginRight="36dp"
+        android:background="?attr/selectableItemBackground"
         android:src="@drawable/ic_btn_bomo_01"
         app:layout_constraintLeft_toRightOf="@id/movieView_shareDialog_preview"
         app:layout_constraintTop_toTopOf="@id/movieView_shareDialog_preview" />
 
     <ImageView
         android:id="@+id/iv_shareDialog_youtube"
-        android:tint="@android:color/darker_gray"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginLeft="36dp"
-        android:layout_marginTop="16dp"
         android:layout_marginRight="36dp"
+        android:layout_marginTop="16dp"
         android:src="@drawable/ic_btn_youtube_01"
+        android:tint="@android:color/darker_gray"
         app:layout_constraintLeft_toRightOf="@id/movieView_shareDialog_preview"
         app:layout_constraintTop_toBottomOf="@id/iv_shareDialog_bomo" />
 
     <ImageView
         android:id="@+id/iv_shareDialog_facebook"
-        android:tint="@android:color/darker_gray"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginLeft="36dp"
-        android:layout_marginTop="16dp"
         android:layout_marginRight="36dp"
+        android:layout_marginTop="16dp"
         android:src="@drawable/ic_btn_facebook_01"
+        android:tint="@android:color/darker_gray"
         app:layout_constraintLeft_toRightOf="@id/movieView_shareDialog_preview"
         app:layout_constraintTop_toBottomOf="@id/iv_shareDialog_youtube" />
 
     <ImageView
         android:id="@+id/iv_shareDialog_twitter"
-        android:tint="@android:color/darker_gray"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginLeft="36dp"
-        android:layout_marginTop="16dp"
         android:layout_marginRight="36dp"
+        android:layout_marginTop="16dp"
         android:src="@drawable/ic_btn_twitter_01"
+        android:tint="@android:color/darker_gray"
         app:layout_constraintLeft_toRightOf="@id/movieView_shareDialog_preview"
         app:layout_constraintTop_toBottomOf="@id/iv_shareDialog_facebook" />
 
     <ImageView
         android:id="@+id/iv_shareDialog_more"
-        android:tint="@android:color/darker_gray"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginLeft="36dp"
-        android:layout_marginTop="16dp"
         android:layout_marginRight="36dp"
+        android:layout_marginTop="16dp"
         android:src="@drawable/ic_btn_more_01"
+        android:tint="@android:color/darker_gray"
         app:layout_constraintLeft_toRightOf="@id/movieView_shareDialog_preview"
         app:layout_constraintTop_toBottomOf="@id/iv_shareDialog_twitter" />
 
     <ImageView
         android:id="@+id/iv_shareDialog_play"
-        android:tint="@android:color/darker_gray"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginTop="8dp"
@@ -193,28 +193,29 @@
         tools:text="0:20/3:00" />
 
     <SeekBar
+        android:id="@+id/seekBarMoviePlay"
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_marginLeft="16dp"
         android:layout_marginRight="16dp"
-        android:progressTint="@android:color/darker_gray"
-        android:thumbTint="@android:color/darker_gray"
         app:layout_constraintBottom_toBottomOf="@id/iv_shareDialog_play"
         app:layout_constraintLeft_toRightOf="@id/iv_shareDialog_play"
         app:layout_constraintRight_toLeftOf="@id/tv_shareDialog_time"
         app:layout_constraintTop_toTopOf="@id/iv_shareDialog_play"
         tools:progress="100" />
 
-    <View
-        android:visibility="invisible"
-        android:id="@+id/view_shareDialog_scenes"
-        android:layout_width="560dp"
+    <android.support.v7.widget.RecyclerView
+        android:id="@+id/sceneList"
+        android:layout_width="0dp"
         android:layout_height="88dp"
-        android:layout_marginTop="8dp"
         android:layout_marginBottom="24dp"
-        android:background="@color/pale_peach"
+        android:layout_marginTop="8dp"
+        android:background="#f0ebe1"
+        android:paddingEnd="4dp"
+        android:paddingStart="4dp"
         app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintLeft_toLeftOf="parent"
-        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintLeft_toLeftOf="@id/movieView_shareDialog_preview"
+        app:layout_constraintRight_toRightOf="@id/movieView_shareDialog_preview"
         app:layout_constraintTop_toBottomOf="@id/iv_shareDialog_play" />
+
 </android.support.constraint.ConstraintLayout>

+ 15 - 0
src/main/res/layout/scene_item_view.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="144dp"
+    android:layout_height="88dp">
+
+    <ImageView
+        android:id="@+id/screenshot"
+        android:layout_width="144dp"
+        android:layout_height="72dp"
+        android:adjustViewBounds="true"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+</android.support.constraint.ConstraintLayout>