Преглед на файлове

feature-layer-management-item-move

faterhenry преди 5 години
родител
ревизия
b6a0e44f1c

+ 16 - 5
src/main/java/com/bomostory/sceneeditmodule/SceneEditActivity.kt

@@ -1491,11 +1491,11 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         popupWindow.isOutsideTouchable = true
         var valueXInPixels = resources.getDimension(R.dimen.actor_width)
         when(layerNum){
-            1 -> popupWindow.showAsDropDown(layerManagementDialog.rv_layer_management_layer1, valueXInPixels.toInt() * position, 0)
-            2 -> popupWindow.showAsDropDown(layerManagementDialog.rv_layer_management_layer2, valueXInPixels.toInt() * position, 0)
-            3 -> popupWindow.showAsDropDown(layerManagementDialog.rv_layer_management_layer2, valueXInPixels.toInt() * position + valueXInPixels.toInt(),0)
-            4 -> popupWindow.showAsDropDown(layerManagementDialog.rv_layer_management_layer1, valueXInPixels.toInt() * position, 0)
-            5 -> popupWindow.showAsDropDown(layerManagementDialog.rv_layer_management_layer2, valueXInPixels.toInt() * position, 0)
+            1 -> popupWindow.showAsDropDown(layerManagementDialog.rv_layer_management_layer4, valueXInPixels.toInt() * position, 0)
+            2 -> popupWindow.showAsDropDown(layerManagementDialog.rv_layer_management_layer5, valueXInPixels.toInt() * position, 0)
+            3 -> popupWindow.showAsDropDown(layerManagementDialog.rv_layer_management_layer5, valueXInPixels.toInt() * position + valueXInPixels.toInt(),0)
+            4 -> popupWindow.showAsDropDown(layerManagementDialog.rv_layer_management_layer4, valueXInPixels.toInt() * position, 0)
+            5 -> popupWindow.showAsDropDown(layerManagementDialog.rv_layer_management_layer5, valueXInPixels.toInt() * position, 0)
         }
             }
         }
@@ -1555,4 +1555,15 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         startActivity(intent)
         finish()
     }
+
+    override fun onItemChange(scene: Scene) {
+        project.story?.let {
+            it.scenes?.let {
+                for (i in 0 until 5) {
+                    setActorPositionZ(it[currentSceneIndex].layers[i].actors)
+                }
+                sceneEditView.scene = scene
+            }
+        }
+    }
 }

+ 7 - 0
src/main/java/com/bomostory/sceneeditmodule/layermanagement/ItemMoveSwipeListener.kt

@@ -0,0 +1,7 @@
+package com.bomostory.sceneeditmodule.layermanagement
+
+interface ItemMoveSwipeListener {
+    fun onItemMove(fromPosition: Int, toPosition: Int): Boolean
+    fun onItemSwipe(position: Int)
+    fun clearView()
+}

+ 26 - 0
src/main/java/com/bomostory/sceneeditmodule/layermanagement/ItemTouchHelpCallback.kt

@@ -0,0 +1,26 @@
+package com.bomostory.sceneeditmodule.layermanagement
+
+import android.support.v7.widget.RecyclerView
+import android.support.v7.widget.helper.ItemTouchHelper
+
+
+class ItemTouchHelpCallback (private val itemMoveSwipeListener: ItemMoveSwipeListener) : ItemTouchHelper.Callback() {
+
+    override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
+        val dragFlags = ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT
+        val swipeFlags = 0
+        return makeMovementFlags(dragFlags, swipeFlags)
+    }
+
+    override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
+        return itemMoveSwipeListener.onItemMove(viewHolder.adapterPosition, target.adapterPosition)
+    }
+    override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
+        itemMoveSwipeListener.onItemSwipe(viewHolder.adapterPosition)
+    }
+
+    override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
+        itemMoveSwipeListener.clearView()
+        super.clearView(recyclerView, viewHolder)
+    }
+}

+ 26 - 2
src/main/java/com/bomostory/sceneeditmodule/layermanagement/LayerAdapter.kt

@@ -6,12 +6,16 @@ import android.view.*
 import com.bomostory.sceneeditmodule.basicdata.Actor
 import com.example.tfat.myapplication.R
 import kotlinx.android.synthetic.main.actor_item.view.*
