Skip to content

Commit

Permalink
- Hide last before dismissing overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandrpriadko committed Aug 3, 2020
1 parent 4e5c9d6 commit 3e4f487
Showing 1 changed file with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import com.android.oleksandrpriadko.overlay.HideMethod.BACK_PRESSED
import com.android.oleksandrpriadko.overlay.HideMethod.CLICK_ON_BACKGROUND
import com.android.oleksandrpriadko.overlay.HideMethod.DEFAULT
import com.android.oleksandrpriadko.overlay.HideMethod.HIDE_ALL
import com.android.oleksandrpriadko.overlay.OverlayState.*
import com.android.oleksandrpriadko.overlay.OverlayState.DISMISSED
import com.android.oleksandrpriadko.overlay.OverlayState.DISMISSED_BACKGROUND_CLICK
import com.android.oleksandrpriadko.overlay.OverlayState.DISMISS_IN_PROGRESS
import com.android.oleksandrpriadko.overlay.OverlayState.DISMISS_IN_PROGRESS_BACKGROUND_CLICK
import com.android.oleksandrpriadko.overlay.OverlayState.DISPLAYING
import com.android.oleksandrpriadko.overlay.OverlayState.DISPLAY_IN_PROGRESS
import com.android.oleksandrpriadko.overlay.OverlayState.IDLE

open class OverlayManager(containerViewGroup: ViewGroup) {

Expand Down Expand Up @@ -70,8 +76,8 @@ open class OverlayManager(containerViewGroup: ViewGroup) {
}
}

override fun onDismiss(overlay: Overlay, hideMethod: HideMethod)
= toDismiss(overlay, hideMethod)
override fun onDismiss(overlay: Overlay,
hideMethod: HideMethod) = toDismiss(overlay, hideMethod)

override fun onBackgroundClicked(overlay: Overlay) {
log(message = "onBackgroundClicked:${getTagOf(overlay)}")
Expand Down Expand Up @@ -142,13 +148,14 @@ open class OverlayManager(containerViewGroup: ViewGroup) {
if (areAllHidden()) false
else overlayList[overlayList.size - 1].rootViewGroup === rootViewGroupInOverlay

fun getTopView() : View? {
fun getTopView(): View? {
return if (areAllHidden()) {
null
} else {
overlayList[overlayList.size - 1].rootViewGroup
}
}

/**
* Check validity of [Overlay] and [.attach] if valid
*/
Expand All @@ -171,11 +178,9 @@ open class OverlayManager(containerViewGroup: ViewGroup) {
}
}

private fun isStateValidToCommit(overlayHolder: Overlay): Boolean
= overlayHolder.isReadyToDisplay()
private fun isStateValidToCommit(overlayHolder: Overlay): Boolean = overlayHolder.isReadyToDisplay()

private fun hasSameOverlay(overlayHolder: Overlay): Boolean
= overlayList.contains(overlayHolder)
private fun hasSameOverlay(overlayHolder: Overlay): Boolean = overlayList.contains(overlayHolder)

/**
* 1) Shows container of all [Overlay]s if necessary;
Expand Down Expand Up @@ -220,6 +225,27 @@ open class OverlayManager(containerViewGroup: ViewGroup) {
}
}

fun requestHideFirstBeforeDismissing() {
if (isHidingAll) {
log(message = "hideLastOverlay:dismissAll in progress")
return
}

if (overlayList.isEmpty()) {
log(message = "hideLastOverlay: disallowed")
return
}

val firstBeforeDismissing: Overlay? = overlayList.findLast {
it.state == DISPLAYING || it.state == DISPLAY_IN_PROGRESS || it.state == IDLE
}

if (firstBeforeDismissing != null) {
log(message = "hideFirstBeforeDismissing:allowed ${getTagOf(firstBeforeDismissing)}")
overlayRenderer.hide(firstBeforeDismissing, false, DEFAULT)
}
}

/**
* @return true - if queue has [Overlay] after hideLast, false - otherwise
*/
Expand Down Expand Up @@ -309,7 +335,9 @@ open class OverlayManager(containerViewGroup: ViewGroup) {
}

@VisibleForTesting
internal fun dismissFromEndInLoop(size: Int, handlerPopInLoop: Handler, hideMethod: HideMethod) {
internal fun dismissFromEndInLoop(size: Int,
handlerPopInLoop: Handler,
hideMethod: HideMethod) {
var indexOfLastActive = -1

for (i in size - 1 downTo 0) {
Expand Down

0 comments on commit 3e4f487

Please sign in to comment.