Skip to content

Commit 8380496

Browse files
committed
feat: add library
1 parent 59041b2 commit 8380496

25 files changed

+1746
-4
lines changed

app/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ android {
2222

2323
dependencies {
2424
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
25-
implementation 'com.android.support:appcompat-v7:28.0.0'
25+
implementation 'androidx.appcompat:appcompat:1.0.2'
26+
implementation 'androidx.core:core-ktx:1.0.2'
27+
implementation 'com.google.android.material:material:1.0.0'
28+
implementation project(':library')
2629
}

app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="io.iftech.android.slidelayout">
2+
xmlns:tools="http://schemas.android.com/tools" package="io.iftech.android.slidelayout">
33

44
<application android:allowBackup="true"
55
android:label="@string/app_name"
66
android:icon="@mipmap/ic_launcher"
77
android:roundIcon="@mipmap/ic_launcher_round"
88
android:supportsRtl="true"
9-
android:theme="@style/AppTheme"/>
9+
android:theme="@style/Theme.AppCompat.Light.NoActionBar" tools:ignore="GoogleAppIndexingWarning">
10+
<activity android:name=".DebugSlideActivity">
11+
<intent-filter>
12+
<action android:name="android.intent.action.MAIN"/>
13+
<action android:name="android.intent.action.VIEW"/>
14+
<category android:name="android.intent.category.LAUNCHER"/>
15+
</intent-filter>
16+
</activity>
17+
</application>
1018
</manifest>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package io.iftech.android.slidelayout
2+
3+
import android.annotation.SuppressLint
4+
import android.graphics.Color
5+
import android.os.Bundle
6+
import android.view.LayoutInflater
7+
import android.view.View
8+
import android.view.ViewGroup
9+
import androidx.appcompat.app.AppCompatActivity
10+
import androidx.recyclerview.widget.LinearLayoutManager
11+
import androidx.recyclerview.widget.RecyclerView
12+
import io.iftech.android.library.dip
13+
import io.iftech.android.library.slide.configSlideChildTypeHeader
14+
import io.iftech.android.library.slide.configSlideChildTypeSlider
15+
import kotlinx.android.synthetic.main.activity_debug_slide.*
16+
import kotlinx.android.synthetic.main.list_item_debug_slide_slider.view.*
17+
18+
class DebugSlideActivity : AppCompatActivity() {
19+
override fun onCreate(savedInstanceState: Bundle?) {
20+
super.onCreate(savedInstanceState)
21+
setContentView(R.layout.activity_debug_slide)
22+
setupHeader()
23+
fillSlider()
24+
layHeader.minimumHeight = dip(55)
25+
laySlider.setMinVerticalMargin(layHeader.minimumHeight)
26+
laySlide.setOffset(layHeader.minimumHeight)
27+
layRefresh.refreshInterface = MyRefreshViewImpl(this)
28+
}
29+
30+
private fun setupHeader() {
31+
nestedScrollView.configSlideChildTypeHeader()
32+
}
33+
34+
private fun fillSlider() {
35+
val adapter = object : RecyclerView.Adapter<VH>() {
36+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
37+
val v = LayoutInflater.from(parent.context).inflate(R.layout.list_item_debug_slide_slider, parent, false)
38+
return VH(v)
39+
}
40+
41+
override fun getItemCount() = 20
42+
43+
override fun onBindViewHolder(holder: VH, position: Int) {
44+
holder.bindView(position)
45+
}
46+
}
47+
recyclerView.apply {
48+
layoutManager = LinearLayoutManager(this@DebugSlideActivity)
49+
this.adapter = adapter
50+
configSlideChildTypeSlider()
51+
setBackgroundColor(Color.WHITE)
52+
}
53+
}
54+
55+
class VH(view: View) : RecyclerView.ViewHolder(view) {
56+
@SuppressLint("SetTextI18n")
57+
fun bindView(pos: Int) {
58+
(itemView.layoutParams as? ViewGroup.MarginLayoutParams)?.topMargin =
59+
if (pos == 0) 0 else itemView.context.dip(10)
60+
itemView.tvTitle.text = "This is ${pos + 1} title."
61+
}
62+
}
63+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.iftech.android.slidelayout
2+
3+
import android.annotation.SuppressLint
4+
import android.content.Context
5+
import android.view.Gravity
6+
import android.view.View
7+
import android.widget.TextView
8+
import io.iftech.android.library.refresh.RefreshView
9+
10+
class MyRefreshViewImpl(context: Context) : RefreshView {
11+
12+
private val internalView = TextView(context).apply {
13+
gravity = Gravity.CENTER
14+
text = "下拉刷新"
15+
}
16+
private var visibleHeight = 0
17+
private var isLoading = false
18+
set(value) {
19+
field = value
20+
internalView.text = if (value) "正在加载..." else "下拉刷新"
21+
}
22+
private var isRestore = false
23+
24+
override val view: View
25+
get() = internalView
26+
27+
override fun canDrag(): Boolean {
28+
return isLoading.not() && isRestore.not()
29+
}
30+
31+
override fun canRefresh(): Boolean {
32+
return visibleHeight > REFRESH_HEIGHT
33+
}
34+
35+
override fun isLoading(): Boolean {
36+
return isLoading
37+
}
38+
39+
override fun isRestore(): Boolean {
40+
return isRestore
41+
}
42+
43+
@SuppressLint("SetTextI18n")
44+
override fun updateDragging(fraction: Float) {
45+
}
46+
47+
override fun startLoading() {
48+
isLoading = true
49+
}
50+
51+
override fun restore() {
52+
if (isLoading) {
53+
isLoading = false
54+
isRestore = true
55+
}
56+
}
57+
58+
override fun reset() {
59+
isLoading = false
60+
isRestore = false
61+
}
62+
63+
override fun updateVisibleHeight(height: Int) {
64+
visibleHeight = height
65+
if (isLoading.not()) {
66+
internalView.text = if (canRefresh()) "松手加载" else "下拉加载"
67+
}
68+
}
69+
70+
companion object {
71+
const val REFRESH_HEIGHT = 300
72+
}
73+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<io.iftech.android.library.slide.SlideLayout
8+
android:id="@+id/laySlide"
9+
android:layout_width="match_parent"
10+
android:layout_height="match_parent"
11+
android:background="#eeeeee"
12+
app:widget_disable_slider_refresh="true">
13+
14+
<io.iftech.android.library.slide.MinVerticalMarginFrameLayout
15+
android:id="@+id/layHeader"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
app:widget_min_vertical_margin="70dp">
19+
20+
<androidx.core.widget.NestedScrollView
21+
android:id="@+id/nestedScrollView"
22+
android:layout_width="match_parent"
23+
android:layout_height="wrap_content">
24+
25+
<include layout="@layout/layout_debug_slide_header" />
26+
</androidx.core.widget.NestedScrollView>
27+
</io.iftech.android.library.slide.MinVerticalMarginFrameLayout>
28+
29+
<io.iftech.android.library.slide.MinVerticalMarginFrameLayout
30+
android:id="@+id/laySlider"
31+
android:layout_width="match_parent"
32+
android:layout_height="match_parent">
33+
34+
<LinearLayout
35+
android:layout_width="match_parent"
36+
android:layout_height="match_parent"
37+
android:orientation="vertical">
38+
39+
<io.iftech.android.library.slide.SlideBarLayout
40+
android:id="@+id/laySlideBar"
41+
android:layout_width="match_parent"
42+
android:layout_height="wrap_content"
43+
android:background="#ffffff"
44+
android:minHeight="44dp">
45+
46+
<TextView
47+
android:layout_width="wrap_content"
48+
android:layout_height="wrap_content"
49+
android:layout_gravity="center"
50+
android:text="scroll bar" />
51+
</io.iftech.android.library.slide.SlideBarLayout>
52+
53+
<androidx.recyclerview.widget.RecyclerView
54+
android:id="@+id/recyclerView"
55+
android:layout_width="match_parent"
56+
android:layout_height="match_parent" />
57+
</LinearLayout>
58+
</io.iftech.android.library.slide.MinVerticalMarginFrameLayout>
59+
60+
<io.iftech.android.library.refresh.RefreshViewLayout
61+
android:id="@+id/layRefresh"
62+
android:layout_width="match_parent"
63+
android:layout_height="wrap_content" />
64+
</io.iftech.android.library.slide.SlideLayout>
65+
66+
<androidx.appcompat.widget.Toolbar
67+
android:id="@+id/toolbar"
68+
android:layout_width="match_parent"
69+
android:layout_height="55dp"
70+
android:background="#000000"
71+
app:title="debug slide"
72+
app:titleTextColor="#ffffff" />
73+
</FrameLayout>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical"
6+
android:paddingBottom="15dp"
7+
android:paddingEnd="15dp"
8+
android:paddingStart="15dp"
9+
android:paddingTop="70dp">
10+
11+
<ImageView
12+
android:layout_width="300dp"
13+
android:layout_height="150dp"
14+
android:src="#e4583e" />
15+
16+
<TextView
17+
android:layout_width="wrap_content"
18+
android:layout_height="wrap_content"
19+
android:layout_marginTop="20dp"
20+
android:text="@string/debug_slide_header_title"
21+
android:textSize="18sp" />
22+
23+
<TextView
24+
android:layout_width="wrap_content"
25+
android:layout_height="wrap_content"
26+
android:layout_marginTop="20dp"
27+
android:lineSpacingExtra="5sp"
28+
android:text="@string/debug_slide_header_description"
29+
android:textSize="16sp" />
30+
31+
<ImageView
32+
android:layout_width="300dp"
33+
android:layout_height="150dp"
34+
android:layout_marginTop="20dp"
35+
android:src="#03a9f4" />
36+
37+
<TextView
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_marginTop="20dp"
41+
android:lineSpacingExtra="5sp"
42+
android:text="@string/debug_slide_header_description"
43+
android:textSize="16sp" />
44+
45+
</LinearLayout>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:background="#f0f3f5"
7+
android:orientation="vertical"
8+
android:padding="15dp">
9+
10+
<ImageView
11+
android:layout_width="100dp"
12+
android:layout_height="100dp"
13+
android:src="#FFE411" />
14+
15+
<TextView
16+
android:id="@+id/tvTitle"
17+
android:layout_width="wrap_content"
18+
android:layout_height="wrap_content"
19+
android:layout_marginTop="10dp"
20+
tools:text="This is a title." />
21+
22+
</LinearLayout>

app/src/main/res/values/strings.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
<resources>
22
<string name="app_name">SlideLayout</string>
3+
<string name="debug_slide_header_title">NestedScrolling</string>
4+
<string name="debug_slide_header_description">
5+
This interface should be implemented by View subclasses that wish to support dispatching nested scrolling operations to a cooperating parent ViewGroup.\n
6+
Classes implementing this interface should create a final instance of a NestedScrollingChildHelper as a field and delegate any View methods to the NestedScrollingChildHelper methods of the same signature.
7+
Views invoking nested scrolling functionality should always do so from the relevant ViewCompat, ViewGroupCompat or ViewParentCompat compatibility shim static methods. This ensures interoperability with nested scrolling views on Android 5.0 Lollipop and newer.
8+
Dispatch a fling to a nested scrolling parent.
9+
This method should be used to indicate that a nested scrolling child has detected suitable conditions for a fling. Generally this means that a touch scroll has ended with a velocity in the direction of scrolling that meets or exceeds the minimum fling velocity along a scrollable axis.
10+
If a nested scrolling child view would normally fling but it is at the edge of its own content, it can use this method to delegate the fling to its nested scrolling parent instead. The parent may optionally consume the fling or observe a child fling.
11+
</string>
312
</resources>

library/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

library/build.gradle

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
5+
android {
6+
compileSdkVersion 28
7+
buildToolsVersion "29.0.0"
8+
9+
10+
defaultConfig {
11+
minSdkVersion 21
12+
targetSdkVersion 28
13+
versionCode 1
14+
versionName "1.0"
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
}
24+
25+
dependencies {
26+
implementation 'androidx.appcompat:appcompat:1.0.2'
27+
implementation 'androidx.core:core-ktx:1.0.2'
28+
}

0 commit comments

Comments
 (0)