|
@@ -1,13 +1,11 @@
|
|
package com.bomostory.sceneeditmodule.screen.movie
|
|
package com.bomostory.sceneeditmodule.screen.movie
|
|
|
|
|
|
-import android.app.AlertDialog
|
|
|
|
import android.app.ProgressDialog
|
|
import android.app.ProgressDialog
|
|
import android.arch.lifecycle.Observer
|
|
import android.arch.lifecycle.Observer
|
|
import android.arch.lifecycle.ViewModelProviders
|
|
import android.arch.lifecycle.ViewModelProviders
|
|
import android.content.DialogInterface
|
|
import android.content.DialogInterface
|
|
import android.content.Intent
|
|
import android.content.Intent
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
-import android.os.Environment
|
|
|
|
import android.os.Handler
|
|
import android.os.Handler
|
|
import android.support.v4.app.DialogFragment
|
|
import android.support.v4.app.DialogFragment
|
|
import android.support.v4.content.FileProvider
|
|
import android.support.v4.content.FileProvider
|
|
@@ -33,7 +31,6 @@ import com.bomostory.sceneeditmodule.share.ExportPdfDialog
|
|
import com.bomostory.sceneeditmodule.share.ShareDialog
|
|
import com.bomostory.sceneeditmodule.share.ShareDialog
|
|
import com.bomostory.sceneeditmodule.utils.FileUtils
|
|
import com.bomostory.sceneeditmodule.utils.FileUtils
|
|
import com.bomostory.sceneeditmodule.utils.MoviePlayerV2
|
|
import com.bomostory.sceneeditmodule.utils.MoviePlayerV2
|
|
-import com.bomostory.sceneeditmodule.utils.MusicPlayerV2
|
|
|
|
import com.bomostory.sceneeditmodule.utils.Utils
|
|
import com.bomostory.sceneeditmodule.utils.Utils
|
|
import com.example.exportmedia.MediaHelper
|
|
import com.example.exportmedia.MediaHelper
|
|
import com.example.tfat.myapplication.R
|
|
import com.example.tfat.myapplication.R
|
|
@@ -52,93 +49,47 @@ class MovieEditActivity : AppCompatActivity(),
|
|
MusicEditDialog.OnFragmentInteractionListener {
|
|
MusicEditDialog.OnFragmentInteractionListener {
|
|
|
|
|
|
override fun onMusicImportClick(music: Music) {
|
|
override fun onMusicImportClick(music: Music) {
|
|
|
|
+ viewModel.importMusic(music)
|
|
moviePlayer.init()
|
|
moviePlayer.init()
|
|
|
|
|
|
- val musics: ArrayList<Music> = viewModel.musicListLiveData.value as ArrayList<Music>
|
|
|
|
- musics.add(music)
|
|
|
|
- viewModel.musicListLiveData.value = musics
|
|
|
|
- viewModel.musicLiveData.value = music
|
|
|
|
-
|
|
|
|
- val dialogFragment = supportFragmentManager.findFragmentByTag(MUSIC_SELECT_DIALOG_TAG) as DialogFragment
|
|
|
|
- dialogFragment.dismiss()
|
|
|
|
|
|
+ musicSelectDialog?.dismiss()
|
|
}
|
|
}
|
|
|
|
|
|
override fun onMusicPreCastClick(music: Music) {
|
|
override fun onMusicPreCastClick(music: Music) {
|
|
- musicPlayer.apply {
|
|
|
|
- this.music = music
|
|
|
|
- stop()
|
|
|
|
- init()
|
|
|
|
- start()
|
|
|
|
- }
|
|
|
|
|
|
+ viewModel.precastMusic(music)
|
|
}
|
|
}
|
|
|
|
|
|
override fun onMusicPlayClick(music: Music, startPosition: Int) {
|
|
override fun onMusicPlayClick(music: Music, startPosition: Int) {
|
|
- musicPlayer.apply {
|
|
|
|
- this.music = music
|
|
|
|
- playChangedListener = object : MusicPlayerV2.OnPlayChangedListener {
|
|
|
|
- override fun OnPlayChanged(position: Int) {
|
|
|
|
- runOnUiThread {
|
|
|
|
- musicEditDialog?.currentPosition = position
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- init()
|
|
|
|
- seekTo(startPosition)
|
|
|
|
- start()
|
|
|
|
- }
|
|
|
|
|
|
+ viewModel.playMusic(music, startPosition)
|
|
}
|
|
}
|
|
|
|
|
|
override fun onMusicVolumeChanged(volume: Float) {
|
|
override fun onMusicVolumeChanged(volume: Float) {
|
|
- musicPlayer.setVolume(volume)
|
|
|
|
|
|
+ viewModel.setMusicVolume(volume)
|
|
}
|
|
}
|
|
|
|
|
|
override fun onMusicPauseClick() {
|
|
override fun onMusicPauseClick() {
|
|
- musicPlayer.pause()
|
|
|
|
|
|
+ viewModel.pauseMusic()
|
|
}
|
|
}
|
|
|
|
|
|
override fun onMusicStop() {
|
|
override fun onMusicStop() {
|
|
- musicPlayer.stop()
|
|
|
|
|
|
+ viewModel.stopMusic()
|
|
}
|
|
}
|
|
|
|
|
|
override fun onMusicEditFinish(music: Music) {
|
|
override fun onMusicEditFinish(music: Music) {
|
|
|
|
+ viewModel.importEditMusic(music)
|
|
moviePlayer.init()
|
|
moviePlayer.init()
|
|
-
|
|
|
|
- //TODO change path to correct path
|
|
|
|
- val outputFile = File(Environment.getExternalStorageDirectory(), "test${System.currentTimeMillis()}.mp3")
|
|
|
|
-
|
|
|
|
- val pd = ProgressDialog(this).apply {
|
|
|
|
- setMessage("progressing")
|
|
|
|
- setCancelable(false)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- viewModel.exportEditAudio(music, outputFile)
|
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
- .doOnSubscribe {
|
|
|
|
- pd.show()
|
|
|
|
- }
|
|
|
|
- .doFinally {
|
|
|
|
- pd.dismiss()
|
|
|
|
- }
|
|
|
|
- .subscribe({
|
|
|
|
- music.path = outputFile.path
|
|
|
|
-
|
|
|
|
- val musics: ArrayList<Music> = viewModel.musicListLiveData.value as ArrayList<Music>
|
|
|
|
- musics[musics.indexOf(viewModel.musicLiveData.value)] = music
|
|
|
|
- viewModel.musicListLiveData.value = musics
|
|
|
|
- viewModel.musicLiveData.value = music
|
|
|
|
- }, {
|
|
|
|
-
|
|
|
|
- })
|
|
|
|
}
|
|
}
|
|
|
|
|
|
override fun onDismiss(dialog: DialogInterface?) {
|
|
override fun onDismiss(dialog: DialogInterface?) {
|
|
- musicPlayer.stop()
|
|
|
|
|
|
+ viewModel.stopMusic()
|
|
delayedHide(100)
|
|
delayedHide(100)
|
|
}
|
|
}
|
|
|
|
|
|
private var musicEditDialog: MusicEditDialog? = null
|
|
private var musicEditDialog: MusicEditDialog? = null
|
|
|
|
+ private var musicSelectDialog: MusicSelectDialog? = null
|
|
|
|
+
|
|
private val shareDialog = ShareDialog()
|
|
private val shareDialog = ShareDialog()
|
|
|
|
+ private lateinit var progressDialog: ProgressDialog
|
|
|
|
|
|
private val mHideHandler = Handler()
|
|
private val mHideHandler = Handler()
|
|
private val mHidePart2Runnable = Runnable {
|
|
private val mHidePart2Runnable = Runnable {
|
|
@@ -159,8 +110,6 @@ class MovieEditActivity : AppCompatActivity(),
|
|
|
|
|
|
private val moviePlayer = MoviePlayerV2()
|
|
private val moviePlayer = MoviePlayerV2()
|
|
|
|
|
|
- private val musicPlayer = MusicPlayerV2()
|
|
|
|
-
|
|
|
|
private val mediaHelper = MediaHelper()
|
|
private val mediaHelper = MediaHelper()
|
|
|
|
|
|
companion object {
|
|
companion object {
|
|
@@ -177,6 +126,11 @@ class MovieEditActivity : AppCompatActivity(),
|
|
super.onCreate(savedInstanceState)
|
|
super.onCreate(savedInstanceState)
|
|
setContentView(R.layout.activity_movie_edit)
|
|
setContentView(R.layout.activity_movie_edit)
|
|
|
|
|
|
|
|
+ progressDialog = ProgressDialog(this).apply {
|
|
|
|
+ setMessage("progressing")
|
|
|
|
+ setCancelable(false)
|
|
|
|
+ }
|
|
|
|
+
|
|
mediaHelper.init(this)
|
|
mediaHelper.init(this)
|
|
|
|
|
|
viewModel = ViewModelProviders.of(this).get(MovieEditViewModel::class.java)
|
|
viewModel = ViewModelProviders.of(this).get(MovieEditViewModel::class.java)
|
|
@@ -205,6 +159,20 @@ class MovieEditActivity : AppCompatActivity(),
|
|
movieEditView.currentAudioPosition = indexOf(it)
|
|
movieEditView.currentAudioPosition = indexOf(it)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
+ viewModel.musicPlayPosition.observe(this, Observer {
|
|
|
|
+ it?.let {
|
|
|
|
+ musicEditDialog?.currentPosition = it
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ viewModel.showProgressingLiveData.observe(this, Observer {
|
|
|
|
+ it?.let {
|
|
|
|
+ if (it) {
|
|
|
|
+ if (!progressDialog.isShowing) progressDialog.show()
|
|
|
|
+ } else {
|
|
|
|
+ if (progressDialog.isShowing) progressDialog.dismiss()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
|
|
|
@@ -252,11 +220,7 @@ class MovieEditActivity : AppCompatActivity(),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
movieEditView.onLoopSwitchChangedListener = CompoundButton.OnCheckedChangeListener { _, isChecked ->
|
|
movieEditView.onLoopSwitchChangedListener = CompoundButton.OnCheckedChangeListener { _, isChecked ->
|
|
- val musics: ArrayList<Music> = viewModel.musicListLiveData.value as ArrayList<Music>
|
|
|
|
- for (music in musics) {
|
|
|
|
- music.isLoop = isChecked
|
|
|
|
- }
|
|
|
|
- viewModel.musicListLiveData.value = musics
|
|
|
|
|
|
+ viewModel.setMusicLoopEnable(isChecked)
|
|
}
|
|
}
|
|
|
|
|
|
moviePlayer.moviePlayListener = object : MoviePlayerV2.OnMoviePlayListener {
|
|
moviePlayer.moviePlayListener = object : MoviePlayerV2.OnMoviePlayListener {
|
|
@@ -318,8 +282,8 @@ class MovieEditActivity : AppCompatActivity(),
|
|
private fun addMusic(view: View) {
|
|
private fun addMusic(view: View) {
|
|
viewModel.parseDeviceMusic(contentResolver)
|
|
viewModel.parseDeviceMusic(contentResolver)
|
|
|
|
|
|
- val musicSelectDialog = MusicSelectDialog.newInstance(Gson().toJson(viewModel.musicSource))
|
|
|
|
- musicSelectDialog.show(supportFragmentManager, MUSIC_SELECT_DIALOG_TAG)
|
|
|
|
|
|
+ musicSelectDialog = MusicSelectDialog.newInstance(Gson().toJson(viewModel.musicSource))
|
|
|
|
+ musicSelectDialog?.show(supportFragmentManager, MUSIC_SELECT_DIALOG_TAG)
|
|
}
|
|
}
|
|
|
|
|
|
private fun editMusic(view: View) {
|
|
private fun editMusic(view: View) {
|
|
@@ -328,9 +292,7 @@ class MovieEditActivity : AppCompatActivity(),
|
|
}
|
|
}
|
|
|
|
|
|
private fun deleteMusic(view: View) {
|
|
private fun deleteMusic(view: View) {
|
|
- val musics: ArrayList<Music> = viewModel.musicListLiveData.value as ArrayList<Music>
|
|
|
|
- musics.remove(viewModel.musicLiveData.value)
|
|
|
|
- viewModel.musicListLiveData.value = musics
|
|
|
|
|
|
+ viewModel.deleteMusic()
|
|
}
|
|
}
|
|
|
|
|
|
private fun onClickSaveAndShareBtn(view: View) {
|
|
private fun onClickSaveAndShareBtn(view: View) {
|
|
@@ -393,11 +355,11 @@ class MovieEditActivity : AppCompatActivity(),
|
|
onSave = View.OnClickListener { it ->
|
|
onSave = View.OnClickListener { it ->
|
|
if (storyName == "") {
|
|
if (storyName == "") {
|
|
showEmptyProjectNameMsg()
|
|
showEmptyProjectNameMsg()
|
|
- /** TODO: 目前不支援 rename **/
|
|
|
|
- /**
|
|
|
|
- } else if (storyName != oldName && viewModel.isProjectNameExist(storyName)) {
|
|
|
|
|
|
+ /** TODO: 目前不支援 rename **/
|
|
|
|
+ /**
|
|
|
|
+ } else if (storyName != oldName && viewModel.isProjectNameExist(storyName)) {
|
|
showDuplicatedProjectNameMsg()
|
|
showDuplicatedProjectNameMsg()
|
|
- **/
|
|
|
|
|
|
+ **/
|
|
} else {
|
|
} else {
|
|
if (coverFile == null) {
|
|
if (coverFile == null) {
|
|
project.coverFile = null
|
|
project.coverFile = null
|
|
@@ -416,7 +378,7 @@ class MovieEditActivity : AppCompatActivity(),
|
|
.doOnSubscribe { pd.show() }
|
|
.doOnSubscribe { pd.show() }
|
|
.doFinally { pd.dismiss() }
|
|
.doFinally { pd.dismiss() }
|
|
.subscribe {
|
|
.subscribe {
|
|
-// projectManager.reloadProjects()
|
|
|
|
|
|
+ // projectManager.reloadProjects()
|
|
dismiss()
|
|
dismiss()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -610,4 +572,25 @@ class MovieEditActivity : AppCompatActivity(),
|
|
onComplete.run()
|
|
onComplete.run()
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ override fun onPause() {
|
|
|
|
+ super.onPause()
|
|
|
|
+
|
|
|
|
+ musicSelectDialog?.dismiss()
|
|
|
|
+ musicEditDialog?.dismiss()
|
|
|
|
+
|
|
|
|
+ moviePlayer.pause()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onStop() {
|
|
|
|
+ super.onStop()
|
|
|
|
+
|
|
|
|
+ moviePlayer.init()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onDestroy() {
|
|
|
|
+ super.onDestroy()
|
|
|
|
+
|
|
|
|
+ viewModel.onDestroy()
|
|
|
|
+ }
|
|
}
|
|
}
|