From 34ac70737b40914502d0bc909d0e6041b69d1acc Mon Sep 17 00:00:00 2001 From: Jassiel Date: Thu, 13 May 2021 17:09:49 -0500 Subject: [PATCH 1/5] Added onHideListener to hide() & clearCurrent() methods --- .../main/java/com/tapadoo/alerter/Alerter.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt b/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt index 59af38e..174ccfd 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt @@ -770,34 +770,38 @@ 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) } } /** * 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) } } - 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)) } } } @@ -819,10 +823,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) + (childView.parent as? ViewGroup)?.removeView(childView).also { + listener?.onHide() + } } } } From 40cb024ded473e1852370c0b1707f22c01dd4e00 Mon Sep 17 00:00:00 2001 From: Jassiel Date: Thu, 13 May 2021 17:28:54 -0500 Subject: [PATCH 2/5] Overwrote the clearCurrent() method to allow passing only the activity and the listener --- .../src/main/java/com/tapadoo/alerter/Alerter.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt b/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt index 174ccfd..1cd89e8 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt @@ -784,6 +784,19 @@ class Alerter private constructor() { } } + /** + * 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 From 3e4b60bff9549fd08b5c4143f9c0745c6000b896 Mon Sep 17 00:00:00 2001 From: Jassiel Date: Fri, 14 May 2021 12:48:18 -0500 Subject: [PATCH 3/5] Call listener?.onHide() when views or dialogs are null --- alerter/src/main/java/com/tapadoo/alerter/Alerter.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt b/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt index 1cd89e8..e76d163 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt @@ -781,7 +781,7 @@ class Alerter private constructor() { activity?.window?.decorView as? ViewGroup }?.also { removeAlertFromParent(it, listener) - } + } ?: listener?.onHide() } /** @@ -806,7 +806,7 @@ class Alerter private constructor() { fun hide(listener: OnHideAlertListener? = null) { decorView?.get()?.let { removeAlertFromParent(it, listener) - } + } ?: listener?.onHide() } private fun removeAlertFromParent(decorView: ViewGroup, listener: OnHideAlertListener?) { @@ -839,10 +839,9 @@ class Alerter private constructor() { private fun getRemoveViewRunnable(childView: Alert?, listener: OnHideAlertListener?): Runnable { return Runnable { childView?.let { - (childView.parent as? ViewGroup)?.removeView(childView).also { - listener?.onHide() - } + (childView.parent as? ViewGroup)?.removeView(childView) } + listener?.onHide() } } } From 45c110b8e94f8b67a8e0fb20216683f5055ab1a5 Mon Sep 17 00:00:00 2001 From: Jassiel Date: Fri, 14 May 2021 12:48:59 -0500 Subject: [PATCH 4/5] CHANGELOG updated with new Release notes 7.2.0 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aed4c81..54812ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. From 006127526fee5d54f17a275741f83af333b89978 Mon Sep 17 00:00:00 2001 From: Jassiel Date: Fri, 14 May 2021 12:49:23 -0500 Subject: [PATCH 5/5] Bump library version to 7.2.0 --- alerter/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alerter/build.gradle b/alerter/build.gradle index 7d02e7f..fc374fb 100644 --- a/alerter/build.gradle +++ b/alerter/build.gradle @@ -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"