|
| 1 | +package com.nyakokishi.app; |
| 2 | + |
| 3 | +import android.os.Bundle |
| 4 | +import android.os.Handler |
| 5 | +import android.support.v7.app.AppCompatActivity |
| 6 | +import android.support.v7.widget.GridLayoutManager |
| 7 | +import android.support.v7.widget.LinearLayoutManager |
| 8 | +import cn.nekocode.itempool.ItemPool |
| 9 | +import kotlinx.android.synthetic.main.activity_main.* |
| 10 | + |
| 11 | +class MainActivity : AppCompatActivity() { |
| 12 | + |
| 13 | + val itemPool = ItemPool() |
| 14 | + var count = 0 |
| 15 | + |
| 16 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 17 | + super.onCreate(savedInstanceState) |
| 18 | + setContentView(R.layout.activity_main) |
| 19 | + |
| 20 | + itemPool.addType(DemoItem::class.java) |
| 21 | + |
| 22 | + loadData() |
| 23 | + |
| 24 | + // LinearLayoutManager - normal |
| 25 | + recyclerView.layoutManager = LinearLayoutManager(this) |
| 26 | + |
| 27 | + // LinearLayoutManager - reverse |
| 28 | + recyclerView.layoutManager = LinearLayoutManager(this).apply { |
| 29 | + reverseLayout = true |
| 30 | + } |
| 31 | + |
| 32 | + // GridLayoutManager |
| 33 | + recyclerView.layoutManager = GridLayoutManager(this, 2) |
| 34 | + |
| 35 | + recyclerView.adapter = itemPool.adapter |
| 36 | + recyclerView.setLoadingListener { |
| 37 | + Handler().postDelayed({ |
| 38 | + loadData() |
| 39 | + }, 1500) |
| 40 | + } |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + fun loadData() { |
| 46 | + |
| 47 | + itemPool.add(DemoItem.ColorVO(0xffEE5C42.toInt())) |
| 48 | + itemPool.add(DemoItem.ColorVO(0xff5CACEE.toInt())) |
| 49 | + itemPool.add(DemoItem.ColorVO(0xffAB82FF.toInt())) |
| 50 | + itemPool.add(DemoItem.ColorVO(0xffEE6AA7.toInt())) |
| 51 | + itemPool.add(DemoItem.ColorVO(0xffE6E6FA.toInt())) |
| 52 | + itemPool.add(DemoItem.ColorVO(0xffEEB4B4.toInt())) |
| 53 | + itemPool.add(DemoItem.ColorVO(0xffD1EEEE.toInt())) |
| 54 | + |
| 55 | + itemPool.notifyDataSetChanged() |
| 56 | + recyclerView.loadMoreComplete() |
| 57 | + recyclerView.setHasMore(count++ <= 3) |
| 58 | + } |
| 59 | + |
| 60 | +} |
0 commit comments