diff options
-rw-r--r-- | .idea/codeStyles/Project.xml | 127 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt | 17 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt | 9 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt | 5 | ||||
-rw-r--r-- | docs/Migration.md | 7 | ||||
-rw-r--r-- | sample/src/main/res/xml/kau_changelog.xml | 3 |
7 files changed, 160 insertions, 10 deletions
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..3962e1c --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,127 @@ +<component name="ProjectCodeStyleConfiguration"> + <code_scheme name="Project" version="173"> + <JetCodeStyleSettings> + <option name="PACKAGES_TO_USE_STAR_IMPORTS"> + <value> + <package name="kotlinx.android.synthetic" withSubpackages="true" static="false" /> + </value> + </option> + <option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" /> + <option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" /> + <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> + </JetCodeStyleSettings> + <codeStyleSettings language="XML"> + <indentOptions> + <option name="CONTINUATION_INDENT_SIZE" value="4" /> + </indentOptions> + <arrangement> + <rules> + <section> + <rule> + <match> + <AND> + <NAME>xmlns:android</NAME> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>xmlns:.*</NAME> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + <order>BY_NAME</order> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*:id</NAME> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*:name</NAME> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>name</NAME> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>style</NAME> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*</NAME> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + <order>BY_NAME</order> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*</NAME> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + <order>ANDROID_ATTRIBUTE_ORDER</order> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*</NAME> + <XML_NAMESPACE>.*</XML_NAMESPACE> + </AND> + </match> + <order>BY_NAME</order> + </rule> + </section> + </rules> + </arrangement> + </codeStyleSettings> + <codeStyleSettings language="kotlin"> + <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> + <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" /> + <option name="KEEP_BLANK_LINES_IN_CODE" value="1" /> + <option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" /> + <option name="ALIGN_MULTILINE_PARAMETERS" value="false" /> + <indentOptions> + <option name="CONTINUATION_INDENT_SIZE" value="4" /> + </indentOptions> + </codeStyleSettings> + </code_scheme> +</component>
\ No newline at end of file @@ -48,7 +48,9 @@ dependencies { implementation "ca.allanwang.kau:core-ui:$KAU" implementation "ca.allanwang.kau:about:$KAU" + implementation "ca.allanwang.kau:adapter:$KAU" implementation "ca.allanwang.kau:colorpicker:$KAU" + implementation "ca.allanwang.kau:fastadapter:$KAU" implementation "ca.allanwang.kau:kpref-activity:$KAU" implementation "ca.allanwang.kau:mediapicker:$KAU" implementation "ca.allanwang.kau:searchview:$KAU" diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt index 0cb6935..a8c71a4 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt @@ -34,8 +34,12 @@ internal object SwipeBackHelper { private operator fun get(activity: Activity): SwipeBackPage? = pageStack.firstOrNull { it.activityRef.get() === activity } - fun onCreate(activity: Activity, builder: SwipeBackContract.() -> Unit = {}) { - val page = this[activity] ?: pageStack.push(SwipeBackPage(activity).apply { builder() }) + fun onCreate( + activity: Activity, + builder: SwipeBackContract.() -> Unit = {} + ): SwipeBackContract { + val swipeBackPage = SwipeBackPage(activity).apply(builder) + val page = this[activity] ?: pageStack.push(swipeBackPage) val startAnimation: Int = when (page.edgeFlag) { SWIPE_EDGE_LEFT -> R.anim.kau_slide_in_right SWIPE_EDGE_RIGHT -> R.anim.kau_slide_in_left @@ -45,6 +49,7 @@ internal object SwipeBackHelper { activity.overridePendingTransition(startAnimation, 0) page.onPostCreate() KL.v { "KauSwipe onCreate ${activity.localClassName}" } + return swipeBackPage } fun onDestroy(activity: Activity) { @@ -73,13 +78,17 @@ internal object SwipeBackHelper { * * Lastly, don't forget to call [kauSwipeOnDestroy] as well when the activity is destroyed. */ -fun Activity.kauSwipeOnCreate(builder: SwipeBackContract.() -> Unit = {}) = SwipeBackHelper.onCreate(this, builder) +fun Activity.kauSwipeOnCreate(builder: SwipeBackContract.() -> Unit = {}): SwipeBackContract = + SwipeBackHelper.onCreate(this, builder) /** * Deprecated as onPostCreate seems unreliable. * We will instead initialize everything during [kauSwipeOnCreate] */ -@Deprecated(level = DeprecationLevel.WARNING, message = "All functionality has been moved to kauSwipeOnCreate") +@Deprecated( + level = DeprecationLevel.WARNING, + message = "All functionality has been moved to kauSwipeOnCreate" +) fun Activity.kauSwipeOnPostCreate() { } diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt index 921cd1f..5f462b4 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt @@ -169,8 +169,6 @@ internal class SwipeBackLayout @JvmOverloads constructor( val minVel = MIN_FLING_VELOCITY * density // allow touch from anywhere on the screen edgeSize = Math.max(resources.displayMetrics.widthPixels, resources.displayMetrics.heightPixels) - minVelocity = minVel -// maxVelocity = 2.5f * minVel edgeFlag = edgeFlag sensitivity = 0.3f addListener(chromeFadeListener) @@ -244,19 +242,18 @@ internal class SwipeBackLayout @JvmOverloads constructor( } override fun onInterceptTouchEvent(event: MotionEvent): Boolean { - if (!swipeEnabled || disallowIntercept) { - return false - } + if (!swipeEnabled || disallowIntercept) return false return try { dragHelper.shouldInterceptTouchEvent(event) } catch (e: Exception) { false + } } @SuppressLint("ClickableViewAccessibility") override fun onTouchEvent(event: MotionEvent): Boolean { - if (!swipeEnabled) return false + if (!swipeEnabled || disallowIntercept) return false try { dragHelper.processTouchEvent(event) } catch (e: Exception) { diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt index bc5b459..c85625a 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt @@ -75,6 +75,7 @@ internal interface SwipeBackContractInternal : SwipeBackContract { interface SwipeBackContract { /** * Toggle main touch intercept + * Disabling will remove the swipe back handler */ var swipeEnabled: Boolean /** @@ -91,6 +92,10 @@ interface SwipeBackContract { * Set the scrolling threshold for wish a page is deemed closing */ var scrollThreshold: Float + /** + * Toggle main touch intercept + * Disabling will just ignore touch events, but the handler will remain attached + */ var disallowIntercept: Boolean /** * Set the min velocity of the view drag helper diff --git a/docs/Migration.md b/docs/Migration.md index a7162fa..fb29f7b 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -2,6 +2,13 @@ Below are some highlights on major refactoring/breaking changes +# v5.1.0 + +## KPref + +You'll notice some errors with kpref imports. You can simply remove (optimize) them. +Extension functions were converted to interfaces to allow for mocking, so imports are no longer necessary. + # v5.0.0 ## Material Dialog Update diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index 5fee3cb..7baecd8 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -15,6 +15,9 @@ <item text=":adapter: Make NoAnimatorChange an object; previously a class" /> <item text=":core: KPref now supports in memory only variants for testing; pass KPrefBuilderInMemory to KPref constructor" /> <item text=":core: KPref initializer takes in SharedPreferences so user can configure it" /> + <item text="" /> + <item text="" /> + <item text="" /> <version title="v5.0.0" /> <item text="Update Android SDK to 29 and Kotlin to 1.3.31" /> |