+import java.util.*
 
 
-class LayerAdapter (actorData: ArrayList<Actor>, actorListeners: ArrayList<View.OnTouchListener>) : RecyclerView.Adapter<LayerAdapter.ViewHolder>() {
+class LayerAdapter (actorData: ArrayList<Actor>, actorListeners: ArrayList<View.OnTouchListener>) : RecyclerView.Adapter<LayerAdapter.ViewHolder>(), ItemMoveSwipeListener {
 
-    var data = actorData
+    private var data = actorData
     private var listeners = actorListeners
+    lateinit var listener: ItemMoveListener
+    var layerNum = 0
+
     override fun getItemCount(): Int {
         return data.size
     }
@@ -36,4 +40,24 @@ class LayerAdapter (actorData: ArrayList<Actor>, actorListeners: ArrayList<View.
             itemView.setOnTouchListener(onTouchListener)
         }
     }
+
+    override fun onItemMove(fromPosition: Int, toPosition: Int): Boolean {
+        Collections.swap(listeners,fromPosition,toPosition)
+        notifyItemMoved(fromPosition, toPosition)
+        listener.onItemMove(layerNum, fromPosition, toPosition)
+        return true
+    }
+
+    override fun onItemSwipe(position: Int) {
+    }
+
+    override fun clearView() {
+        listener.clearView()
+    }
+
+    interface ItemMoveListener{
+        fun onItemMove(layerNum: Int, fromPosition: Int, toPosition: Int)
+        fun clearView()
+
+    }
 }

+ 81 - 6
src/main/java/com/bomostory/sceneeditmodule/layermanagement/LayerManagementDialog.kt

@@ -8,16 +8,19 @@ import android.graphics.Color
 import android.os.Bundle
 import android.support.v4.app.DialogFragment
 import android.support.v7.widget.LinearLayoutManager
+import android.support.v7.widget.helper.ItemTouchHelper
 import android.view.*
 import com.bomostory.sceneeditmodule.basicdata.Actor
 import com.bomostory.sceneeditmodule.basicdata.Scene
+import com.bomostory.sceneeditmodule.layermanagement.ItemTouchHelpCallback
 import com.bomostory.sceneeditmodule.layermanagement.LayerAdapter
 import com.example.tfat.myapplication.R
 import kotlinx.android.synthetic.main.layer_management_fragment.*
 import kotlinx.android.synthetic.main.layer_management_fragment.view.*
+import java.util.*
 import kotlin.collections.ArrayList
 
