diff options
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 |