Browse Source

New: add music edit dialog tamplate

Shan-PC\Shan 6 năm trước cách đây
mục cha
commit
38eb7133aa

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

@@ -2,6 +2,7 @@ package com.bomostory.sceneeditmodule
 
 import android.content.DialogInterface
 import android.graphics.*
+import android.net.Uri
 import android.support.v7.app.AppCompatActivity
 import android.os.Bundle
 import android.os.Environment
@@ -29,7 +30,15 @@ import java.util.AbstractMap
 import kotlin.math.pow
 
 
-class MovieEditActivity : AppCompatActivity(), DialogInterface.OnDismissListener, MusicSelectFragment.OnFragmentInteractionListener {
+class MovieEditActivity : AppCompatActivity(),
+        DialogInterface.OnDismissListener,
+        MusicSelectFragment.OnFragmentInteractionListener,
+        MusicEditDialog.OnFragmentInteractionListener {
+
+    override fun onFragmentInteraction(uri: Uri) {
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    }
+
     override fun onDismiss(dialog: DialogInterface?) {
         musicPlayer.stop()
         musicPlayer.release()
@@ -125,6 +134,7 @@ class MovieEditActivity : AppCompatActivity(), DialogInterface.OnDismissListener
     companion object {
         const val PROJECT_KEY = "project_key"
         const val MUSIC_SELECT_DIALOG_TAG = "music_select_dialog_tag"
+        const val MUSIC_EDIT_DIALOG_TAG = "music_edit_dialog_tag"
         const val FPS: Int = 30
         private const val UI_ANIMATION_DELAY = 300
     }
@@ -235,8 +245,11 @@ class MovieEditActivity : AppCompatActivity(), DialogInterface.OnDismissListener
         musicSelectDialog.show(supportFragmentManager, MUSIC_SELECT_DIALOG_TAG)
     }
 
-    private fun editMusic(view:View){
-        Log.d("Debug","edit music track $currentAudioPosition")
+    private fun editMusic(view: View) {
+        Log.d("Debug", "edit music track $currentAudioPosition")
+
+        val musicEditDialog = MusicEditDialog.newInstance("", "")
+        musicEditDialog.show(supportFragmentManager, MUSIC_EDIT_DIALOG_TAG)
     }
 
     private fun deleteMusic(view: View) {

+ 102 - 0
src/main/java/com/bomostory/sceneeditmodule/MusicEditDialog.kt

@@ -0,0 +1,102 @@
+package com.bomostory.sceneeditmodule
+
+import android.content.Context
+import android.net.Uri
+import android.os.Bundle
+import android.support.v4.app.DialogFragment
+import android.support.v4.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+
+import com.example.tfat.myapplication.R
+
+// 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"
+
+/**
+ * A simple [Fragment] subclass.
+ * Activities that contain this fragment must implement the
+ * [MusicEditDialog.OnFragmentInteractionListener] interface
+ * to handle interaction events.
+ * Use the [MusicEditDialog.newInstance] factory method to
+ * create an instance of this fragment.
+ *
+ */
+class MusicEditDialog : DialogFragment() {
+    // TODO: Rename and change types of parameters
+    private var param1: String? = null
+    private var param2: String? = 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)
+        }
+    }
+
+    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)
+    }
+
+    // TODO: Rename method, update argument and hook method into UI event
+    fun onButtonPressed(uri: Uri) {
+        listener?.onFragmentInteraction(uri)
+    }
+
+    override fun onAttach(context: Context) {
+        super.onAttach(context)
+        if (context is OnFragmentInteractionListener) {
+            listener = context
+        } else {
+            throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
+        }
+    }
+
+    override fun onDetach() {
+        super.onDetach()
+        listener = null
+    }
+
+    /**
+     * This interface must be implemented by activities that contain this
+     * fragment to allow an interaction in this fragment to be communicated
+     * to the activity and potentially other fragments contained in that
+     * activity.
+     *
+     *
+     * See the Android Training lesson [Communicating with Other Fragments]
+     * (http://developer.android.com/training/basics/fragments/communicating.html)
+     * for more information.
+     */
+    interface OnFragmentInteractionListener {
+        // TODO: Update argument type and name
+        fun onFragmentInteraction(uri: Uri)
+    }
+
+    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) =
+                MusicEditDialog().apply {
+                    arguments = Bundle().apply {
+                        putString(ARG_PARAM1, param1)
+                        putString(ARG_PARAM2, param2)
+                    }
+                }
+    }
+}

+ 13 - 0
src/main/res/layout/fragment_music_edit_dialog.xml

@@ -0,0 +1,13 @@
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="com.bomostory.sceneeditmodule.MusicEditDialog">
+
+    <!-- TODO: Update blank fragment layout -->
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:text="@string/hello_blank_fragment" />
+
+</FrameLayout>

+ 3 - 0
src/main/res/values/strings.xml

@@ -4,4 +4,7 @@
     <string name="title_activity_movie_edit">MovieEditActivity</string>
     <string name="dummy_button">Dummy Button</string>
     <string name="dummy_content">DUMMY\nCONTENT</string>
+
+    <!-- TODO: Remove or change this placeholder text -->
+    <string name="hello_blank_fragment">Hello blank fragment</string>
 </resources>