-class LayerManagementDialog : DialogFragment() {
+class LayerManagementDialog : DialogFragment(), LayerAdapter.ItemMoveListener {
 
     private var listener: DialogInterface.OnDismissListener? = null
     private var layerChangeListener: OnLayerChange? = null
@@ -37,6 +40,7 @@ class LayerManagementDialog : DialogFragment() {
     private val layer5Listeners = ArrayList<View.OnTouchListener>()
     private val layer5Adapter = LayerAdapter(layer5Data, layer5Listeners)
     private var selectLayer = 0
+    private var scene: Scene? = null
 
     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
         return inflater.inflate(R.layout.layer_management_fragment, container).apply {
@@ -47,6 +51,11 @@ class LayerManagementDialog : DialogFragment() {
                     orientation = LinearLayoutManager.HORIZONTAL
                 }
             }
+            var itemTouchHelperCallBack1 = ItemTouchHelpCallback(layer1Adapter)
+            var itemTouchHelper1 = ItemTouchHelper(itemTouchHelperCallBack1)
+            itemTouchHelper1.attachToRecyclerView(rv_layer_management_layer1)
+            layer1Adapter.listener = this@LayerManagementDialog
+            layer1Adapter.layerNum = 1
             layout_layer_management_layer1.apply {
                 setOnDragListener(onDragListener(1))
                 setOnClickListener(onClickLayerListener(1))
@@ -57,6 +66,11 @@ class LayerManagementDialog : DialogFragment() {
                     orientation = LinearLayoutManager.HORIZONTAL
                 }
             }
+            var itemTouchHelperCallBack2 = ItemTouchHelpCallback(layer2Adapter)
+            var itemTouchHelper2 = ItemTouchHelper(itemTouchHelperCallBack2)
+            itemTouchHelper2.attachToRecyclerView(rv_layer_management_layer2)
+            layer2Adapter.listener = this@LayerManagementDialog
+            layer2Adapter.layerNum = 2
             layout_layer_management_layer2.apply {
                 setOnDragListener(onDragListener(2))
                 setOnClickListener(onClickLayerListener(2))
@@ -67,6 +81,11 @@ class LayerManagementDialog : DialogFragment() {
                     orientation = LinearLayoutManager.HORIZONTAL
                 }
             }
+            var itemTouchHelperCallBack3 = ItemTouchHelpCallback(layer3Adapter)
+            var itemTouchHelper3 = ItemTouchHelper(itemTouchHelperCallBack3)
+            itemTouchHelper3.attachToRecyclerView(rv_layer_management_layer3)
+            layer3Adapter.listener = this@LayerManagementDialog
+            layer3Adapter.layerNum = 3
             layout_layer_management_layer3.apply {
                 setOnDragListener(onDragListener(3))
                 setOnClickListener(onClickLayerListener(3))
@@ -77,6 +96,11 @@ class LayerManagementDialog : DialogFragment() {
                     orientation = LinearLayoutManager.HORIZONTAL
                 }
             }
+            var itemTouchHelperCallBack4 = ItemTouchHelpCallback(layer4Adapter)
+            var itemTouchHelper4 = ItemTouchHelper(itemTouchHelperCallBack4)
+            itemTouchHelper4.attachToRecyclerView(rv_layer_management_layer1)
+            layer4Adapter.listener = this@LayerManagementDialog
+            layer4Adapter.layerNum = 4
             layout_layer_management_layer4.apply {
                 setOnDragListener(onDragListener(4))
                 setOnClickListener(onClickLayerListener(4))
@@ -87,6 +111,11 @@ class LayerManagementDialog : DialogFragment() {
                     orientation = LinearLayoutManager.HORIZONTAL
                 }
             }
+            var itemTouchHelperCallBack5 = ItemTouchHelpCallback(layer5Adapter)
+            var itemTouchHelper5 = ItemTouchHelper(itemTouchHelperCallBack5)
+            itemTouchHelper5.attachToRecyclerView(rv_layer_management_layer5)
+            layer5Adapter.listener = this@LayerManagementDialog
+            layer5Adapter.layerNum = 5
             layout_layer_management_layer5.apply {
                 setOnDragListener(onDragListener(5))
                 setOnClickListener(onClickLayerListener(5))
@@ -114,6 +143,7 @@ class LayerManagementDialog : DialogFragment() {
     }
 
     fun setData(scene: Scene){
+        this.scene = scene
         this.layer1Data.apply {
             clear()
             addAll(scene.layers[0].actors)
@@ -199,7 +229,19 @@ class LayerManagementDialog : DialogFragment() {
             layout_layer_management_layer3.setBackgroundColor(Color.parseColor("#ffffff"))
             layout_layer_management_layer4.setBackgroundColor(Color.parseColor("#ffffff"))
             layout_layer_management_layer5.setBackgroundColor(Color.parseColor("#ffffff"))
+            iv_layer_management_edit_layer1.visibility = View.INVISIBLE
+            iv_layer_management_edit_layer2.visibility = View.INVISIBLE
+            iv_layer_management_edit_layer3.visibility = View.INVISIBLE
+            iv_layer_management_edit_layer4.visibility = View.INVISIBLE
+            iv_layer_management_edit_layer5.visibility = View.INVISIBLE
             it.setBackgroundColor(Color.parseColor("#efeae1"))
+            when (selectLayer) {
+//                1 -> iv_layer_management_edit_layer1.visibility = View.VISIBLE
+//                2 -> iv_layer_management_edit_layer2.visibility = View.VISIBLE
+//                3 -> iv_layer_management_edit_layer3.visibility = View.VISIBLE
+//                4 -> iv_layer_management_edit_layer4.visibility = View.VISIBLE
+//                5 -> iv_layer_management_edit_layer5.visibility = View.VISIBLE
+            }
         }
     }
 
@@ -247,17 +289,50 @@ class LayerManagementDialog : DialogFragment() {
         layout_layer_management_layer3.setBackgroundColor(Color.parseColor("#ffffff"))
         layout_layer_management_layer4.setBackgroundColor(Color.parseColor("#ffffff"))
         layout_layer_management_layer5.setBackgroundColor(Color.parseColor("#ffffff"))
+        iv_layer_management_edit_layer1.visibility = View.INVISIBLE
+        iv_layer_management_edit_layer2.visibility = View.INVISIBLE
+        iv_layer_management_edit_layer3.visibility = View.INVISIBLE
+        iv_layer_management_edit_layer4.visibility = View.INVISIBLE
+        iv_layer_management_edit_layer5.visibility = View.INVISIBLE
         when (selectLayer) {
-            1 -> layout_layer_management_layer1.setBackgroundColor(Color.parseColor("#efeae1"))
-            2 -> layout_layer_management_layer2.setBackgroundColor(Color.parseColor("#efeae1"))
-            3 -> layout_layer_management_layer3.setBackgroundColor(Color.parseColor("#efeae1"))
-            4 -> layout_layer_management_layer4.setBackgroundColor(Color.parseColor("#efeae1"))
-            5 -> layout_layer_management_layer5.setBackgroundColor(Color.parseColor("#efeae1"))
+            1 -> {
+                layout_layer_management_layer1.setBackgroundColor(Color.parseColor("#efeae1"))
+                //iv_layer_management_edit_layer1.visibility = View.VISIBLE
+            }
+            2 -> {
+                layout_layer_management_layer2.setBackgroundColor(Color.parseColor("#efeae1"))
+                //iv_layer_management_edit_layer2.visibility = View.VISIBLE
+            }
+            3 -> {
+                layout_layer_management_layer3.setBackgroundColor(Color.parseColor("#efeae1"))
+                //iv_layer_management_edit_layer3.visibility = View.VISIBLE
+            }
+            4 -> {
+                layout_layer_management_layer4.setBackgroundColor(Color.parseColor("#efeae1"))
+                //iv_layer_management_edit_layer4.visibility = View.VISIBLE
+            }
+            5 -> {
+                layout_layer_management_layer5.setBackgroundColor(Color.parseColor("#efeae1"))
+                //iv_layer_management_edit_layer5.visibility = View.VISIBLE
+            }
+        }
+    }
+
+    override fun onItemMove(layer: Int,fromPosition: Int, toPosition: Int) {
+        scene?.let {
+            Collections.swap(it.layers[layer - 1].actors,fromPosition,toPosition)
+        }
+    }
+    override fun clearView() {
+        scene?.let {
+            setData(it)
+            layerChangeListener?.onItemChange(it)
         }
     }
 
     interface OnLayerChange{
         fun onLayerChange(layerFrom: Int, layerTo: Int, position: Int)
         fun onLayerManagementDialog(layer: Int, position: Int)
+        fun onItemChange(scene: Scene)
     }
 }

+ 10 - 0
src/main/res/drawable/ic_cancel.xml

@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+  <path
+      android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"
+      android:fillColor="#4E342E"
+      android:fillType="nonZero"/>
+</vector>

+ 2 - 2
src/main/res/drawable/ic_edit.xml

@@ -4,13 +4,13 @@
     android:viewportWidth="24"
     android:viewportHeight="24">
   <path
-      android:pathData="M5,18.08l0,0.92l0.92,0l9.06,-9.06l-0.92,-0.92z"
+      android:pathData="M5,18.08V19h0.92l9.06,-9.06 -0.92,-0.92z"
       android:strokeAlpha="0.3"
       android:fillColor="#4E342E"
       android:fillType="nonZero"
       android:fillAlpha="0.3"/>
   <path
-      android:pathData="M20.71,7.04C21.1,6.65 21.1,6.02 20.71,5.63L18.37,3.29C18.17,3.09 17.92,3 17.66,3 17.4,3 17.15,3.1 16.96,3.29L15.13,5.12 18.88,8.87 20.71,7.04zM3,17.25L3,21 6.75,21 17.81,9.94 14.06,6.19 3,17.25zM5.92,19L5,19 5,18.08 14.06,9.02 14.98,9.94 5.92,19z"
+      android:pathData="M20.71,7.04a0.996,0.996 0,0 0,0 -1.41l-2.34,-2.34c-0.2,-0.2 -0.45,-0.29 -0.71,-0.29 -0.26,0 -0.51,0.1 -0.7,0.29l-1.83,1.83 3.75,3.75 1.83,-1.83zM3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM5.92,19H5v-0.92l9.06,-9.06 0.92,0.92L5.92,19z"
       android:fillColor="#4E342E"
       android:fillType="nonZero"/>
 </vector>

+ 61 - 2
src/main/res/layout/layer_management_fragment.xml

@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:layout_width="832dp"
+    android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@drawable/bg_layer_management_dialog">
     <LinearLayout
         android:id="@+id/tv_layer_management_title"
-        android:layout_width="match_parent"
+        android:layout_width="832dp"
         android:layout_height="37dp"
         android:orientation="vertical"
         app:layout_constraintTop_toTopOf="parent">
@@ -97,4 +97,63 @@
             android:layout_height="1dp"
             android:background="#33000000"/>
     </LinearLayout>
+    <ImageView
+        android:id="@+id/iv_layer_management_edit_layer5"
+        android:layout_width="56dp"
+        android:layout_height="56dp"
+        android:scaleType="center"
+        android:src="@drawable/ic_edit"
+        android:background="@drawable/btn_edit_brush_color_circle_color4"
+        android:layout_marginRight="16dp"
+        android:visibility="invisible"
+        app:layout_constraintTop_toBottomOf="@+id/layout_layer_management_layer5"
+        app:layout_constraintBottom_toTopOf="@id/layout_layer_management_layer4"
+        app:layout_constraintRight_toRightOf="parent"/>
+    <ImageView
+        android:id="@+id/iv_layer_management_edit_layer4"
+        android:layout_width="56dp"
+        android:layout_height="56dp"
+        android:scaleType="center"
+        android:src="@drawable/ic_edit"
+        android:background="@drawable/btn_edit_brush_color_circle_color4"
+        android:layout_marginRight="16dp"
+        android:visibility="invisible"
+        app:layout_constraintTop_toBottomOf="@+id/layout_layer_management_layer4"
+        app:layout_constraintBottom_toTopOf="@id/layout_layer_management_layer3"
+        app:layout_constraintRight_toRightOf="parent"/>
+    <ImageView
+        android:id="@+id/iv_layer_management_edit_layer3"
+        android:layout_width="56dp"
+        android:layout_height="56dp"
+        android:scaleType="center"
+        android:src="@drawable/ic_edit"
+        android:background="@drawable/btn_edit_brush_color_circle_color4"
+        android:layout_marginRight="16dp"
+        android:visibility="invisible"
+        app:layout_constraintTop_toBottomOf="@+id/layout_layer_management_layer3"
+        app:layout_constraintBottom_toTopOf="@id/layout_layer_management_layer2"
+        app:layout_constraintRight_toRightOf="parent"/>
+    <ImageView
+        android:id="@+id/iv_layer_management_edit_layer2"
+        android:layout_width="56dp"
+        android:layout_height="56dp"
+        android:scaleType="center"
+        android:src="@drawable/ic_edit"
+        android:background="@drawable/btn_edit_brush_color_circle_color4"
+        android:layout_marginRight="16dp"
+        android:visibility="invisible"
+        app:layout_constraintTop_toBottomOf="@+id/layout_layer_management_layer2"
+        app:layout_constraintBottom_toTopOf="@id/layout_layer_management_layer1"
+        app:layout_constraintRight_toRightOf="parent"/>
+    <ImageView
+        android:id="@+id/iv_layer_management_edit_layer1"
+        android:layout_width="56dp"
+        android:layout_height="56dp"
+        android:scaleType="center"
+        android:src="@drawable/ic_edit"
+        android:background="@drawable/btn_edit_brush_color_circle_color4"
+        android:layout_marginRight="16dp"
+        android:visibility="invisible"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintRight_toRightOf="parent"/>
  </android.support.constraint.ConstraintLayout>