|
@@ -2,6 +2,8 @@ package com.bomostory.sceneeditmodule.screen.movie
|
|
|
|
|
|
import android.app.AlertDialog
|
|
|
import android.app.ProgressDialog
|
|
|
+import android.arch.lifecycle.Observer
|
|
|
+import android.arch.lifecycle.ViewModelProviders
|
|
|
import android.content.DialogInterface
|
|
|
import android.content.Intent
|
|
|
import android.net.Uri
|
|
@@ -14,20 +16,20 @@ import android.view.View
|
|
|
import android.widget.CompoundButton
|
|
|
import android.widget.SeekBar
|
|
|
import android.widget.Toast
|
|
|
-import com.bomostory.sceneeditmodule.*
|
|
|
+import com.bomostory.sceneeditmodule.Config
|
|
|
+import com.bomostory.sceneeditmodule.PdfMaker
|
|
|
+import com.bomostory.sceneeditmodule.SuperMovieMaker
|
|
|
import com.bomostory.sceneeditmodule.basicdata.*
|
|
|
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.ExportPdfDialog
|
|
|
import com.bomostory.sceneeditmodule.share.ShareDialog
|
|
|
import com.bomostory.sceneeditmodule.utils.MoviePlayer
|
|
|
import com.bomostory.sceneeditmodule.utils.MusicPlayer
|
|
|
-import com.bomostory.sceneeditmodule.utils.TimeUtils
|
|
|
import com.bomostory.sceneeditmodule.screen.view.AudioTrackGroupView
|
|
|
import com.bomostory.sceneeditmodule.screen.view.MovieSelectView
|
|
|
+import com.bomostory.sceneeditmodule.share.ExportPdfDialog
|
|
|
import com.example.exportmedia.MediaHelper
|
|
|
-import com.example.exportmedia.audio.AudioEditor
|
|
|
import com.example.tfat.myapplication.R
|
|
|
import com.google.gson.Gson
|
|
|
import io.reactivex.Observable
|
|
@@ -43,10 +45,10 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
MusicEditDialog.OnFragmentInteractionListener {
|
|
|
|
|
|
override fun onMusicImportClick(music: Music) {
|
|
|
+ val musics: ArrayList<Music> = viewModel.musicListLiveData.value as ArrayList<Music>
|
|
|
musics.add(music)
|
|
|
- moviePlayer.init()
|
|
|
- moviePlayer.addMusic(music)
|
|
|
- movieEditView.musics = musics
|
|
|
+ viewModel.musicListLiveData.value = musics
|
|
|
+ viewModel.musicLiveData.value = music
|
|
|
|
|
|
val dialogFragment = supportFragmentManager.findFragmentByTag(MUSIC_SELECT_DIALOG_TAG) as DialogFragment
|
|
|
dialogFragment.dismiss()
|
|
@@ -67,8 +69,6 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
runOnUiThread {
|
|
|
musicEditDialog?.currentPosition = position
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
musicPlayer.play(startPosition)
|
|
@@ -87,22 +87,23 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
}
|
|
|
|
|
|
override fun onMusicEditFinish(music: Music) {
|
|
|
- if (music.endTime - music.startTime > moviePlayer.totalPeriod) {
|
|
|
- music.endTime = music.startTime + moviePlayer.totalPeriod
|
|
|
- }
|
|
|
-
|
|
|
- val builder = AudioEditor.Builder(mediaHelper)
|
|
|
- builder.editAudioFile = File(music.path)
|
|
|
- builder.startTime = TimeUtils.getEncodeTimeFormt(music.startTime)
|
|
|
- builder.endTime = TimeUtils.getEncodeTimeFormt(music.endTime)
|
|
|
- builder.volume = music.volume
|
|
|
-
|
|
|
- val fileName = "test${System.currentTimeMillis()}.mp3"
|
|
|
- val outputFile = File(Environment.getExternalStorageDirectory(), fileName)
|
|
|
- val audioEditor = builder.build()
|
|
|
- audioEditor.output(outputFile).subscribe({
|
|
|
- }, {
|
|
|
- })
|
|
|
+ viewModel.exportEditAudio(music)
|
|
|
+// if (music.endTime - music.startTime > moviePlayer.totalPeriod) {
|
|
|
+// music.endTime = music.startTime + moviePlayer.totalPeriod
|
|
|
+// }
|
|
|
+//
|
|
|
+// val builder = AudioEditor.Builder(mediaHelper)
|
|
|
+// builder.editAudioFile = File(music.path)
|
|
|
+// builder.startTime = TimeUtils.getEncodeTimeFormt(music.startTime)
|
|
|
+// builder.endTime = TimeUtils.getEncodeTimeFormt(music.endTime)
|
|
|
+// builder.volume = music.volume
|
|
|
+//
|
|
|
+// val fileName = "test${System.currentTimeMillis()}.mp3"
|
|
|
+// val outputFile = File(Environment.getExternalStorageDirectory(), fileName)
|
|
|
+// val audioEditor = builder.build()
|
|
|
+// audioEditor.output(outputFile).subscribe({
|
|
|
+// }, {
|
|
|
+// })
|
|
|
|
|
|
}
|
|
|
|
|
@@ -113,8 +114,8 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
delayedHide(100)
|
|
|
}
|
|
|
|
|
|
- private val shareDialog = ShareDialog()
|
|
|
private var musicEditDialog: MusicEditDialog? = null
|
|
|
+ private val shareDialog = ShareDialog()
|
|
|
|
|
|
private val mHideHandler = Handler()
|
|
|
private val mHidePart2Runnable = Runnable {
|
|
@@ -133,51 +134,10 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
hide()
|
|
|
}
|
|
|
|
|
|
- private var project: Project? = null
|
|
|
- set(value) {
|
|
|
- field = value
|
|
|
- value?.let {
|
|
|
- story = it.story
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private var story: Story? = null
|
|
|
- set(value) {
|
|
|
- field = value
|
|
|
- moviePlayer.story = value
|
|
|
- movieEditView.story = value
|
|
|
- value?.let {
|
|
|
- scene = it.scenes[0]
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private var scene: Scene? = null
|
|
|
- set(value) {
|
|
|
- field = value
|
|
|
- value?.let {
|
|
|
- movieView.scene = value
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private var isLoop = false
|
|
|
- set(value) {
|
|
|
- field = value
|
|
|
- movieEditView.isLoop = value
|
|
|
- }
|
|
|
-
|
|
|
- private var currentAudioPosition = 0
|
|
|
- set(value) {
|
|
|
- field = value
|
|
|
- movieEditView.currentAudioPosition = value
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
private val moviePlayer = MoviePlayer()
|
|
|
|
|
|
private val musicPlayer = MusicPlayer()
|
|
|
|
|
|
- private val musics = ArrayList<Music>()
|
|
|
-
|
|
|
private val mediaHelper = MediaHelper()
|
|
|
|
|
|
companion object {
|
|
@@ -188,13 +148,42 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
private const val UI_ANIMATION_DELAY = 300
|
|
|
}
|
|
|
|
|
|
+ private lateinit var viewModel: MovieEditViewModel
|
|
|
+
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
setContentView(R.layout.activity_movie_edit)
|
|
|
|
|
|
- supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
+ mediaHelper.init(this)
|
|
|
|
|
|
- project = Gson().fromJson<Project>(intent.extras.getString(PROJECT_KEY), Project::class.java)
|
|
|
+ viewModel = ViewModelProviders.of(this).get(MovieEditViewModel::class.java)
|
|
|
+ viewModel.mediaHelper = mediaHelper
|
|
|
+ viewModel.project = Gson().fromJson<Project>(intent.extras.getString(PROJECT_KEY), Project::class.java)
|
|
|
+ viewModel.storyLiveData.observe(this, Observer {
|
|
|
+ movieEditView.story = it
|
|
|
+ moviePlayer.story = it
|
|
|
+ })
|
|
|
+ viewModel.storyPeriodLiveData.observe(this, Observer {
|
|
|
+ movieEditView.period = it ?: 0
|
|
|
+ moviePlayer.totalPeriod = it ?: 0
|
|
|
+ })
|
|
|
+ viewModel.sceneLiveData.observe(this, Observer {
|
|
|
+ movieView.scene = it
|
|
|
+ })
|
|
|
+ viewModel.musicListLiveData.observe(this, Observer {
|
|
|
+ movieEditView.musics = it as ArrayList<Music>
|
|
|
+ movieEditView.isAudioTrackGroupViewVisible = it.isNotEmpty()
|
|
|
+ moviePlayer.musics = it
|
|
|
+ moviePlayer.init()
|
|
|
+
|
|
|
+ })
|
|
|
+ viewModel.musicLiveData.observe(this, Observer {
|
|
|
+ viewModel.musicListLiveData.value?.apply {
|
|
|
+ movieEditView.currentAudioPosition = indexOf(it)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
|
|
|
movieEditView.onPlayClickListener = View.OnClickListener(this::playMovie)
|
|
|
movieEditView.onPauseClickListener = View.OnClickListener(this::pauseMovie)
|
|
@@ -217,35 +206,43 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
}
|
|
|
movieEditView.onMovieSelectListener = object : MovieSelectView.OnMovieSelectListener {
|
|
|
override fun onMoveSelect(scene: Scene) {
|
|
|
- this@MovieEditActivity.scene = scene
|
|
|
+ viewModel.sceneLiveData.value = scene
|
|
|
}
|
|
|
}
|
|
|
movieEditView.onAudioTrackSelectListener = object : AudioTrackGroupView.OnAudioTrackSelectListener {
|
|
|
override fun onAudioTrackSelect(position: Int) {
|
|
|
- currentAudioPosition = position
|
|
|
+ viewModel.musicListLiveData.value?.let {
|
|
|
+ viewModel.musicLiveData.value = it[position]
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
movieEditView.onAudioTrackScrollListener = object : AudioTrackGroupView.OnAudioTrackScrollListener {
|
|
|
override fun onAudioTrackScroll(position: Int, scrollRatio: Double) {
|
|
|
- scene?.record?.period?.let {
|
|
|
+ val musics: ArrayList<Music> = viewModel.musicListLiveData.value as ArrayList<Music>
|
|
|
+ viewModel.sceneLiveData.value?.record?.period?.let {
|
|
|
musics[position].offsetTime = (it * scrollRatio).toLong()
|
|
|
}
|
|
|
+ viewModel.musicListLiveData.value = musics
|
|
|
}
|
|
|
}
|
|
|
movieEditView.onLoopSwitchChangedListener = CompoundButton.OnCheckedChangeListener { _, isChecked ->
|
|
|
- isLoop = isChecked
|
|
|
+ val musics: ArrayList<Music> = viewModel.musicListLiveData.value as ArrayList<Music>
|
|
|
+ for (music in musics) {
|
|
|
+ music.isLoop = isChecked
|
|
|
+ }
|
|
|
+ viewModel.musicListLiveData.value = musics
|
|
|
}
|
|
|
|
|
|
moviePlayer.moviePlayListener = object : MoviePlayer.OnMoviePlayListener {
|
|
|
override fun onMovieSceneUpdate(scene: Scene) {
|
|
|
- if (scene != this@MovieEditActivity.scene) {
|
|
|
- this@MovieEditActivity.scene = scene
|
|
|
+ if (viewModel.sceneLiveData.value != scene) {
|
|
|
+ viewModel.sceneLiveData.value = scene
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun onMoviePlayComplete() {
|
|
|
- story?.scenes?.let {
|
|
|
- this@MovieEditActivity.scene = it[0]
|
|
|
+ viewModel.project?.story?.let {
|
|
|
+ viewModel.sceneLiveData.value = it.scenes[0]
|
|
|
}
|
|
|
movieEditView.isBtnPanelEnable = true
|
|
|
}
|
|
@@ -259,9 +256,10 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- mediaHelper.init(this)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
override fun onPostResume() {
|
|
|
super.onPostResume()
|
|
|
delayedHide(100)
|
|
@@ -289,39 +287,26 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
}
|
|
|
|
|
|
private fun addMusic(view: View) {
|
|
|
- val libraryPaths = ArrayList<String>()
|
|
|
+ viewModel.parseDeviceMusic(contentResolver)
|
|
|
|
|
|
- project?.let {
|
|
|
- val assetFolder = it.assetFolder.path
|
|
|
- it.themeAssetIndex.contains.music.values.forEach {
|
|
|
- libraryPaths.add("$assetFolder/$it")
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- val musicSource = DataParser.parseMusicSource(contentResolver, libraryPaths)
|
|
|
- val musicSelectDialog = MusicSelectDialog.newInstance(Gson().toJson(musicSource))
|
|
|
+ val musicSelectDialog = MusicSelectDialog.newInstance(Gson().toJson(viewModel.musicSource))
|
|
|
musicSelectDialog.show(supportFragmentManager, MUSIC_SELECT_DIALOG_TAG)
|
|
|
}
|
|
|
|
|
|
private fun editMusic(view: View) {
|
|
|
- musicEditDialog = MusicEditDialog.newInstance(Gson().toJson(musics[currentAudioPosition]))
|
|
|
+ musicEditDialog = MusicEditDialog.newInstance(Gson().toJson(viewModel.musicLiveData.value))
|
|
|
musicEditDialog?.show(supportFragmentManager, MUSIC_EDIT_DIALOG_TAG)
|
|
|
}
|
|
|
|
|
|
private fun deleteMusic(view: View) {
|
|
|
- if (currentAudioPosition in 0 until musics.size) {
|
|
|
- moviePlayer.init()
|
|
|
- moviePlayer.removeMusic(musics[currentAudioPosition])
|
|
|
-
|
|
|
- musics.removeAt(currentAudioPosition)
|
|
|
-
|
|
|
- movieEditView.musics = musics
|
|
|
- }
|
|
|
+ val musics: ArrayList<Music> = viewModel.musicListLiveData.value as ArrayList<Music>
|
|
|
+ musics.remove(viewModel.musicLiveData.value)
|
|
|
+ viewModel.musicListLiveData.value = musics
|
|
|
}
|
|
|
|
|
|
private fun onClickSaveAndShareBtn(view: View) {
|
|
|
shareDialog.apply {
|
|
|
- project = this@MovieEditActivity.project ?: return@apply
|
|
|
+ project = viewModel.project ?: return@apply
|
|
|
onClickBomo = Runnable { saveMovie() }
|
|
|
onClickExportPdf = Runnable { onClickExportPdf() }
|
|
|
}.show(supportFragmentManager)
|
|
@@ -329,28 +314,28 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
|
|
|
private fun onClickExportPdf() {
|
|
|
ExportPdfDialog().also { exportPdfDialog ->
|
|
|
- exportPdfDialog.image1Path = project?.scene1File?.path ?: ""
|
|
|
- exportPdfDialog.image2Path = project?.scene2File?.path ?: ""
|
|
|
+ exportPdfDialog.image1Path = viewModel.project?.scene1File?.path ?: ""
|
|
|
+ exportPdfDialog.image2Path = viewModel.project?.scene2File?.path ?: ""
|
|
|
exportPdfDialog.onClickPrint = Runnable {
|
|
|
when (exportPdfDialog.type) {
|
|
|
ExportPdfDialog.Type.Standard -> {
|
|
|
- val name = "standard_${project?.name}_${System.currentTimeMillis()}.pdf"
|
|
|
+ val name = "standard_${viewModel.project?.name}_${System.currentTimeMillis()}.pdf"
|
|
|
if (!Config.PDF_FOLDER.exists()) {
|
|
|
Config.PDF_FOLDER.mkdirs()
|
|
|
}
|
|
|
val file = File(Config.PDF_FOLDER, name)
|
|
|
file.createNewFile()
|
|
|
- val observable = PdfMaker.makeStandard(this@MovieEditActivity, project!!, file)
|
|
|
+ val observable = PdfMaker.makeStandard(this@MovieEditActivity, viewModel.project!!, file)
|
|
|
Pair(file, observable)
|
|
|
}
|
|
|
ExportPdfDialog.Type.Booklet -> {
|
|
|
- val name = "booklet_${project?.name}_${System.currentTimeMillis()}.pdf"
|
|
|
+ val name = "booklet_${viewModel.project?.name}_${System.currentTimeMillis()}.pdf"
|
|
|
if (!Config.PDF_FOLDER.exists()) {
|
|
|
Config.PDF_FOLDER.mkdirs()
|
|
|
}
|
|
|
val file = File(Config.PDF_FOLDER, name)
|
|
|
file.createNewFile()
|
|
|
- val observable = PdfMaker.makeBooklet(this@MovieEditActivity, project!!, file)
|
|
|
+ val observable = PdfMaker.makeBooklet(this@MovieEditActivity, viewModel.project!!, file)
|
|
|
Pair(file, observable)
|
|
|
}
|
|
|
}.apply {
|
|
@@ -369,7 +354,7 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
val scaleHeight = resources.getDimensionPixelSize(R.dimen.movie_height)
|
|
|
|
|
|
val pd = ProgressDialog(this).apply {
|
|
|
- val t = scene?.record?.period ?: 0
|
|
|
+ val t = viewModel.storyPeriodLiveData.value ?: 0
|
|
|
max = (t / 33).toInt()
|
|
|
setMessage("progressing")
|
|
|
setCancelable(false)
|
|
@@ -377,12 +362,12 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
|
|
|
val fileName = "test${System.currentTimeMillis()}.mp4"
|
|
|
val outputFile = File(Environment.getExternalStorageDirectory(), fileName)
|
|
|
- val project = project ?: return
|
|
|
+ val project = viewModel.project ?: return
|
|
|
|
|
|
SuperMovieMaker().make(
|
|
|
outputFile,
|
|
|
project,
|
|
|
- musics,
|
|
|
+ viewModel.musicListLiveData.value ?: ArrayList<Music>(),
|
|
|
scaledWidth,
|
|
|
scaleHeight,
|
|
|
mediaHelper)
|
|
@@ -464,5 +449,4 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
}
|
|
|
}.show()
|
|
|
}
|
|
|
-
|
|
|
}
|