Browse Source

fix actor pose

faterhenry 6 years ago
parent
commit
277a56d807

+ 29 - 13
src/main/java/com/bomostory/sceneeditmodule/navigationbar/actor/ActorAdapter.kt

@@ -4,13 +4,16 @@ import android.content.ClipData
 import android.content.ClipDescription
 import android.content.Context
 import android.graphics.drawable.Drawable
+import android.support.v7.widget.LinearLayoutManager
 import android.support.v7.widget.RecyclerView
 import android.view.*
 import android.widget.ImageView
 import android.widget.LinearLayout
+import com.bomostory.sceneeditmodule.navigationbar.actor.ActorPoseAdapter
 import com.bomostory.sceneeditmodule.screen.view.LayerView
 
 import com.example.tfat.myapplication.R
+import kotlinx.android.synthetic.main.item_actor.view.*
 import kotlin.collections.ArrayList
 
 class ActorAdapter(var context : Context, var data: ArrayList<ArrayList<String>>, layerView: LayerView, onActorDragListener: OnActorDragListener) : RecyclerView.Adapter<ActorAdapter.ViewHolder>() {
@@ -25,7 +28,7 @@ class ActorAdapter(var context : Context, var data: ArrayList<ArrayList<String>>
     }
 
     override fun onBindViewHolder(holder: ViewHolder, position: Int) {
-        holder.bind(bitmapData?.get(position), position, initActorImageView(data)[position])
+        holder.bind(bitmapData?.get(position), position, data[position])
     }
 
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
@@ -73,21 +76,34 @@ class ActorAdapter(var context : Context, var data: ArrayList<ArrayList<String>>
     }
 
     class ViewHolder (view : View) : RecyclerView.ViewHolder(view) {
-        fun bind(path: String?, position: Int, data: ArrayList<ImageView>) {
+        fun bind(path: String?, position: Int, data: ArrayList<String>) {
             itemView.findViewById<ImageView>(R.id.actor_image).setImageDrawable(Drawable.createFromPath(path))
             itemView.findViewById<ImageView>(R.id.actor_image).setOnTouchListener(boMoOnTouchListener(position,0))
-            itemView.findViewById<LinearLayout>(R.id.actor_rotate).removeAllViews()
-            for (i in 0 until data.size) {
-                itemView.findViewById<LinearLayout>(R.id.actor_rotate).addView(data[i])
-                data[i].setOnClickListener(View.OnClickListener {
-                    itemView.findViewById<ImageView>(R.id.actor_image).setImageDrawable(data[i].drawable)
-                    itemView.findViewById<ImageView>(R.id.actor_image).setOnTouchListener(boMoOnTouchListener(position,i))
-                })
-                var lParams = data[i].layoutParams
-                lParams.height = 100
-                lParams.width = 100
-                data[i].layoutParams = lParams
+            //itemView.findViewById<LinearLayout>(R.id.actor_rotate).removeAllViews()
+            itemView.actor_rotate.apply {
+                var onClickListeners = ArrayList<View.OnClickListener>()
+                for (i in 0 until data.size) {
+                    onClickListeners.add(View.OnClickListener {
+                        itemView.findViewById<ImageView>(R.id.actor_image).setImageDrawable(Drawable.createFromPath(data[i]))
+                        itemView.findViewById<ImageView>(R.id.actor_image).setOnTouchListener(boMoOnTouchListener(position,i))
+                    })
+                }
+                adapter = ActorPoseAdapter(data, onClickListeners)
+                layoutManager = LinearLayoutManager(context).apply {
+                    orientation = LinearLayoutManager.HORIZONTAL
+                }
             }
+//            for (i in 0 until data.size) {
+//                itemView.findViewById<LinearLayout>(R.id.actor_rotate).addView(data[i])
+//                data[i].setOnClickListener(View.OnClickListener {
+//                    itemView.findViewById<ImageView>(R.id.actor_image).setImageDrawable(data[i].drawable)
+//                    itemView.findViewById<ImageView>(R.id.actor_image).setOnTouchListener(boMoOnTouchListener(position,i))
+//                })
+//                var lParams = data[i].layoutParams
+//                lParams.height = 100
+//                lParams.width = 100
+//                data[i].layoutParams = lParams
+//            }
         }
         private fun boMoOnTouchListener(position: Int, index: Int) : View.OnTouchListener {
             return View.OnTouchListener {view, motionEvent ->

+ 33 - 0
src/main/java/com/bomostory/sceneeditmodule/navigationbar/actor/ActorPoseAdapter.kt

@@ -0,0 +1,33 @@
+package com.bomostory.sceneeditmodule.navigationbar.actor
+
+import android.graphics.drawable.Drawable
+import android.support.v7.widget.RecyclerView
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import com.example.tfat.myapplication.R
+import kotlinx.android.synthetic.main.item_actor.view.*
+
+class ActorPoseAdapter(var data: ArrayList<String>, var onClickListeners: ArrayList<View.OnClickListener>): RecyclerView.Adapter<ActorPoseAdapter.ViewHolder>() {
+
+
+    override fun getItemCount(): Int {
+        return data.size
+    }
+
+    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
+        holder.bind(data?.get(position), onClickListeners[position])
+    }
+
+    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ActorPoseAdapter.ViewHolder {
+        val v1 = LayoutInflater.from(parent.context).inflate(R.layout.actor_pose_item, parent, false)
+        return ViewHolder(v1)
+    }
+
+    class ViewHolder (view : View) : RecyclerView.ViewHolder(view) {
+        fun bind(ObjectResource: String, onClickListener: View.OnClickListener) {
+            itemView.actor_image.setImageDrawable(Drawable.createFromPath(ObjectResource))
+            itemView.actor_image.setOnClickListener(onClickListener)
+        }
+    }
+}

+ 0 - 6
src/main/java/com/bomostory/sceneeditmodule/navigationbar/actor/ObjectAdapter.kt

@@ -17,7 +17,6 @@ class ObjectAdapter(var data: ArrayList<String>, var onTouchListeners: ArrayList
 
     override fun onBindViewHolder(holder: ViewHolder, position: Int) {
         holder.bind(data?.get(position), onTouchListeners[position])
-//        holder.bind(data?.get(position))
     }
 
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ObjectAdapter.ViewHolder {
@@ -31,9 +30,4 @@ class ObjectAdapter(var data: ArrayList<String>, var onTouchListeners: ArrayList
             itemView.actor_image.setOnTouchListener(onTouchListener)
         }
     }
-//    class ViewHolder (view : View) : RecyclerView.ViewHolder(view) {
-//        fun bind(ObjectResource: String) {
-//            itemView.actor_image.setImageDrawable(Drawable.createFromPath(ObjectResource))
-//        }
-//    }
 }

+ 12 - 0
src/main/res/layout/actor_pose_item.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/actor"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content">
+    <ImageView
+        android:id="@+id/actor_image"
+        android:scaleType="center"
+        android:layout_marginLeft="4dp"
+        android:layout_width="40dp"
+        android:layout_height="40dp"/>
+</LinearLayout>

+ 3 - 3
src/main/res/layout/item_actor.xml

@@ -13,12 +13,12 @@
             android:layout_gravity="center"
             android:layout_width="96dp"
             android:layout_height="96dp"/>
-        <LinearLayout
+        <android.support.v7.widget.RecyclerView
             android:id="@+id/actor_rotate"
             android:layout_width="wrap_content"
-            android:layout_height="60dp"
+            android:layout_height="wrap_content"
             android:orientation="horizontal">
-        </LinearLayout>
+        </android.support.v7.widget.RecyclerView>
     </LinearLayout>
     <ImageView
         android:layout_width="1dp"