Skip to content

Commit cdd915d

Browse files
committed
只构建library
1 parent 8c057c2 commit cdd915d

File tree

4 files changed

+62
-39
lines changed

4 files changed

+62
-39
lines changed

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':app', ':test'
1+
include ':library'

test/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ dependencies {
3535
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3636
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
3737
implementation 'com.android.support:recyclerview-v7:28.0.0'
38-
implementation project(':app')
38+
implementation project(':library')
3939
}

test/src/main/java/k/lhl/test/MainActivity.kt

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import android.os.Bundle
55
import android.support.v7.widget.LinearLayoutManager
66
import android.util.SparseArray
77
import android.widget.Toast
8-
import k.lhl.adapter.Adapter
9-
import k.lhl.adapter.MultiRecyclerAdapter
10-
import k.lhl.adapter.RecyclerAdapter
11-
import k.lhl.adapter.positon
8+
import k.lhl.adapter.*
129
import kotlinx.android.synthetic.main.activity_main.*
1310
import kotlinx.android.synthetic.main.item_test.view.*
1411

@@ -18,62 +15,88 @@ class MainActivity : AppCompatActivity() {
1815
super.onCreate(savedInstanceState)
1916
setContentView(R.layout.activity_main)
2017

21-
val data = mutableListOf<String>()
22-
for (i in 0..10) {
23-
data.add(i.toString())
24-
}
18+
// val data = mutableListOf<String>()
19+
// for (i in 10..30) {
20+
// data.add(i.toString())
21+
// }
2522
//
2623
// recyList.layoutManager = LinearLayoutManager(this).apply { orientation = LinearLayoutManager.VERTICAL }
27-
//
28-
// recyList.adapter = RecyclerAdapter(data, R.layout.item_test) { item, position ->
29-
// tvNum.text = item
24+
// recyList.adapter = RecyclerAdapter(data, R.layout.item_test) {
25+
// tvNum.text = it
3026
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击" + position, Toast.LENGTH_SHORT).show() }
3127
// }.setOnItemClickListener {
32-
// Toast.makeText(this@MainActivity, "点击 $position", Toast.LENGTH_SHORT).show()
28+
// Toast.makeText(this@MainActivity, "点击 $position $it", Toast.LENGTH_SHORT).show()
3329
// }.setOnItemLongClickListener {
34-
// Toast.makeText(this@MainActivity, "长按 $position", Toast.LENGTH_SHORT).show()
30+
// Toast.makeText(this@MainActivity, "长按 $position $it", Toast.LENGTH_SHORT).show()
3531
// }
3632

3733
//
38-
lvList.adapter = Adapter(data, R.layout.item_test) {
39-
tvNum.text = this.item
40-
btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击" + item, Toast.LENGTH_SHORT).show() }
41-
}
42-
43-
// val data = mutableListOf<Pair<Int, String>>()
44-
// for (i in 1..20) {
45-
// if (i < 4)
46-
// data.add(Pair(0, i.toString()))
47-
// else
48-
// data.add(Pair(1, i.toString()))
49-
// }
5034
//
51-
// recyList.layoutManager = LinearLayoutManager(this).apply { orientation = LinearLayoutManager.VERTICAL }
52-
// recyList.adapter = MultiRecyclerAdapter(data, SparseArray<Int>().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) { item, position ->
53-
// tvNum.text = item
35+
// lvList.adapter = Adapter(data, R.layout.item_test) {
36+
// tvNum.text = it
5437
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击" + position, Toast.LENGTH_SHORT).show() }
38+
// }
39+
40+
val data = mutableListOf<Pair<Int, String>>()
41+
for (i in 10..30) {
42+
if (i < 14 || i > 28)
43+
data.add(Pair(0, i.toString()))
44+
else
45+
data.add(Pair(1, i.toString()))
46+
}
47+
48+
recyList.layoutManager = LinearLayoutManager(this).apply { orientation = LinearLayoutManager.VERTICAL }
49+
recyList.adapter = MultiRecyclerAdapter(data, SparseArray<Int>().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) {
50+
when (type) {
51+
0 -> {
52+
tvNum.text = it
53+
btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击类型1 $position", Toast.LENGTH_SHORT).show() }
54+
}
55+
1 -> {
56+
tvNum.text = it
57+
btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击类型2 $position", Toast.LENGTH_SHORT).show() }
58+
}
59+
}
60+
}.setOnItemClickListener {
61+
Toast.makeText(this@MainActivity, "点击 $position $it", Toast.LENGTH_SHORT).show()
62+
}.setOnItemLongClickListener {
63+
Toast.makeText(this@MainActivity, "长按 $position $it", Toast.LENGTH_SHORT).show()
64+
}
65+
66+
// recyList.adapter = MulRecyclerAdapter(data, 0, R.layout.item_test) {
67+
// tvNum.text = it
68+
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击类型1 $position", Toast.LENGTH_SHORT).show() }
69+
// }.addItemType(1, R.layout.item_test_2) {
70+
// tvNum.text = it
71+
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击类型2 $position", Toast.LENGTH_SHORT).show() }
5572
// }.setOnItemClickListener {
56-
// Toast.makeText(this@MainActivity, "点击 $item", Toast.LENGTH_SHORT).show()
73+
// Toast.makeText(this@MainActivity, "点击 $position $it", Toast.LENGTH_SHORT).show()
5774
// }.setOnItemLongClickListener {
58-
// Toast.makeText(this@MainActivity, "长按 $position", Toast.LENGTH_SHORT).show()
75+
// Toast.makeText(this@MainActivity, "长按 $position $it", Toast.LENGTH_SHORT).show()
5976
// }
6077

6178

62-
//
63-
//
64-
// lvList.adapter = MultiAdapter(data, SparseArray<Int>().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) { type, item, position ->
79+
// lvList.adapter = MultiAdapter(data, SparseArray<Int>().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) {
6580
// when (type) {
6681
// 0 -> {
67-
// tvNum.text = "$item 类型0"
82+
// tvNum.text = "$it 类型0"
6883
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型0", Toast.LENGTH_SHORT).show() }
6984
// }
7085
// 1 -> {
71-
// tvNum.text = "$item 类型1"
86+
// tvNum.text = "$it 类型1"
7287
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型1", Toast.LENGTH_SHORT).show() }
7388
// }
7489
// }
7590
// }
7691

92+
// lvList.adapter = MulAdapter(data, 0, R.layout.item_test) {
93+
// tvNum.text = "$it 类型1"
94+
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型1", Toast.LENGTH_SHORT).show() }
95+
// }.addItemType(1, R.layout.item_test_2) {
96+
// tvNum.text = "$it 类型2"
97+
// btn.setOnClickListener { Toast.makeText(this@MainActivity, "点击$position 类型2", Toast.LENGTH_SHORT).show() }
98+
// }
99+
77100

78101
}
79102
}

test/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
android:layout_width="match_parent"
1212
android:layout_height="match_parent"
1313
android:text="Hello World!"
14-
android:visibility="visible"
14+
android:visibility="gone"
1515
app:layout_constraintBottom_toBottomOf="parent"
1616
app:layout_constraintLeft_toLeftOf="parent"
1717
app:layout_constraintRight_toRightOf="parent"
1818
app:layout_constraintTop_toTopOf="parent" />
1919

2020
<android.support.v7.widget.RecyclerView
21-
android:visibility="gone"
21+
android:visibility="visible"
2222
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
2323
android:id="@+id/recyList"
2424
android:layout_width="match_parent"

0 commit comments

Comments
 (0)