diff options
author | Allan Wang <me@allanwang.ca> | 2017-08-05 14:49:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-05 14:49:47 -0700 |
commit | c707d42b311f96cbabc1971f98598c8b8922ba16 (patch) | |
tree | 3c592c2a8bdd2fb759e3632adf038b5d7cecfabb /core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt | |
parent | bafc1996d803862d30a2c7d0c402d30c79c4f647 (diff) | |
download | kau-c707d42b311f96cbabc1971f98598c8b8922ba16.tar.gz kau-c707d42b311f96cbabc1971f98598c8b8922ba16.tar.bz2 kau-c707d42b311f96cbabc1971f98598c8b8922ba16.zip |
Swipe (#24)
* Test emulator
* Update readme
* Update fastadapter and about listing
* Make faq parser asynchronous
* Modularize about panels
* Add basis for faq
* Test and finalize the faq panel
* Update readme
* Update changelog
* Remove emulator for now
* Update sample
* Change back to manual versioning to avoid suggestion errors
* Add awesome-kt banner
* Fix faq background color
* Fix merge conflicts 2
* Add waffle badge
* Update readme
* Fix lint
* Create FileUtils and NotificationUtils
* Remove frost hardcode
* Fix simple date
* Update swipe to use weak references
* Initializing test dependencies
* Update to gradle 4.1
* Fix lint warnings
* Drop back down and fix errors
* Finalize swipe with example
* Finalize weak reference and ordering
* Update test code
* Make loggers inline
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt | 18 |
1 files changed, 13 insertions, 5 deletions
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 81ddb62..3132f8c 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackPage.kt @@ -4,15 +4,17 @@ import android.app.Activity import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.view.ViewGroup +import ca.allanwang.kau.logging.KL +import java.lang.ref.WeakReference /** * Created by Mr.Jude on 2015/8/3. * * Updated by Allan Wang on 2017/07/05 */ -class SwipeBackPage(activity: Activity) : SwipeBackContract by SwipeBackLayout(activity) { +internal class SwipeBackPage(activity: Activity) : SwipeBackContractInternal by SwipeBackLayout(activity) { - var activity: Activity? = activity + var activityRef = WeakReference(activity) var slider: RelativeSlider /** @@ -38,8 +40,9 @@ class SwipeBackPage(activity: Activity) : SwipeBackContract by SwipeBackLayout(a } private fun handleLayout() { - if (swipeEnabled) swipeBackLayout.attachToActivity(activity!!) - else swipeBackLayout.removeFromActivity(activity!!) + val activity = activityRef.get() ?: return KL.v("KauSwipe activity ref gone during handleLayout") + if (swipeEnabled) swipeBackLayout.attachToActivity(activity) + else swipeBackLayout.removeFromActivity(activity) } fun setClosePercent(percent: Float): SwipeBackPage { @@ -49,6 +52,10 @@ class SwipeBackPage(activity: Activity) : SwipeBackContract by SwipeBackLayout(a } +internal interface SwipeBackContractInternal : SwipeBackContract { + val swipeBackLayout: SwipeBackLayout +} + interface SwipeBackContract { /** * Toggle main touch intercept @@ -59,7 +66,6 @@ interface SwipeBackContract { * This dynamically fades as the page gets closer to exiting */ var scrimColor: Int - val swipeBackLayout: SwipeBackLayout var edgeSize: Int /** * Set the flag for which edge the page is scrolling from @@ -92,7 +98,9 @@ interface SwipeBackContract { * Sets edge size based on screen size */ fun setEdgeSizePercent(swipeEdgePercent: Float) + fun addListener(listener: SwipeListener) fun removeListener(listener: SwipeListener) + fun hasListener(listener: SwipeListener): Boolean fun scrollToFinishActivity() }
\ No newline at end of file |