Przeglądaj źródła

New: pass music data to music edit dialog

Shan-PC\Shan 6 lat temu
rodzic
commit
f9219d0f25

+ 1 - 3
src/main/java/com/bomostory/sceneeditmodule/MovieEditActivity.kt

@@ -245,9 +245,7 @@ class MovieEditActivity : AppCompatActivity(),
     }
 
     private fun editMusic(view: View) {
-        Log.d("Debug", "edit music track $currentAudioPosition")
-
-        val musicEditDialog = MusicEditDialog.newInstance("", "")
+        val musicEditDialog = MusicEditDialog.newInstance(Gson().toJson(musics[currentAudioPosition]))
         musicEditDialog.show(supportFragmentManager, MUSIC_EDIT_DIALOG_TAG)
     }
 

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

@@ -8,13 +8,14 @@ import android.support.v4.app.Fragment
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import com.bomostory.sceneeditmodule.basicdata.Music
+import com.bomostory.sceneeditmodule.utils.TimeUtils
 
 import com.example.tfat.myapplication.R
+import com.google.gson.Gson
+import kotlinx.android.synthetic.main.fragment_music_edit_dialog.view.*
 
-// TODO: Rename parameter arguments, choose names that match
-// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
-private const val ARG_PARAM1 = "param1"
-private const val ARG_PARAM2 = "param2"
+private const val ARG_PARAM1 = "editMusic"
 
 /**
  * A simple [Fragment] subclass.
@@ -27,22 +28,23 @@ private const val ARG_PARAM2 = "param2"
  */
 class MusicEditDialog : DialogFragment() {
     // TODO: Rename and change types of parameters
-    private var param1: String? = null
-    private var param2: String? = null
+    private var editMusic: Music? = null
     private var listener: OnFragmentInteractionListener? = null
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         arguments?.let {
-            param1 = it.getString(ARG_PARAM1)
-            param2 = it.getString(ARG_PARAM2)
+            editMusic = Gson().fromJson(it.getString(ARG_PARAM1), Music::class.java)
         }
     }
 
     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                               savedInstanceState: Bundle?): View? {
-        // Inflate the layout for this fragment
-        return inflater.inflate(R.layout.fragment_music_edit_dialog, container, false)
+        return inflater.inflate(R.layout.fragment_music_edit_dialog, container, false).apply {
+            editMusic?.let {
+                musicName.text = it.name
+            }
+        }
     }
 
     // TODO: Rename method, update argument and hook method into UI event
@@ -81,21 +83,11 @@ class MusicEditDialog : DialogFragment() {
     }
 
     companion object {
-        /**
-         * Use this factory method to create a new instance of
-         * this fragment using the provided parameters.
-         *
-         * @param param1 Parameter 1.
-         * @param param2 Parameter 2.
-         * @return A new instance of fragment MusicEditDialog.
-         */
-        // TODO: Rename and change types and number of parameters
         @JvmStatic
-        fun newInstance(param1: String, param2: String) =
+        fun newInstance(editMusic: String) =
                 MusicEditDialog().apply {
                     arguments = Bundle().apply {
-                        putString(ARG_PARAM1, param1)
-                        putString(ARG_PARAM2, param2)
+                        putString(ARG_PARAM1, editMusic)
                     }
                 }
     }