Skip to content

Commit 3afee44

Browse files
committed
Merge branch 'master' into androidx_feature
1 parent 72a459c commit 3afee44

8 files changed

Lines changed: 366 additions & 37 deletions

File tree

app/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ android {
2222
dependencies {
2323
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
2424
implementation 'com.android.support:appcompat-v7:28.0.0'
25+
implementation 'com.android.support:recyclerview-v7:28.0.0'
26+
2527
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-23'
2628
implementation 'com.github.bumptech.glide:glide:4.9.0' //not compat androidx yet.
2729

2830
//implementation project(":lib")
29-
implementation 'com.github.YvesCheung:SlidableLayout:1.0.0'
31+
implementation 'com.github.YvesCheung:SlidableLayout:1.1.0'
3032
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
<activity android:name=".DemoForLoopHorizontally" />
2626
<activity android:name=".DemoForAutoSlide" />
2727
<activity android:name=".DemoForDataSetChanged" />
28+
<activity android:name=".DemoForNestedScroll" />
29+
<activity android:name=".DemoForCrossScroll" />
2830
</application>
2931

3032
</manifest>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.yy.mobile.slidablelayout
2+
3+
import android.content.Context
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import com.yy.mobile.widget.SlidableLayout
8+
import com.yy.mobile.widget.SlidableLayout.Companion.HORIZONTAL
9+
import com.yy.mobile.widget.SlideAdapter
10+
import com.yy.mobile.widget.SlideDirection
11+
import com.yy.mobile.widget.SlideViewAdapter
12+
import com.yy.mobile.widget.SlideViewHolder
13+
14+
/**
15+
* @author YvesCheung
16+
* 2020-02-23
17+
*/
18+
class DemoForCrossScroll : BaseDemoActivity() {
19+
20+
override fun createAdapter(data: SimpleQueue<PageInfo>): SlideAdapter<out SlideViewHolder> {
21+
return OuterScrollAdapter(data)
22+
}
23+
24+
private class OuterScrollAdapter(
25+
val data: SimpleQueue<PageInfo>
26+
) : SlideViewAdapter() {
27+
28+
override fun onCreateView(context: Context, parent: ViewGroup, inflater: LayoutInflater): View =
29+
SlidableLayout(context).apply {
30+
orientation = HORIZONTAL
31+
setAdapter(InnerScrollAdapter(data))
32+
}
33+
34+
override fun onBindView(view: View, direction: SlideDirection) {}
35+
36+
override fun canSlideTo(direction: SlideDirection): Boolean = true
37+
}
38+
39+
private class InnerScrollAdapter(data: SimpleQueue<PageInfo>) : DemoForLoop.LoopAdapter(data)
40+
}

app/src/main/java/com/yy/mobile/slidablelayout/DemoForLoop.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open class DemoForLoop : BaseDemoActivity() {
2121
override fun createAdapter(data: SimpleQueue<PageInfo>): SlideAdapter<out SlideViewHolder> =
2222
LoopAdapter(data)
2323

24-
private class LoopAdapter(val data: SimpleQueue<PageInfo>) : SlideViewAdapter() {
24+
open class LoopAdapter(val data: SimpleQueue<PageInfo>) : SlideViewAdapter() {
2525

2626
private var curIdx = 0
2727

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.yy.mobile.slidablelayout
2+
3+
import android.content.Context
4+
import android.graphics.Color
5+
import android.os.Bundle
6+
import android.support.v7.widget.LinearLayoutManager
7+
import android.support.v7.widget.RecyclerView
8+
import android.support.v7.widget.RecyclerView.VERTICAL
9+
import android.view.LayoutInflater
10+
import android.view.View
11+
import android.view.ViewGroup
12+
import android.widget.TextView
13+
import com.yy.mobile.widget.SlideAdapter
14+
import com.yy.mobile.widget.SlideDirection
15+
import com.yy.mobile.widget.SlideViewAdapter
16+
import com.yy.mobile.widget.SlideViewHolder
17+
import kotlinx.android.synthetic.main.activity_demo.*
18+
import java.util.*
19+
20+
/**
21+
* @author YvesCheung
22+
* 2020-02-18
23+
*/
24+
class DemoForNestedScroll : BaseDemoActivity() {
25+
26+
private val orientation = VERTICAL //HORIZONTAL also ok
27+
28+
override fun onCreate(savedInstanceState: Bundle?) {
29+
super.onCreate(savedInstanceState)
30+
slidable_layout.orientation = orientation
31+
}
32+
33+
override fun createAdapter(data: SimpleQueue<PageInfo>): SlideAdapter<out SlideViewHolder> {
34+
return NestedScrollingAdapter(orientation)
35+
}
36+
37+
open class NestedScrollingAdapter(private val orientation: Int) : SlideViewAdapter() {
38+
39+
override fun onCreateView(
40+
context: Context,
41+
parent: ViewGroup,
42+
inflater: LayoutInflater
43+
): View {
44+
val backgroundColor = Random().nextInt() or 0xFF000000.toInt()
45+
return RecyclerView(context).apply {
46+
layoutManager = LinearLayoutManager(context, orientation, false)
47+
adapter = RecyclerViewAdapter()
48+
setBackgroundColor(backgroundColor)
49+
}
50+
}
51+
52+
override fun onBindView(view: View, direction: SlideDirection) {
53+
//Do Nothing.
54+
}
55+
56+
override fun canSlideTo(direction: SlideDirection): Boolean = true
57+
}
58+
59+
private class RecyclerViewAdapter : RecyclerView.Adapter<Holder>() {
60+
61+
override fun onCreateViewHolder(parent: ViewGroup, position: Int): Holder =
62+
Holder(TextView(parent.context))
63+
64+
override fun getItemCount(): Int = 30
65+
66+
override fun onBindViewHolder(viewHolder: Holder, position: Int) {
67+
viewHolder.textView.text = position.toString()
68+
viewHolder.textView.setTextColor(Color.BLACK)
69+
viewHolder.textView.textSize = 25f
70+
viewHolder.textView.setPadding(20, 20, 20, 20)
71+
}
72+
}
73+
74+
private class Holder(val textView: TextView) : RecyclerView.ViewHolder(textView)
75+
}

app/src/main/java/com/yy/mobile/slidablelayout/MainActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,12 @@ class MainActivity : FragmentActivity() {
3535
fun toDemoForDataSetChanged(v: View) {
3636
startActivity(Intent(this, DemoForDataSetChanged::class.java))
3737
}
38+
39+
fun toDemoForNestedScroll(v: View) {
40+
startActivity(Intent(this, DemoForNestedScroll::class.java))
41+
}
42+
43+
fun toDemoForCrossScroll(v: View) {
44+
startActivity(Intent(this, DemoForCrossScroll::class.java))
45+
}
3846
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,28 @@
7676
android:text="Example: NotifyDataSetChanged"
7777
android:textColor="#ffffff"
7878
android:textStyle="bold" />
79+
80+
<TextView
81+
android:layout_width="match_parent"
82+
android:layout_height="wrap_content"
83+
android:layout_margin="10dp"
84+
android:background="@color/colorAccent"
85+
android:gravity="center"
86+
android:onClick="toDemoForNestedScroll"
87+
android:padding="10dp"
88+
android:text="Example: Nested Scrolling"
89+
android:textColor="#ffffff"
90+
android:textStyle="bold" />
91+
92+
<TextView
93+
android:layout_width="match_parent"
94+
android:layout_height="wrap_content"
95+
android:layout_margin="10dp"
96+
android:background="@color/colorAccent"
97+
android:gravity="center"
98+
android:onClick="toDemoForCrossScroll"
99+
android:padding="10dp"
100+
android:text="Example: Cross Scrolling"
101+
android:textColor="#ffffff"
102+
android:textStyle="bold" />
79103
</LinearLayout>

0 commit comments

Comments
 (0)