Skip to content

Commit

Permalink
Merge pull request #261 from Tapadoo/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
kpmmmurphy committed May 17, 2021
2 parents 17f9f77 + fb1eb1f commit d47a334
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

## 7.2.0 - 14/05/2021
* OnHideAlertListener added to hide() and clearCurrent() methods.

## 7.0.1 - 05/02/2021
* updated navigation_bar height getter.

Expand Down
2 changes: 1 addition & 1 deletion alerter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ apply from: rootProject.file('quality.gradle')

final String GROUP_ID = "com.tapadoo.android"

final String VERSION = "7.1.0"
final String VERSION = "7.2.0"

final String DESCRIPTION = "An Android Alerting Library"
final String GITHUB_URL = "https://github.com/Tapadoo/Alerter"
Expand Down
36 changes: 27 additions & 9 deletions alerter/src/main/java/com/tapadoo/alerter/Alerter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -770,34 +770,51 @@ class Alerter private constructor() {
*
* @param activity The current Activity
* @param dialog The current Dialog
* @param listener OnHideAlertListener to known when Alert is dismissed
*/
@JvmStatic
fun clearCurrent(activity: Activity?, dialog: Dialog?) {
@JvmOverloads
fun clearCurrent(activity: Activity?, dialog: Dialog?, listener: OnHideAlertListener? = null) {
dialog?.let {
it.window?.decorView as? ViewGroup
} ?: kotlin.run {
activity?.window?.decorView as? ViewGroup
}?.also {
removeAlertFromParent(it)
}
removeAlertFromParent(it, listener)
} ?: listener?.onHide()
}

/**
* Cleans up the currently showing alert view, if one is present. Either pass
* the calling Activity, or the calling Dialog
*
* @param activity The current Activity
* @param listener OnHideAlertListener to known when Alert is dismissed
*/
@JvmStatic
@JvmOverloads
fun clearCurrent(activity: Activity?, listener: OnHideAlertListener? = null) {
clearCurrent(activity, null, listener)
}

/**
* Hides the currently showing alert view, if one is present
* @param listener to known when Alert is dismissed
*/
@JvmStatic
fun hide() {
@JvmOverloads
fun hide(listener: OnHideAlertListener? = null) {
decorView?.get()?.let {
removeAlertFromParent(it)
}
removeAlertFromParent(it, listener)
} ?: listener?.onHide()
}

private fun removeAlertFromParent(decorView: ViewGroup) {
private fun removeAlertFromParent(decorView: ViewGroup, listener: OnHideAlertListener?) {
//Find all Alert Views in Parent layout
for (i in 0..decorView.childCount) {
val childView = if (decorView.getChildAt(i) is Alert) decorView.getChildAt(i) as Alert else null
if (childView != null && childView.windowToken != null) {
ViewCompat.animate(childView).alpha(0f).withEndAction(getRemoveViewRunnable(childView))
ViewCompat.animate(childView).alpha(0f).withEndAction(getRemoveViewRunnable(childView, listener))
}
}
}
Expand All @@ -819,11 +836,12 @@ class Alerter private constructor() {
return isShowing
}

private fun getRemoveViewRunnable(childView: Alert?): Runnable {
private fun getRemoveViewRunnable(childView: Alert?, listener: OnHideAlertListener?): Runnable {
return Runnable {
childView?.let {
(childView.parent as? ViewGroup)?.removeView(childView)
}
listener?.onHide()
}
}
}
Expand Down

0 comments on commit d47a334

Please sign in to comment.