From 47935b25760c68dedc6f9afd47e1a2e31b4424e6 Mon Sep 17 00:00:00 2001 From: Gabriel Rohden Date: Mon, 10 Dec 2018 00:29:33 -0200 Subject: [PATCH 1/2] Added remove listeners functions --- .../-wendy-config/index.html | 20 +++++++++++++ .../java/com/levibostian/wendy/WendyConfig.kt | 29 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/docs/wendy/com.levibostian.wendy/-wendy-config/index.html b/docs/wendy/com.levibostian.wendy/-wendy-config/index.html index a433e46..9784c8d 100644 --- a/docs/wendy/com.levibostian.wendy/-wendy-config/index.html +++ b/docs/wendy/com.levibostian.wendy/-wendy-config/index.html @@ -87,6 +87,26 @@

Companion Object Functions

Listen to updates about a specific task and how it is going. Get updated when this specific task gets run by the task runner, then if it fails/succeeds/gets skipped.

+ + +

removeTaskRunnerListener

+ + +fun removeTaskRunnerListener(listener: TaskRunnerListener): Boolean +

Removes a listener instance added one or more times with addTaskRunnerListener +Note: if you added the same instance more than one times, this function will remove all of them

+ + + + +

removeTaskStatusListener

+ + +fun removeTaskStatusListener(listener: PendingTaskStatusListener): Boolean +

Removes a listener instance added one or more times with addTaskStatusListenerForTask +Note: if you added the same instance more than one times, this function will remove all of them

+ + diff --git a/wendy/src/main/java/com/levibostian/wendy/WendyConfig.kt b/wendy/src/main/java/com/levibostian/wendy/WendyConfig.kt index 78176bd..c5377f4 100644 --- a/wendy/src/main/java/com/levibostian/wendy/WendyConfig.kt +++ b/wendy/src/main/java/com/levibostian/wendy/WendyConfig.kt @@ -56,6 +56,21 @@ class WendyConfig { * @see TaskRunnerListener to learn more about what callbacks to expect. */ fun addTaskRunnerListener(listener: TaskRunnerListener) = taskRunnerListeners.add(WeakReference(listener)) + + /** + * Removes a listener instance added one or more times with [addTaskRunnerListener] + * Note: if you added the same instance more than one times, this function will remove all of them + * + * @param listener the listener instance to be removed + * + * @return true if the listener was removed at least once, false if it was collected by the GC + * or you didn't added it before + */ + fun removeTaskRunnerListener(listener: TaskRunnerListener): Boolean { + return taskRunnerListeners + .removeAll { it.get()?.equals(listener) ?: false } + } + internal fun getTaskRunnerListeners(): List { if (Looper.getMainLooper().thread != Thread.currentThread()) throw RuntimeException("You must be on UI thread.") return taskRunnerListeners @@ -90,6 +105,20 @@ class WendyConfig { listener.errorRecorded(taskId, latestError.errorMessage, latestError.errorId) } } + + /** + * Removes a listener instance added one or more times with [addTaskStatusListenerForTask] + * Note: if you added the same instance more than one times, this function will remove all of them + * + * @param listener the listener instance to be removed + * + * @return true if the listener was removed at least once, false if it was collected by the GC + * or you didn't added it before + */ + fun removeTaskStatusListener(listener: PendingTaskStatusListener): Boolean { + return taskStatusListeners + .removeAll { it.listener.get()?.equals(listener) ?: false } + } } internal class TaskStatusListener(val taskId: Long, val listener: WeakReference) From aaddf4bca861dc7cbd275beae368cc446dd5276a Mon Sep 17 00:00:00 2001 From: Gabriel Rohden Date: Mon, 10 Dec 2018 00:36:55 -0200 Subject: [PATCH 2/2] Typo --- wendy/src/main/java/com/levibostian/wendy/WendyConfig.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wendy/src/main/java/com/levibostian/wendy/WendyConfig.kt b/wendy/src/main/java/com/levibostian/wendy/WendyConfig.kt index c5377f4..3cac1d3 100644 --- a/wendy/src/main/java/com/levibostian/wendy/WendyConfig.kt +++ b/wendy/src/main/java/com/levibostian/wendy/WendyConfig.kt @@ -59,7 +59,7 @@ class WendyConfig { /** * Removes a listener instance added one or more times with [addTaskRunnerListener] - * Note: if you added the same instance more than one times, this function will remove all of them + * Note: if you added the same instance more than one time, this function will remove all of them * * @param listener the listener instance to be removed * @@ -108,7 +108,7 @@ class WendyConfig { /** * Removes a listener instance added one or more times with [addTaskStatusListenerForTask] - * Note: if you added the same instance more than one times, this function will remove all of them + * Note: if you added the same instance more than one time, this function will remove all of them * * @param listener the listener instance to be removed *