Skip to content

Commit

Permalink
- Resolve issue #28
Browse files Browse the repository at this point in the history
  • Loading branch information
tingyik90 committed Dec 19, 2019
1 parent 99edfdb commit b4f3f98
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ internal class SnackProgressBarCore private constructor(

}

/**
* Gets the show duration.
*/
internal fun getShowDuration(): Int {
return showDuration
}

/**
* Gets the attached snackProgressBar.
*/
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<View>()
viewsToMove?.forEach {
val view = it.get()
Expand All @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit b4f3f98

Please sign in to comment.