瀏覽代碼

Merge branch 'change-save-movie-flow'

Wayne 6 年之前
父節點
當前提交
bb081135e1

+ 2 - 0
src/main/java/com/bomostory/sceneeditmodule/Config.kt

@@ -13,4 +13,6 @@ object Config {
     val PROJECTS_FOLDER = File(Environment.getExternalStorageDirectory(), PROJECTS_FOLDER_PATH)
     const val PROJECT_FILE_NAME = "index"
     val PDF_FOLDER = File(ROOT, "pdf")
+
+    const val VIDEO_FILE_NAME = "video.mp4"
 }

+ 45 - 39
src/main/java/com/bomostory/sceneeditmodule/screen/movie/MovieEditActivity.kt

@@ -29,6 +29,7 @@ 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.FileUtils
 import com.bomostory.sceneeditmodule.utils.MoviePlayerV2
 import com.bomostory.sceneeditmodule.utils.MusicPlayerV2
 import com.bomostory.sceneeditmodule.utils.Utils
@@ -356,8 +357,17 @@ class MovieEditActivity : AppCompatActivity(),
     }
 
     private fun onClickSaveAndShareBtn(view: View) {
+        saveMovie(object : OnMovieSavedListener {
+            override fun onSaved(file: File) {
+                showShareDialog(file)
+            }
+        })
+    }
+
+    private fun showShareDialog(videoFile: File) {
         shareDialog.apply {
-            project = viewModel.project ?: return@apply
+            val p = viewModel.project ?: return
+            project = p
             storyPeriod = viewModel.storyPeriodLiveData.value ?: 0
             dismissListener = DialogInterface.OnDismissListener {
                 moviePlayer.moviePlayListener = editMoviePlayListener
@@ -379,44 +389,36 @@ class MovieEditActivity : AppCompatActivity(),
                 }
             }
             onClickBomo = Runnable {
-                saveMovie(object : OnMovieSavedListener {
-                    override fun onSaved(file: File) {
-                        val pd = ProgressDialog(this@MovieEditActivity).apply {
-                            isCancelable = false
-                        }
-                        viewModel.uploadVideo(this@MovieEditActivity, file, project)
-                                .subscribeOn(Schedulers.io())
-                                .observeOn(AndroidSchedulers.mainThread())
-                                .doOnSubscribe { pd.show() }
-                                .doFinally { pd.dismiss() }
-                                .subscribe({
-                                    val context = this@MovieEditActivity
-                                    when (it.errorCode) {
-                                        4013 -> Toast.makeText(context, R.string.share_dialog_upload_failed, Toast.LENGTH_SHORT).show()
-                                        else -> {
-                                            Toast.makeText(context, R.string.share_dialog_upload_suc, Toast.LENGTH_SHORT).show()
-                                        }
-                                    }
-                                }, {
-                                    Toast.makeText(this@MovieEditActivity, R.string.share_dialog_upload_failed, Toast.LENGTH_SHORT).show()
-                                })
-                    }
-                })
+                val pd = ProgressDialog(this@MovieEditActivity).apply {
+                    setCancelable(false)
+                }
+                viewModel.uploadVideo(this@MovieEditActivity, videoFile, project)
+                        .subscribeOn(Schedulers.io())
+                        .observeOn(AndroidSchedulers.mainThread())
+                        .doOnSubscribe { pd.show() }
+                        .doFinally { pd.dismiss() }
+                        .subscribe({
+                            val context = this@MovieEditActivity
+                            when (it.errorCode) {
+                                4013 -> Toast.makeText(context, R.string.share_dialog_upload_failed, Toast.LENGTH_SHORT).show()
+                                else -> {
+                                    Toast.makeText(context, R.string.share_dialog_upload_suc, Toast.LENGTH_SHORT).show()
+                                }
+                            }
+                        }, {
+                            Toast.makeText(this@MovieEditActivity, R.string.share_dialog_upload_failed, Toast.LENGTH_SHORT).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, ""))
-                    }
-                })
+                val authority = "$packageName"
+                val context = this@MovieEditActivity
+                val uri = FileProvider.getUriForFile(context, authority, videoFile)
+
+                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 {
@@ -483,9 +485,13 @@ class MovieEditActivity : AppCompatActivity(),
             setCancelable(false)
         }
 
-        val fileName = "test${System.currentTimeMillis()}.mp4"
-        val outputFile = File(Environment.getExternalStorageDirectory(), fileName)
         val project = viewModel.project ?: return
+        val outputFile = FileUtils.getVideoFile(project)
+
+        if (outputFile.exists()) {
+            outputFile.delete()
+        }
+        outputFile.createNewFile()
 
         SuperMovieMaker().make(
                 this,

+ 6 - 0
src/main/java/com/bomostory/sceneeditmodule/utils/FileUtils.kt

@@ -15,6 +15,12 @@ import java.io.FileOutputStream
 import java.io.FileWriter
 
 object FileUtils {
+
+    fun getVideoFile(project: Project): File {
+        val projectFolder = File(Config.PROJECTS_FOLDER, project.name)
+        return File(projectFolder, Config.VIDEO_FILE_NAME)
+    }
+
     fun saveImageForActor(context: Context, uri: Uri, fileName: String){
         val dir = File(Config.IMAGE_FOLDER,"")
         dir.mkdir()