Skip to content

Commit

Permalink
只构建library
Browse files Browse the repository at this point in the history
  • Loading branch information
luohaolun committed Jul 3, 2019
1 parent 8c057c2 commit cdd915d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 39 deletions.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':test'
include ':library'
2 changes: 1 addition & 1 deletion test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
93 changes: 58 additions & 35 deletions test/src/main/java/k/lhl/test/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

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

val data = mutableListOf<String>()
for (i in 0..10) {
data.add(i.toString())
}
// val data = mutableListOf<String>()
// 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<Pair<Int, String>>()
// 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<Int>().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<Pair<Int, String>>()
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<Int>().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<Int>().apply { put(0, R.layout.item_test);put(1, R.layout.item_test_2) }) { type, item, position ->
// lvList.adapter = MultiAdapter(data, SparseArray<Int>().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() }
// }


}
}
4 changes: 2 additions & 2 deletions test/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<android.support.v7.widget.RecyclerView
android:visibility="gone"
android:visibility="visible"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
android:id="@+id/recyList"
android:layout_width="match_parent"
Expand Down

0 comments on commit cdd915d

Please sign in to comment.