Skip to content

Commit fed8885

Browse files
committed
update demo
1 parent 374a605 commit fed8885

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+396
-348
lines changed

ptr-demo/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</activity>
2323

2424
<activity
25-
android:name="wtf.s1.android.ptr.demo.md.CheeseDetailActivity"
25+
android:name="wtf.s1.android.ptr.demo.md.TiDetailActivity"
2626
android:parentActivityName="wtf.s1.android.ptr.demo.MainActivity"
2727
android:theme="@style/Theme.DesignDemo">
2828
<meta-data

ptr-demo/src/main/java/wtf/s1/android/ptr/demo/InstagramView.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ class InstagramView @JvmOverloads constructor(
3333
addView(
3434
NSPtrEZLayout(context).apply {
3535
addView(
36-
SimpleTextListView(context).apply {
37-
count = 100
38-
},
36+
SimpleTextListView(context),
3937
NSPtrLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
4038
)
4139

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package wtf.s1.android.ptr.demo
2+
3+
import wtf.s1.android.ptr_support_design.R
4+
import java.util.*
5+
6+
data class Post(
7+
val name: Int,
8+
val text: Int,
9+
val avatar: Int,
10+
val pic: Int? = 0
11+
)
12+
13+
val Undying = Post(R.string.undying, R.string.undying_line, R.drawable.undying)
14+
val BeastMaster = Post(R.string.bm, R.string.bm_line, R.drawable.beastmaster)
15+
val Clinkz = Post(R.string.clinkz, R.string.clinkz_line, R.drawable.clinkz)
16+
val Haskar = Post(R.string.huskar, R.string.huskar_line, R.drawable.huskar)
17+
val BatRider = Post(R.string.batrider, R.string.batrider_line, R.drawable.batrider)
18+
val BrewMaster = Post(R.string.brewmaster, R.string.brewmaster_line, R.drawable.brewmaster)
19+
val NeverMore = Post(R.string.nevermore, R.string.nevermore_line, R.drawable.nevermore)
20+
val Antimage = Post(R.string.am, R.string.am_line, R.drawable.antimage)
21+
val Mirana = Post(R.string.mirana, R.string.mirana_line, R.drawable.mirana)
22+
val Rubick = Post(R.string.rubick, R.string.rubick_line, R.drawable.rubick)
23+
val Invoker = Post(R.string.invoker, R.string.invoker_line, R.drawable.invoker)
24+
val Grimstroke = Post(R.string.grimstroke, R.string.grimstroke_line, R.drawable.grimstroke)
25+
val NA = Post(R.string.na, R.string.na_line, R.drawable.nyx_assassin)
26+
val FV = Post(R.string.fv, R.string.fv_line, R.drawable.faceless_void)
27+
val Zeus = Post(R.string.zeus, R.string.zeus_line, R.drawable.zuus)
28+
val Sladar = Post(R.string.slardar, R.string.slardar_line, R.drawable.slardar)
29+
val TW = Post(R.string.tw, R.string.tw_line, R.drawable.troll_warlord)
30+
val NightStalker = Post(R.string.ns, R.string.ns_line, R.drawable.night_stalker)
31+
val ElderTitan = Post(R.string.eldertitan, R.string.eldertitan_line, R.drawable.elder_titan)
32+
val ChaosKnight = Post(R.string.ck, R.string.ck_line, R.drawable.chaos_knight)
33+
val BountyHunter = Post(R.string.bh, R.string.bh_line, R.drawable.bounty_hunter)
34+
val PL = Post(R.string.pl, R.string.pl_line, R.drawable.phantom_lancer)
35+
val Pudge = Post(R.string.pudge, 0, R.drawable.pudge)
36+
37+
val DotaList = arrayListOf(
38+
Undying,
39+
Clinkz,
40+
ElderTitan,
41+
NightStalker,
42+
NA,
43+
FV,
44+
BatRider,
45+
BrewMaster,
46+
Antimage,
47+
PL,
48+
BountyHunter,
49+
Mirana,
50+
Rubick,
51+
Invoker,
52+
ChaosKnight,
53+
Grimstroke,
54+
Haskar,
55+
BeastMaster,
56+
Zeus,
57+
Sladar,
58+
TW,
59+
NeverMore,
60+
)
61+
62+
private val RANDOM = Random()
63+
64+
val RandomDrawable: Int
65+
get() {
66+
return when (RANDOM.nextInt(5)) {
67+
0 -> R.drawable.wp1
68+
1 -> R.drawable.wp2
69+
2 -> R.drawable.wp3
70+
3 -> R.drawable.wp4
71+
4 -> R.drawable.wp5
72+
else -> R.drawable.wp1
73+
}
74+
}
75+
76+
77+
78+
79+
80+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package wtf.s1.android.ptr.demo
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.util.AttributeSet
6+
import android.view.ViewGroup
7+
import android.widget.FrameLayout
8+
import android.widget.ImageView
9+
import android.widget.TextView
10+
import androidx.recyclerview.widget.RecyclerView
11+
import com.bumptech.glide.Glide
12+
import com.drakeet.multitype.ViewDelegate
13+
import wtf.s1.android.ptr.demo.md.TiDetailActivity
14+
import wtf.s1.android.ptr_support_design.R
15+
16+
class SimpleItemView @JvmOverloads constructor(
17+
context: Context, attrs: AttributeSet? = null
18+
) : FrameLayout(context, attrs) {
19+
20+
private val mImageView: ImageView by lazy { findViewById(R.id.avatar) }
21+
private val mTextView: TextView by lazy { findViewById(android.R.id.text1) }
22+
23+
init {
24+
inflate(context, R.layout.list_item, this)
25+
setOnClickListener { v ->
26+
val context = v.context
27+
val intent = Intent(context, TiDetailActivity::class.java)
28+
29+
context.startActivity(intent)
30+
}
31+
}
32+
33+
fun bind(post: Post) {
34+
mTextView.text = resources.getString(post.name)
35+
Glide.with(context)
36+
.load(post.avatar)
37+
.fitCenter()
38+
.into(mImageView)
39+
}
40+
}
41+
42+
class SimpleItemDelegate : ViewDelegate<Post, SimpleItemView>() {
43+
override fun onBindView(view: SimpleItemView, item: Post) {
44+
view.bind(item)
45+
}
46+
47+
override fun onCreateView(context: Context): SimpleItemView {
48+
return SimpleItemView(context).apply {
49+
layoutParams = RecyclerView.LayoutParams(
50+
ViewGroup.LayoutParams.MATCH_PARENT,
51+
ViewGroup.LayoutParams.WRAP_CONTENT
52+
)
53+
}
54+
}
55+
56+
}

ptr-demo/src/main/java/wtf/s1/android/ptr/demo/SimpleTextListView.kt

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
package wtf.s1.android.ptr.demo
22

33
import android.content.Context
4-
import android.graphics.Color
54
import android.util.AttributeSet
6-
import android.view.Gravity
7-
import android.view.View
8-
import android.view.ViewGroup
9-
import android.widget.TextView
105
import androidx.core.view.NestedScrollingChild3
116
import androidx.recyclerview.widget.LinearLayoutManager
127
import androidx.recyclerview.widget.RecyclerView
13-
import wtf.s1.android.ptr.demo.md.Cheeses
14-
import wtf.s1.android.ptr.demo.md.SimpleStringRecyclerViewAdapter
8+
import com.drakeet.multitype.MultiTypeAdapter
159
import wtf.s1.pudge.hugo2.DebugLog
16-
import java.util.*
1710

1811
@DebugLog
1912
class SimpleTextListView @JvmOverloads constructor(
@@ -22,39 +15,20 @@ class SimpleTextListView @JvmOverloads constructor(
2215
RecyclerView(context, attrs, defStyleAttr),
2316
NestedScrollingChild3
2417
{
25-
26-
companion object {
27-
private fun getRandomSublist(array: Array<String>, amount: Int): List<String> {
28-
val list = ArrayList<String>(amount)
29-
val random = Random()
30-
while (list.size < amount) {
31-
list.add(array[random.nextInt(array.size)])
32-
}
33-
return list
34-
}
35-
36-
fun getRandomSubList(count: Int): List<String> {
37-
return getRandomSublist(Cheeses.sCheeseStrings, count)
38-
}
39-
}
40-
4118
init {
4219
overScrollMode = OVER_SCROLL_NEVER
4320
}
4421

45-
var count: Int = 100
46-
set(value) {
47-
field = value
48-
currentAdapter?.bind(getRandomSubList(count))
49-
}
50-
5122

52-
var currentAdapter: SimpleStringRecyclerViewAdapter? = null
23+
var currentAdapter: MultiTypeAdapter? = null
5324

5425
init {
5526
layoutManager = LinearLayoutManager(context)
5627

57-
currentAdapter = SimpleStringRecyclerViewAdapter(context, arrayListOf())
28+
currentAdapter = MultiTypeAdapter(arrayListOf<Post>()).apply {
29+
register(SimpleItemDelegate())
30+
items = DotaList
31+
}
5832
adapter = currentAdapter
5933
}
6034

ptr-demo/src/main/java/wtf/s1/android/ptr/demo/WeChatMainView.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package wtf.s1.android.ptr.demo
33
import android.content.Context
44
import android.graphics.Color
55
import android.util.AttributeSet
6+
import android.util.TypedValue
67
import android.view.Gravity
78
import android.widget.FrameLayout
89
import android.widget.LinearLayout
@@ -11,6 +12,7 @@ import androidx.core.view.updatePadding
1112
import wtf.s1.android.ptr.NSPtrConfig
1213
import wtf.s1.android.ptr.NSPtrLayout
1314
import wtf.s1.android.ptr.demo.util.dp
15+
import wtf.s1.android.ptr_support_design.R
1416

1517
class WeChatMainView @JvmOverloads constructor(
1618
context: Context, attrs: AttributeSet? = null
@@ -26,9 +28,9 @@ class WeChatMainView @JvmOverloads constructor(
2628
addView(
2729
TextView(context).apply {
2830
setTextColor(Color.BLACK)
29-
text = "WeChat"
31+
text = context.getString(R.string.wechat)
32+
setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f)
3033
updatePadding(left = 12.dp)
31-
textSize = 12.dp.toFloat()
3234
gravity = Gravity.CENTER
3335
},
3436
LinearLayout.LayoutParams(
@@ -37,9 +39,7 @@ class WeChatMainView @JvmOverloads constructor(
3739
)
3840
)
3941
addView(
40-
SimpleTextListView(context).apply {
41-
count = 100
42-
},
42+
SimpleTextListView(context),
4343
LinearLayout.LayoutParams(
4444
LayoutParams.MATCH_PARENT,
4545
LayoutParams.MATCH_PARENT
@@ -55,11 +55,11 @@ class WeChatMainView @JvmOverloads constructor(
5555
return this@apply
5656
}
5757

58-
override fun refreshPosition(): Int {
58+
override fun contentRefreshPosition(): Int {
5959
return requireLayout().height - 80.dp
6060
}
6161

62-
override fun overToRefreshPosition(): Boolean {
62+
override fun isContentOverRefreshPosition(): Boolean {
6363
return requireLayout().contentTopPosition > 20.dp
6464
}
6565

0 commit comments

Comments
 (0)