Skip to content

Commit 9d6528d

Browse files
Align with Kotlin 1.4.31 & changes around calculating header top.
1 parent c48f017 commit 9d6528d

8 files changed

Lines changed: 128 additions & 116 deletions

File tree

dependencies.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
ext {
2-
gradlePluginVersion = '7.0.4'
2+
gradlePluginVersion = '3.6.0'
33
projectMinSdkVersion = 16
4-
compileVersionSdk = 30
4+
compileVersionSdk = 29
55
targetSdkVersion = compileVersionSdk
66
projectVersionCode = 1
77
projectVersionName = "0.0.1"
88

9-
kotlinVersion = '1.6.10'
9+
kotlinVersion = '1.4.31'
1010
kotlinSdk = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
1111

1212
androidXCoreVersion = '1.3.2'
@@ -85,4 +85,4 @@ ext {
8585
mockWebServer : "com.squareup.okhttp3:mockwebserver:$mockWebServerVersion",
8686
idlingResource : "com.jakewharton.espresso:okhttp3-idling-resource:$idlingResourceVersion"
8787
]
88-
}
88+
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip

gradlew.bat

Lines changed: 90 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library/publish.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ afterEvaluate {
55
publications {
66
release(MavenPublication) {
77
from components.release
8-
groupId = 'weekend.coder'
9-
artifactId = 'sticky-scrollview'
10-
version = '1.0.4'
8+
groupId = 'com.github.amarjain07'
9+
artifactId = 'StickyScrollView'
10+
version = '1.0.3.1-Kotlin1.4.31'
1111
}
1212
}
1313
}
14-
}
14+
}

library/src/main/java/com/amar/library/ui/StickyScrollView.kt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class StickyScrollView @JvmOverloads constructor(
4747
mStickyScrollPresenter.recomputeFooterLocation(getFooterTop())
4848
}
4949
stickyHeaderView?.let {
50-
mStickyScrollPresenter.recomputeHeaderLocation(it.top)
50+
mStickyScrollPresenter.recomputeHeaderLocation(getRelativeHeaderTop(it))
5151
}
5252
}
5353

@@ -99,32 +99,42 @@ class StickyScrollView @JvmOverloads constructor(
9999
this.scrollViewListener = scrollViewListener
100100
}
101101

102-
private fun initialiseHeader(){
103-
mStickyScrollPresenter.initStickyHeader(stickyHeaderView?.top)
102+
private fun initialiseHeader() {
103+
stickyHeaderView?.let {
104+
mStickyScrollPresenter.initStickyHeader(getRelativeHeaderTop(it))
105+
}
104106
}
105107

106-
private fun initialiseFooter(){
108+
private fun initialiseFooter() {
107109
mStickyScrollPresenter.initStickyFooter(
108110
stickyFooterView?.measuredHeight,
109111
getFooterTop()
110112
)
111113
}
112114

113-
private fun getRelativeTop(myView: View): Int {
115+
private fun getRelativeHeaderTop(myView: View): Int {
116+
return if (myView.parent === this) {
117+
myView.top
118+
} else {
119+
myView.top + getRelativeHeaderTop(myView.parent as View)
120+
}
121+
}
122+
123+
private fun getRelativeFooterTop(myView: View): Int {
114124
return if (myView.parent === myView.rootView) {
115125
myView.top
116126
} else {
117-
myView.top + getRelativeTop(myView.parent as View)
127+
myView.top + getRelativeFooterTop(myView.parent as View)
118128
}
119129
}
120130

121131
private fun getFooterTop(): Int {
122132
return stickyFooterView?.let {
123-
return getRelativeTop(it) - it.topCutOutHeight()
133+
return getRelativeFooterTop(it) - it.topCutOutHeight()
124134
} ?: 0
125135
}
126136

127-
private inner class StickyScrollPresentation: IStickyScrollPresentation {
137+
private inner class StickyScrollPresentation : IStickyScrollPresentation {
128138
override val currentScrollYPos: Int
129139
get() = scrollY
130140

@@ -143,6 +153,7 @@ class StickyScrollView @JvmOverloads constructor(
143153
stickyHeaderView?.let {
144154
it.translationY = translationY.toFloat()
145155
PropertySetter.setTranslationZ(it, 1f)
156+
PropertySetter.setTranslationZ(it.parent as View, 1f)
146157
}
147158
}
148159

@@ -183,4 +194,4 @@ class StickyScrollView @JvmOverloads constructor(
183194
private const val STATE_SUPER = "super_state"
184195
private const val STATE_NAV_BAR_HEIGHT = "nav_bar_height_state"
185196
}
186-
}
197+
}

sample/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ android {
2424
}
2525

2626
compileOptions {
27-
sourceCompatibility = JavaVersion.VERSION_11
28-
targetCompatibility = JavaVersion.VERSION_11
27+
sourceCompatibility = JavaVersion.VERSION_1_8
28+
targetCompatibility = JavaVersion.VERSION_1_8
2929
}
3030
}
3131

@@ -36,4 +36,4 @@ dependencies {
3636
externalLibs.values().forEach { implementation it }
3737
testLibs.values().forEach { testImplementation it }
3838
uiTestLibs.values().forEach { androidTestImplementation it }
39-
}
39+
}

sample/src/main/java/com/amar/sample/MainActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
3131
})
3232
findViewById<View>(R.id.buy).setOnClickListener(this)
3333
findViewById<View>(R.id.save).setOnClickListener(this)
34-
findViewById<View>(R.id.title).setOnClickListener(this)
34+
findViewById<View>(R.id.title_child).setOnClickListener(this)
3535
findViewById<View>(R.id.other_product).setOnClickListener(this)
3636
mainShoeView = findViewById(R.id.main_shoe_picture)
3737
scrollView?.setFooterView(R.id.buttons)
@@ -47,7 +47,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
4747
if (scrollView!!.isFooterSticky) "Footer is Sticky" else "Footer is not sticky",
4848
Toast.LENGTH_SHORT
4949
).show()
50-
R.id.title -> Toast.makeText(
50+
R.id.title_child -> Toast.makeText(
5151
this,
5252
if (scrollView!!.isHeaderSticky) "Header is Sticky" else "Header is not sticky",
5353
Toast.LENGTH_SHORT
@@ -80,4 +80,4 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
8080
r.displayMetrics
8181
)
8282
}
83-
}
83+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
android:id="@+id/scrollView"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
8-
app:stickyHeader="@+id/title"
8+
app:stickyHeader="@+id/title_child"
99
tools:context="com.amar.sample.MainActivity">
1010

1111
<LinearLayout
@@ -34,6 +34,7 @@
3434
android:padding="15dp">
3535

3636
<TextView
37+
android:id="@+id/title_child"
3738
android:layout_width="wrap_content"
3839
android:layout_height="wrap_content"
3940
android:text="@string/product_title"
@@ -181,4 +182,4 @@
181182
android:src="@drawable/similar_2" />
182183
</LinearLayout>
183184
</LinearLayout>
184-
</com.amar.library.ui.StickyScrollView>
185+
</com.amar.library.ui.StickyScrollView>

0 commit comments

Comments
 (0)