Przeglądaj źródła

Merge branch 'share-video' into feature_share_dialog

Wayne 6 lat temu
rodzic
commit
d8aa5af8e8

+ 47 - 19
src/main/java/com/bomostory/sceneeditmodule/screen/movie/MovieEditActivity.kt

@@ -11,6 +11,7 @@ import android.os.Bundle
 import android.os.Environment
 import android.os.Handler
 import android.support.v4.app.DialogFragment
+import android.support.v4.content.FileProvider
 import android.support.v7.app.AppCompatActivity
 import android.view.View
 import android.widget.CompoundButton
@@ -19,14 +20,16 @@ import android.widget.Toast
 import com.bomostory.sceneeditmodule.Config
 import com.bomostory.sceneeditmodule.PdfMaker
 import com.bomostory.sceneeditmodule.SuperMovieMaker
-import com.bomostory.sceneeditmodule.basicdata.*
+import com.bomostory.sceneeditmodule.basicdata.Music
+import com.bomostory.sceneeditmodule.basicdata.Project
+import com.bomostory.sceneeditmodule.basicdata.Scene
 import com.bomostory.sceneeditmodule.screen.movie.music.MusicEditDialog
 import com.bomostory.sceneeditmodule.screen.movie.music.MusicSelectDialog
 import com.bomostory.sceneeditmodule.screen.movie.music.MusicSelectFragment
-import com.bomostory.sceneeditmodule.share.ShareDialog
 import com.bomostory.sceneeditmodule.screen.view.AudioTrackGroupView
 import com.bomostory.sceneeditmodule.screen.view.MovieSelectView
 import com.bomostory.sceneeditmodule.share.ExportPdfDialog
+import com.bomostory.sceneeditmodule.share.ShareDialog
 import com.bomostory.sceneeditmodule.utils.MoviePlayerV2
 import com.bomostory.sceneeditmodule.utils.MusicPlayerV2
 import com.example.exportmedia.MediaHelper
@@ -375,7 +378,42 @@ class MovieEditActivity : AppCompatActivity(),
                 override fun onStopTrackingTouch(seekBar: SeekBar?) {
                 }
             }
-            onClickBomo = Runnable { saveMovie() }
+            onClickBomo = Runnable {
+                saveMovie(object : OnMovieSavedListener {
+                    override fun onSaved(file: File) {
+                    AlertDialog.Builder(this@MovieEditActivity)
+                            .setMessage("Complete")
+                            .setPositiveButton("Play") { _, _ ->
+                                val uri = Uri.parse(file.absolutePath)
+                                val intent = Intent(Intent.ACTION_VIEW, uri).apply {
+                                    setDataAndType(uri, "video/mp4")
+                                }
+                                if (intent.resolveActivity(packageManager) != null) {
+                                    Intent.createChooser(intent, "").apply {
+                                        startActivity(this)
+                                    }
+                                } else {
+                                    Toast.makeText(this@MovieEditActivity, "No app can play video", Toast.LENGTH_SHORT).show()
+                                }
+                            }.show()
+                    }
+                })
+            }
+            onClickMore = Runnable {
+                saveMovie(object : OnMovieSavedListener {
+                    override fun onSaved(file: File) {
+                        val authority = "$packageName"
+                        val context = this@MovieEditActivity
+                        val uri = FileProvider.getUriForFile(context, authority, file)
+
+                        val intent = Intent(Intent.ACTION_SEND)
+                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
+                        intent.type = "video/mp4"
+                        intent.putExtra(Intent.EXTRA_STREAM, uri)
+                        startActivity(Intent.createChooser(intent, ""))
+                    }
+                })
+            }
             onClickExportPdf = Runnable { onClickExportPdf() }
             onClickPlay = Runnable {
                 moviePlayer.moviePlayListener = dialogMoviePlayListener
@@ -422,7 +460,11 @@ class MovieEditActivity : AppCompatActivity(),
         }.show(supportFragmentManager)
     }
 
-    private fun saveMovie() {
+    interface OnMovieSavedListener {
+        fun onSaved(file: File)
+    }
+
+    private fun saveMovie(onMovieSavedListener: OnMovieSavedListener) {
         val scaledWidth = resources.getDimensionPixelSize(R.dimen.movie_width)
         val scaleHeight = resources.getDimensionPixelSize(R.dimen.movie_height)
 
@@ -462,21 +504,7 @@ class MovieEditActivity : AppCompatActivity(),
                     AlertDialog.Builder(this).setMessage(msg).show()
                     delayedHide(100)
                 }, {
-                    AlertDialog.Builder(this)
-                            .setMessage("Complete")
-                            .setPositiveButton("Play") { _, _ ->
-                                val uri = Uri.parse(outputFile.absolutePath)
-                                val intent = Intent(Intent.ACTION_VIEW, uri).apply {
-                                    setDataAndType(uri, "video/mp4")
-                                }
-                                if (intent.resolveActivity(packageManager) != null) {
-                                    Intent.createChooser(intent, "").apply {
-                                        startActivity(this)
-                                    }
-                                } else {
-                                    Toast.makeText(this, "No app can play video", Toast.LENGTH_SHORT).show()
-                                }
-                            }.show()
+                    onMovieSavedListener.onSaved(outputFile)
                     delayedHide(100)
                 })
     }

+ 3 - 1
src/main/res/layout/dialog_share.xml

@@ -124,6 +124,7 @@
 
     <ImageView
         android:id="@+id/iv_shareDialog_youtube"
+        android:visibility="gone"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginLeft="36dp"
@@ -136,6 +137,7 @@
 
     <ImageView
         android:id="@+id/iv_shareDialog_facebook"
+        android:visibility="gone"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginLeft="36dp"
@@ -148,6 +150,7 @@
 
     <ImageView
         android:id="@+id/iv_shareDialog_twitter"
+        android:visibility="gone"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginLeft="36dp"
@@ -166,7 +169,6 @@
         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" />