Explorar o código

Refactor: movie edit dialog

Shan-PC\Shan %!s(int64=6) %!d(string=hai) anos
pai
achega
55a2c8b480

+ 22 - 27
src/main/java/com/bomostory/sceneeditmodule/MovieEditActivity.kt

@@ -10,7 +10,6 @@ import android.os.Environment
 import android.os.Handler
 import android.support.v4.app.DialogFragment
 import android.support.v7.app.AppCompatActivity
-import android.util.Log
 import android.view.View
 import android.widget.CompoundButton
 import android.widget.SeekBar
@@ -37,11 +36,24 @@ class MovieEditActivity : AppCompatActivity(),
         MusicSelectFragment.OnFragmentInteractionListener,
         MusicEditDialog.OnFragmentInteractionListener {
 
-    override fun onMusicStop() {
+    override fun onMusicImportClick(music: Music) {
+        musics.add(music)
+        moviePlayer.init()
+        moviePlayer.addMusic(music)
+        movieEditView.musics = musics
+
+        val dialogFragment = supportFragmentManager.findFragmentByTag(MUSIC_SELECT_DIALOG_TAG) as DialogFragment
+        dialogFragment.dismiss()
+    }
+
+    override fun onMusicPreCastClick(music: Music) {
         musicPlayer.stop()
+        musicPlayer.clear()
+        musicPlayer.add(music)
+        musicPlayer.play()
     }
 
-    override fun onMusicPlayClick2(music: Music, startPosition: Int) {
+    override fun onMusicPlayClick(music: Music, startPosition: Int) {
         musicPlayer.clear()
         musicPlayer.add(music)
         musicPlayer.playChangedListener = object : MusicPlayer.OnPlayChangedListener {
@@ -56,40 +68,23 @@ class MovieEditActivity : AppCompatActivity(),
         musicPlayer.play(startPosition)
     }
 
-    override fun onMusicSeekTo(mSec: Int) {
-        musicPlayer.seekTo(mSec)
-    }
-
     override fun onMusicVolumeChanged(volume: Float) {
         musicPlayer.setVolume(volume)
     }
 
-    override fun onDismiss(dialog: DialogInterface?) {
-        musicPlayer.stop()
-        musicPlayer.release()
-
-        delayedHide(100)
+    override fun onMusicPauseClick() {
+        musicPlayer.pause()
     }
 
-    override fun onMusicPlayClick(music: Music) {
+    override fun onMusicStop() {
         musicPlayer.stop()
-        musicPlayer.clear()
-        musicPlayer.add(music)
-        musicPlayer.play()
     }
 
-    override fun onMusicPauseClick() {
-        musicPlayer.pause()
-    }
-
-    override fun onMusicImportClick(music: Music) {
-        musics.add(music)
-        moviePlayer.init()
-        moviePlayer.addMusic(music)
-        movieEditView.musics = musics
+    override fun onDismiss(dialog: DialogInterface?) {
+        musicPlayer.stop()
+        musicPlayer.release()
 
-        val dialogFragment = supportFragmentManager.findFragmentByTag(MUSIC_SELECT_DIALOG_TAG) as DialogFragment
-        dialogFragment.dismiss()
+        delayedHide(100)
     }
 
     private val shareDialog = ShareDialog()

+ 14 - 11
src/main/java/com/bomostory/sceneeditmodule/MusicEditDialog.kt

@@ -41,14 +41,17 @@ class MusicEditDialog : DialogFragment() {
             editMusic?.let {
                 val endPosition = endScrollRatio * it.duration
 
-                var playPosition = currentPosition
-                if (currentPosition >= endPosition) {
-                    playPosition = 0
+                if (field >= endPosition) {
+                    field = (headScrollRatio * it.duration).toInt()
+
                     listener?.onMusicStop()
+
                     editAudioTrackView.playProgressDialogVisible = false
+                    play.visibility = View.VISIBLE
+                    pause.visibility = View.INVISIBLE
                 }
-                editAudioTrackView.playProgress = playPosition.toFloat() / it.duration
-                editAudioTrackView.playProgressText = TimeUtils.getAudioTimeFormat(playPosition.toLong())
+                editAudioTrackView.playProgress = field.toFloat() / it.duration
+                editAudioTrackView.playProgressText = TimeUtils.getAudioTimeFormat(field.toLong())
             }
         }
 
@@ -87,12 +90,14 @@ class MusicEditDialog : DialogFragment() {
                 volumeText.text = "${volumeSeekBar.progress} %"
 
                 play.setOnClickListener { _ ->
-                    var playPosition = currentPosition
                     val startPosition = it.duration * headScrollRatio
+                    var playPosition = currentPosition
+
                     if (startPosition > currentPosition) {
                         playPosition = startPosition.toInt()
                     }
-                    listener?.onMusicPlayClick2(it, playPosition)
+
+                    listener?.onMusicPlayClick(it, playPosition)
 
                     editAudioTrackView.playProgressDialogVisible = true
                     play.visibility = View.INVISIBLE
@@ -100,10 +105,9 @@ class MusicEditDialog : DialogFragment() {
                 }
 
                 pause.setOnClickListener { _ ->
-                    editAudioTrackView.playProgressDialogVisible = false
-
                     listener?.onMusicPauseClick()
 
+                    editAudioTrackView.playProgressDialogVisible = false
                     play.visibility = View.VISIBLE
                     pause.visibility = View.INVISIBLE
                 }
@@ -209,10 +213,9 @@ class MusicEditDialog : DialogFragment() {
      * for more information.
      */
     interface OnFragmentInteractionListener {
-        fun onMusicPlayClick2(music: Music, startPosition: Int)
+        fun onMusicPlayClick(music: Music, startPosition: Int)
         fun onMusicPauseClick()
         fun onMusicVolumeChanged(volume: Float)
-        fun onMusicSeekTo(mSec: Int)
         fun onMusicStop()
     }
 

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

@@ -40,7 +40,7 @@ class MusicSelectFragment : Fragment() {
 
     interface OnFragmentInteractionListener {
 
-        fun onMusicPlayClick(music: Music)
+        fun onMusicPreCastClick(music: Music)
 
         fun onMusicPauseClick()
 
@@ -108,7 +108,7 @@ class MusicSelectFragment : Fragment() {
                     pause.visibility = if (p1 == playPosition) View.VISIBLE else View.INVISIBLE
 
                     play.setOnClickListener {
-                        listener?.onMusicPlayClick(musics[p1])
+                        listener?.onMusicPreCastClick(musics[p1])
 
                         playPosition = p1
                         notifyDataSetChanged()