Skip to content

Commit

Permalink
Align with Kotlin 1.4.31 & changes around calculating header top.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertZagorski committed Feb 18, 2022
1 parent c48f017 commit 9d6528d
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 116 deletions.
8 changes: 4 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ext {
gradlePluginVersion = '7.0.4'
gradlePluginVersion = '3.6.0'
projectMinSdkVersion = 16
compileVersionSdk = 30
compileVersionSdk = 29
targetSdkVersion = compileVersionSdk
projectVersionCode = 1
projectVersionName = "0.0.1"

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

androidXCoreVersion = '1.3.2'
Expand Down Expand Up @@ -85,4 +85,4 @@ ext {
mockWebServer : "com.squareup.okhttp3:mockwebserver:$mockWebServerVersion",
idlingResource : "com.jakewharton.espresso:okhttp3-idling-resource:$idlingResourceVersion"
]
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip
180 changes: 90 additions & 90 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windowz variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windowz variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
8 changes: 4 additions & 4 deletions library/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ afterEvaluate {
publications {
release(MavenPublication) {
from components.release
groupId = 'weekend.coder'
artifactId = 'sticky-scrollview'
version = '1.0.4'
groupId = 'com.github.amarjain07'
artifactId = 'StickyScrollView'
version = '1.0.3.1-Kotlin1.4.31'
}
}
}
}
}
29 changes: 20 additions & 9 deletions library/src/main/java/com/amar/library/ui/StickyScrollView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class StickyScrollView @JvmOverloads constructor(
mStickyScrollPresenter.recomputeFooterLocation(getFooterTop())
}
stickyHeaderView?.let {
mStickyScrollPresenter.recomputeHeaderLocation(it.top)
mStickyScrollPresenter.recomputeHeaderLocation(getRelativeHeaderTop(it))
}
}

Expand Down Expand Up @@ -99,32 +99,42 @@ class StickyScrollView @JvmOverloads constructor(
this.scrollViewListener = scrollViewListener
}

private fun initialiseHeader(){
mStickyScrollPresenter.initStickyHeader(stickyHeaderView?.top)
private fun initialiseHeader() {
stickyHeaderView?.let {
mStickyScrollPresenter.initStickyHeader(getRelativeHeaderTop(it))
}
}

private fun initialiseFooter(){
private fun initialiseFooter() {
mStickyScrollPresenter.initStickyFooter(
stickyFooterView?.measuredHeight,
getFooterTop()
)
}

private fun getRelativeTop(myView: View): Int {
private fun getRelativeHeaderTop(myView: View): Int {
return if (myView.parent === this) {
myView.top
} else {
myView.top + getRelativeHeaderTop(myView.parent as View)
}
}

private fun getRelativeFooterTop(myView: View): Int {
return if (myView.parent === myView.rootView) {
myView.top
} else {
myView.top + getRelativeTop(myView.parent as View)
myView.top + getRelativeFooterTop(myView.parent as View)
}
}

private fun getFooterTop(): Int {
return stickyFooterView?.let {
return getRelativeTop(it) - it.topCutOutHeight()
return getRelativeFooterTop(it) - it.topCutOutHeight()
} ?: 0
}

private inner class StickyScrollPresentation: IStickyScrollPresentation {
private inner class StickyScrollPresentation : IStickyScrollPresentation {
override val currentScrollYPos: Int
get() = scrollY

Expand All @@ -143,6 +153,7 @@ class StickyScrollView @JvmOverloads constructor(
stickyHeaderView?.let {
it.translationY = translationY.toFloat()
PropertySetter.setTranslationZ(it, 1f)
PropertySetter.setTranslationZ(it.parent as View, 1f)
}
}

Expand Down Expand Up @@ -183,4 +194,4 @@ class StickyScrollView @JvmOverloads constructor(
private const val STATE_SUPER = "super_state"
private const val STATE_NAV_BAR_HEIGHT = "nav_bar_height_state"
}
}
}
6 changes: 3 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

Expand All @@ -36,4 +36,4 @@ dependencies {
externalLibs.values().forEach { implementation it }
testLibs.values().forEach { testImplementation it }
uiTestLibs.values().forEach { androidTestImplementation it }
}
}
6 changes: 3 additions & 3 deletions sample/src/main/java/com/amar/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
})
findViewById<View>(R.id.buy).setOnClickListener(this)
findViewById<View>(R.id.save).setOnClickListener(this)
findViewById<View>(R.id.title).setOnClickListener(this)
findViewById<View>(R.id.title_child).setOnClickListener(this)
findViewById<View>(R.id.other_product).setOnClickListener(this)
mainShoeView = findViewById(R.id.main_shoe_picture)
scrollView?.setFooterView(R.id.buttons)
Expand All @@ -47,7 +47,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
if (scrollView!!.isFooterSticky) "Footer is Sticky" else "Footer is not sticky",
Toast.LENGTH_SHORT
).show()
R.id.title -> Toast.makeText(
R.id.title_child -> Toast.makeText(
this,
if (scrollView!!.isHeaderSticky) "Header is Sticky" else "Header is not sticky",
Toast.LENGTH_SHORT
Expand Down Expand Up @@ -80,4 +80,4 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
r.displayMetrics
)
}
}
}
5 changes: 3 additions & 2 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:stickyHeader="@+id/title"
app:stickyHeader="@+id/title_child"
tools:context="com.amar.sample.MainActivity">

<LinearLayout
Expand Down Expand Up @@ -34,6 +34,7 @@
android:padding="15dp">

<TextView
android:id="@+id/title_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/product_title"
Expand Down Expand Up @@ -181,4 +182,4 @@
android:src="@drawable/similar_2" />
</LinearLayout>
</LinearLayout>
</com.amar.library.ui.StickyScrollView>
</com.amar.library.ui.StickyScrollView>

0 comments on commit 9d6528d

Please sign in to comment.