From b4f3f98d5fa9800e5d8fd79addeba9ca74b1ac55 Mon Sep 17 00:00:00 2001 From: tingyik90 Date: Thu, 19 Dec 2019 17:35:51 +0800 Subject: [PATCH] - Resolve issue #28 --- .../snackprogressbar/SnackProgressBarCore.kt | 9 +++++++++ .../SnackProgressBarManager.kt | 20 +++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/src/main/java/com/tingyik90/snackprogressbar/SnackProgressBarCore.kt b/lib/src/main/java/com/tingyik90/snackprogressbar/SnackProgressBarCore.kt index f4caf93..6370caf 100644 --- a/lib/src/main/java/com/tingyik90/snackprogressbar/SnackProgressBarCore.kt +++ b/lib/src/main/java/com/tingyik90/snackprogressbar/SnackProgressBarCore.kt @@ -88,6 +88,13 @@ internal class SnackProgressBarCore private constructor( } + /** + * Gets the show duration. + */ + internal fun getShowDuration(): Int { + return showDuration + } + /** * Gets the attached snackProgressBar. */ @@ -287,6 +294,8 @@ internal class SnackProgressBarCore private constructor( snackProgressBarLayout.actionNextLineText.text = action.toUpperCase() // Set the onClickListener val onClickListener = View.OnClickListener { + // Remove the dismiss callback to avoid calling it twice + handler.removeCallbacks(runnable) onActionClickListener?.onActionClick() dismiss() } diff --git a/lib/src/main/java/com/tingyik90/snackprogressbar/SnackProgressBarManager.kt b/lib/src/main/java/com/tingyik90/snackprogressbar/SnackProgressBarManager.kt index b2569e1..b662c50 100644 --- a/lib/src/main/java/com/tingyik90/snackprogressbar/SnackProgressBarManager.kt +++ b/lib/src/main/java/com/tingyik90/snackprogressbar/SnackProgressBarManager.kt @@ -538,15 +538,8 @@ class SnackProgressBarManager(providedView: View, lifecycleOwner: LifecycleOwner currentQueue = queue val snackProgressBar = queueBars[queue] val onDisplayId = queueOnDisplayIds[queue] - var duration = queueDurations[queue] - // Change duration to LENGTH_SHORT if is not last item - if (duration == LENGTH_INDEFINITE) { - if (queue < queueBars.size - 1) { - duration = LENGTH_SHORT - } - } + val duration = queueDurations[queue] // Create SnackProgressBarCore - val finalDuration = duration val finalViewsToMove = mutableListOf() viewsToMove?.forEach { val view = it.get() @@ -570,6 +563,11 @@ class SnackProgressBarManager(providedView: View, lifecycleOwner: LifecycleOwner override fun onShown(snackProgressBarCore: SnackProgressBarCore) { // callback onDisplayListener onDisplayListener?.onShown(snackProgressBarCore.getSnackProgressBar(), onDisplayId) + // play next item if this item is going to show indefinitely + // if next item is empty, this will reset queue + if (snackProgressBarCore.getShowDuration() == LENGTH_INDEFINITE) { + nextQueue() + } } override fun onDismissed(snackProgressBarCore: SnackProgressBarCore, event: Int) { @@ -578,15 +576,11 @@ class SnackProgressBarManager(providedView: View, lifecycleOwner: LifecycleOwner // callback onDisplayListener onDisplayListener?.onDismissed(snackProgressBarCore.getSnackProgressBar(), onDisplayId) // play next if this item is dismissed automatically later - if (finalDuration != LENGTH_INDEFINITE) { + if (snackProgressBarCore.getShowDuration() != LENGTH_INDEFINITE) { nextQueue() } } }) - // Reset queue if this is last item in queue with LENGTH_INDEFINITE - if (duration == LENGTH_INDEFINITE) { - resetQueue() - } // Allow users to manipulate the view onDisplayListener?.onLayoutInflated( snackProgressBarCore.snackProgressBarLayout,