diff --git a/settings.gradle b/settings.gradle index 3b011ba..d8f14a1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':test' +include ':library' diff --git a/test/build.gradle b/test/build.gradle index 42ac5be..b3d0427 100644 --- a/test/build.gradle +++ b/test/build.gradle @@ -35,5 +35,5 @@ dependencies { androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation 'com.android.support:recyclerview-v7:28.0.0' - implementation project(':app') + implementation project(':library') } diff --git a/test/src/main/java/k/lhl/test/MainActivity.kt b/test/src/main/java/k/lhl/test/MainActivity.kt index 766094f..20808e0 100644 --- a/test/src/main/java/k/lhl/test/MainActivity.kt +++ b/test/src/main/java/k/lhl/test/MainActivity.kt @@ -5,10 +5,7 @@ import android.os.Bundle import android.support.v7.widget.LinearLayoutManager import android.util.SparseArray import android.widget.Toast -import k.lhl.adapter.Adapter -import k.lhl.adapter.MultiRecyclerAdapter -import k.lhl.adapter.RecyclerAdapter -import k.lhl.adapter.positon +import k.lhl.adapter.* import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.item_test.view.* @@ -18,62 +15,88 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - val data = mutableListOf() - for (i in 0..10) { - data.add(i.toString()) - } +// val data = mutableListOf() +// for (i in 10..30) { +// data.add(i.toString()) +// } // // recyList.layoutManager = LinearLayoutManager(this).apply { orientation = LinearLayoutManager.VERTICAL } -// -// recyList.adapter = RecyclerAdapter(data, R.layout.item_test) { item, position -> -// tvNum.text = item +// recyList.adapter = RecyclerAdapter(data, R.layout.item_test) { +// tvNum.text = it // btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击" + position, Toast.LENGTH_SHORT).show() } // }.setOnItemClickListener { -// Toast.makeText(this@MainActivity, "点击 $position", Toast.LENGTH_SHORT).show() +// Toast.makeText(this@MainActivity, "点击 $position $it", Toast.LENGTH_SHORT).show() // }.setOnItemLongClickListener { -// Toast.makeText(this@MainActivity, "长按 $position", Toast.LENGTH_SHORT).show() +// Toast.makeText(this@MainActivity, "长按 $position $it", Toast.LENGTH_SHORT).show() // } // - lvList.adapter = Adapter(data, R.layout.item_test) { - tvNum.text = this.item - btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击" + item, Toast.LENGTH_SHORT).show() } - } - -// val data = mutableListOf>() -// for (i in 1..20) { -// if (i < 4) -// data.add(Pair(0, i.toString())) -// else -// data.add(Pair(1, i.toString())) -// } // -// recyList.layoutManager = LinearLayoutManager(this).apply { orientation = LinearLayoutManager.VERTICAL } -// recyList.adapter = MultiRecyclerAdapter(data, SparseArray().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) { item, position -> -// tvNum.text = item +// lvList.adapter = Adapter(data, R.layout.item_test) { +// tvNum.text = it // btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击" + position, Toast.LENGTH_SHORT).show() } +// } + + val data = mutableListOf>() + for (i in 10..30) { + if (i < 14 || i > 28) + data.add(Pair(0, i.toString())) + else + data.add(Pair(1, i.toString())) + } + + recyList.layoutManager = LinearLayoutManager(this).apply { orientation = LinearLayoutManager.VERTICAL } + recyList.adapter = MultiRecyclerAdapter(data, SparseArray().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) { + when (type) { + 0 -> { + tvNum.text = it + btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击类型1 $position", Toast.LENGTH_SHORT).show() } + } + 1 -> { + tvNum.text = it + btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击类型2 $position", Toast.LENGTH_SHORT).show() } + } + } + }.setOnItemClickListener { + Toast.makeText(this@MainActivity, "点击 $position $it", Toast.LENGTH_SHORT).show() + }.setOnItemLongClickListener { + Toast.makeText(this@MainActivity, "长按 $position $it", Toast.LENGTH_SHORT).show() + } + +// recyList.adapter = MulRecyclerAdapter(data, 0, R.layout.item_test) { +// tvNum.text = it +// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击类型1 $position", Toast.LENGTH_SHORT).show() } +// }.addItemType(1, R.layout.item_test_2) { +// tvNum.text = it +// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击类型2 $position", Toast.LENGTH_SHORT).show() } // }.setOnItemClickListener { -// Toast.makeText(this@MainActivity, "点击 $item", Toast.LENGTH_SHORT).show() +// Toast.makeText(this@MainActivity, "点击 $position $it", Toast.LENGTH_SHORT).show() // }.setOnItemLongClickListener { -// Toast.makeText(this@MainActivity, "长按 $position", Toast.LENGTH_SHORT).show() +// Toast.makeText(this@MainActivity, "长按 $position $it", Toast.LENGTH_SHORT).show() // } -// -// -// lvList.adapter = MultiAdapter(data, SparseArray().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) { type, item, position -> +// lvList.adapter = MultiAdapter(data, SparseArray().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) { // when (type) { // 0 -> { -// tvNum.text = "$item 类型0" +// tvNum.text = "$it 类型0" // btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型0", Toast.LENGTH_SHORT).show() } // } // 1 -> { -// tvNum.text = "$item 类型1" +// tvNum.text = "$it 类型1" // btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型1", Toast.LENGTH_SHORT).show() } // } // } // } +// lvList.adapter = MulAdapter(data, 0, R.layout.item_test) { +// tvNum.text = "$it 类型1" +// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型1", Toast.LENGTH_SHORT).show() } +// }.addItemType(1, R.layout.item_test_2) { +// tvNum.text = "$it 类型2" +// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型2", Toast.LENGTH_SHORT).show() } +// } + } } diff --git a/test/src/main/res/layout/activity_main.xml b/test/src/main/res/layout/activity_main.xml index 0a54e42..5bb8bbc 100644 --- a/test/src/main/res/layout/activity_main.xml +++ b/test/src/main/res/layout/activity_main.xml @@ -11,14 +11,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:text="Hello World!" - android:visibility="visible" + android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" />